Friday, June 14, 2013

Working with WebRadioGroup

QTP WebRadioGroup means a radio button on the web page. Identifying and working with them can be easy or difficult. Sometimes they works out fine and at times executing the same code gives you error. 

If you have two radio buttons on the screen for example Gender selection options the code below might give problem.

Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Male"
Where "Male" can be the id or the value of the radio button (Spy the object). So what is the problem in the code above? As there are two radio buttons QTP identifies them as same, so we need to differentiate between them. Index is a property by which you can differentiate, it tells the position of the object. So if we write the same code below with an additional index property it will work fine.
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender", "index:= 1").Select "Female"
This code is intended to select a radio button among two, what if you have a list of radio buttons let’s say 5-6 or more, than the above code won’t help. For that you need to create description of a radiogroup i.e. we will instruct everything to QTP.

''''''=====Initialize variables
Dim oWebRadio
Dim oWebRadioCount
Dim RadioToSelect_Val 

''''''Create description using Description.Create build-in method
Set oWebRadio = Description.Create
oWebRadio ("micclass").value = "WebRadioGroup"
oWebRadio ("type").value = "radio"
oWebRadio ("name").value="Gender"

''''''Pass the description in another variable using ChildObjects method
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
''''''Loop to select desired value
For i = 0 to oWebRadioCount
RadioToSelect = oWebRadioCount (i).GetROProperty("value")
oWebRadioCount (i).Select RadioToSelect
Next

''''''Pass Child count in a variable
allItems = oChild.Count

''''''Loop & Use items count property to get Total items
For j = 0 to allItems-1
   itemsCount =oChild.Item(j).GetRoProperty("items count")

      If (itemsCount = 5) Then
          Print "Found 5 radio " 
      else
          Print "More than 5 radio listed"
      End If

Next

So there are two ways to deal with descriptive programming, either pass the properties directly or create your descriptions and pass or select your values.


'============= Ways to select value from WebList =======================

Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "#3"
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "2218866589&15-5-2013"


Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "#0"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Female"


'========== To Count Number and Name of WebRadioGrouppresent on a Page Using MicClass ======

'Example: 1  This page has One Radio Group

SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/qtp-web-table_5925.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount

For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next

'Example: 2 This page has Two Radio Groups

SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/student-registration-formhtml.html"

Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount

For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next


'To find Number of Radio Buttons present in particular Group along with its value

With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")

vrAllItem = .GetROProperty("all items")
msgbox vrAllItem

vrArr = Split(vrAllItem, ";", -1, 1)

For i=0 to UBound(vrArr)
          msgbox vrArr(i)
          vrLeftPNR = Left(vrArr(i),10)
          msgbox vrLeftPNR
          If vrPNR = vrLeftPNR Then
                   vrIndex = i
        .Select "#"&vrIndex
                   Exit For
          End If
Next
End With


'=========Select  WebRadio button where PNR# is 5018866589================

vrPNR = "5018866589"
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")

vrAllItem = .GetROProperty("all items")
msgbox vrAllItem

vrArr = Split(vrAllItem, ";", -1, 1)

For i=0 to UBound(vrArr)
          msgbox vrArr(i)
          vrLeftPNR = Left(vrArr(i),10)
          msgbox vrLeftPNR
          If vrPNR = vrLeftPNR Then
                   vrIndex = i
        .Select "#"&vrIndex
                   Exit For
          End If
Next
End With


Saturday, June 8, 2013

Repositories - Dynamic Management

One of the new feature of QTP 9.2 is Dynamic Management of OR.

>>ADD
RepositoriesCollection.Add("D:\google.tsr")
-- it will add the 'test.tsr' file during the run time

>>FIND
Pos = RepositoriesCollection.Find("D:\google.tsr")
-- it will return a numeric value to the variable 'Pos' this
is nothing but the index value of the specified file

>>MOVETOPOS
RepositoriesCollection.MoveToPos(2,5)
-- here 2 is the current index and 5 is the new index
position. In this case it will move 2nd item to 5th position

>>REMOVE
RepositoriesCollection.Remove(5)
--it removes the 5th object repository file from the OR

>>REMOVEALL
RepositoriesCollection.RemoveAll
--it removes the full items from OR. Makes object repository
empty

>>COUNT
no = RepositoriesCollection.Count
--stores the number of repository items to 'no'

>>ITEM
desc = RepositoriesCollection.Item(4)
--returns the path of the 4th object repository file.

Dim qtApp
    Dim qtRepositories
    Set qtApp = CreateObject("QuickTest.Application")
    Set qtRepositories = qtApp.Test.Actions("ActionName").ObjectRepositories
   
qtRepositories.Add "D:\Documents\sharedRepository.tsr

Friday, June 7, 2013

Returning a value from a Function in QTP

To return a value from a function, we need to take care of the following two things:
 1) To return a value from a function, you need to use the statement functionName = ReturnValue, where functionName is the actual name of the function and ReturnValue is the value you want to return.
 2) To capture the returned value, you need to use the statement someVariable =functionName(parameters) while calling the function.
Let us understand this with the help of an example.

Returning value from a Function


'==========================================================
'  Function Name:   fnSum(var1, var2)
'  Function Scope:   Public
'  Parameters:   var1 and var2- Enter a number , result will display Sum
'  Description:   To find addition of two numbers
'  Author      :   Hardeep
'==========================================================

Function fnSum(var1, var2)
vrSum = var1 + var2   'return the result
 fnSum = vrSum
'This Statement Returns the value from Function i.e. functionName = ReturnValue
End Function

'Calling the Function and capturing the return value in variable "vrResult"

