不要追求绝对的公平,红尘之中没有公平而言,人活一世,难得糊涂。                                           it is no use doing what you like, you have got to like what you do.

对比使用 Robot 和Functional Tester

上一篇 / 下一篇  2007-01-09 11:52:53 / 个人分类:Robot技术

51Testing软件测试网 h o)y-Fw

本文是为那些疑惑转换到 Rational Functional Tester 是否真的那么容易的 Rational Robot 的用户准备的。答案是:简单。利用定制的验证点作为实例,本文将对比这两种产品,向您展示它们的使用是多么相似。51Testing软件测试网2| d ]7jX

v7T%r7rnR1w B0  引言
m.H&C Y x&}o051Testing软件测试网$a"CWs0yJD+_
  使用 IBM? Rational? Robot 的客户常常问,从 Rational Robot 迁移到 IBM? Rational? Functional Tester (RFT) 上有多难。本文使用了一些实例来告诉您进行迁移是多么容易,并且用户的使用经验是多么相似。人工编码可以增加测试脚本的功能和稳定性,所以人工验证点将是比较和对比 Rational Robot 和 RFT 的基础。要介绍一些实际的实例,就有必要在此验证点周围建立某种逻辑。该逻辑安排在不同的部分中:51Testing软件测试网$OAc(W4]N9H

  • 读取 Place Order 按钮的文本属性(参见图 1)
  • 打开并创建文件
  • 将文本属性写入该文件
  • 打开另一个文件,并读取该文件的内容(期望值=BASELINE)
  • 将基线与实际结果比较
  • 撰写一条日志消息
51Testing软件测试网"Z!G/Zw:`.CTz5fF

每一个部分都显示出为 Rational Robot 和 RFT 编码的区别。此外,所有的实例测试脚本包含同样的内容。尽管 RFT Java? 脚本实例包含额外的错误处理。解释 Rational Robot 和 RFT 是什么已超出本文的范围。本文也不介绍如何记录并回放测试脚本。   51Testing软件测试网x8oB.m2p)h

(O9P(\Tk0  安装与配置
'].SK%X@!i051Testing软件测试网PaUxN2l }i
  您应该安装以下内容:51Testing软件测试网1^)n6J,k5CPSfb

  • Rational Robot
  • RFT Java
  • RFT VB .NET
  • Java ClassicsB Application
51Testing软件测试网*A/N@5F5fk a%W

使用记事本(或者类似的纯文本编辑器),创建一个名为 Expected.txt 的文件,内容是Place Orders,并且将其保存在 C:\ 之下。其将作为之前提到的基线文件。要为此实例配置您的环境,按照以下步骤:51Testing软件测试网U\c0c#f4gB

  1. 在安装完 Rational Robot 之后,运行 Java 测试启动器,单击 Start > Programs > Rational Software > Rational Test > Java Enabler
  2. 在安装完 Rational Functional Tester 之后,启动环境并启动用于测试的应用程序。要做到这些,在 RFT 菜单上单击Configure > Enable Environment for Testing and Configure > Configure Application for Testing
  3. 使用该实例代码的最佳途径是获取一个名为 read_and_write 的空脚本,复制实例脚本来替代它。
  4. 打开对象映射并插入 Place Order 按钮,如图 1 所示。
51Testing软件测试网 } wIa@

图 1. Place Order 按钮51Testing软件测试网jHGT:K*BE
  51Testing软件测试网 k0qQt"f&mVj;Db
  创建一个人工验证点

8p2X _IJ7LF y051Testing软件测试网%t,Iw*W-TnY%@?h^7Z

 图 2 例举了在每个产品中的人工验证点编码。51Testing软件测试网t@9~J)UF @y

