advanced ibm rational functional tester, java scripting
TRANSCRIPT
1
Advanced IBM Rational Functional Tester, Java Scripting
Advanced IBM Rational Functional Tester, Java
Scripting
Class Book
Advanced IBM Rational Functional Tester, Java Scripting
Course Outline
• Module 1: Regular Expressions• Module 2: Functional Tester API• Module 3: HelperSuper Classes• Module 4: Dynamic Object Handling• Module 5: Custom Verification Points• Module 6: Handling Non-Java/Browser Windows
2
Advanced IBM Rational Functional Tester, Java Scripting
Prerequisities
• The prerequisities for this course is completionof either:
– The online training class titled Essentials of IBM Rational Functional Tester, Java Scripting: The Basics
– The instructor-led course titled Essentials of IBM Rational Functional Tester, Java Scripting: The Basics
And
– Java for IBM Rational Functional Tester
Advanced IBM Rational Functional Tester, Java Scripting
Course Materials
• There are 2 books issued with this class:
– Class Book– Lab Book
3
Advanced IBM Rational Functional Tester, Java Scripting
Suggested Daily Schedule
5:30 pmClass end
2:00 pmLunch
11:00 amMorning Break
9:00 amClass Start
Advanced IBM Rational Functional Tester, Java Scripting
Technical Support Information
www.qaforums.comwww.dundee.net/sqa
User Groups:QA ForumsSQA User Group
(+52) (55) 3300-0650www.itera.com.mx
Era Contact Information
www.rational.com/supportIBM Rational Software Support
www.ibm.com/developerworksIBM Developer Works
Rational TechnicalSupport
4
Advanced IBM Rational Functional Tester, Java Scripting
Help & ReferencesJava DocumentYou can view/download java documentation online at
http://java.sun.com/reference/api/(current version of the java compiler used by Functional Tester: 1.4.2)
Functional Tester DocumentationFunctional Tester documentation is accessed from the Functional Tester HelpMenu
Learning JavaFriedl, Jeffrey. Mastering Regular Expressions, 2nd Edition. O’Reilly, 2002Van der Linden, Peter. Just Java 2, Fifth Edition. Prentice Hal PTR, 2001-
Advanced IBM Rational Functional Tester, Java Scripting
Introductions
• Your organization• Your role• Your background, experience
– Software development experience
– Rational tools experience– Testing experience
• What you want from this course
5
Advanced IBM Rational Functional Tester, Java Scripting
Module 1
Regular Expressions
Advanced IBM Rational Functional Tester, Java Scripting
Regular Expressions
• Functional Tester installs with Rational's lightweight regular expression class- import com.rational.test.util.regex.*;
• Sun's regular expression package is in JDK 1.4.x:- java.util.regex
• We will cover com.rational.test.util.regex.*
6
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regular Expression Syntax: – public boolean matches(String strToCompare)
• /* The RE pattern is passed to the constructor to "compile" the regular expression. The match string is passed to the matches() method */
– Regex pattern = new Regex("in");– boolean b = pattern.matches("Fox in Socks");
• RE engine matches patterns without special characters.• Returns true, since 'in' is a subset of 'Fox in Socks'
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Selected Regex operators:
– * (asterisk)– + (plus)– . (period)– ? (question mark)– | (pipe)– () (parentheses)– [] (square brackets)– {} (curly braces)
Note: See the Functional Tester documentation for a more complete listing of regular expression operators.
7
Advanced IBM Rational Functional Tester, Java Scripting
• Regex character class operator: []used to match any one of several characters
Regex pattern = new Regex("gr[ae]y");pattern.matches("gray matter");
Returns true
pattern.matches("graey");Returns false
Regex pattern = new Regex ("www-[1-6]");
pattern.matches ("www-6.ibm.com") ;Returns true
Regex: matches()
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex negated character class: [^][^] negated character class
Regex pattern = new Regex("[A-E]-[^0-9]");
boolean b = pattern.matches("B-V");Returns true
b = pattern.matches("B-5");Returns false
8
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: . (period)– matches any single character
Regex pattern = new Regex("212.240.9050");boolean b =pattern.matches("212-240-9050"); b = pattern.matches("212 240 9050"); b = pattern.matches("212/240/9050")
Returns true
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: * (asterisk)– * matches 0 or more of the previous pattern
Regex pattern =new Regex("[0-9]* Dalmations");boolean b = pattern.matches("101 " + "Dalmations");
Returns true
b = pattern.matches("Red Dalmations");Returns true
b = pattern.matches("101 Terriers");Returns false
9
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: ? (question mark) – ? matches 0 or 1 of the previous pattern
Regex pattern =new Regex ("https?://");
b = pattern.matches ("https://");
Returns true
b = pattern.matches("http://");
Returns true
b = pattern .matches("httpx://");
Returns false
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: + (plus)– + matches 1 or more of the previous pattern
Regex pattern = new Regex("a+d");b = pattern.matches("aaaaad");
Returns true
b = pattern.matches ("d") ;Returns false, since 'd' is not 1 or more a's followed by a 'd'
b = pattern.matches("bbbbbd");Returns false, since 'bbbbbd' is not 1 or more 'a's followed
by a 'd'
10
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: | (pipe)– | acts as a logical Or
Regex pattern =new Regex("FunctionalTester|WinRunner|Silk");
boolean b =pattern.matches("They use SilkTest");
Returns true
b = pattern.matches("They switched to Functional");
Returns false
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: () (parentheses)– () are used to group patterns
Regex pattern = new Regex("a(bc)+d");b = pattern.matches("abcbcbcbcd");
Returns true
b = pattern.matches("bcbcbcbcd");Returns false
11
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Regex operator: {} (curly braces)– {} match a pattern a defined number of times.
• x{n} match 'x' exactly n times. • x{n,} match 'x' at least n times. • x{n,m} match 'x' at least n times and not more than m
times Regex pattern = new Regex("ba{3}d"); b = pattern.matches("baaad");
Returns trueb = pattern.matches("baaaad");
Returns falseRegex pattern = new Regex("ba{3,}d");b = pattern.matches("baad");
Returns falseb = pattern.matches("baaaad");
Returns true
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• Escaping regex operators
Regex pattern = new Regex("a[(]bc[)]d");b = pattern.matches("a(bc)d");
returns trueb = pattern.matches("abcd");
returns falseRegex pattern = new Regex("a+b+c");b = pattern.matches("a+b+c");
returns falseRegex pattern = new Regex("a[+]b[+]c"); b = pattern.matches("a+b+c");
returns true
12
Advanced IBM Rational Functional Tester, Java Scripting
Regex: matches()
• POSIX character classes– Use character classes as match patternRegex pattern = new Regex("[:digit:]"); b = pattern.matches("3");
Returns trueb = pattern.matches("a");
Returns false
– Selected POSIX character classes:• [:alnum: ] Alphanumeric characters.• [:alpha:] Alphabetic characters.• [:digit:] Numeric characters.• [:lower:] Lower-case alphabetic characters.• [:upper:] Upper-case alphabetic characters.• [:punct:] Punctuation characters.
Advanced IBM Rational Functional Tester, Java Scripting
Regex: getMatch()
• public String getMatch()– Returns the part of the string that matched the
pattern.
String sRet = "";Regex pattern = new Regex ("a*dd") ;b = pattern.matches ("baaaaadd") ;
sRet = pattern.getMatch();
sRet= "aaaaadd"
13
Advanced IBM Rational Functional Tester, Java Scripting
Regex: getMatch()
• public String getMatch(int n)– Returns the substring that matched one of the
parenthesized subexpressions of the regular expression, in indexed order.
Regex pattern = new Regex("(value=)(\"[:alnum:]+\")");boolean b = pattern.matches("value=\"hidden\"");
System.out.println(pattern.getMatch());
System.out.println(pattern.getMatch(1));System.out.println(pattern.getMatch(2));
– getMatch() returns: value="hidden"– getMatch(1) returns: value=– getMatch(2) returns: "hidden"
Advanced IBM Rational Functional Tester, Java Scripting
Regex: Closure
• Two types of closure
– greedy: matches as many string elements as possible.– reluctant: matches as few string elements as possible.
• Greedy closure is the default closure. • Reluctant closure is indicated by a trailing '?' after the
operators: +, *, ?, {m,n}
14
Advanced IBM Rational Functional Tester, Java Scripting
Regex: Closure
• // greedy closure:Regex pattern = new Regex("j.*z");b = pattern.matches("jazjazjaz"); ret = pattern.getMatch();
ret = "jazjazjaz"
• // reluctant closure:Regex pattern = new Regex("j.*?z");b = pattern.matches("jazjazjaz"); ret = pattern.getMatch();
ret = "jaz"
Advanced IBM Rational Functional Tester, Java Scripting
Lab 1.1
Regular Expressions
15
Advanced IBM Rational Functional Tester, Java Scripting
Module 2
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
IGraphicalSubitem
StatelessGUISubitemTestObject
IToggle
ToggleTestObject
ISubitem
SubitemTestObject
Test Object
IScrollable
IGraphical
ScrollTestObject
IScreenIWindowITopWindow
ProcessTestObjectGuiTestObjectDomainTestObject
ISubitem, IGraphicalSubitem
GUISubitemTestObject
IFrame
FrameTestObject
ToggleGUITestObject
IToggleGUI
BrowserTestObject
IBrowserObject
FileDialogTestObject
IFileDialog
Package: com.rational.test.ft.object.interfaces
ITopWindow
TopLevelTestObject
16
Advanced IBM Rational Functional Tester, Java Scripting
• TestObject
– A TestObject contains a reference to a corresponding object in the software under test (SUT)
– A TestObject is a Java object "owned" by Functional Tester that serves as a proxy between Functional Tester and the corresponding object in the SUT
– A TestObject is usually (but not always) constructed from the Object Map (a "mapped" TestObject).
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
• TestObject children
- DomainTestObjectFunctional Tester models objects into groups called domains. Java and HTML are the two currently supported domains.Class provides access to information about these domains.
– ProcessTestObjectRepresents a Functional Tester-initiated process.
– GUITestObjectBase class for modeling all objects in the software under test that have a GUI.
– SubitemTestObjectModels subitems that are contained in other objects – for example, lists.
Functional Tester API
17
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
Object Map:
Link_RealTimeTechnologySolutio()
List_country()
Table_HtmlTable_2()
Text_zip()
Button_Gosubmit()
Table_HtmlTable_0()
Table_NameLastChangeChg()
Table_HtmlTable_0_2()
Html_title001()
Advanced IBM Rational Functional Tester, Java Scripting
• Object Map methods return TestObjectS:
// Recorded list selection:List_country().click();
List_country().click(atText("France"));// List selection using TestObject & GuiSubitemTestObject
TestObject tObj = List_country(); GuiSubitemTestObject gui = (GuiSubitemTestObject)tObj;
gui.click();
gui.click(atText("France"));// Or, even more tersely:
GuiSubitemTestObject gsto = List_country();
gsto.click();
gsto.click(atText("Denmark"));
Functional Tester API
18
Advanced IBM Rational Functional Tester, Java Scripting
Selected methods of TestObject:
• boolean exists();• void waitForExistence();• Hashtable getProperties();• Object getProperty(String propertyName);• setProperty(String propertyName, Object value);• getSubitem();• Hashtable getTestDataTypes();
• ITestData getTestData(String testDataType)
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
• public boolean exists();– tests whether object exists at runtime
boolean exists = Button_Gosubmit().exists();System.out.println(exists) ;
Functional Tester API
19
Advanced IBM Rational Functional Tester, Java Scripting
• public void waitForExistence()– Pauses script execution until object appears.
– Arguments:• MAXIMUM_FIND_OBJECT_TIME
– maximum amount of time (seconds) to wait for object (default: 20 s).
• FIND_OBJECT _DELAY_BETWEEN_RETRIES
– amount of time (seconds) to wait between attempts to find the object (default: 1s)
Button_Gosubmit().waitForExistence(10.0,1.0);
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
• Functional Tester Data Capture– Data capture from target objects can be performed by
calling one of 2 methods in TestObject:• getProperty()
– used if the data is a property of the object that Functional Tester can "see"
– returns the data as an Object
• getTestData()– used to capture any data that a data verification point
can "see"– returns the data as an ITestData interface
– usually requires more method calls
Functional Tester API
20
Advanced IBM Rational Functional Tester, Java Scripting
For capture with getProperty(), you need a TestObject'savailable property:
public Hashtable getProperties();– Returns Hashtable of Functional Tester’s properties
import java.util.*;
Hashtable htbl = Button_Gosubmit().getProperties();int i = 1;
Enumeration eKeys = htbl.keys();
Enumeration eElems = htbl.elements();for ( ; eKeys.hasMoreElements() ; i++) {
System.out.println("Hashtable key " + i + ":" +eKeys.nextElement() + "-" + eElems.nextElement());
};
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
With a property name from getProperties(), use getProperty() to capture:
– public Object getProperty(String propName);Returns the value of the specified property as an Object
Object propObj = Button_Gosubmit().getProperty(".name");
String prop = propObj.toString(); System.out.println( prop );
/ / return value: "Go button"
Functional Tester API
21
Advanced IBM Rational Functional Tester, Java Scripting
For HTML objects, getProperty () returns browser DOM properties, too:
String outerHTML=
(String)Html_title001().getProperty("outerHTML");
String outerText =(String)Html_title001().getProperty(".text");
System.out.println("outerHTML: " + outerHTML);
System.out.println(".text: " + outerText);
Functional Tester API
outerHTML: <DIV class=title id=title001 style="FONT-WEIGHT: bold"> FunctionalTester TEST WEB PAGE </DIV>.text: Functional Tester TEST WEB PAGE
Advanced IBM Rational Functional Tester, Java Scripting
void setProperty(String property, Object value)
Can be used to set data in objects
Functional Tester API
String expDate = "12/04";TestObject field = Text2();field.setProperty("text",
expDate);
22
Advanced IBM Rational Functional Tester, Java Scripting
Each script inherits methods (from RationalTestScript) to identify items for capture:
getSubitem() returns an ObjectWith the atIndex(),atText(),atCell(),atRow() and atColumn() methods, specific instance data can be accessed by item index, item name, cell indices, row index or column index
List Example: getSubitem(atIndex (n)):
TestObject secondItem =
(TestObject)List_country().getSubitem(atIndex(1));String country=secondItem.getProperty(".text").toString();
System.out.println(country);
country = México
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
To capture from table objects:
getSubitem(atCell(atRow(atIndex(n)), atColumn(atIndex(m))));
TestObject tblcell = (TestObject)Table_NameLastChanqeChq().getSubitem(
atCell(atRow(atlndex(3)),atColumn(atIndex(1))));
// indices are 0-basedString cell=
tblcell.getProperty(".text").toString();System.out.println(cell);
cell = 1,267.83
Functional Tester API
23
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester Data Capture• Data capture from target objects can be performed by
calling one of 2 methods in TestObject:– Object getProperty(String property)
used if the data is a property of the object that Functional Tester can "see"returns the data as an Object
– ITestData getTestData(String testDataType)
used to capture any data that a data verification point can "see"returns the data as an ITestData interface
usually requires more method calls
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
You can determine a TestObject's test data types from the Test Script Explorer
TestObject tree = tree();
ITestDataTree idata =
(ITeStDataTree)tree.getTestData("tree");
Functional Tester API
24
Advanced IBM Rational Functional Tester, Java Scripting
To determine a TestObject's test data types in code, use getTestDataTypes() :
public Hashtable getTestDataTypes();
Provides access to object property data types–Returns Hashtable of test data types and descriptions–Can be used to find specific data types at runtime:
Hashtable dataTypes = tree().getTestDataTypes();
// return value: {tree = tree Hierarchy;// selected = selected tree Hierarchy}
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
• With a dataType, you can get an ITestData interface reference:– public ITestData getTestData(String dataType)
• The dataType argument is one of the Hashtable keysreturned by getTestDataTypes()
• Returns an object that implements ITestData
• The returned interface reference can be used to capture data from target application objects, usually by casting to a subinterface
Functional Tester API
25
Advanced IBM Rational Functional Tester, Java Scripting
package com.rational.test.ft.vp
– ITestData• ITestDataText• ITestDataList• ITestDataTable• ITestDataTree• ITestDataMenu• ITestDataProperties
– ITestDataElement– ITestDataElementList– ITestDataTreeNode– ITestDataTreeNodes– IFtVerificationPoint
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
ITestDataTableITestDataList
ITestData
ITestDataText
ITestDataTreeNodeITestDataElementListITestDataElement
ITestDataTree
Package: com.rational.test.ft.vp
ITestDataTreeNodes
26
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataText
– Useful for objects that contain a single piece of interesting text
– Can be used to capture:• the selected element from a Java list object
("selected"). • the entire contents (as one long string) of an HTML
Table ("text"). • the entire contents (as one long string) of an HTML
list object ("text")
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
getTestData() and ITestData
// get an ITestData interface:ITestData htmlDataObj =
Html_title001().getTestData("text");// ITestDataText extends ITestData
// ITestDataText has getText();
// ITestData does not cast to an ITestDataTextITestDataText htmlDataText =
(ITestDataText)htmlDataObj;
//execute getText() method to get the text:String htmlText = htmlDataText.getText();
System.out.println("HTML Text: " + htmlText);
htmlText: Functional Tester TEST WEB PAGE
Functional Tester API
27
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataText interface with HTML text objects
// cast to an ITestDataText object directly:
ITestDataText htmlTestObj =
(ITestDataText)Html_title001().getTestData("text");// execute getText() on the resultinq interface:
String htmlText = htmlTestObj.getText();
System.out.println("HTML Text: " + html);
htmlText: Functional Tester TEST WEB PAGE
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
You can get HTML listbox text from ITestDataText:ITestDataText listTextObj =
(ITestDataText) List_country().getTestData("text");
String listText = listTextObj.getText();System.out.println("listbox text: " + listText);
The text of an HTML list object is also accessible using getProperty():String listText = (String) List_country().getProperty
(".text");
System.out.println("listbox text: " + listText);
Functional Tester API
28
Advanced IBM Rational Functional Tester, Java Scripting
Lab 2.1
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
ITestDataTableITestDataList
ITestData
ITestDataText
ITestDataTreeNodeITestDataElementListITestDataElement
ITestDataTree
Package: com.rational.test.ft.vp
ITestDataTreeNodes
29
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataTable
– HTML tables have 3 test data types:• contents • Grid• Text ITestDataText
– Java tables have 2 test data types:• selected• contents
Functional Tester API
ITestDataTable
ITestDataTable
Advanced IBM Rational Functional Tester, Java Scripting
Methods in ITestDataTable
– getColumnCount()– getRowCount()– getCell( int row, int col )
Functional Tester API
30
Advanced IBM Rational Functional Tester, Java Scripting
• Implementation: contents data
ITestDataTable table = (ITestDataTable) Table_NameLastChangeChq().getTestData("contents");
int cols = table.getColumnCount();int rows = table.getRowCount();// loop throuqh cells (by columns) to retrieve cell contentsfor (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {Object data = table.getCell(row, col);if (data != null) {
String cell = data.toStrinq(); System.out.println(row + "," + col +"=" + cell);
}}
}
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Lab 2.2
Functional Tester API
31
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
ITestDataTableITestDataList
ITestData
ITestDataText
ITestDataTreeNodeITestDataElementListITestDataElement
ITestDataTree
Package: com.rational.test.ft.vp
ITestDataTreeNodes
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataList
– HTML list objects have 3 test data types:• list returns the entire contents of the list object as ITestDataList
• selected returns selected item as ITestDataList• text returns the entire contents of the list object as ITestDataText
– Java list objects have 2 test data types:• selected returns data as ITestDataText• list returns data as ITestDataList
Functional Tester API
32
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataList
Functional Tester Interfaces used with lists:– ITestDataList
• getElementCount()• getElements()
– ITestDataElementList• getElement(int)
– ITestDataElement• getElement()
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataList
ITestDataList list =(ITestDataList) List_country().getTestData("list");
int count = list.getElementCount();
System.out.println( count );ITestDataElementList dataElemList = list.getElements();
for (int i = 0; i < count; i++) {
ITestDataElement dataElem =dataElemList.getElement(i);
String elem = dataElem.getElement().toStrinq();System.out.println( elem );
}
Functional Tester API
33
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataList
ITestDataList listSel = (ITestDataList) List_country().getTestData("selected");
ITestDataElementList selObj = listSel.getElements();
// Assumption: only 1 item is selected ITestDataElement selElem = selObj.getElement(0);
String selText = selElem.getElement().toString();
System.out.println("list selection: "+ selText);
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Lab 2.3
Functional Tester API
34
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
ITestDataTableITestDataList
ITestData
ITestDataText
ITestDataTreeNodeITestDataElementListITestDataElement
ITestDataTree
Package: com.rational.test.ft.vp
ITestDataTreeNodes
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester API
Root Node
Child nodes
Leaf nodes
ClassicsJavaA
ClassicsJavaATestObjects:
tree()
35
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataTree
• Java trees have 2 test data types:– tree
• Returns every node in the tree
– selected
• Returns complete path from selected node(s) to root node
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
ITestDataTree
• Functional Tester Interfaces used with trees:– ITestDataTree
• getTreeNodes()– ITestDataTreeNodes
• getRootNodes()• getNodeCount()
– ITestDataTreeNode• getNode()• getChildCount()• getChildren()• getparent()
Functional Tester API
36
Advanced IBM Rational Functional Tester, Java Scripting
Capture Tree data
Coding tasks:1. Cast ITestData to ITestDataTree2. Use getTreeNodes() from ITestDataTree to return
ITestDataTreeNodes3. Use getRootNodes() and getNodeCount() to return
an array of root nodes and the node count 4. Use the root node array to getChildCount() and to
getChildren()5. Return an array of child nodes from getChildren()6. Child nodes have getNode() , which returns a generic
object reference for each child node
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Implementation - tree data
ITestDataTree treeObj =(ITestDataTree) tree().getTestData("tree");
ITestDataTreeNodes treeNodes = treeObj.getTreeNodes();
ITestDataTreeNode[] rootNodes =treeNodes.getRootNodes();ITestDataTreeNode[] childNodes =
rootNodes[0].getChildren();
int rootChildCnt = rootNodes[0].getChildCount(); for(int i = 0; i < rootChildCnt; i++) {
String child = childNodes[i].getNode().toString();
System.out.println( child );}
Functional Tester API
37
Advanced IBM Rational Functional Tester, Java Scripting
• Implementation - selected data
– selected data is held as the complete path from the root node down to the selected branch:
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
• Implementation - selected data
// Frame: ClassicsCDtree().click(atPath("Composers->Schubert"));
ITestDataTree dataObj =
(ITestDataTree)tree().getTestData("selected");ITestDataTreeNodes treeNodes = dataObj.getTreeNodes();
// we have 2 tree nodes in the collection:
System.out.println("node count = " + treeNodes.getNodeCount());
Functional Tester API
38
Advanced IBM Rational Functional Tester, Java Scripting
//continued from previous slide
ITestDataTreeNode[] nodes = treeNodes.getRootNodes();System.out.println("root node: " +
nodes[0].getNode().toString());
//can only be 1 since we are travelling down a//single branch
System.out.println("child count: " +
nodes[0].getChildCount();//the string value of the node = "Schubert"
ITestDataTreeNode[] firstgen = nodes[0].getChildren();
System.out.println("selected child: " +firstgen[0].getNode().toString());
Functional Tester API
Advanced IBM Rational Functional Tester, Java Scripting
Lab 2.4
Functional Tester API
39
Advanced IBM Rational Functional Tester, Java Scripting
Module 3
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
HelperSuper Classes
The default inheritance of your TestScript is:
RationalTestScript
"TestScriptHelper" Class
"TestScript“ Class
40
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester gives you the option of adding a HelperSuper Class to the hierarchy:
HelperSuper Classes
RationalTestScript
"TestScriptHelper" Class
"TestScript“ Class
HelperSuper
Advanced IBM Rational Functional Tester, Java Scripting
Uses of a HelperSuper class:
– Any methods that you want inherited by any or all scripts can be put in the HelperSuper class.
– Methods of the RationalTestScript class can be overridden in the HelperSuper
HelperSuper Classes
41
Advanced IBM Rational Functional Tester, Java Scripting
HelperSuper classes follow certain rules:
1. A HelperSuper class may have any valid Java class name.
2. A HelperSuper class must extend RationalTestScript.
3. A HelperSuper file can be in the datastore root orsubfolder, or an external .jar file.
4. Every participating TestScriptHelper must inherit from theHelperSuper class
5. The actual TestScript class itself requires no modification toinherit from a HelperSuper
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
Implementing a HelperSuper:Create a HelperSuper class in your datastore:
1. Create a New Test Folder in your datastore (call it 'util')
2. Create a new Java class using the File -> New -> Other Dialog.
3. Choose Java in the left panel and Class on the right panel in the wizard
4. Choose the folder, the package, a class name, and choose a superclass of: com.rational.test.ft.script.RationalTestScript
5. Press the finish button
HelperSuper Classes
42
Advanced IBM Rational Functional Tester, Java Scripting
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
Choose Java folder and Class inside the folder in the wizard
HelperSuper Classes
43
Advanced IBM Rational Functional Tester, Java Scripting
HelperSuper Classes
Datastore Name
Class Name
Parent Name
Advanced IBM Rational Functional Tester, Java Scripting
Functional Tester creates a stubbed superclasswith the characteristics you have requested:
package util;
import com.rational.test.ft.script.Rational.TestScript;
public class MyHelperSuper extends RationalTestScript {
//insert code here }
HelperSuper Classes
44
Advanced IBM Rational Functional Tester, Java Scripting
Implementing a HelperSuper:
Make MyHelperSuper inheritance the default for all new scripts.
– Right-click on the project in the Functional Test Project view, and select Properties.
– Select 'Functional Test Project' and change the 'Script Helper Superclass' field to 'util.MyHelperSuper'
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
Implementing a HelperSuper– Set MyHelperSuper inheritance for preexisting
TestScript
HelperSuper Classes
45
Advanced IBM Rational Functional Tester, Java Scripting
The Functional Tester Execution Framework
Functional Tester performs housekeeping tasks, before and after testMain(), is called Execution FrameworkAmong these tasks, two methods are called before and after testMain()
The sequence is:• onInitialize();• testMain();• onTerminate();
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
The Functional Tester Execution Framework
– Two methods, onInitialize() and onTerminate()are for your own initialization and termination tasks.
– You can override onInitialize() and onTerminate()in your HelperSuper class to handle, for example, application initialization and termination.
Another methods to override– onObjectNotFound();– onAmbiguousRecognition();– onTestObjectMethodException();
HelperSuper Classes
46
Advanced IBM Rational Functional Tester, Java Scripting
The Functional Tester Execution Framework
package util;import com.rational.test.ft.script.RationalTestScript;import com.rational.test.ft.object.interfaces.ProcessTestObject;
Public class MyHelperSuper extends RationalTestScript {ProcessTestObject pto = null;
public void onInitialize() {pto =startApp("ClassicsJavaA");
}public void onTerminate() {
if (pto.isAlive()) {pto.kill();
}}
}
HelperSuper Classes
Advanced IBM Rational Functional Tester, Java Scripting
Lab 3.1
HelperSuper Classes
47
Advanced IBM Rational Functional Tester, Java Scripting
Module 4
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Dynamic Object Handling
Mapped Objects
− When you record a TestScript, methods are recorded, which also appear as entries in the Object Map.
− Each method from the Object Map returns a TestObjectreference that refers to an object in the target application
− These objects are termed 'Mapped objects'
− This is the typical way to access target objects
48
Advanced IBM Rational Functional Tester, Java Scripting
Object Map Internals.
– The Functional Tester Object Map is implemented in each TestScript's TestScriptHelper class.
– For every object in the Map, methods are automatically written into the TestScriptHelper class that return TestObject references when the methods are called from the TestScript class.
– Verification point methods are also written to the TestScriptHelper class, and are called from the TestScriptclass.
– Object Map data is persisted in datastore as XMLs.
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Object Map InternalsExample methods from a TestScriptHelper class that return a reference to a TestObject which refers to an HTML link:
protected GuiTestObject Link_IslandAdventures() {return new GuiTestObject(
getMappedTestObject("Link_IslandAdventures"));}protected GuiTestObjectLink_IslandAdventures(TestObject anchor, long flags) {
return new GuiTestObject( getMappedTestObject("Link_IslandAdventures"),
anchor, flags);}
Dynamic Object Handling
49
Advanced IBM Rational Functional Tester, Java Scripting
Object Map Internals
The Functional Tester Object Map is 2-tiered:
• All objects that are put in an Object Map are persisted in a Map XML file in the datastore.
• The subset of objects in a Map that are visible to a TestScriptappear in the Script Explorer View, and are persisted in a Script Definition XML in the datastore.
• If an object is deleted from the Script Explorer, it is deleted from the Script Definition and is not deleted from the Object Map.
• If an object is deleted from the Object Map in the Object Map tool, it is lost and must be re-entered into the Map if it is needed.
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Object Map Internals
• The Map XML is stored in the datastore 'resources' directory.
• The XML file is named by the following convention:– yourScriptName.rftxmap
• Sample XML structure:– Objects appear in <MTO> tags ("Mapped Test Objects")
– Key Object characteristics each have their own tag (<Id>,<Name>,<Parent>,<TO>,<Dom>Java</Dom>,<Class>,<Role>,<Proxy>)
– Object properties are held in <Prop> tags
Dynamic Object Handling
50
Advanced IBM Rational Functional Tester, Java Scripting
Dynamic Object Handling
Object Map InternalsSample Object Map XML
<MTO L=".MTO"><Id>0.5vYm2Dr5yw0:1eHQrh:KNho7eA:8WW</Id><Name>ClassicsJava</Name><Parent/><TO>TopLevelTestObject</TO><Dom>Java</Dom><Class>ClassicsJava</Class><Role>Frame</Role><Proxy>.java.jfc.JFrameProxy</Proxy><Prop L=".MtoProp">
<Key>.captionText</Key><Val L=".caption">
<Caption></Caption></Val><Wt>75</Wt>
</Prop>…
</MTO>
Advanced IBM Rational Functional Tester, Java Scripting
Object Map Internals
• The Script Definition XML is persisted in the datastore'resources' directory.
• The XML file is named by the following convention:yourScriptName.rftdef.
• This XML contains the "Script Definition"– Script Definition includes the mapped objects that have
been 'added' to your TestScript
– Script Definition also contains other script data, such as Verification Point information.
Dynamic Object Handling
51
Advanced IBM Rational Functional Tester, Java Scripting
Object Map InternalsSample Script Definition XML
Dynamic Object Handling
<ScriptDefinition L=".ScriptDefinition"><ScriptName>MusicVendor</ScriptName><Language>java</Language><Map>MusicVendorTestObjectMap.rftmap</Map><Datapool/>…<HelperSuper>util.MyHelperSuper</HelperSuper><ScriptNameMap L=".ScriptDefinitionNameMap">
<TestObject L=".ScriptDefNameMapElement"><Name>cardNumberIncludeTheSpacesText</Name><ID>A.5vYm2Dr5yw0:1ZLw93:KNi6Bz7:8WW</ID><Role>Text</Role><Deleted>false</Deleted>
</TestObject>…</ScriptNameMap>
…</ScriptDefinition>
Advanced IBM Rational Functional Tester, Java Scripting
Unmapped Objects.
– Several Functional Tester methods return TestObjectreferences that are unmapped.
– These are called 'bound references', 'found references' or 'unmapped references'.
– You can use these references to dynamically access objects
Dynamic Object Handling
52
Advanced IBM Rational Functional Tester, Java Scripting
Unmapped Objects– Some TestObject methods that return bound
references: – find();– getChildren();– getMappableChildren();– getparent();– getMappableParent();– getTopParent();– getTopMappableParent();– getOwnedObjects();– getOwner();
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Comparing Mapped to Unmapped ObjectsEvery time you invoke an action on a mapped TestObject, Functional Tester must do a lookup in the map, and then create a new TestObject.
• For example, if you completely expand the ClassicsJavaAComposers tree while recording, you see in your script:
tree().click(atPath("Composers->Schubert->Location (PLUS_MINUS)"));
tree().click(atPath("Composers->Haydn->Location (PLUS_MINUS)")); tree().click(atPath("Composers->Bach->Location (PLUS_MINUS)"));tree().setState(Action.vScroll(128));tree().click(atPath("Composers->Beethoven->
Location(PLUS_MINUS)")); tree().setState(Action.vScroll(176));tree().click (atPath("Composers->Mozart->Location
(PLUS_MINUS)"));
This means that 7 tree() TestObjectS are created in the script process -- consuming the resources of 7 objects
Dynamic Object Handling
53
Advanced IBM Rational Functional Tester, Java Scripting
Unmapped ObjectsCoding tasks:– Each Object Map method returns a TestObject– To execute GUI methods on a TestObject, you have to cast
to a GuiTestObject, or one of its subclasses.
– You can find which specific cast is required from the Object Map tool, under Administrative Properties, Test Object Class Name.
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Comparing Mapped to Unmapped ObjectsYou could use the find() method to return a bound reference to the composers tree, and execute all the methods using the bound reference:
GuiSubitemTestObject oTree = (GuiSubitemTestObject) tree().find(); oTree.click(atPath("Composers->Schubert->
Location(PLUS_MlNUS)")); oTree.click(atPath("Composers->Haydn->Location(PLUS_MINUS)"));oTree.click(atPath("Composers->Bach->Location(PLUS_MINUS)")); oTree.setState(Action.vScroll(128));oTree.click(atPath("Composers->Beethoven->
Location(PLUS_MINUS)")); oTree.setState(Action.vScroll(176)); oTree.click(atPath("Composers->Mozart->
Location(PLUS_MINUS)"));oTree.unregister(); //Highly recommended to unregister bound refs!
Dynamic Object Handling
54
Advanced IBM Rational Functional Tester, Java Scripting
Unregistering Unmapped Objects
–oTree.unregister();–unregisterAll();
Because bound references can "pin" an object in the target application (i.e., the object will not be collected by the garbage collector as long as Functional Tester's bound reference points to it), if bound references are left registered, system resources may not be released. Over a long run, this can consume large amounts of resources. Calling the appropriate unreqister() method releases the bound reference, and allows release of system resources.
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Comparing Mapped to Unmapped Objects.
– Using the unmapped reference runs about 10% faster than using a mapped reference in the simple ClassicsJavaA tree() example (1 GHz processor).
– This time difference represents the map lookup time (each call to a mapped object requires a separate lookup) plus the time to create 7 TestObjectS vs. only one TestObject.
– Call the unreqister() method to release the bound reference. This ensures that the bound resources are released.
Dynamic Object Handling
55
Advanced IBM Rational Functional Tester, Java Scripting
Nothing in the Object Map?
– getDomains() returns an array of DomainTestObjectS
– DomainTestObject has a getTopObjects() method that returns an array of TestObjectS
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Coding Task:
DomainTestObject[] domains = getDomains(); ArrayList topWins = new ArrayList();for(int d = 0; d < domains.length; d++) {
TestObject[] tWins = domains[d].getTopObjects();for(int w = 0; w < tWins.length; w++) {
topWins.add( tWins[w] );}System. out.println ("domain: " + domains
[d].getName() + "; Num wins: " + tWins.length);
}
Dynamic Object Handling
Domain: Java; Num wins: 1Domain: Html; Num wins: 0Domain: Process; Num wins: 0
56
Advanced IBM Rational Functional Tester, Java Scripting
Lab 4.1Lab 4.2
Dynamic Object Handling
Advanced IBM Rational Functional Tester, Java Scripting
Module 5
Custom Verification Points
57
Advanced IBM Rational Functional Tester, Java Scripting
Custom Verification Points
• RationalTestScript gives you access to a range of custom Verification Points
• Two RationalTestScript methods give you access to verification point methods:– vpManual();– vpDynamic();
• Each returns a reference to an IFtVerificationPointinterface.
• This interface has several methods for creating Verification Point behavior
Advanced IBM Rational Functional Tester, Java Scripting
Two vpManual() Signatures:
vpManual(Strinq vpName, Object data);– On first execution of performTest(), creates a VP in
Script Explorer and persists the second argument as the expected data.
– On subsequent executions of performTest(), compares the second argument with data persisted from first run
vpManual(Strinq vpName, Object expected, Object actual);– compares expected and actual arguments, and writes result
to log.
– this syntax does not create a VP in the Script Explorer
Custom Verification Points
58
Advanced IBM Rational Functional Tester, Java Scripting
vpManual(name,baseline,actual).performTest();
String baseline = "Bill Wu"; /* code to select a
recording and login
as Bill Wu */String actual = (String) text().getProperty("text") ;
vpManual.("UserName", baseline, actual).performTest();
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
vpManual(name,baseline,actual).performTest();– The data you compare using vpManual() must be Objects.– Primitive data can be used with the wrappers:
double baseline = 19.99;String actual =
((String)totalAmount().getProperty("text")).substring(1);Double b = new Double(baseline);Double a = new Double(actual);
vpManual ("TotalAmount", b, a).performTest();
Custom Verification Points
59
Advanced IBM Rational Functional Tester, Java Scripting
Valid Data Types
you can pass vpManual:– ITestData– String– Primitive Wrapper– Vector– Hashtable– Array[]– Array[][]
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Using ITestData with vpManual().performTest();startApp("ClassicsJavaA");menubar().click(atPath("Admin"));
menubar().click(atPath("Admin->Customers..."));
OK().click();// capture the table
ITestDataTable iTblBase =
(ITestDataTable) table().getTestData("contents");// ...change the table and recapture:
ITestDataTable iTblAct =
(ITestDataTable) table().getTestData("contents");// compare the two table versions:
vpManual("table", iTblBase, iTblAct).performTest();
Custom Verification Points
60
Advanced IBM Rational Functional Tester, Java Scripting
Using Hashtables with vpManual().performTest();
– To compare hashtables, the data needs to be of type ITestDataProperties
– The static method VpUtil.getTestData() accepts a hashtable argument and returns it as an object of type ITestDataProperties
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Using Hashtables with vpManual().performTest();
// Implementing your own properties VP:// Frame: ClassicsCD
Hashtable props = tree().getProperties();
ITestDataProperties baseline = VpUtil.getTestData(props);
props = ...
ITestDataProperties actual =VpUtil.getTestData(props);
vpManual("TreeProperties", baseline, actual).performTest();
Custom Verification Points
61
Advanced IBM Rational Functional Tester, Java Scripting
Using Collections with vpManual().performTest();
Hashtable baseline = new Hashtable(); baseline.put( "Russia", "Ruble"); baseline.put( "US", "Dollar"); baseline.put("France", "Euro");Hashtable actual = new Hashtable(); actual.put("France", "Euro"); actual.put ("Russia", "Ruble"); actual.put("US", "Dollar");vpManual("Currencies", VpUtil.getTestData(baseline),
VpUtil.getTestData(actual)).performTest();
Custom Verification Points
Passes
Advanced IBM Rational Functional Tester, Java Scripting
Using Vectors with vpManual().performTest();– Vectors can be passed directly
Vector baseline = new Vector(); baseline.add("Visa");baseline.add("MasterCard"); baseline.add("Amex");Vector actual = new Vector(); actual.add("Visa");actual.add("Amex");actual.add("MasterCard");vpManual ("CreditCards", baseline, actual).perfomTest();
Custom Verification Points
Fails
62
Advanced IBM Rational Functional Tester, Java Scripting
Using Collections with vpManual().performTest();
– Vectors can be converted to ITestDataList
ITestDataList actual =
(ITestDataList) somelistObject().getTestData("list");
Vector b =aMethodThatGetsDataAndPutsInVector();
ITestDataList baseline = Vputil.getTestData(b);
vpManual("CreditCards", baseline, actual).performTest();
Custom Verification Points
Fails
Advanced IBM Rational Functional Tester, Java Scripting
Persisting Data withvpManual(Name, data).performTest();
String baseline = “Trent Culpito";vpManual("UserName", baseline).performTest();/* code to select a recording and log in as
Trent Culpito */String actual = (String)text().getProperty("text");
vpManual("UserName", actual).performTest();
Custom Verification Points
63
Advanced IBM Rational Functional Tester, Java Scripting
Persisting Data withvpManual(Name, data).performTest();
Hashtable props = tree().getProperties();
ITestDataProperties baseline = VpUtil.getTestData(props);
vpManual("TreeProperties", baseline).performTest();
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Selected IFtVerificationPoint methods:
– performTest();– getActualData()– getExpectedData();– compare();– compareAndLog();– getVPName();
Custom Verification Points
64
Advanced IBM Rational Functional Tester, Java Scripting
Calling vpManual() and performTest() separately
String baseline = “Trent Culpito";
String actual =text().getProperty("text").toString();
/* Catch the reference returned by vpManual - 3 argument version */
IFtVerificationPoint vp =vpManual("UserName", baseline, actual);
// Compare and log result:
vp.performTest();
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Calling vpManual() and performTest() separately
ITestDataTree baseline =
(ITestDataTree)tree().getTestData("selected");
/* Catch the reference returned by vpManual - 2 argument version */
IFtVerificationPoint vp =
vpManual("SelectedItem", baseline);// Persist the baseline data in datastore
vp.performTest();
Custom Verification Points
65
Advanced IBM Rational Functional Tester, Java Scripting
getExpectedData() & getActualData()
String exp = “Trent Culpito";// set exp as expected value:
IFtVerificationPoint vp = vpManual("User", exp);
// Persist data:
vp.performTest();String actual = "Emma Trenchenza";
// Supply the actual value
vp = vpManual("User", actual); // return expected and actual data:
exp = (String) vp.getExpectedData();
actual = (String) vp.getActualData();
// Compare and log results: vp.performTest();
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
compare()
compare() returns a boolean evaluation of the 'expected' and 'actual' arguments:
String exp = "Trent Culpito";IFtVerificationPoint vp = vpManual("User", exp);
actual = "Gail Wu";
vp = vpManual("User", actual);
boolean b = vp.compare();
Custom Verification Points
Returns false
66
Advanced IBM Rational Functional Tester, Java Scripting
compareAndLog()
compareAndLog() compares actual with expected and writes a pass/fail to the log (equivalent to performTest())
actual = "Gail Wu";IFtVerificationPoint vp = vpManual("User" ,actual);
boolean b = vp.compareAndLog();
Custom Verification Points
returns false
Advanced IBM Rational Functional Tester, Java Scripting
compareAndLog(boolean compareTrue)
– If compareTrue is set ta false, expected and actual data must be different in order to get a passing result
String act = "Wendy Wu"; // actual valueIFtVerificationPoint vp = vpManual("User", act);
boolean b = vp.compareAndLog(false);
Custom Verification Points
Logs a pass
67
Advanced IBM Rational Functional Tester, Java Scripting
vpDynamic()
Two signatures:• vpDynamic("vpDyn1").performTest();• vpDynamic("vpDynl", mappedTestObject).
performTest();– first signature:
• On first playback, brings up VP wizard and creates aVerification Point in the Script Explorer on any mapped TestObject
– second signature:
• On first playback, brings up VP wizard and create aVerification Point in the Script Explorer on the passed TestObject
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Log methods in RationalTestScript
– logInfo(String info)– logError(String error)– logWarning(String warning)– logTestResult(String headline, boolean passed,
String additionalInfo)
Custom Verification Points
68
Advanced IBM Rational Functional Tester, Java Scripting
logTestResult()
signature: logTestResult(String headline, boolean passed,
String additionalInfo);
example:logTestResult("vp1", (exp.equals(act)),
"addn1 info") ;
Custom Verification Points
Advanced IBM Rational Functional Tester, Java Scripting
Lab 5.1
Custom Verification Points
69
Advanced IBM Rational Functional Tester, Java Scripting
Module 6
Handling non-Java / Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
Non-Java/Browser Windows
• While recording, Functional Tester only recognizes actions performed against Java and browser windows
• There may be cases where you need to perform actions against other types of windows
• Functional Tester API has 2 interfaces you can use to perfom actions against any window:
– IScreen– IWindow
70
Advanced IBM Rational Functional Tester, Java Scripting
IScreen and IWindow
– Limited set of methods– The IScreen API has no methods that retrieve data– You cannot cast from IScreen to TestObject
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
IScreen
– An interface designed to perform actions against the currently active window.
– Since IScreen is an interface, there is no constructor. – You get an IScreen by calling getScreen()
• a method in RationalTestScript
Non-Java/Browser Windows
71
Advanced IBM Rational Functional Tester, Java Scripting
Methods that perform GUI actions
– .click(), click(Point), click(Modifiers), doubleClick(), drag(), mouseMove(), nClick()
– inputChars(String)– inputKeys(String)– inputKeys and inputChars send characters to the
current active window wherever the cursor is focused – If you need to send characters to a particular object
within a window, you might have to add navigational actions
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
IScreen
Bad NewsThere are no methods in IScreen that retrieve interesting information (properties, data) from a window
– isEnabled(), isShowing(), hasFocus()– getMousePosition(), getChildAtPoint()
Good NewsThere are methods in IWindow that allow you get limited information about a window
Non-Java/Browser Windows
72
Advanced IBM Rational Functional Tester, Java Scripting
IWindow
– IScreen has methods that return an IWindow• getActiveWindow();• windowFromHandle( long );• windowFromPoint( java.awt.Point );
IScreen scrn = getScreen();IWindow win = scrn.getActiveWindow();Point p = scrn.getMousePosition(); win = scrn.windowFromPoint(p);
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
IWindow
More Good News– RationalTestScript has a method that returns an
array of all the top level windows on the screen:• getTopWindows();
IWindow[] allWins = getTopWindows();
Non-Java/Browser Windows
73
Advanced IBM Rational Functional Tester, Java Scripting
IWindowGetting Information from a Window – IWindow has methods that query windows:
• getText() - returns the window caption . • getWindowClassName()
• getHandle() - return the native window handle (hWnd on Windows).
• getId() - returns the Windows control ID. • getPid() - returns the process ID for the window
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
IWindowGUI actions– If the IWindow is a TopLevelWindow, you can call these
methods:• close()• activate()• maximize()• minimize()• contextHelp() - activates the window's context-
sensitive Help mode.
Non-Java/Browser Windows
74
Advanced IBM Rational Functional Tester, Java Scripting
IWindowRelated Window Objects– IWindow has methods that return IWindow references
to objects related to the same window:– IWindow[] getChildren();– IWindow getparent();– IWindow getTopParent();– IWindow getOwned();– IWindow getOwner();
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
IWindow
What if you need to get data from an object?
– There are no methods in IWindow that do this
– If you can copy the data to the clipboard, you can use Java to access the clipboard
Non-Java/Browser Windows
75
Advanced IBM Rational Functional Tester, Java Scripting
Accessing the ClipboardRetrieve the Contents of the System Clipboard
import java.awt.datatransfer.*; import java.awt.Toolkit;…Clipboard clipboard =
Toolkit.getDefaultToolkit().getSystemClipboard();Transferable t = clipboard.getContents(null);String data = null;try {
data = t.getTransferData(DataFlavor. stringFlavor).toString();
} catch (UnsupportedFlavorException ufe) {
} catch( IOException ioe ) { }
Non-Java/Browser Windows
Advanced IBM Rational Functional Tester, Java Scripting
Accessing the ClipboardSend Text to the System Clipboard
import java.awt.datatransfer.*; import java.awt.Toolkit;…Clipboard clipboard = Toolkit.getDefaultToolkit()
.getSystemClipboard();String data = "How now brown cow";StringSelection ss = new StringSelection( data );
clipboard.setContents( ss, ss );
Non-Java/Browser Windows
76
Advanced IBM Rational Functional Tester, Java Scripting
Lab 6.1
Non-Java/Browser Windows