***Working with Web Tables***
Finding number of Rows in Web Table: -
Ex: -MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").RowCount
Finding number of Columns in Web Table: -
Ex: -MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").ColumnCount(1)
Retrieving Required Cell Data: -
Ex: - MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").GetCellData(2,5)
ScriptNo42: - Write a script to copy Web Table content in to Excel
Set objXl = CreateObject("Excel.Application")
Set objWrkBk = objXl.Workbooks.Add
Set objWrkSht = objWrkBk.Worksheets("sheet1")
Set obj = Browser("rediff").Page("rediff")
iRowCnt = obj.WebTable("rediff").RowCount
iColCnt = obj.WebTable("rediff").ColumnCount(1)
For iRowNum = 1To iRowCnt
For iColNum = 1 To iColCnt
sString = obj.WebTable("rediff").GetCellData(iRowNum,iColNum)
objWrkSht.Cells(iRowNum,iColNum) = sString
Next
Next
objWrkBk.SaveAs"C:\Documents and Settings\ASB\Desktop\script\script.xls"
objWrkBk.Close
objXl.Quit
Set objWrkSht = Nothing
Set objWrkBk = Nothing Set objXl = Nothing
Web Tables
ScriptNo45: - Write a script to find link existence in given cell, if it exist click on it in web table (Ex: - Row number 1 and column number 1)
iFlag = 0
iObjCnt = Browser("WebTable").Page("WebTable").WebTable("gmail").ChildItemCount(1,1,"Link")
'MsgBox iObjCnt
If iObjCnt > 0 Then
For index = 0 To iObjCnt - 1
Set obj = Browser("WebTable").Page("WebTable").WebTable("gmail").ChildItem(1,1,"Link",index)
sLnkName = obj.GetRoProperty("Name")
If sLnkName = "gmail" Then
iFlag = 1
obj.Click
End If
Next
End If
If iFlag = 0 Then
MsgBox "Given Link is not found"
End If
ScriptNo46: - Delete the rows that have less then are equals to 6 years experience
Set obj = Browser("Employee").Page("Employee")
iRowCnt = obj.WebTable("Employee").RowCount
For iRowNum = 2 To iRowCnt
iExp = obj.WebTable(iRowNum,3)
Set objCnt = obj.WebTable("Employee").ChildItemCount(iRowNum,1,"WebCheckBox")
If objCnt > 0 Then
Set objChBx = obj.WebTable("Employee").ChildItem(iRowNum,1,"WebCheckBox",0)
objChBx.Set"ON"
Set objCnt = obj.WebTable("Employee").ChildItemCount(iRowNum,5,"WebButton")
If objCnt > 0 Then
Set objBtn = obj.WebTable("Employee").ChildItem(iRowNum,5,"WebButton",0)
If objBtn.GetROProperty("Enabled") Then
objBtn.Click
Else
MsgBox "Delete Button is disabled in the row num:"&iRowNum
End If
Else
MsgBox "Delete button is not exist in row Number"&iiRowNum
End If
Next
Finding number of Rows in Web Table: -
Ex: -MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").RowCount
Finding number of Columns in Web Table: -
Ex: -MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").ColumnCount(1)
Retrieving Required Cell Data: -
Ex: - MsgBox Browser("Rediff").Page("Rediff").WebTable("Scheme").GetCellData(2,5)
ScriptNo42: - Write a script to copy Web Table content in to Excel
Set objXl = CreateObject("Excel.Application")
Set objWrkBk = objXl.Workbooks.Add
Set objWrkSht = objWrkBk.Worksheets("sheet1")
Set obj = Browser("rediff").Page("rediff")
iRowCnt = obj.WebTable("rediff").RowCount
iColCnt = obj.WebTable("rediff").ColumnCount(1)
For iRowNum = 1To iRowCnt
For iColNum = 1 To iColCnt
sString = obj.WebTable("rediff").GetCellData(iRowNum,iColNum)
objWrkSht.Cells(iRowNum,iColNum) = sString
Next
Next
objWrkBk.SaveAs"C:\Documents and Settings\ASB\Desktop\script\script.xls"
objWrkBk.Close
objXl.Quit
Set objWrkSht = Nothing
Set objWrkBk = Nothing Set objXl = Nothing
Web Tables
ScriptNo45: - Write a script to find link existence in given cell, if it exist click on it in web table (Ex: - Row number 1 and column number 1)
iFlag = 0
iObjCnt = Browser("WebTable").Page("WebTable").WebTable("gmail").ChildItemCount(1,1,"Link")
'MsgBox iObjCnt
If iObjCnt > 0 Then
For index = 0 To iObjCnt - 1
Set obj = Browser("WebTable").Page("WebTable").WebTable("gmail").ChildItem(1,1,"Link",index)
sLnkName = obj.GetRoProperty("Name")
If sLnkName = "gmail" Then
iFlag = 1
obj.Click
End If
Next
End If
If iFlag = 0 Then
MsgBox "Given Link is not found"
End If
ScriptNo46: - Delete the rows that have less then are equals to 6 years experience
Set obj = Browser("Employee").Page("Employee")
iRowCnt = obj.WebTable("Employee").RowCount
For iRowNum = 2 To iRowCnt
iExp = obj.WebTable(iRowNum,3)
Set objCnt = obj.WebTable("Employee").ChildItemCount(iRowNum,1,"WebCheckBox")
If objCnt > 0 Then
Set objChBx = obj.WebTable("Employee").ChildItem(iRowNum,1,"WebCheckBox",0)
objChBx.Set"ON"
Set objCnt = obj.WebTable("Employee").ChildItemCount(iRowNum,5,"WebButton")
If objCnt > 0 Then
Set objBtn = obj.WebTable("Employee").ChildItem(iRowNum,5,"WebButton",0)
If objBtn.GetROProperty("Enabled") Then
objBtn.Click
Else
MsgBox "Delete Button is disabled in the row num:"&iRowNum
End If
Else
MsgBox "Delete button is not exist in row Number"&iiRowNum
End If
Next
________________________________________________________________________________
Chapter XIX
Working with Database
Whenever test data based on database then we execute the queries and retrieve the data then we use QTP and Database connections.
Creating a Database Connection: -
Creating Database object: -
Set objDb = CreateObject ("ADODB.Connection")
Creating Table Object: -
Set objTable = CreateObject ("ADODB.RecordSet")
Setup QTP and Database Connection: -
objDb.Open"DSN=QT_Flight32"
Validate the Connection Status: -
MsgBox objDb.State
Executing Query: -
objTable.Open"Select customer_name from orders",objDb
objTable.Open"Select customer_name from orders order by order_number desc",objDb
Retrieve the data after executing Query: -
MsgBox objTable("customer_name")
Retrieving all the data: -
While objTable.EOF = "False"
Print objTable("customer_name")
objTable.MoveNext
Wend
ScriptNo47: - Write a script to retrieve the data from Database for given orders and maintain order information in excel file.
What is adodb connection?
The ADO (ActiveX Data Objects) Connection object is used to create a connection to a data source. Through this connection, you can access and manipulate a database.
What is adodb RecordSet?
The ADO Recordset object is used to hold a set of records from a database table. To be able to read database data, the data should be loaded into a recordset.
Note: The database we are using here is MS Access. Before running this script creates a table in MS - Access. In the above script I used table called "emp" and column 'names as "v1" and "v2". "D: testdata.mdb" is path of the table which we created. The main use of this script is to use test data of table (which is in ' database) in the application. In the above script we are passing values from database to Textboxes in Windows Application.
ScriptNo47: - Write a script to retrieve the data from Database for given orders and maintain order information in excel file.
What is adodb connection?
The ADO (ActiveX Data Objects) Connection object is used to create a connection to a data source. Through this connection, you can access and manipulate a database.
What is adodb RecordSet?
The ADO Recordset object is used to hold a set of records from a database table. To be able to read database data, the data should be loaded into a recordset.
Note: The database we are using here is MS Access. Before running this script creates a table in MS - Access. In the above script I used table called "emp" and column 'names as "v1" and "v2". "D: testdata.mdb" is path of the table which we created. The main use of this script is to use test data of table (which is in ' database) in the application. In the above script we are passing values from database to Textboxes in Windows Application.
QTP – QC Integration
Converting a manual test
case in to Test Script:
-
Prerequisites: - QUICKTEST_TEST add-in should be installed
Navigation: - QCàTest PlanàSelect Required Test
CaseàSelect Design Steps TabàFrom Generate Script
DropdownàSelect QUICKTEST_TESTàObserve that Manual Test Case icon is changed to
Automation icon
(QTP) àSelect Test Script TabàObserve that QTP Test script is generated and
Lunch QTP icon is available.
If we click on lunch QTP
icon if lunches QTP with required script, but all add-ins will disable except
“WEB” Add-
In. That is the reason
after convert manual test case in to test script we open QC Test Script from
QTP. To do this
we required QTP and QC
Integrations.
QTP – QC Integration: -
Navigation: - QTP while lunching QTP select require add-inàFile menuàSelect Quality Center
ConnectionàEnter URL for QCàClick Connect ButtonàEnter User Name and passwordàclick Authenticate
buttonàSelect domain and project and click login
button.
After Integration doneàClick Openàobserve that Quality Center Test Plan icon is displayedàClick on itàBrowse
and open required test
scriptàfile menuàSettingàClick modify buttonàcheck required add-ins check boxàClick
OKàClick Save.
After opened Test Script
displays below: -
1. All steps, user
actions and expected results are displaying as comments.
2. Remove all comments
if we want, design a test script for the same and save test script
Executing a Test Script: -
Navigation: -
Step1: - We need to add Test Plan Test Scripts to
Test Lab
Navigation: - Test LabàSelect required TestSetàClick Select Test ButtonàFrom Right side pane select required
test scripts and click
add to test set buttonàclick Left arrow iconàClick refresh button.
Step2: - We can execute in two ways
Way 1: - QTPàopen a QC TestScriptàClick Run ButtonàCheck “New Run Results
in Quality Center project”
radio ButtonàSelect Required TestSetàClick OK Button.
Way 2: - TestLabàSelect TestSetàselect required test ScriptsàClick Run Buttonàcheck “Run All Test locally”
and enable Log Check BoxàClick Run All button.
View Test Results: - After executing a TestScripts QTP save the
Test Results in respective TestLab TestSetàGo to
the corresponding
TestSetàDouble Click on required executed TestScriptàSelect required RunàClick Lunch
report button
Recovery Scenario
manager
QTP recovery scenarios
provide a method for scripts to recover from different types of run time error
conditions.
This is requiring for an
un-attended 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 = 4/y
On Error Resume Next
X = 4/y
If Err.Number = 11 then
MsgBox “Error code
divide by zero handled”
Else
‘Un Known error. Handler
for Un Known errors.
MsgBox Err.Description
&”. “&Err.Source
EndIf
The above scenario
produces a predicated specific error in a specific location in the code. This
type of
situation can only be
handed using the “OnErrorResumeNext” 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
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
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
next à select recovery
operation
àclick
on next
button ànext àEnter name and
description àClick
on next button àClick
on Finish
àSave
the created with “.qrs”
extension
Associated
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.
Disassociated
Created RSM:
-
File àSettings àRecovery tab àselect
associated file àClick
on “-” button àclick
Apply button àclick
OK button.
Error Handling: -
By using OnErrorResumeNext
statement we can handle runtime error. It closes runtime error and continue to
next
step.
Err.Number: It holds the
runtime error number
Err.Clear: It clears the
runtime error number
No comments :
Post a Comment