&P`}_;Z6r#jS/r0  图 2. 对验证点编码
dyqC-G QK0  51Testing软件测试网3|L.a.| {7W!c-qn {

  Rational Robot SQA Basic 命令中,您需要在脚本中撰写对象识别参数,这需要对您的部分进行额外的考虑。然后,将来自属性(Property)文本的值分配给字符串变量 MyText。一般来说,将所有可识别属性分配给一个变量是可能的。RFT 脚本中的对象指向对象映射中的对象。要输入代码,使用编辑器功能是非常有帮助的。在这种情况下,输入前两个字符并按下 strg 和 space 键。一个有效方法的列表出现了,您可以快速简单地进行选择。
t$@ ]$W?G!PlV)vKf#t9r0
G)} U'?(Gp0  在 Java 和 VB .NET 脚本中,您可以直接从左到右阅读验证点。这使您更容易理解其内容。例如:String 变量 strProperty_Text 的内容等于与对象 placeOrder 有关的内容。对象和方法之间的关系位于对象之后。51Testing软件测试网Jmf:[]

P Avvpnx.G0  在此实例中,方法为 getProperty。要指定属性,您需要输入属性的类型(“Text”)。这样 srtProperty_text 变量从placeOrder 对象那里获得了文本(Place Order)的属性值。51Testing软件测试网#L1[6C FR
51Testing软件测试网 jR+D/W%B0tE/M6a5HU
  创建并打开文件51Testing软件测试网Pl$he0O6G#v{%s'[

yh7jf%L@[:g0  在此部分中,脚本将打开文件 c:\Buton_Text.txt 并保存属性值文本,如图 3 所示。
0DV R i2_,s|jI051Testing软件测试网)@@]/[3e
  图 3. 脚本打开文件并保存属性文本
M.G]WWA u@x0  
p+Edv6y`eX]0
SR1[5G"x0  通过此实例,应该更加清楚的是,在 Rational Robot 和 RFT 中,创建此类验证方法的命令和功能是类似的。在每个产品中,用三行代码创建、打开并撰写文件都是可能的。
L1I#p1["@(N{/|0
GeK8e Im:ka0  打开并阅读文件
OE)k%J'^%i051Testing软件测试网w8q yZu
  图 4 显示如何打开文件 c:\Expected.txt 并在 String 中书写内容。
-U&ZvYC#G8f0  图 4. 打开并阅读文件51Testing软件测试网?N7W9d1UKUX
  51Testing软件测试网dRHQ-D#j$x8D
51Testing软件测试网T7r^p/s}3HB
  比较数据51Testing软件测试网F9Mj2e:M

7r7G7P)i#}8N0  图 5 中的脚本比较了两个 String 变量并生成了一个日志消息。51Testing软件测试网%{-gLkP/a#i0q5|
  图 5. 比较数据
O?0?Y-Gr0  
q!D6e R b5H5M-?-v9D051Testing软件测试网3Y i;L2xW A'b
  如您所见,除了一些开发环境的细节,两个产品之间的编码差别是极小的。不论您使用 Rational Robot 或是 RFT,实现此类编码的工作是一样的。此外,如果您知道SQA-Basic 命令,那么在测试脚本中实现额外的功能 —— 利用 RFT 编辑器(输入开头字符并按下 Strg 和 Space 键)的帮助—— 是很容易的。
ge['BP(c051Testing软件测试网&g8vBg!US2X3@@c
  清单
,aJi&W(S/n051Testing软件测试网 r!|k)D Z Vo;K
  清单 1. Rational Robot 脚本:SQA Basic
Sub Main
1ne)Y%EB0Dim Result As Integer51Testing软件测试网T+I o\ \8_b
Dim MyText as Variant51Testing软件测试网 S1cW An3y y^
Dim strFilename as String51Testing软件测试网vw4Gp-M4b+Jq
Dim intFileNum as Integer51Testing软件测试网YK'{ a%N/JO
Dim strZeile as String
Yq}E!iv.A.h0Dim strLine as string51Testing软件测试网|;Nl(L[r ~GLJ|
strFileName= "c:\Button_Text"51Testing软件测试网l.w*o"M pOcF
intFileNum = FreeFile()51Testing软件测试网*Q#Wm/K3~rf|
'scrīpt Name: read_and_write51Testing软件测试网v)d o#n$tI d)Z
51Testing软件测试网#Jod&K/\q|b

.y!@0qg v6df0StartJavaApplication Class:=51Testing软件测试网|3W1aZj/pd"eo*Q
"""C:\Program Files\IBM\Rational\SDP\6.0\FTSamples\ClassicsJavaB.jar""",51Testing软件测试网|1A]"JK/M+UF:u'p
JvmKey:="Java", JvmOpts:="-jar"51Testing软件测试网PhJ3qsW

9f+bO W^0Window SetContext, "Caption=ClassicsCD", ""51Testing软件测试网\6p3u7s"?6kP"f&]

