Sub Main
Dim Result As Integer
Dim MyText as Variant
Dim strFilename as String
Dim intFileNum as Integer
Dim strZeile as String
Dim strLine as string
strFileName= "c:\Button_Text"
intFileNum = FreeFile()
'Script Name: read_and_write
StartJavaApplication Class:=
"""C:\Program Files\IBM\Rational\SDP\6.0\FTSamples\ClassicsJavaB.jar""",
JvmKey:="Java", JvmOpts:="-jar"
Window SetContext, "Caption=ClassicsCD", ""
Result = SQAGetPropertyAsString("Type=PushButton;Name=Place Order", "Text", MyText)
Open strFilename For Output AS # intFileNum
Print #intFileNum,MyText
' The Value of the Pushbutton property text will be save in c:\Button_Text
Close # intFileNum
'Open the file to read the content
If strLine = myText then
SQALogMessage sqaPass, "The Button Text is correct: " + MyText, ""
else
SQALogMessage sqaFail, " Expected Pusch-button-Text = " + strLine,
"The Button Text is incorrect"
end if
End Sub
清单 2. RFT 脚本:Java
import resources.read_and_writeHelper;
import java.io.*;
import javax.swing.JOptionPane;
public class read_and_write extends read_and_writeHelper
{
/* Before you can use this script you must create a c:\Expected.txt file
* Write the value inside this file and save it.
* Description : Functional Test Script
* @author Andreas Franke
public void testMain(Object[] args)
{
FileWriter f1;
BufferedReader f2;
String line;
startApp("ClassicsJavaB");
String strProperty_Text=(String)placeOrder().getProperty("Text");
// Read the property Text from the Pushbutton
try
{
f1 = new FileWriter("c:\\Button_Text.txt");
// create a an outputfile
f1.write(strProperty_Text);
// write the result from strProperty_Text in this file
f1.close();
}
catch (IOException e)
{
System.out.println("ERROR to create the folder");
logTestResult("ERROR to create the folder", false);
// Write an Error-message in the tes-tmanager-
log
}
try
{
f2 = new BufferedReader(new FileReader("c:\\Expected.txt"));
while ((line = f2.readLine()) != null)
{
if (line.equalsIgnoreCase(strProperty_Text))
{
logTestResult("The Button Text is correct", true);
}
else
{
logTestResult("The Button Text is incorrect ", false,
"Expected '"+line+"' but found '"+strProperty_Text+"'");
JOptionPane.showMessageDialog(null,line,"The Button Text is
incorrect",JOptionPane.INFORMATION_MESSAGE);
}
}
f2.close();
}
catch (IOException e)
{
System.out.println("Can`t find File");
logTestResult("Can`t find File", false);
}
}
}
清单 3. Rational Functional Tester 脚本:VB .NET
#Region " Script Header "
' Functional Test Script
' author Administrator
Imports Microsoft.VisualBasic
Imports Rational.Test.Ft
Imports Rational.Test.Ft.Object.Interfaces
Public Class read_and_write
Inherits read_and_writeHelper
'Script Name : read_and_write
'author Andreas Franke
Public Function TestMain(ByVal args() As Object)
StartApp("ClassicsJavaB")
' Frame: ClassicsCD
REM PlaceOrder().Click()
Dim strFilename As String = "c:\Button_Text"
Dim strExpected As String = "c:\Expected.txt"
Dim strProperty_text As String
Dim intFileNum As Integer
Dim strLine As String
intFileNum = FreeFile()
strProperty_text = PlaceOrder.GetProperty("Text")
MsgBox
(strProperty_text, MsgBoxStyle.Information, "The Text on the Pushbutton is")
FileOpen(intFileNum, strFilename, OpenMode.Output)
Print(intFileNum, strProperty_text)
' The Value of the Pushbutton property text will be save in
'c:\Button_Text
FileClose(intFileNum)
FileOpen(intFileNum, strExpected, OpenMode.Input)
Input(intFileNum, strLine)
If strProperty_text = strLine Then
LogTestResult
("The Pushbutton Text is correct", True, "Expected Text = Actual Text")
Else
LogTestResult
("The Pushbutton Text is incorrect!! Expected Text is :
" + strLine, False, "but found the actual Text : " + strProperty_text)
MsgBox
(strProperty_text, MsgBoxStyle.Critical, "The Curent Text is not the expected Text")
End If
End Function
End Class