QTP tips
上一篇 / 下一篇 2008-04-17 21:26:59 / 个人分类:QTP
yE5y5N.Tx.k8~0This is more to do with MS excel then QTP!! but useful to know because at times it becomes frustrating to the novices.
~O/r,ug I1h.Xj)M0Just append ' to the number
+W ui7ekYsG0Ex: if you wish to enter 1234567 in datatable then write it as '123456751Testing软件测试网"A,|` ~@ l[1m
51Testing软件测试网uQOD r%N)? C5g
2) How can i check if a parameter exists in DataTable or not?
4p7K/{9v)YV&{J0The best way would be to use the below code:51Testing软件测试网r"Y Y&E7l4P~
on error resume next
L2c)n*G{2K"b0val=DataTable("ParamName",dtGlobalSheet)
*z'xS)g&kU-?F l0G0if err.number<> 0 then51Testing软件测试网Y0R~&cQ S
'Parameter does not exist
lE_uc5t{K$N0else51Testing软件测试网)y9YF:Ys
'Parameter exists51Testing软件测试网*fu%M}#gf^c
end if
7M}Bij1T/w._;@0
*VX"Nji03) How can i check if a checkpoint passes or not?51Testing软件测试网{BU9u2h6{B4| q
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))51Testing软件测试网]2n0`]jx
if chk_PassFail then
[^:`RW nv0Rv YS0MsgBox "Check Point passed"51Testing软件测试网;GZ+h-MhC;O N
else MsgBox "Check Point failed"
w&]]V0^"B0end if
jlg Td`'M]051Testing软件测试网P;Q2Nx(w:CuN$|T
4) My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing due to checpoint failure?
l#D!zaLx0Reporter.Filter = rfDisableAll 'Disables all the reporting stuff51Testing软件测试网Kwp5A1nH%^
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
B1b%[{O^:tWY0Reporter.Filter = rfEnableAll 'Enable all the reporting stuff51Testing软件测试网/@*g\.L;R
if chk_PassFail then
&O%|.MC|0N7ex/s0MsgBox "Check Point passed"51Testing软件测试网Xyg.Q#i9M@6t6^
else
hqLpf(uo1n0MsgBox "Check Point failed"
'Le_i F^Dh:g.G]0end if51Testing软件测试网|@u i ^6~
&J(yu)YTLu05) What is the difference between an Action and a function?
3?(us]:qnX\0Action is a thing specific to QTP while functions are a generic thing which is a feature of VB scrīpting. Action can have a object repository associated with it while a function can't. A function is just lines of code with some/none parameters and a single return value while an action can have more than one output parameters.
GFPS8X Si0
6F*L:V%r^!S#vJ#b8vx06) Where to use function or action?
8Gn1uw Z`{ [0Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the functionality is not about any automation scrīpt i.e. a function like getting a string between to specific characters, now this is something not specific to QTP and can be done on pure VB scrīpt, so this should be done in a function and not an action. Code specific to QTP can also be put into an function using DP. Decision of using function/action depends on what any one would be comfortable using in a given situation.
;z r\ l!d w+U051Testing软件测试网%m#d)p'j3v.Y*i-@B(b@-c
7) When to use a Recovery Scenario and when to us on error resume next?51Testing软件测试网 O.gj9_+Co
Recovery scenarios are used when you cannot predict at what step the error can occur or when you know that error won't occur in your QTP scrīpt but could occur in the world outside QTP, again the example would be "out of paper", as this error is caused by printer device driver. "On error resume next" should be used when you know if an error is expected and dont want to raise it, you may want to have different actions depending upon the error that occurred. Use err.number & err.descrīption to get more details about the error.51Testing软件测试网l,?_+U)HQ9^l
51Testing软件测试网Z!feq8E V
8) How to use environment variable?51Testing软件测试网$]H5xc7Q |-P
A simple defintion could be... it is a variable which can be used across the reusable actions and is not limited to one reusable action.
*H5j9RO.XOV@u c0There are two types of environment variables:
U(f)|R'C%yk01. User-defined51Testing软件测试网Ijf3d`yu
2. Built-in
!imL5@$yt2w0We can retrieve the value of any environment variable. But we can set the value of onlyuser-definedenvironment variables.
m8_"|rl Rf0bpm0
U4j*r!dQh;F0To set the value of a user-defined environment variable:
2N-cJm)bD4q,D0Environment (VariableName) = NewValue
1FTV t&Y)Pr*u\051Testing软件测试网m"Z$g*PB@;qr
To retrieve the value of a loaded environment variable:
0M8v?$lI7U@0CurrValue = Environment (VariableName)
mG0pE4D*S051Testing软件测试网 B)\q9?T!^'b!Z
Example51Testing软件测试网&}I:zq;\ y7}
The following example creates a new internal user-defined variable named MyVariable with a value of 10, and then retrieves the variable value and stores it in the MyValue variable.51Testing软件测试网l$TC9{:X?^9Ht
51Testing软件测试网m+\ZS8Xs
Environment.Value("MyVariable")=10
o&s0Z*t&v6V9`s0MyValue=Environment.Value("MyVariable")
9) What are the files and subfolders of a QuickTest Professional test?51Testing软件测试网LW:\$o@F
Y4\tm8I0The following table provides a descrīption, the type, and comments regarding the files that make up a QuickTest Professional test.
File Name | Descrīption | Type | Comments Regarding File |
Test.tsp | Test settings | Binary | Do not edit |
Default.xls | Data table parameters | Excel similar | Can be edited using Excel |
Parameters.mtr | Parameterization information | Binary | Do not edit |
Action | Action folder (See other table) | <!--[if !supportEmptyParas]--> <!--[endif]--> 8@G?W:P0 | <!--[if !supportEmptyParas]--> <!--[endif]--> a1mi0LAU,K^Ld0 |
Default.cfg | Load test configuration file | Text | Do not edit |
Default.prm | Load test configuration file | Text | Do not edit |
Default.usp | Load test configuration file | Text | Do not edit |
Load test configuration file | Text | Do not edit | |
Thick_usr.dat | Load test configuration file | Text | Do not edit |
Thin_usr.dat | Load test configuration file | Text | Do not edit |
Files within Action folder:
File Name | Descrīption | Type | Comments Regarding File |
scrīpt.mts | Action scrīpt | Text | Edit text preceding the @@ sign only |
Resource.mtr | Object Repository | Binary | Do not edit |
Snapshots | Active screen files | Folder | Do not edit |
.MTB Batch File51Testing软件测试网,zm'hV;m'g2k
.LCK Locked
51Testing软件测试网F4H"~'{LGe\
,]&hWCKg0Example:
WKihK?^G0Window("Notepad").WinEditor("Edit").Check CheckPoint("Edit")51Testing软件测试网/I4`t:Y0d$x5_$X@
In the above example, the user would like to change the name of the CheckPoint object from "Edit" to something more meaningful.
[%g"P$dXi{/|5udK0Note:51Testing软件测试网K(kQ{:I,G/|
This functionality is new to QuickTest Professional 9.0.This is not available for QTP 8.2 and below.51Testing软件测试网$si,g8Wjq[
1. Right-click on the Checkpoint step in the Keyword View or on the Checkpoint object in Expert View.51Testing软件测试网%K_)IJ'_}
2. Select "Checkpoint Properties" from the pop-up menu.51Testing软件测试网+q'q Trv/A&|w*LR
3. In the Name field, enter the new checkpoint name.
TE:fO&z!fxW04. Click
-{{O"V@NG0W1d0Example:51Testing软件测试网 `#?z._x:t4I
Window("Notepad").WinEditor("Edit").Check CheckPoint("NewCheckPointName")51Testing软件测试网VLm&B
fz:SsUH
Note:
C[H:N.na~vjZ0{0You must use the QuickTest Professional user interface to change the name of the checkpoint. If you manually change the name of the checkpoint in the scrīpt, QuickTest Professional will generate an error during replay. The error message will be similar to the following:
"The "
The CheckPoint object is not a visible object within the object repository, so if you manually modify the name, you may need to recreate the checkpoint to resolve the error.
<!--[if !supportEmptyParas]--> <!--[endif]-->
11) Does QuickTest Professional support Internet Explorer 7.0?
AM`bPLS
a C
~/u0QuickTest Professional 9.151Testing软件测试网j?-[%\![{Z!Uz#Q2Z
QuickTest Professional 9.1 supports Microsoft Internet Explorer 7.0 Beta 3. Internet Explorer version 7.0 is now certified to work and to be tested with QuickTest Professional version 9.1.51Testing软件测试网M*r5_ JSNl
QuickTest Professional 9.0
KEZjS0~
[i^ A
F0QuickTest Professional 9.0 supports Internet Explorer 7.0 Beta 2.51Testing软件测试网6h)m\ V \4]
QuickTest Professional 8.2 and below51Testing软件测试网*^7V4qV
`g O
QuickTest Professional 8.2 and below do not include support for Internet Explorer 7.0.
Does QuickTest Professional support Firefox?
-vz;{ll,n[w aw0QuickTest Professional 9.1 and 9.2
uwmn\X0QuickTest Professional 9.1 provides replay support for Mozilla Firefox 1.5 and Mozilla Firefox 2.0 Alpha 3 (Alpha-level support for Bon Echo 2.0a3).51Testing软件测试网Ve1b-S+X3M0Og}
Notes:
QuickTest Professional 9.1 will not record on FireFox. You can record a test on Microsoft Internet Explorer and run it on any other supported browser, such as FireFox.
The .Object property for web objects is not supported in FireFox.
QuickTest Professional 9.051Testing软件测试网h%H#LjY`7z-L
QuickTest Professional 9.0 provides replay support for Mozilla FireFox 1.5.51Testing软件测试网5w&[px(\&u-k1C
Notes:
QuickTest Professional 9.0 will not record on FireFox. You can record a test on Microsoft Internet Explorer and run it on any other supported browser, such as FireFox.
The .Object property for web objects is not supported in FireFox.
QuickTest Professional 8.2 and below
QuickTest Professional 8.2 and below do not have support for Firefox.
q|(V7Qqyw051Testing软件测试网d@7T
b4jU
51Testing软件测试网5c {y]Z8k4`Y
<!--[if !supportLineBreakNewLine]-->12) Problem
H R @R!E0After Quick Test Professional is started, Windows Media will not start. It returns the error message "wmplayer.exe has generated errors and will be closed by Windows. You will need to restart the program. An error log is being created."
If you start Window's Media Player first, it will continue to work normally after starting QuickTest Professional.
Solution:
Include the Windows Media Player's executable in the NoBBTApps section of the mic.ini file
1. Close QuickTest Professional.51Testing软件测试网]L8wn'm*{3`na9N
2. Go to
0}4G5f
kxZPO03. Includewmplayer.exein the NoBBTApps section of mic.ini file.
Example:
H\#Bui0d.t|-b0[NoBBTApps]
%]Y[#\[0wmplayer.exe=rek
4. Save the mic.ini file and restart QuickTest Professional.
13)What is the lservrc file in QTP?51Testing软件测试网#`1c"FSJr;[$[&u2` J
51Testing软件测试网$mt
XnVS!U-`]
The lservrc file contains the license codes that have been installed
The lservrc file contains the license codes that have been installed. Whenever a new license is created, the license code is automatically added to this file. The lservrc file is a text file, with no extension.
File Location:
/}0E/fR!qu;?$@zY&O051Testing软件测试网n+p*IdE]*?"t
1) For a Concurrent (Floating) license installation:
"#server installation directory#\#language#"
Example:51Testing软件测试网g|5q&q|_8{^i
C:\Program Files\XYZ Technologies\ABC Server\English\lservrc
2) For a Seat (Stand-alone) license installation:
#AQT/QTP installation directory#\bin"
Example:
5r#?!f Cl9Ym`0C:\Program Files\Mercury Interactive\QuickTest Professional\Bin\lservrc
51Testing软件测试网x+yFK_
Da3f
14) What to do if you are not able to run QTP from quality center?
dP2jNSr0f9Q0This is for especially for newbies with QTP.51Testing软件测试网dZ
jj|u
Check that you have selected Allow other mercury products to run tests and components from Tools--> Options--> Run Tab.
15) Does QuickTest Professional support Macintosh operating systems?
$n,G/AY2b*v0No, QTP is not expected to run on this OS.51Testing软件测试网3mHe'oP
16) The follow situation need to use Parentheses.
o$M;`6i2t0When programming in VBscrīpt, it is important that you follow the rules for using or not using parentheses () in your statements.
;ZWn/H F]3K%F0You must use parentheses around method arguments if you are calling a method that returns a value and you are using the return value. For example, use parentheses around method arguments if you are returning a value to a variable, if you are using the method in anIfstatement, or if you are using theCallkeyword to call an action. You also need to add parentheses around the name of a checkpoint if you want to retrieve its return value.51Testing软件测试网1A?3[5K2FRam
Tip: If you receive anExpected end of statementerror message when running a step in your test, it may indicate that you need to add parentheses around the arguments of the step's method.51Testing软件测试网b+O Gj/|7J n4y"k$W
Following are several examples showing when to use or not use parentheses.51Testing软件测试网~8Z+l/Fu${$x@
The following example requires parentheses around method arguments, since it returns a value to a variable.
KL'A2td)\H[0Set WebEditObj = Browser("Mercury Tours").Page("Method of Payment").WebTable("FirstName").ChildItem (8, 2, "WebEdit", 0)51Testing软件测试网-BXQf}(kF[
WebEditObj.Set "Example"
*p[ZA"P4p+M0The following example requires parentheses around method arguments, sinceCallis being used.
,cbier\A6WOR-l0Call RunAction("BookFlight", oneIteration)
k2nv Szm5d!qmM0The following example requires parentheses around method arguments, since the method is used in anIfstatement.51Testing软件测试网 M mRR?0{
If Browser("index").Page("index").Link("All kind of").WaitProperty("attribute/readyState", "complete", 4) Then Browser("index").Page("index").Link("All kind of").Click
~TFnuH XS0The following example requires parentheses around method arguments, since it returns the value of the checkpoint.
/JP6^pq%dO&N0c0a = Browser("MyBrowser").Page("MyPage").Check (CheckPoint("MyProperty"))51Testing软件测试网 h,@Rd+t0N$|%fU X
The following example does not require parentheses around theClickmethod arguments, since it does not return a value.
F:_!D/{FBCp*c t0Browser("Mercury Tours").Page("Method of Payment").WebTable("FirstName").Click 3,451Testing软件测试网X"zv;zq~
17) Encrypts a string.51Testing软件测试网,XeYJ(e"g#e
In the following example, a password is taken from a database and encrypted using theEncryptmethod, and then placed in the password edit box using theSetSecuremethod.51Testing软件测试网 zu z7^TA&M
pwd = "GetPasswordfromSomewhere"
Zz1\/EUF6e0e_pwd = Crypt.Encrypt(pwd)
&`G.a0N0pl|#lR0Browser("dfgd").Dialog("pass").WinEdit("pwd").SetSecure e_pwd51Testing软件测试网?5Y7f!}:hliR
18) Environment object example:51Testing软件测试网m'U;pIjR
The following example uses the ExternalFileName property to check whether an environment variable file is loaded, and if not, loads a specific file and then displays one of the values from the file.51Testing软件测试网f!kv#X Ya8T
'Check if an External Environment file is loaded and if not, load it.
d Q&x,T%r&B)B)D0fileName = Environment.ExternalFileName51Testing软件测试网 |V3w*?:ci s
If (fileName = "") Then