Dim vrResult
vrResult =  fnSum(25,10
'parameters should be passed using parenthesis when the function returns a value
msgbox vrResult


Wednesday, June 5, 2013

Handle Pop Up Dialog Window in Browser

' *************************************************************************
' Function  fnGetPopUpText() 
' This function Get the lable text message from Popup Dialog window in Browser page and enter the label text in Result Excel Sheet
' Note Dialog Window Must be child of  Parent oect
' Input Parameters   := None
' Output(ReturnType) := None
' *************************************************************************

Call fnGetPopUpText()

Public function fnGetPopUpText()

     Set oStaticText =Description.Create()
oStaticText("nativeclass").value ="Static"
oStaticText("text").value =".*[a-z].*"
     Set oWinButton =Description.Create()
oWinButton("micclass").value ="WinButton"

With Window("regexpwndtitle:=Windows Internet Explorer","regexpwndclass:=IEFrame").Dialog("regexpwndtitle:=Windows Internet Explorer","regexpwndclass:=#32770?")

    If .Exist(2) then
.Activate
    Set oStaticText = .ChildObjects(oStaticText)
For i=0 to oStaticText.Count-1
vrDescription =oStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next

    Set oWinbutton = .ChildObjects(oWinbutton)
For i=0 to oWinButton.count-1
oWinButton(i).Click
Exit for
Next
     fnGetPopUpText = vrDescription
End if

End With

End Function

'**********************************************************************************

Public function fnGetPopUpText()
    Set oStaticText =Description.Create()
oStaticText("nativeclass").value ="Static"
oStaticText("text").value =".*[a-z].*"

Set oWinButton =Description.Create()
oWinButton("micclass").value ="WinButton"

With Browser("title:=.*(Page).*").Dialog("text:=Windows Internet Explorer","nativeclass:=#32770?")
If .Exist(2) then
.Activate
Set oStaticText = .ChildObjects(oStaticText)
For i=0 to oStaticText.count-1
vrDescription =oStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next
Set oWinButton = .ChildObjects(oWinButton)
For i=0 to oWinButton.count-1
oWinButton(i).Click
Exit for
Next

fnGetPopUpText = vrDescription
End if
End With
End Function

What Test Cases To Automate

It is impossible to automate all testing; the first step to successful automation is to determine what test cases should be automated first.

The benefit of automated testing is correlated with how many times a given test can be repeated. Tests that are only performed a few times are better left for manual testing. Good test cases for automation are those that are run frequently and require large amounts of data to perform the same action.

You can get the most benefit out of your automated testing efforts by automating:
  • Ø  Repetitive tests that run for multiple builds
  • Ø  Tests that are highly subject to human error
  • Ø  Tests that require multiple data sets
  • Ø  Frequently-used functionality that introduces high risk conditions
  • Ø  Tests that run on several different hardware or software platforms and configurations
  • Ø  Tests that take a lot of effort and time when doing manual testing


Success in test automation requires careful planning and design work. Start out by creating an automation plan. This plan allows you to identify the initial set of tests to automate, and serve as a guide for future tests. First, you should define your goal for automated testing and determine which types of tests to automate. There are a few different types of testing, and each has its place in the testing process. For instance, unit testing is used to test a small part of the intended application. Load testing is performed when you need to know how a web service responds under a heavy workload. To test a certain piece of the application’s UI, you would use functional or GUI testing.

After determining your goal and which types of tests to automate, you should decide what actions your automated tests will perform. Don’t just create test steps that test various aspects of the application’s behaviour at one time. Large, complex automated tests are difficult to edit and debug. It is best to divide your tests into several logical, smaller tests. This structure makes your test environment more coherent and manageable and allows you to share test code, test data and processes. You will get more opportunities to update your automated tests just by adding small tests that address new functionality. Test the functionality of your application as you add it, rather than waiting until the whole feature is implemented.

When creating tests, try to keep them small and focused on one objective. For example, use separate tests for read-only versus read/write tests. This separation allows you to use these individual tests repeatedly without including them in every automated test.

Once you create several simple automated tests, you can group your tests into one, larger automated test. You can organize automated tests by the application’s functional area, major/minor division in the application, common functions or a base set of test data. If an automated test refers to other tests, you may need to create a test tree, where you can run tests in a specific order.


Tuesday, June 4, 2013

Files Generated while Recording in QTP

After the normal mode of recording, different files will be generated at the test script and action level.
After recording and saving the test script a folder will be created with the script name.
Each QTP test script is a directory itself. The name of the QTP script directory will be the name of the script. Change in the name of this folder will result in change in the script name, i.e. TestScript.usr

The files generated at the test script are:
default.cfg - Configuration file
default.usp - Run logic file
default.xls - Data file, which contains Global and Action1 sheet
Parameters.mtr - Test script parameters
Test.tsp – Contains the Test Settings and is a binary file
TestScript.usr - Test script main file. TestScript here is the name of the script saved by user.
Action0 folder - Contains the script settings to load the supportive actions and actions sequence scripts
Action1 folder - Contains actual action scripts which can be executable

By default each QTP script contains two sub folders “Action 0” and “Action1”. If we increase the number of actions then the number of the subfolders will increase accordingly.
The files generated at Action Level folder are

script.mts - Test script.
Resource.mtr - Action parameters.
ObjectRepository.bdb - Object repository.
Snapshots folder - Contains all the step level snapshots.


PS: In case of Analog Recording apart from the above mentioned files. The additional file generated is - AnalogTrackList.dat. All the mouse movements and key board events will be captured in the .dat file.