Friday, 9 August 2013

What Constitute Recovery Scenarios

A recovery scenario consists of the following:
  • Trigger Event. The event that interrupts your run session. For example, a window that may pop up on screen, or a QTP run error.
  • Recovery Operations. The operations to perform to enable QTP to continue running the test after the trigger event interrupts the run session. For example, clicking an OK button in a pop-up window, or restarting Microsoft Windows.
  • Post-Recovery Test Run Option. The instructions on how QTP should proceed after the recovery operations have been performed, and from which point in the test QTP should continue, if at all. For example, you may want to restart a test from the beginning, or skip a step entirely and continue with the next step in the test.
  • Recovery scenarios are saved in recovery scenario files having the extension .rs. A recovery scenario file is a logical collection of recovery scenarios, grouped according to your own specific requirements.

How Can I Import Environment from a File on Disk

Environment.LoadFromFile “C:\Env.xml”

How to Close All Open Browsers Using QTP

Method 1 -
'Check the existence of a browser and close it
'until no more browsers exist

While Browser("creationtime:=0").Exist(0)

    'Close the browser
    Browser("creationtime:=0").Close

Wend
Limitation – The code does not allow to ignore any specific browser (like Quality Center)
Though there another way by which can enumerate all open browser and close them in QTP and below demonstrates the same

Method 2 -
'Create a description for browser

Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"

Set oPage = Description.Create
oPage("micclass").Value = "Page"

'Get all browsers
Set allBrowser = Desktop.ChildObjects(oBrowser)

Dim i, iCount

iCount = allBrowser.Count - 1

For i = 0 To iCount
    'Get the page object from the browser
    Set oPg = allBrowser(i).ChildObjects(oPage)(0)

    'Get the URL of the
    If InStr(oPg.GetROProperty("title"), "Quality Center", vbTextCompare) = 0 Then
        'Close the browser
        allBrowser(i).Close
    End If
Next
Method 3 -
Closing processes using WMI
Another way to close a process is to use Window management instrumentation (WMI)
'Name/IP of the computer
sComp = "."

'Get the WMI object
Set WMI = GetObject("winmgmts:\\" & sComp & "\root\cimv2")

'Get collection of processes for with name iexplore.exe
Set allIE = WMI.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'")

'Loop through each process and terminate it
For Each IE in allIE
    IE.Terminate()
Next

QTP - How to count vowel in a string

To Count Number of Vowels.
STR = “VowelConstantA”
counter = 0
For i=1 to Len(STR)
If Chr(Asc(Mid(lcase(STR),i,1))) = “a” or Chr(Asc(Mid(lcase(STR),i,1))) = “e” or Chr(Asc(Mid(lcase(STR),i,1))) = “i” or _
Chr(Asc(Mid(lcase(STR),i,1))) = “o” or Chr(Asc(Mid(lcase(STR),i,1))) = “u” Then
counter = counter + 1
End if
Next
msgbox counter

QTP - Description Object

Description Object also do the same thing as static way do but there are some differences.
– Description Object stores the properties and values of a particular object in an instance of
that object. So it become easy to use it in the code.
– Description Object are used with ChildObjects property of QTP.
– It’s more useful if you are using multiple properties to identify object. As you will use only
instance name in your statement, your code looks more organized.
– It’s very handy if you are using index property for object identification
Example of a Description Object approach,
Browser(“name:=my”).page(“title:=myPage”).webbutton(“name:=Ok”,”type:=Submit”).click
We have used 3 different objects in above statement i.e. Browser, Page, webbutton.
Dim oBrowser, oPage, oButton ‘ declaration is not mandatory in vbscript, its a good programming approach
Set oBrowser = Description.Create
Set oPage = Description.Create
Set oButton = Description.Create
Now add identification properties & values to these objects.
oBrowser(”name”).value = “my”
oPage(”title”).value = “myPage”
oButton(”name”).value = “Ok”
oButton(”type”).value = “Submit”
oButton(”x”).value = “200″
Our objects are now ready to use now.
Browser(oBrowser).page(oPage).webbutton(oButton).click
You need to mention only instance name (oButton) instead of all properties and values in statement. This approach helps in writing neat & clean code.
Explore the following code to make the things clear…
1. Browser(”my”).page(“myPage”).webbutton(“Ok”).click – OR
approach
2. Browser(“name:=my”).page(“title:=myPage”).webbutton(“name:=Ok”,”type:=
Submit”).click – Static DP.
3. Browser(oBrowser).page(oPage).webbutton(oButton).click – Dynamic DP
First statement is written using OR approach. For this, objects must be stored in Object Repository.
Second statement is written using Static DP. All the properties are given directly in the code. Convenient!!
Third statement is written using Dynamic DP. You need to create a description for every object.
We can write statement that is mixture of above said all three ways. Example is as follows –
Browser(”my”).page(“title:=myPage”).webbutton(oButton).click
In Above written code, we have used all 3 ways..
Browser – Object Repository
Page – Static DP
webbutton – Dynamic DP