共同探讨QTP相关问题

QTP tips

上一篇 / 下一篇  2008-04-17 21:26:59 / 个人分类:QTP

1) How to add a constant number in a datatable?
yE5y5N.Tx.k8~0
This 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 u i7ek YsG0Ex: 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"N ji03) 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 n v0Rv YS0MsgBox "Check Point passed"51Testing软件测试网;GZ+h-Mh C;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!z aLx0
Reporter.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"
'L e_iF^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_"|rlRf0bpm0
U4j*r!dQh;F0To set the value of a user-defined environment variable:
2N-cJm)b D4q,D0Environment (VariableName) = NewValue
1FTV t&Y)Pr*u\051Testing软件测试网m"Z$g*PB@;qr
To retrieve the value of a loaded environment variable:
0M8v?$l I7U@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软件测试网L W:\$o@F
The files and folders hold binary and text data that are required for the test to run successfully.
Y4\tm8I0The following table provides a descrīption, the type, and comments regarding the files that make up a QuickTest Professional test.

W&D]%]wo0

File Name51Testing软件测试网oc x2Jr+_

Descrīption51Testing软件测试网}k;^ R bb

Type

`s;zg!WZ0

Comments Regarding File

(A a*fVCX*s7|$z/F'b0

Test.tsp

x\9E:D H0

Test settings51Testing软件测试网:oD e'q4k3`0k

Binary51Testing软件测试网!FW9l"usN

Do not edit51Testing软件测试网V*Z yUMS9Luq

Default.xls51Testing软件测试网,u} k/i"_7K.`5[|

Data table parameters51Testing软件测试网iIf0en5s6B&S

Excel similar

I-`8?,^&hS0

Can be edited using Excel51Testing软件测试网)[3k5k-f*C$y*J

Parameters.mtr51Testing软件测试网\%y)uB*z)?[A Z

Parameterization information51Testing软件测试网7`X h7Pv;c-O_

Binary

1|?+_v8Ho0

Do not edit

uYdn1n$y_b0

Action

4?!A D)irvo(_0

Action folder (See other table)51Testing软件测试网4v^Trq1y0m

<!--[if !supportEmptyParas]--> <!--[endif]-->51Testing软件测试网.a$B(x/Z7J V ar^


8@G? W:P0

<!--[if !supportEmptyParas]--> <!--[endif]-->

@;HI@5@2L\0
a1mi0LAU,K^Ld0

Default.cfg

dc d#py)]V)}$[0

Load test configuration file51Testing软件测试网m m,bz%A-T;C

Text

nu1B~5m4x0

Do not edit

n-sWNK8VG0i@0

Default.prm

,W,]FI!G4Y!q0

Load test configuration file51Testing软件测试网 Y/N8~)r,vN9{3N

Text51Testing软件测试网v j]~ t$o,x

Do not edit51Testing软件测试网Ruxx$M9x

Default.usp51Testing软件测试网e(Q? ^V x%kw$wz4v`

Load test configuration file51Testing软件测试网)B+] c`:Gz,f

Text

1``0ab P6ks0

Do not edit

"NC_)Sa-J:P3Y\u0

.usr

M,I'@8I(j'gO!bl0

Load test configuration file51Testing软件测试网&zl$zX r{Y

Text51Testing软件测试网.m-B1S7E q7F*\d8Oe

Do not edit

:kw){e,[I0

Thick_usr.dat

"@%Tnn#dG0

Load test configuration file

tu*Q P!`(L6Oq2F:I0

Text

3` ~+`c#pv0H:jF0

Do not edit51Testing软件测试网5nGm @.yq;nyki

Thin_usr.dat

E^ Q:P w$V0

Load test configuration file51Testing软件测试网 ?CP6E!e|

Text51Testing软件测试网3R a6?TaR'|4[8w

Do not edit

JZ3E3B#|/W0

Files within Action folder:

h b*O8y-[9o%[)j0

File Name51Testing软件测试网$\4c"??9Ui(~

Descrīption51Testing软件测试网~8Hb*eU-]L!l

Type

!k9y%Cp g q-cJ0

Comments Regarding File

~|,I4u2a0

scrīpt.mts

JH3`1{x] fp0]%V0

Action scrīpt

cm;o%{J0

Text51Testing软件测试网-J0Z ^"GX/SK!a0t

Edit text preceding the @@ sign only51Testing软件测试网)N@b*gm

Resource.mtr

R+D0ss)I+n-mrr0

Object Repository51Testing软件测试网%`3|k JF9M%lgO2p$K ? p

Binary51Testing软件测试网{)z~iYtT*pg

Do not edit51Testing软件测试网*X y1B[}~aG

Snapshots51Testing软件测试网J"J(t@^?

Active screen files51Testing软件测试网})s7_ J;~Z

Folder

`S5|Mfs v0

Do not edit

u6l8]z2?0

There are few more files extensions like51Testing软件测试网CE4G|@n2mV

.MTB Batch File51Testing软件测试网,zm'hV;m'g2k
.LCK Locked

om4k_ a.DYd0

