Wednesday, April 17, 2013

Object Identification

Object Identification is a mechanism that how QTP is identifies the objects uniquely.
 

Object Identification is divided into 2 types.
 

1.    Normal identification
2.    Smart Identification

1.     Normal Identification:

Normal Identification is divided into 2 properties Mandatory and Assistive properties.

Mandatory properties: The properties which are mandatory for objects are calling as Mandatory properties like Class Name, text………….

Assistive properties are assistance for Mandatory properties like enabled, focused

2.    Smart Identification:

Smart Identification is divided into 2 properties Base Filter and Optional Filter properties.



Along with Normal and Smart Identification there is another option is Ordinal Identifier.

QTP only uses when there are multiple object matches for a given description.

Ordinal Identifier:

These are 2 types

Location: IF at all the location is selected as Ordinal Identifier, and then QTP will generate sequence of NO. From 0, 1, 2, 3…………..  Based on the sequence of the objects located in the application.

Index: IF at all the Index is select as Ordinal Identifier, then QTP will generate sequence of No 0,1,2,3…….. based on the sequence of the programs of the corresponding objects
 
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Recovery Scenario Manager

QTP recovery scenarios provide a method for scripts to recover from different types of runtime error conditions. This is required for an unattended test case execution.

When not to use recovery scenarios?

Consider the following code, which has the potential to generate a divide by zero error exception:

‘Sample code with error probability
Y = z – 2
Y= 4 / y

We can handle this class or error using the On Error statement:

‘Handling predictable errors
Z = 2
Y = z – 2
On Error Resume Next
X = 4 / y
If Err.Number = 11 then
    MsgBox “Error code divide by zero handled”
Else
    ‘Unknow error. Handler for unknown errors.
    Msgbox err.Description & “ , “& err.source
End If

The above scenario produces a predicted specific error in a specific location in the code. This type of situation can only be handled using the “On Error Resume Next” statement, rather than a recovery scenario.

When to use recovery scenario?

We can use a recovery scenario when we know what type of error can occur, but don’t know when or where it might occur.

A recovery scenario consists of following components:

A Trigger Event: It is event that unexpectedly interrupts script execution. This event can be any one of the following:
            Pop-up window
            Object State
            Test run error
            Application Crash

A Recovery Action: This specifies what action needs to be taken after the associated trigger event has occurred and it can be any one of the following:
           
            Keyboard or mouse operation
            Close Application process
            Function Call
            Restart Microsoft Windows

Post Recovery Action: This specified what should be done once the recovery action has been successfully completed and this can be any one of the following:

        Repeat current steps and continue
        Proceed to next step
        Proceed to next action iteration
        Proceed to next test iteration
        Restart current test run
        Stop the test run

Navigation for applying RSM;

Resource menu -> Recovery Scenario Manager -> Click on New Scenario -> Click on Next button in wizard -> Select Trigger Event and identify corresponding object -> Click on Next button -> Select Recovery Operation -> Click on Next button -> Click on Next button ->Enter Name and Description -> Click on Next button -> Click on Finish button -> Save the created with .qrs extention.

Associating Created RSM

File -> Settings -> Recovery tab -> Click on ‘+’ button and browse the corresponding recovery file -> Click on Add Scenario button -> Click Apply button -> Click OK button.

Disassociating RSM:

File -> Settings -> Recovery tab -> Select associated fie -> Click on ‘X’ button -> Click Apply button -> Click OK button.

Contributed by: Vamshi Goutham

Tuesday, April 16, 2013

Regular Expression Characters


1. Match Any Single character (.)
The “ . “ character matches any single character. For example, “…” will match “12B”, “B3B”, “123”, “ABC”, “$g%” etc…
   
2. Match Any single character in list [xyz]
A character list inside square brackets matches any of the single characters in the list. For example, “[abc][12]” will match “a1”, “a2”, “b1”, “b2”, “c1” and “c2”

3. Match any single character Not in a list [^xyz]
The “^” character is a negation character used to exclude a pattern from the regular expression. For example, “[^a][12]” will not match “a1” and “a2” but will match “11”, “12”, “c1” etc………

