Beruflich Dokumente
Kultur Dokumente
Scripting
1
Contents
2
Java Objects
A Java object is a set of data combined with methods for manipulating data.
An object is made from a class; a class is the blueprint for the object.
Each object made from a class will have its own values for the instance variables of
that class.
The three steps to creating a Java object are:
Object Declaration
Object Instantiation
Object Initialization
Object Declaration - Declaring an object associates a variable name with an object.
Object Instantiation - Instantiating an object allocated space in memory for the
object. This is accomplished with the new operator
Object Initialization - Initializing an object fills the objects varibles with an initial set
of values. This is accomplished using a constructor.
3
Create Objects
This statement creates a new Date object (Date is a class in the java.util package).
This single statement actually performs three actions: declaration, instantiation, and initialization.
Object Instantiation
(new)
4
Java Class
A Java class is a group of Java methods and variables.
The implementation of a class is comprised of two components: the class declaration
and the class body.
The class declaration component declares the name of the class along with other
attributes such as the class's superclass, and whether the class is public, final, or
abstract.
The class body contains declarations for all instance variables and class variables
(known collectively as member variables) for the class
class Sample
{
class int variable a;
declaration int variable b; class body
String name;
}
5
Java Methods
A java method is a series of statements that perform some repeated task.
Every Java program must have one main() method.
A method implementation consists of two parts: the method declaration and the method
body.
A method declaration has a name and a return type indicating the data type of the value
returned by the method.
The method body is where all of the action of a method takes place.
method { method
declaration System.out.println{"Hello World!"); body
}
6
Steps for Java scripting
Identify the scenarios to be created as method and group of method to be
created as task
Create task and testcase folder
Add Empty Script
Declare Methods
Insert Test Object
Perform Action Under Test
Insert Verification Points
Call methods in test case script
Playback the Script
7
Create Task and Test Case folder
8
Add Empty Script
• Right Click on test folder Add Empty
Script.
• Enter name of script(Login_demo) and
click on Finish.
9
Declare Methods
By default one main method is already declared in script .
Syntax to declare method is ‘returnType methodName() { . . . } ‘
Below is the code to declare the method names ‘loginDetails’
10
Insert Test Object
In this step insert the test object which are required for the method
Step 1: Right Click on test objects and select insert test object.
Step 2: Test Object will now appear in test object map
11
Perform Action Under Test
Tester insert the action to be undertaken on the test object inserted in
pervious step.
AUT Command
12
Insert Verification Points
In this step insert the verification which are expected to be verified.
Step 1 : Right click on VP and select Insert VP Step 2: Select Object to be verified.
mainwindow().performTest( mainPanelVP() );
13
Script view
After adding test object , AUT and verification points script will
appear like this
14
Call methods in test case script
Import the script from task folder
whose method is to be used here.
15
Call methods in test case script
After calling methods in test case script it appears like this :
16
Best Practices for RFT Script Writing
Handle uncaught exception by surrounding with try/catch or adding catch block to a
surrounding try block.
17
Try catch
Handle uncaught exception by surrounding with try/catch or adding catch block to a surrounding
try block .
18
TestObject.find
The TestObject.find method is a Java™ method that the IBM Rational Functional
Tester tool uses to locate a TestObject in the application under test (AUT)
dynamically, at runtime.
The advantage is that you do not have to change the recognition properties stored
in an Object Map, so you avoid the more tedious and time-consuming way of using
the Object Map UI to make the changes or rerecording the object to update it.
Methods which can be used with find are :
atChild searches for any direct child of the TestObject.
atList lets you specify a list of atChild, atDescendant, and atProperty objects, so
you can narrow the search.
19
Delete cookies
20
readyState()
Sample Code
21
waitForExistance()
Each browser start up time is different .for e.g. wait time in IE is less as compared to
Netscape.
Above property causes problem while doing cross platform execution.
To avoid the above problem tester can use ‘waitForExistence()’ method of RFT
Below is the sample code.
startApp(“test”);
browser_html. waitForExistence();
home().click();
22
Selection of type of VP to be used
When to use Manual VP
Manual verification points are useful when tester create the data for the verification point
yourself, and than want to compare the data.
The data could be the result of a calculation or could come from an external source, such as a
spreadsheet, datapool, database, or custom calculation.
vpManual ("ManualVP_01", "Check something manually.", "Check something
manually.").performTest();
23
Questions
24
Thank You
25