51Testing软件测试网F4H"~'{LGe\
10) How to rename a checkpoint (QTP 9.0)?
,]&hWC Kg0Example:
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'qTr v/A&|w*LR
3. In the Name field, enter the new checkpoint name.
TE:fO&z!fxW04. Click. The name of the checkpoint object will be updated within the scrīpt.
-{{O"V@NG0W1d0Example:51Testing软件测试网`#?z._x:t4I
Window("Notepad").WinEditor("Edit").Check CheckPoint("NewCheckPointName")51Testing软件测试网VLm&B fz:SsUH
Note:
C[H:N.n a~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:

e9l!N1hvx%DJ9Y;o+k0

"The "" CheckPoint object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object."

C#hH+Jp0

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.

e ESK:K-u"Vk0

<!--[if !supportEmptyParas]--> <!--[endif]-->

a;wRQ.|6M*t u0

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
K EZjS0~ [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 `gO
QuickTest Professional 8.2 and below do not include support for Internet Explorer 7.0.51Testing软件测试网/d3X#@4|^Ho/T-m&} u

Does QuickTest Professional support Firefox?
-vz;{ll,n[waw0QuickTest 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:51Testing软件测试网_3_/YL:|HvS9l0m

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.

"[i"t;f*w0

The .Object property for web objects is not supported in FireFox.51Testing软件测试网8f}6@n-}+\

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:

8M(q"Ox1g0

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.51Testing软件测试网!E*G'e@&z K0EF1z

The .Object property for web objects is not supported in FireFox.51Testing软件测试网n-WB-D3fb1`

QuickTest Professional 8.2 and below

|pyDN(a#Cd0

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
HR@R!E0
After 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."

:e!U5S#E E9D4}ll0

If you start Window's Media Player first, it will continue to work normally after starting QuickTest Professional.51Testing软件测试网:N/o']Y%`

Solution:51Testing软件测试网}/e~ n0B6Y%ln v

Include the Windows Media Player's executable in the NoBBTApps section of the mic.ini file51Testing软件测试网W:v6Dpj#J bl

1. Close QuickTest Professional.51Testing软件测试网]L8wn'm*{3`na9N
2. Go to\bin\mic.ini.
0}4G5f kx ZPO03. Includewmplayer.exein the NoBBTApps section of mic.ini file.
51Testing软件测试网%zbf6@ `5Gi

Example:
H\#Bui0d.t|-b0[NoBBTApps]
%]Y[#\[0wmplayer.exe=rek
51Testing软件测试网p!]1a(R(} ] Y

4. Save the mic.ini file and restart QuickTest Professional.51Testing软件测试网7XcN ^Q

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
51Testing软件测试网 fLs IaJ"u*F

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.

;jLN4NFu0

File Location:
/}0E/fR!q u;?$@zY&O0
51Testing软件测试网n+p*Id E]*?"t
1) For a Concurrent (Floating) license installation:
51Testing软件测试网l sF `Nm

"#server installation directory#\#language#"

RE;x @Q6[Gka0

Example:51Testing软件测试网 g|5q&q|_8{^i
C:\Program Files\XYZ Technologies\ABC Server\English\lservrc
51Testing软件测试网,^kF#R.^r'C6s

2) For a Seat (Stand-alone) license installation:

.C}4IDp@M0

#AQT/QTP installation directory#\bin"

K'Z%smps0

Example:
5r#?!f Cl9Ym`0C:\Program Files\Mercury Interactive\QuickTest Professional\Bin\lservrc
51Testing软件测试网)R({{,fonE

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.

)}Z4q?1`(a;a R@s'Y0

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;`6i2t0

When 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%F0

You 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[5K2F Ram

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[0

Set WebEditObj = Browser("Mercury Tours").Page("Method of Payment").WebTable("FirstName").ChildItem (8, 2, "WebEdit", 0)51Testing软件测试网-BXQf}(k F[

WebEditObj.Set "Example"

*p[ZA"P4p+M0

The following example requires parentheses around method arguments, sinceCallis being used.

,cb ier\A6WOR-l0

Call RunAction("BookFlight", oneIteration)

k2nv Szm5d!qmM0

The 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

~TF n uH XS0

The following example requires parentheses around method arguments, since it returns the value of the checkpoint.

/JP6^pq%d O&N0c0

a = 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 t0

Browser("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\/EUF6e0

e_pwd = Crypt.Encrypt(pwd)

&`G.a0N0pl|#lR0

Browser("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)D0

fileName = Environment.ExternalFileName51Testing软件测试网 |V3w*?:ci s

If (fileName = "") Then

BT@2w2Q MJ0

       Environment.LoadFromFile("C:\Environment.xml")

1Zl0F!FD)O@Xo8@I0

End If51Testing软件测试网 H9RP2@ T3n

'display value of one of the Environment variables from the External file

t5TxL4|9T1E A0

msgbox Environment("MyVarName")51Testing软件测试网^1Z p\"n1F]"_)S

 51Testing软件测试网1ru,Vz,I@


TAG: QTP

 

评分:0

我来说两句

Open Toolbar