Вы находитесь на странице: 1из 3

)how do i count the no of checkboxes which are on?

ans)

systemutil.closeprocessbyname "iexplore.exe" 'close all open ie browsers


systemutil.run "iexplore.exe","http://www.google.com" ' open google
wait(3)
set objcheckbox = description.create() 'create object description of type checkbox
objcheckbox("micclass").value="webcheckbox"
browser("micclass:=browser").page("micclass:=page").link("innerhtml:=preferences")
.click 'click preferences linkset checkboxcollection =
browser("micclass:=browser").page("micclass:=page").childobjects(objcheckbox) 'get
the child object collection of type checkbox
msgbox checkboxcollection.count 'total number of checkboxes on the page'count
number of checkboxex
checkedj = 0
for i = 0 to checkboxcollection.count-1 'loop through the item(object) in the
collection
if checkboxcollection.item(i).getroproperty("checked") = 1 then
j=j+1
next
msgbox "number of checkboxes checked ="&j 'check few checkboxes on the page
for i = 0 to 7'
checkboxcollection.count-1 'loop through the item(object) in the collection
checkbox
collection.item(i).highlight 'highlight each item(object) in the collection
checkbox
collection.item(i).set "on"
next'count number of checkboxex checked
j = 0
for i = 0 to checkboxcollection.count-1 'loop through the item(object) in the
collection
if checkboxcollection.item(i).getroproperty("checked") = 1 then
j=j+1
next
msgbox "number of checkboxes checked ="&j

(or)
set odesc = description.create()odesc("micclass").value =
"webcheckbox"odesc("classname").value = "compareme"set ocbs =
browser().page().childobjects(odesc)

2) not able to launch qtp


c:\program files\mercury interactive\quicktest
professional\bin\quicktestprofessional.bat

3) problem accessing the file on quality center

first you store the excel file in the 'attachements' tab of you automation folder
in qc (this i believe you already have stored in the qc folder
'[qc]subject\ins\regression testing (rt)' )now in qtp, from main menu, select
'tools->options'. in the options dialog box, go to 'folders' tab and add the above
qc folder where you stored the excel file in the folders tab.when a qtp script,
stored in qc, is executed on a machine, the files stored as attachments in the qc
folder, get downloaded in the local machine. the local path of this copy of the
file can be retrieved using pathfinder.locate statement: so you can use something
like below to get the path of your excel filestrdataexcelfile =
pathfinder.locate("currentpassword.xls")then use this variable
'strmyexcelfilepath' in the getexceldata function for the file name parameter like
below:environment("password") = trim((getexceldata (rowno,colnumber,sheetnumber,
strdataexcelfile )))

4) how to save a value in datasheet attached in qc.


'give the data path as belowdatatable.import "[qc-
attach];;subject\data;;\datasheet.xls"datatable("param1","updatesheet") = "updated
value"datatable.export "[qc-attach];;subject\data;;\datasheet.xls"

5) pass data to a variable.


play="cricket"if(browser("name:=p").page("title:=s").webelement("html
tag:=acronym","innertext:=" & play,"index:=0").exist) thendo thiselsedo thisend if

6) how to get page name


set pg=description.createpg("micclass").value="page"msgbox
browser("xxx").page(pg).getroproperty("name")msgbox
browser("xxx").page(pg).getroproperty("title")
7) qtp 8.2 - toproperty roproperty

gettoproperty returns property value from object repository for particular


object.getroproperty return property value of same object at run time.example.
when u recorded script or added object to or..text field contents value as say
"a"then u r modifying contents of text field thru script and setting it to say
"b"now after modifying text field contents if u perform following
check..webedit().gettoproperty("value")..webedit().getroproperty("value")answer
would be ab

8) accessing qc database from qtp

for i=1 to recset.recordcountif i=1 thenrecset.first()end ifmyrecset =


recset.fieldvalue("tc_iterations")msgbox myrecsetrecset.nextnext

9) invoking qtp from the command line


create a new vbs file with the following content:set qtapp=
createobject("quicktest.application") qtapp.launch qtapp.visible = trueqtapp.open
"c:\tests\mytest"qtapp.test.runqtapp.quitrun it from the command line:cscript
"c:\myvbsfile.vbs"it will start qtp, then open and execute mytest test, then close
qtp.

10) get the number of columns in the table

yes there is a way to get the nubmer of columns in a table..but before that what
type of application are you using?web or anything else?if it is web then use
thiscolcount=browser("xyz").page("abc").webtable("efg").getroproperty("cols")print
colcount

11) how to capture child objects from a webtable

try something like this and seeset objtable=browser().page().webtable()introwcount


= objtable.rowcountfor introwloop =1 to introwcountintcolumncount=
objtable.columncount(introwloop)for intcolumnloop = 1 to
intcolumncountintchildcount=objtable.childitemcount( introwloop,int(intcolumnloop-
1), "webedit")' verify for webedit insite if intchildcount<>0 thenset
objchild=objtable.childitem (introwloop,int(intcolumnloop-1), "webedit",
0)objchild.set "abcd"end ifnextnext
12) adding a sheet and some specific column at run time

set newsheet = datatable.addsheet("mysheet")newsheet.addparameter "username",


""newsheet.addpatameter "step", ""to add values to the sheet at run time can i use
this code datatable.value("username","mysheet") =
"psuk"datatable.value("step","mysheet")= "pisuk"

13) descriptive programming to identify an object

set odesc = description.create ()odesc("property1").value =


value1odesc("property2").value = value2odesc("property3").value = value3set olist
= browser("b").page("p").childobject(odesc)msgbox olist.countif olist.count > -1
thenfor i = 0 to olist.count - 1olist(i).highlightnextelsemsgbox "there is no
object in gui which matches current description"end if

14) how to handle error in qtp using vbscript

do one thing .always use wrong values for ur text boxes now after clicking on ok
it is expected that some validation pop-up message will be displayed . so after
the loc that enters the data into your text boxes when you click on submit write
another loc that clicks on ok of that validation message and now reenter the
correct values and proceed futher.b.p.webedit(user name).set
"&^$%^$%^"b.p.webedit(password).set "$%^$^$%^$^"//parametrize these steps with
incorrect combinations always to check t he
errorsb.p.webbutton.clickb.dialog().winbutton.clickb.p.webedit(user name).set
"correct user name"b.p.webedit(password).set "correct password"b.p.webbutton.click

Вам также может понравиться