Basics of RFT Scripting_TTBB
Transcript of Basics of RFT Scripting_TTBB
![Page 1: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/1.jpg)
1
Basics Of RFT Java Scripting
![Page 2: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/2.jpg)
2
Contents
Basics of Java used for RFT scripting Java Objects Java Class Java Methods Steps for Java scripting Best Practices for RFT Script Writing Demo
![Page 3: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/3.jpg)
3
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.
![Page 4: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/4.jpg)
4
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 Declaration
(type name :Date EMPJoin)
Object Instantiation
(new)
Object Initializationtype(value) : Date(1996,8,30)
![Page 5: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/5.jpg)
5
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
![Page 6: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/6.jpg)
6
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)
{ System.out.println{"Hello World!"); }
method declaration
method body
![Page 7: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/7.jpg)
7
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
![Page 8: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/8.jpg)
8
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.
![Page 9: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/9.jpg)
9
Add Empty Script• Right Click on test folder Add Empty Script.• Enter name of script(Login_demo) and click on Finish.
![Page 10: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/10.jpg)
10
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’
![Page 11: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/11.jpg)
11
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 3: Click on Finish
Step 2: Test Object will now appear in test object map
![Page 12: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/12.jpg)
12
Perform Action Under Test Tester insert the action to be undertaken on the test object inserted in
pervious step.
AUT Command
![Page 13: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/13.jpg)
13
Insert Verification Points
In this step insert the verification which are expected to be verified.
mainwindow().performTest( mainPanelVP() );
Step 1 : Right click on VP and select Insert VP Step 2: Select Object to be verified.
Step 3 : Select type of VP
Step 4: command for VP in Script
![Page 14: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/14.jpg)
14
Script view After adding test object , AUT and verification points script will
appear like this
![Page 15: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/15.jpg)
15
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
![Page 16: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/16.jpg)
16
Call methods in test case script
After calling methods in test case script it appears like this :
![Page 17: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/17.jpg)
17
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
![Page 18: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/18.jpg)
18
Try catch Handle uncaught exception by surrounding with try/catch or adding catch block to a
surrounding try block .
![Page 19: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/19.jpg)
19
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.
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.
![Page 20: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/20.jpg)
20
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
![Page 21: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/21.jpg)
21
readyState()
.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
![Page 22: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/22.jpg)
22
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();
![Page 23: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/23.jpg)
23
Selection of type of VP to be used
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 Manual VP
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();
![Page 24: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/24.jpg)
24
Questions
![Page 25: Basics of RFT Scripting_TTBB](https://reader033.fdocuments.in/reader033/viewer/2022061123/54742374b4af9fcc108b471e/html5/thumbnails/25.jpg)
25
Thank You