4. Match Any single character within a Range ( [x-y] )
The “[d-h]” construct will match any character ranging from d to h. For example, “[abcdef][123]” can also be written as “[a-f][1-3]”

5. Match zero or More specific characters ( * )
The  “*” character is used to match zero or more occurrences of a regular expression that precedes the star. For example, “a*” will match a blank string, “a”, “aa”, “aaa” etc…

“aa*” will match “a”, “aa”, “aaa” etc

“[abc][1-4]*” will match “a”, “b”, “c”, “a1”, “b1”, “a12”, “b12”, “a1234344” etc…

“User.*” will match any string starting with text “User”

6. Match one or more specific characters ( + )
The “+” character is used to match one or more occurrences of a regular expression that precedes the plus sign. For exampale “aa*” can also be written as “a+”

“123+” will match “123”, “1233”, “12333” etc…

“[123]+” will match “1”, “2”, “3”, “12”, “23” etc…

7. Match zero or one specific character ( ? )
A “?” character is used to match zero or one occurrences of a preceding regular expression. For example, “a[123]?” will match “a”, “a1”, “a2” and “a3”

Regular Expressions


Regular expressions are strings containing special Meta characters used to match patterns inside the strings. Text editors use this feature for doing color syntax highlighting and other operations. 
Whenever the object properties are changing during run time then we are applying Regular expressions.

When to use SetToProperty method and Regular Expression?

1) Whenever we are using OR 
2) Whenever we are using DP programming then we have to use only RE
3) Whenever there is fixed change on properties for an object and using OR then we can use SetToProperty method 
4) Whenever there is no fixed change on properties for an object and with or without using OR then we can use RE

Applying RE through OR:

Open OR - select required object -In Test Object details area select required property and click on configure the value button - Enter RE string pattern - Check Regular Expression check box - click on OK button

Applying RE through DP:
Set objDialog=Description.Create
objDialog(“text”).Value=”Fax Order No. *.*”
objDialog(“text”).RegularExpression=True
Msgbox Window(“Flight Reservation”).Dialog(objDialog).Exist

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Close a process


‘Examples of closing a process
‘Give # of closed processes
numClosed=SystemUtil.CloseProcessByName(“iexplore.exe”)

‘Title with a regular expression
SytsemUtil.CloseProcessByWndTitle “Microsoft Internet Explorer.*”,True

‘Title without a regular expression
SystemUtil.CloseProcessByWndTitle “Notepad”

‘Close process by the process id
SystemUtil.ClosePRocessBYId processed

‘Close all processes opened by QTP
SystemUtil.CloseDescedentProcesses

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Utility Objects


1. The Crypt Object:
This object encrypts strings in a format that the QTP SetSecure function understands

myVar=Crypt.Encrypt(“mercury”)
msgbox myVar

2. The OptionalStep object:
This object is used to make a statement optional in situation where the statement might fail.

     OptionalStep.Window(“Flight Reservation”).WinButton(“Insert Order”).click

3. The pathfinder Object
This object is used to find the absolute path to a file. 

Through navigation: QTP allows setting folder paths in the Tools OptionsFolders
During run time: 
Msgbox  PathFinder.Locate(“<path of the file to be searched>”)

4. The RandomNumber object:
This object provides a method to get a random number between two specified values.
Msgbox RandomNumber(1,100)

5. The SystemUtil object:
This object is used to run and close process. Below are few examples of starting process;

‘Run internet explorer
SystemUtil.Run “iexplore.exe”

‘Run internet explorer and pass the starting URL
SystemUtil.Run “iexplore.exe”, http://www.gmail.com

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Script to find total number of winEdits in Flight Reservation window


'Create DP object
Set winEd=Description.Create
winEd("class Name").value="WinEdit"
set winEditCnt=Window("text:=Flight Reservation").ChildObjects(winEd)
msgbox winEditCnt.Count
For num=0 to winEditCnt.Count - 1
msgbox winEditCnt(num).GetRoProperty("attached text")
Next


AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...