Basics of RFT Scripting_TTBB

download Basics of RFT Scripting_TTBB

of 25

  • date post

  • Category


  • view

  • download


Embed Size (px)

Transcript of Basics of RFT Scripting_TTBB

Basics Of RFT Java Scripting



Basics of Java used for RFT scripting Java Objects Java Class Java Methods Steps for Java scripting Best Practices for RFT Script Writing Demo


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.

Date EmpJoin = new

Date (1996, 8, 30 );

Object Instantiation (new) Object Declaration (type name :Date EMPJoin) Object Initialization type(value) : Date(1996,8,30)


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 { int variable a; int variable b; String name; }

class declaration

class body


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.

public static void main (String[] args) method declaration { System.out.println{"Hello World!"); } method body


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


Create Task and Test Case folder

Select the name of the project Right click new folder Enter names (as task and testcase) and select finish.


Add Empty Script Right Click on test folder Add Empty Script. Enter name of script(Login_demo) and click on Finish.


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


Insert Test Object

In this step insert the test object which are required for the methodStep 2: Test Object will now appear in test object map

Step 1: Right Click on test objects and select insert test object.

Step 3: Click on Finish


Perform Action Under Test

Tester insert the action to be undertaken on the test object inserted in pervious step.

AUT Command


Insert Verification Points

In this step insert the verification which are expected to be verified.Step 2: Select Object to be verified.

Step 1 : Right click on VP and select Insert VP

Step 3 : Select type of VP Step 4: command for VP in Script mainwindow().performTest( mainPanelVP() );


Script view

After adding test object , AUT and verification points script will appear like this


Call methods in test case script

Import the script from task folder whose method is to be used here. Declare the method Use the method


Call methods in test case script

After calling methods in test case script it appears like this :


Best Practices for RFT Script Writing

Handle uncaught exception by surrounding with try/catch or adding catch block to a surrounding try block. Use TestObject.find to locate a TestObject in the application under test (AUT) dynamically Use deleteCookies method in your scripts Check the .readystate of the browser object Use waitForExistence method to compensate for browser startup speed Selection of type of VP to be used


Try catch

Handle uncaught exception by surrounding with try/catch or adding catch block to a surrounding try block .



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 timeconsuming 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. atDescendant looks for any 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

By deleting cookies in scripts , script execution become faster. There are two types of method available in RFT for deleting cookies Method 1 delete Cookies() Description :- Deletes all of the browser's cookies. Method 2 delete Cookies (java.lang.String cookie, boolean recursive) Description :- Deletes browser cookies specified by the path in cookie



.readyState () is a property of HTML browser which indicates the current status of browser.i.e it indicates whether the browser is ready for use or not . It indicates the integer value and each integer represents the state in which browser is .For complete state integer value is 4. Sometimes script playback for testing HTML application fails if the ready state of the browser object is not 4 . To avoid above problem tester can capture and ensure that value should be 4 before moving further.String a = browser_html ().getProperty(".readyState").toString();

Sample Code



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();


Selection of type of VP to be usedWhen 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();

When to use Dynamic VP Sometimes, tester need to perform verification points on test objects that aren't in test object map. For that purpose dynamic VP is used Dynamic verification points raise the appropriate user interface the next time that the script is played back. vpDynamic ("DynamicVP_01", TestObjectHere()).performTest();




Thank You