"g7w r3t6|1e\0p1sBGF0Result = SQAGetPropertyAsString("Type=PushButton;Name=Place Order", "Text", MyText)51Testing软件测试网4Ki,G-@7[ }
Open strFilename For Output AS # intFileNum51Testing软件测试网%x"F*U7^k+K T6O-m
Print #intFileNum,MyText51Testing软件测试网(y#F;T ?Q.x2J4QTe2j
' The Value of the Pushbutton property text will be save in c:\Button_Text
cYG-DXx0Close # intFileNum
DM-e"bN0
2YmK"W@'N"@0'Open the file to read the content
kt'cHj.O | R?e0If strLine = myText then51Testing软件测试网.s:Z3`;@z
SQALogMessage sqaPass, "The Button Text is correct: " + MyText, ""51Testing软件测试网?]c.\7G!iHh&o J
else
K x'sa;h`E!K0SQALogMessage sqaFail, " Expected Pusch-button-Text = " + strLine,
q'V6aNC}0"The Button Text is incorrect"51Testing软件测试网#n7j F.Y:z2Y'Rr&G
end if51Testing软件测试网 V0q Hl_)c:A h fn[
End Sub
51Testing软件测试网c&h"UqD
  清单 2. RFT 脚本:Java    
import resources.read_and_writeHelper;51Testing软件测试网,[&k6m3h0z`5pP
import java.io.*;51Testing软件测试网 L$P_,Ao j,w
import javax.swing.JOptionPane;51Testing软件测试网7QlM(t Q

public class read_and_write extends read_and_writeHelper
q0Ym!Q_C9E0{
)L)hU+hS0/* Before you can use this scrīpt you must create a c:\Expected.txt file51Testing软件测试网f9r2rX;`$_0dj%U6vB:f
* Write the value inside this file and save it.51Testing软件测试网P%u$@9w q$|&oMW
* Descrīption : Functional Test scrīpt51Testing软件测试网~9Q F'@l#~L6}
* @author Andreas Franke51Testing软件测试网G0dgp6s8I
public void testMain(Object[] args)51Testing软件测试网&i/up&Er i~.w?S
{51Testing软件测试网)k4yD|"o?
FileWriter f1;51Testing软件测试网O|*QT^L;di
BufferedReader f2;
v,}$E:StcV0String line;
a3S5xWR/T][n&O4C0startApp("ClassicsJavaB");51Testing软件测试网0pfzn9P-jo"?[
String strProperty_Text=(String)placeOrder().getProperty("Text");
:DSM1E,F%k0// Read the property Text from the Pushbutton51Testing软件测试网wm_GZ M0~I8M
try51Testing软件测试网$]EQ Hsny
{51Testing软件测试网*J1[)~O1H"G ?f`O @
f1 = new FileWriter("c:\\Button_Text.txt");51Testing软件测试网f(LdpU(D
// create a an outputfile
r!y qs4d{Jqz0f1.write(strProperty_Text);51Testing软件测试网@2F1O B%PF0o
// write the result from strProperty_Text in this file51Testing软件测试网5s-}Iwi8QI(L%U[wH
f1.close();
ju yTt o |(w0}51Testing软件测试网 PcxyIT^+C,A _S2Z
catch (IOException e)
A n;k.b^0{51Testing软件测试网D"zb I)W
System.out.println("ERROR to create the folder");51Testing软件测试网0c1Nq(y/J
logTestResult("ERROR to create the folder", false);
-i#?c]&s5w*Qn0// Write an Error-message in the tes-tmanager-51Testing软件测试网H)~)t%X#d
log51Testing软件测试网M1Z+h$q4Y z
}
*v oC B n yP0try
!U k6C uUS0{51Testing软件测试网:[,m4Ccd0^Y7e#[
f2 = new BufferedReader(new FileReader("c:\\Expected.txt"));51Testing软件测试网^H#T5Od&l(Gm;J p)FS
while ((line = f2.readLine()) != null)51Testing软件测试网?3] N5@s)V L^z'D
{
-Q] C6D3r'T)`F h0if (line.equalsIgnoreCase(strProperty_Text))
{9k5UWm0{
yDwMD0logTestResult("The Button Text is correct", true);
f ^Wn5C5cU0}
`|mS@l:\0else
7YD0V5Uet#^/m0{51Testing软件测试网|E9U7XN~7|
logTestResult("The Button Text is incorrect ", false,51Testing软件测试网 c+p9F IBU%e/w(d
"Expected '"+line+"' but found '"+strProperty_Text+"'");
#` m1} W] YCH0JOptionPane.showMessageDialog(null,line,"The Button Text is51Testing软件测试网do@"Q$LScWV8|:vs
incorrect",JOptionPane.INFORMATION_MESSAGE);51Testing软件测试网IRd#on i
}51Testing软件测试网Y R9PO?K$j z'n;Y _
}51Testing软件测试网(JN A4B_4|nw
f2.close();51Testing软件测试网2g0@-Y8v&e9h t@:D P
}
`K1fel0@#KA.T(Nb0catch (IOException e)
w/`9cH/`8z(XX{(u0{
7bC%T"\(NUm\0System.out.println("Can`t find File");
9ab d%uW-@d(u]0logTestResult("Can`t find File", false);
!cpvHa+q q/h0}51Testing软件测试网&A z;V&W"e
}51Testing软件测试网Lot)c@n d b
}
/gc)XG1viP9f}0

