51Testing软件测试网/z|U8JtFy4P,k本文是为那些疑惑转换到 Rational Functional Tester 是否真的那么容易的 Rational Robot
的用户准备的。答案是:简单。利用定制的验证点作为实例,本文将对比这两种产品,向您展示它们的使用是多么相似。
JW&m~.\va-x051Testing软件测试网5D{ a/S,}/dr4F
引言
Z4sp+L.}!Z:D
xC051Testing软件测试网f
Qu4UnJA
使用 IBM? Rational? Robot 的客户常常问,从 Rational Robot 迁移到 IBM? Rational?
Functional Tester (RFT) 上有多难。本文使用了一些实例来告诉您进行迁移是多么容易,并且用户的使用经验是多么相似。人工编码可以增加测试脚本的功能和稳定性,所以人工验证点将是比较和对比
Rational Robot 和 RFT 的基础。要介绍一些实际的实例,就有必要在此验证点周围建立某种逻辑。该逻辑安排在不同的部分中:51Testing软件测试网6@#o#k$LWbku
- 读取 Place Order 按钮的文本属性(参见图 1)
- 打开并创建文件
- 将文本属性写入该文件
- 打开另一个文件,并读取该文件的内容(期望值=BASELINE)
- 将基线与实际结果比较
- 撰写一条日志消息
51Testing软件测试网-Lq\!_e o每一个部分都显示出为 Rational Robot 和 RFT 编码的区别。此外,所有的实例测试脚本包含同样的内容。尽管 RFT
Java? 脚本实例包含额外的错误处理。解释 Rational Robot 和 RFT 是什么已超出本文的范围。本文也不介绍如何记录并回放测试脚本。
51Testing软件测试网^
J$R.k0]0G
O
W |4r*G$u;q%M
xo0 安装与配置51Testing软件测试网%\ K
T C o#uWKm
J5A]w"NqE0 您应该安装以下内容:51Testing软件测试网.mK@9`dj
- Rational Robot
- RFT Java
- RFT VB .NET
- Java ClassicsB Application
51Testing软件测试网!sx
LGZF-lR+})Z2X;h+V:E使用记事本(或者类似的纯文本编辑器),创建一个名为 Expected.txt 的文件,内容是Place Orders,并且将其保存在
C:\ 之下。其将作为之前提到的基线文件。要为此实例配置您的环境,按照以下步骤:
l{nwvOn0- 在安装完 Rational Robot 之后,运行 Java 测试启动器,单击 Start > Programs
> Rational Software > Rational Test > Java Enabler
- 在安装完 Rational Functional Tester 之后,启动环境并启动用于测试的应用程序。要做到这些,在
RFT 菜单上单击Configure > Enable Environment for Testing and Configure
> Configure Application for Testing
- 使用该实例代码的最佳途径是获取一个名为 read_and_write 的空脚本,复制实例脚本来替代它。
- 打开对象映射并插入 Place Order 按钮,如图 1 所示。
!bp'f U
b;q^aY2R;H0图 1. Place Order 按钮
y)A;l3Li[IQl*O'}0 51Testing软件测试网2gkB{^.E/B!A
创建一个人工验证点51Testing软件测试网j uKV4w zK
U"q
51Testing软件测试网^u6zW{ ?#pusW$B 图 2 例举了在每个产品中的人工验证点编码。
]dF2q9{ag(ck%\051Testing软件测试网EI"M,?+g1hX0A
图 2. 对验证点编码
~N0vE7E\ye0
hI]:K~-~y`{~0 Rational Robot
SQA Basic 命令中,您需要在脚本中撰写对象识别参数,这需要对您的部分进行额外的考虑。然后,将来自属性(Property)文本的值分配给字符串变量
MyText。一般来说,将所有可识别属性分配给一个变量是可能的。RFT 脚本中的对象指向对象映射中的对象。要输入代码,使用编辑器功能是非常有帮助的。在这种情况下,输入前两个字符并按下
strg 和 space 键。一个有效方法的列表出现了,您可以快速简单地进行选择。
mA`8yw1b5byT0C4z i2~P9u#@0 在 Java 和 VB .NET 脚本中,您可以直接从左到右阅读验证点。这使您更容易理解其内容。例如:String 变量 strProperty_Text
的内容等于与对象 placeOrder 有关的内容。对象和方法之间的关系位于对象之后。
#_5W_yG*ra)m/R
O'j0Kc(S c!rZ4d,q*?;A0 在此实例中,方法为 getProperty。要指定属性,您需要输入属性的类型(“Text”)。这样 srtProperty_text
变量从placeOrder 对象那里获得了文本(Place Order)的属性值。
51Testing软件测试网4|V*TTp,BG`X){U__ fWWBsa0 创建并打开文件0y&oKY_h051Testing软件测试网px%RrYk'_3z 在此部分中,脚本将打开文件 c:\Buton_Text.txt 并保存属性值文本,如图 3 所示。
Q'b)JZ5H}T^051Testing软件测试网m9\4m ]&Q [)[ 图 3. 脚本打开文件并保存属性文本
51Testing软件测试网CN?w@:xVx ;v
y/i&l&ld0GYbW5E;zpb2U0 通过此实例,应该更加清楚的是,在 Rational Robot 和 RFT 中,创建此类验证方法的命令和功能是类似的。在每个产品中,用三行代码创建、打开并撰写文件都是可能的。
51Testing软件测试网iE{:{9h1n~C~
Sg3o!~5Ih%l Hw0 打开并阅读文件
}^*KY
E0e:L"u051Testing软件测试网@R}gAI 图 4 显示如何打开文件 c:\Expected.txt 并在 String 中书写内容。
i.XHBxy&cBK0 图 4. 打开并阅读文件
51Testing软件测试网6rf@Ua#Jqs L3w.St:bz)Vj V051Testing软件测试网A8R4Olo$h 比较数据 m6G f1Kr+]}2e\0,z r\PIy2Uh:f'@0 图 5 中的脚本比较了两个 String 变量并生成了一个日志消息。
51Testing软件测试网DGFP/t+Ddi 图 5. 比较数据
&Z2V\K%h'`{ ~hW|0 51Testing软件测试网I7b1\.k x
w0{MHx{s)wS0b%s0 如您所见,除了一些开发环境的细节,两个产品之间的编码差别是极小的。不论您使用 Rational Robot 或是 RFT,实现此类编码的工作是一样的。此外,如果您知道SQA-Basic
命令,那么在测试脚本中实现额外的功能 —— 利用 RFT 编辑器(输入开头字符并按下 Strg 和 Space 键)的帮助—— 是很容易的。
51Testing软件测试网6P%spSPC's:tay)Ftd8OE Jc
Z)^YJ3t0 清单51Testing软件测试网9?8t&v-zx(Q)Q1FRH~0 清单 1. Rational Robot 脚本:SQA Basic
Sub Main51Testing软件测试网gy
Z6L6N Dim Result As Integer 3x~!S eNW0Dim MyText as Variant51Testing软件测试网1_~ Ez)fpy6h,Tg(m Dim strFilename as String *}H9uTn0Dim intFileNum as Integer &j$[8ex\0UmJH0Dim strZeile as String51Testing软件测试网"^:@9@J%|,[ Dim strLine as string zWaP(~q3J0strFileName= "c:\Button_Text" Qx
zZ8g]:RM,c0intFileNum = FreeFile() {Yp)K+X']K;[qX0'scrīpt Name: read_and_write 3Pi^mN7zKD051Testing软件测试网k5g&p darv3J"b8~ 51Testing软件测试网0U,])C1@"Y0jsQ StartJavaApplication Class:=
hekn+|Ba-A}0"""C:\Program
Files\IBM\Rational\SDP\6.0\FTSamples\ClassicsJavaB.jar""",
C4A2R7TG2R&u0JvmKey:="Java", JvmOpts:="-jar"51Testing软件测试网:J5n7Kr Ec(^ c 51Testing软件测试网+K:hW$A LeV\ Window SetContext, "Caption=ClassicsCD", ""51Testing软件测试网dCL,y
Nd ~#sI
8B8UD!u.I{^&{,M0Result = SQAGetPropertyAsString("Type=PushButton;Name=Place
Order", "Text", MyText) l%[D/[9w~&kKm0Open strFilename For Output AS # intFileNum51Testing软件测试网?X1VSCh!a Print #intFileNum,MyText51Testing软件测试网wF(n9_D:B d~+L ' The Value of the Pushbutton property text will be save in
c:\Button_Text51Testing软件测试网;~ KT/uX Close # intFileNum Tj;FJeZ0Y+P|jQn0 D\;|*fuKiG0'Open the file to read the content (b
{8r3L
}4K@`s0If strLine = myText then51Testing软件测试网`fcc;K/c.G SQALogMessage sqaPass, "The Button Text is correct: "
+ MyText, ""51Testing软件测试网&s?1l|'T else51Testing软件测试网
r}1[O#j[v SQALogMessage sqaFail, " Expected Pusch-button-Text = "
+ strLine, E;@$]OI(l"K0"The Button Text is incorrect"51Testing软件测试网\4yx&jG5qr^|@ end if ;RO/m#q;?m'WDU!R0End Sub |
!N+{9D{A_t0 清单 2. RFT 脚本:Java
import resources.read_and_writeHelper; G`sZrj0import java.io.*;51Testing软件测试网5?;A'H\!s ?v import javax.swing.JOptionPane;(`6_:P,D:Nq&Q/B5x2\c1m0public class read_and_write extends read_and_writeHelper51Testing软件测试网C7v"?K+Y6Q8q {51Testing软件测试网q\!M7r2{4~*n+B)? /* Before you can use this scrīpt you must create a c:\Expected.txt
file
q,n WH
F5ZB0* Write the value inside this file and save it.
j%y{#[h[4]y0* Descrīption : Functional Test scrīpt M#N#hJ^Hs;H0* @author Andreas Franke51Testing软件测试网 N.l+y/LQ"d}7Q;y public void testMain(Object[] args)51Testing软件测试网6r6aCXL { (H!s
} h3m _)R|^0FileWriter f1;51Testing软件测试网,HLtV Z.N"B BufferedReader f2; 'I|-pJ|-l0String line;51Testing软件测试网FUwi\Gs0@ b)s startApp("ClassicsJavaB"); #H-s0]KRG H*Q*T0String strProperty_Text=(String)placeOrder().getProperty("Text");51Testing软件测试网t2T\8Rz\h // Read the property Text from the Pushbutton51Testing软件测试网7c6q!T
k2?%CH/} S try +j\3z[9I
O0{51Testing软件测试网
TJJ&q!e:dr2u f1 = new FileWriter("c:\\Button_Text.txt");
_!Z1K#?9[m-r/F7s*B0// create a an outputfile Uj-r)eY
A
JVU0f1.write(strProperty_Text); &| K&|_5u G
b0// write the result from strProperty_Text in this file Pl]] [,p:x.GI0f1.close(); b)Io,Z'uO|z
x0} 7\5C'B%[9|{K0catch (IOException e)51Testing软件测试网3T8B/eIx
xc7A*g2V {51Testing软件测试网TG7G$BUnoW System.out.println("ERROR to create the folder"); V"z:a8I,SF.?&lL-q0logTestResult("ERROR to create the folder", false);51Testing软件测试网nI4d0D\ u$n // Write an Error-message in the tes-tmanager- ,l Qh?-nV;p)q0log51Testing软件测试网_1N0N'T9]t } EUn$Y)x0try51Testing软件测试网7[1~
gg"PgmA { 0b ET:Sf0f2 = new BufferedReader(new FileReader("c:\\Expected.txt")); u0[0pE.O+Y&[0while ((line = f2.readLine()) != null)51Testing软件测试网X/e!sH)@CJ { sJ sO3{ x0if (line.equalsIgnoreCase(strProperty_Text)) {Gb1i0v
F[8d:A0{51Testing软件测试网 g5W8a6oT9i:i logTestResult("The Button Text is correct", true);51Testing软件测试网,CF?;j"s[A7Vm2j } +h@Q5zq @0else hT%qQqOkj0{ UFv$sU0logTestResult("The Button Text is incorrect ", false, Sm'|{P!lQD0"Expected '"+line+"' but found '"+strProperty_Text+"'");51Testing软件测试网&z i2A f^?7k7A| JOptionPane.showMessageDialog(null,line,"The Button Text
is51Testing软件测试网H'A!jk0sM!h~&i incorrect",JOptionPane.INFORMATION_MESSAGE);51Testing软件测试网9W8O*E/]G\*i
C!{ } {c.m!g!\0`0} ?idJAY'Oh0f2.close(); pNuot4Sk0}51Testing软件测试网 D[2E6Xpm catch (IOException e) O[9X3O9T \J0{51Testing软件测试网LA)a#}T] System.out.println("Can`t find File");51Testing软件测试网m-{M,C;R*F logTestResult("Can`t find File", false);51Testing软件测试网0aLzLu ct } c ?,[T[{D0}51Testing软件测试网!BV3vLuX }51Testing软件测试网8amQ ?XP
7z:j#CjrR5Z0 |
51Testing软件测试网zM-nud-aP 清单 3. Rational Functional Tester 脚本:VB .NET
#Region " scrīpt Header
"
51Testing软件测试网1xJ(uN
dKM' Functional Test scrīpt
51Testing软件测试网"V kT8oE' author Administrator
[5MI9d2Kl?0Imports Microsoft.VisualBasic
51Testing软件测试网6aN9QJa e)bK [6eImports Rational.Test.Ft
|I*X,@0Z8U0Imports Rational.Test.Ft.Object.Interfaces
51Testing软件测试网:G_4n2_^]-|{Public Class read_and_write
~$|W[{
NsUp&ks0Inherits read_and_writeHelper51Testing软件测试网#y'J:z8~)\qe
/E4lE Y-}*c6l(h0'scrīpt Name : read_and_write
s0~-~+w@0HX6Xtb;Q|.Xj.z)lk0'author Andreas Franke
3[wj~0jWv#T
}"J08K.b#I)[I9x0Public Function TestMain(ByVal args() As Object)
hj/N.B'F
}&W0StartApp("ClassicsJavaB")
Gp,S*N'K"`h6D\|G051Testing软件测试网1p-w @
E
~|
' Frame: ClassicsCD51Testing软件测试网s%NlJe5KM&q
REM PlaceOrder().Click()51Testing软件测试网
E)GT+Z$b
Dim strFilename As String = "c:\Button_Text"51Testing软件测试网c i {M:t\QR#O
Dim strExpected As String = "c:\Expected.txt"
nIE7GZ:V0X3h-{~0Dim strProperty_text As String51Testing软件测试网_A8YG1o ?
Dim intFileNum As Integer
$J4O"S%PB*t0Dim strLine As String51Testing软件测试网.LA7SJ)mj
l{L!G1iThD3[0intFileNum = FreeFile()51Testing软件测试网;C5Q&vI]ln7f
51Testing软件测试网ak{ `#HU,srI-l5kjstrProperty_text = PlaceOrder.GetProperty("Text")51Testing软件测试网.P.Ny4HBGip
MsgBox51Testing软件测试网I
EJ,Lc`j9T_
(strProperty_text, MsgBoxStyle.Information, "The Text
on the Pushbutton is")51Testing软件测试网.xg)OGYI
FileOpen(intFileNum, strFilename, OpenMode.Output)
-IASFXF:EJ1|051Testing软件测试网 W3h0fF)`-~!eF$mPrint(intFileNum, strProperty_text)51Testing软件测试网l(i*t{i3o
' The Value of the Pushbutton property text will be save in51Testing软件测试网5G'~%|#l6wUa}K
'c:\Button_Text
&G5E#|(F:M5H&F%LN
dB0FileClose(intFileNum)51Testing软件测试网W2K&Vx&m
FileOpen(intFileNum, strExpected, OpenMode.Input)
r&l]H*@i0Input(intFileNum, strLine)
r{M)Lb0If strProperty_text = strLine Then
9s5dB9Hr0l/@5W0LogTestResult
M7A%yrlh0("The Pushbutton Text is correct", True, "Expected
Text = Actual Text")51Testing软件测试网7IH{IS9Z3qF
Else51Testing软件测试网"tf(O Gbj0_#P H
LogTestResult
*X)WX;Hk:ZqN0("The Pushbutton Text is incorrect!! Expected Text is
:
/cu
x%L%Ug3i.C5]0" + strLine, False, "but found the actual Text :
" + strProperty_text)
CF~h*w&v0MsgBox
:N,\i7a
B"r0(strProperty_text, MsgBoxStyle.Critical, "The Curent
Text is not the expected Text")
.{+S9[I} q|7a0End If
5k K$ot*Bk}0End Function
51Testing软件测试网,Kf)saC
PEnd Class