TESTEVERYTHING

Friday, 17 June 2011

Read Value from Registory / QTP / WScript

Here an example to get get the location where QTP is installed

REM Create shell script object
  Set WshShell = CreateObject(“WScript.Shell”)
REM in variable store the registry key path
  sKey =”HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\Packages\WebFormsPackage\Settings\ConfigurationFile”

REM here using the shell object we can read the registry key value
sQTPpath= WshShell.RegRead(sKey)

msgbox sQTPpath
set WshShell = nothing


Wednesday, 15 June 2011

Get cell data from webtable / QTP

Hi all ,
I found a helpful example in QTP  help file that can be use most of time while working with web table. I hope It will help you.

Description

       Returns the text contained in the specified cell.

Syntax

   object.GetCellData (Row, Column)
Argument Description
object A test object of type WebTable.
Row Required. A Variant value. The row number where the cell is located. The first row in the table is numbered 1.
Column Required. A Variant value. The column number where the cell is located. The first column in the table is numbered 1.

Return Value

A String value.  Returns the data contained in the specified cell.
If the specified cell is not valid, the method returns micCellDoesNotExist
Find All Employees That Live in the Same City

Sub GetCellData_GetRowWithCellText_Example()
        ‘The following example retrieves the names of all employees that live in
       ‘the same city as John Smith so that he can arrange rides home with them.
       ‘First, the example finds the table row containing
      ‘”John Smith”. Then it checks the value of the CityColumnn cell to determine
       ‘the city in which John lives. It searches the table cells to find all other
        ‘employees that live in that city. Finally it uses the GetCellData method to
        ‘return those employees names and, using a function, generates a list
         ‘containing those names.

  CityColumn = 4
  NameColumn = 2

‘Get the row number for employee ‘John Smith’
RowNumber = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).GetRowWithCellText(“John Smith”)
Set AccommodationsCity = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).ChildItem(RowNumber, CityColumn, “WebEdit”, 0)
TableRows = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).RowCount
‘Search for all employees that live in the same city as ‘John Smith’ and add them to his ride home list
For i = 1 To TableRows
   Set CurrentCity =    Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).ChildItem(i, CityColumn, “WebEdit”, 0)
    If CurrentCity.GetROProperty(“value”) = AccommodationsCity.GetROProperty(“value”) Then
      EmployeeName =  Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).GetCellData(i, NameColumn)
      AddToJohnSmithRideHomeList (EmployeeName)
     End If

 Next
End Sub

Tuesday, 7 June 2011

Execute a DOS command in QTP / CMD with QTP

REM using "Wscript.Shell" object we can work on command prompt in qtp.
REM create one instance for "wscript.Shell"

set oShell=CreateObject("Wscript.Shell")

REM using run method we can invoke application
REM /k this will display command prompt.we can also use /c but we can not see command prompt.It will disappear after execution.


oShell.Run "cmd /k dir"
REM for wait in ms
WScript.sleep 3000
REM if we want use multiple commands we can use "&"(amp) symbol
oShell.run "cmd /k dir & md qtp"
REM we can use send keys method here {ENTER} will press enter button
oShell.SendKeys "cd{ENTER}"
REM if we want use multiple commands we can use "&"(amp) symbol

oShell.Sendkeys "cd c:\{ENTER} md qtp ~"


REM ~ for enter key {ENTER} = ~
oShell.Sendkeys "cd d: ~"

set oShell=Nothing

Translate







Tweet