!C}0U dTb-p)]C0

qU A,|4@WFz0  清单 3. Rational Functional Tester 脚本:VB .NET #Region " scrīpt Header "
6TRt G o;A [0' Functional Test scrīpt51Testing软件测试网1i@x'yK/K&ZRhA`
' author Administrator51Testing软件测试网;gsXK&?+n {
Imports Microsoft.VisualBasic51Testing软件测试网R3P8tp:YN{$X
Imports Rational.Test.Ft
*}3S%I)h&v-C6_ Tx*j$s!f-G0Imports Rational.Test.Ft.Object.Interfaces51Testing软件测试网 m \p `1PJ a6[!g

Public Class read_and_write
]U,E-vQ.bP4`kQ0Inherits read_and_writeHelper51Testing软件测试网}w.uB6jTxe?

Z0mP"Ir9A?0'scrīpt Name : read_and_write51Testing软件测试网?7W9B-e:Vd

I#@#zU/[0'author Andreas Franke51Testing软件测试网'b)@,Y#m%EN+[`!e6C

;TeO OxqM0Public Function TestMain(ByVal args() As Object)51Testing软件测试网b!bgeT:KMn
StartApp("ClassicsJavaB")51Testing软件测试网gB E/d \DjC!i

*\*b,g.~,Z'n$^0' Frame: ClassicsCD
5n-E3lPK0REM PlaceOrder().Click()51Testing软件测试网7U#q2D C`TQj@,Th
Dim strFilename As String = "c:\Button_Text"51Testing软件测试网s@~ z]qI/N
Dim strExpected As String = "c:\Expected.txt"51Testing软件测试网"CG.s cF4Gw
Dim strProperty_text As String
qu#E"h:Y ]/b@ l0Dim intFileNum As Integer
Uu?vE6v0Dim strLine As String
C5\ q$Fs4sg0
(O Tb2Xx z*A0intFileNum = FreeFile()

6\H3L$B$r0

Xa,t;Sap!G?0strProperty_text = PlaceOrder.GetProperty("Text")
8}W@JvD3c6bw0MsgBox51Testing软件测试网Jp HC Y`sR
(strProperty_text, MsgBoxStyle.Information, "The Text on the Pushbutton is")
6b3| M#TW$E3N%h0FileOpen(intFileNum, strFilename, OpenMode.Output)

/gh;X R R_!n N4~0

r.o7dcg!QEU W0Print(intFileNum, strProperty_text)51Testing软件测试网m5{p'N N D
' The Value of the Pushbutton property text will be save in51Testing软件测试网b5s!M4tgR9r,k
'c:\Button_Text
~,} u^P o Lj0FileClose(intFileNum)51Testing软件测试网RP-i%C4g.Q/_$o#Vq
FileOpen(intFileNum, strExpected, OpenMode.Input)51Testing软件测试网9eT9P |._W
Input(intFileNum, strLine)
1m$V;j"ur }Ms&L0If strProperty_text = strLine Then51Testing软件测试网hJ:j^4|"p
LogTestResult
eks2Y4F0("The Pushbutton Text is correct", True, "Expected Text = Actual Text")
fj/x+?i0Else51Testing软件测试网'PbN4z+VM"Y
LogTestResult51Testing软件测试网R.GWH ZZ
("The Pushbutton Text is incorrect!! Expected Text is :51Testing软件测试网Q#Y,L4u,rZ
" + strLine, False, "but found the actual Text : " + strProperty_text)
)MP2L/H;Z.a-e5][Uy0MsgBox
6Lf*D*aWB5a)e Gf0(strProperty_text, MsgBoxStyle.Critical, "The Curent Text is not the expected Text")51Testing软件测试网 V;@ IZ$i
End If

+l A-^ |7zbfI'V:xjW0End Function51Testing软件测试网/j]`Y x+{ b/hLO
End Class

TAG: Robot技术

 

评分:0

我来说两句

Open Toolbar