Está en la página 1de 76

Advanced IBM Rational Functional Tester, Java Scripting

Class Book
Advanced IBM Rational Functional Tester, Java Scripting

Course Outline
• • • • • • Module Module Module Module Module Module 1: 2: 3: 4: 5: 6: Regular Expressions Functional Tester API HelperSuper Classes Dynamic Object Handling Custom Verification Points Handling Non-Java/Browser Windows

Advanced IBM Rational Functional Tester, Java Scripting

1

Prerequisities
• The prerequisities for this course is completion of 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

Advanced IBM Rational Functional Tester, Java Scripting

2

Suggested Daily Schedule
Class Start Morning Break Lunch Class end 9:00 am 11:00 am 2:00 pm 5:30 pm

Advanced IBM Rational Functional Tester, Java Scripting

Technical Support Information
Rational Technical Support IBM Developer Works IBM Rational Software Support User Groups: QA Forums SQA User Group Era Contact Information sw_support@us.ibm.com 800-426-7378 www.ibm.com/developerworks www.rational.com/support www.qaforums.com www.dundee.net/sqa (+52) (55) 3300-0650 www.itera.com.mx

Advanced IBM Rational Functional Tester, Java Scripting

3

Help & References
Java Document You 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 Documentation Functional Tester documentation is accessed from the Functional Tester Help Menu Learning Java Friedl, Jeffrey. Mastering Regular Expressions, 2nd Edition. O’Reilly, 2002 Van 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

Advanced IBM Rational Functional Tester, Java Scripting

4

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.*

Advanced IBM Rational Functional Tester, Java Scripting

5

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.

Advanced IBM Rational Functional Tester, Java Scripting

6

Regex: matches()
• 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

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

Advanced IBM Rational Functional Tester, Java Scripting

7

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

Advanced IBM Rational Functional Tester, Java Scripting

8

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'

Advanced IBM Rational Functional Tester, Java Scripting

9

Regex: matches()
• Regex operator: | (pipe)
– | acts as a logical Or
Regex pattern =new Regex("Functional Tester|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

Advanced IBM Rational Functional Tester, Java Scripting

10

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 true

b = pattern.matches("baaaad");
Returns false

Regex pattern = new Regex("ba{3,}d"); b = pattern.matches("baad");
Returns false

b = 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 true

b = pattern.matches("abcd");
returns false

Regex pattern = new Regex("a+b+c"); b = pattern.matches("a+b+c");
returns false

Regex pattern = new Regex("a[+]b[+]c"); b = pattern.matches("a+b+c");
returns true

Advanced IBM Rational Functional Tester, Java Scripting

11

Regex: matches()
• POSIX character classes
– Use character classes as match pattern Regex pattern = new Regex("[:digit:]"); b = pattern.matches("3");
Returns true

b = 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"

Advanced IBM Rational Functional Tester, Java Scripting

12

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}

Advanced IBM Rational Functional Tester, Java Scripting

13

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

Regular Expressions

Lab 1.1

Advanced IBM Rational Functional Tester, Java Scripting

14

Module 2 Functional Tester API

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
Package: com.rational.test.ft.object.interfaces
Test Object DomainTestObject GuiTestObject IGraphical ITopWindow IWindow IScreen

ProcessTestObject

ScrollTestObject IScrollable

SubitemTestObject ISubitem

ToggleTestObject IToggle ToggleGUITestObject IToggleGUI BrowserTestObject IBrowserObject

FrameTestObject IFrame TopLevelTestObject ITopWindow FileDialogTestObject IFileDialog

StatelessGUISubitemTestObject IGraphicalSubitem GUISubitemTestObject ISubitem, IGraphicalSubitem

Advanced IBM Rational Functional Tester, Java Scripting

15

Functional Tester API
• 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).

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• TestObject children
- DomainTestObject
Functional Tester models objects into groups called domains. Java and HTML are the two currently supported domains. Class provides access to information about these domains.

– ProcessTestObject
Represents a Functional Tester-initiated process.

– GUITestObject
Base class for modeling all objects in the software under test that have a GUI.

– SubitemTestObject
Models subitems that are contained in other objects – for example, lists.

Advanced IBM Rational Functional Tester, Java Scripting

16

Functional Tester API
Object Map:
Html_title001() Table_HtmlTable_0_2() Table_NameLastChangeChg() Table_HtmlTable_0() Button_Gosubmit() Text_zip() Table_HtmlTable_2() List_country() Link_RealTimeTechnologySolutio()

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• 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"));

//

Advanced IBM Rational Functional Tester, Java Scripting

17

Functional Tester API
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)

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• public boolean exists();
– tests whether object exists at runtime boolean exists = Button_Gosubmit().exists(); System.out.println(exists) ;

Advanced IBM Rational Functional Tester, Java Scripting

18

Functional Tester API
• 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);

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• 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

Advanced IBM Rational Functional Tester, Java Scripting

19

Functional Tester API
For capture with getProperty(), you need a TestObject's available 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()); };

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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"

Advanced IBM Rational Functional Tester, Java Scripting

20

Functional Tester API
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);

outerHTML: <DIV class=title id=title001 style="FONT-WEIGHT: bold">&nbsp;&nbsp;Functional Tester TEST WEB PAGE&nbsp; </DIV> .text: Functional Tester TEST WEB PAGE

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
void setProperty(String property, Object value) Can be used to set data in objects

String expDate = "12/04"; TestObject field = Text2(); field.setProperty("te xt", expDate);

Advanced IBM Rational Functional Tester, Java Scripting

21

Functional Tester API
Each script inherits methods (from RationalTestScript) to identify items for capture: getSubitem() returns an Object With 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

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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-based

String cell= tblcell.getProperty(".text").toString(); System.out.println(cell);
cell = 1,267.83

Advanced IBM Rational Functional Tester, Java Scripting

22

Functional Tester API
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

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
You can determine a TestObject's test data types from the Test Script Explorer
TestObject tree = tree(); ITestDataTree idata = (ITeStDataTree)tree.getTestData("tree");

Advanced IBM Rational Functional Tester, Java Scripting

23

Functional Tester API
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}

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• With a dataType, you can get an ITestData interface reference: – public ITestData getTestData(String dataType) • The dataType argument is one of the Hashtable keys returned 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

Advanced IBM Rational Functional Tester, Java Scripting

24

Functional Tester API
package com.rational.test.ft.vp
– ITestData • ITestDataText • ITestDataList • ITestDataTable • ITestDataTree • ITestDataMenu • ITestDataProperties – ITestDataElement – ITestDataElementList – ITestDataTreeNode – ITestDataTreeNodes – IFtVerificationPoint

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
Package: com.rational.test.ft.vp

ITestData

ITestDataText

ITestDataList

ITestDataTable

ITestDataTree

ITestDataElement

ITestDataElementList

ITestDataTreeNode ITestDataTreeNodes

Advanced IBM Rational Functional Tester, Java Scripting

25

Functional Tester API
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")

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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 ITestDataText ITestDataText 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
Advanced IBM Rational Functional Tester, Java Scripting

26

Functional Tester API
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

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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);

Advanced IBM Rational Functional Tester, Java Scripting

27

Functional Tester API

Lab 2.1

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
Package: com.rational.test.ft.vp

ITestData

ITestDataText

ITestDataList

ITestDataTable

ITestDataTree

ITestDataElement

ITestDataElementList

ITestDataTreeNode ITestDataTreeNodes

Advanced IBM Rational Functional Tester, Java Scripting

28

Functional Tester API
ITestDataTable
– HTML tables have 3 test data types: • contents ITestDataTable • Grid • Text ITestDataText – Java tables have 2 test data types: • selected ITestDataTable • contents

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
Methods in ITestDataTable
– getColumnCount() – getRowCount() – getCell( int row, int col )

Advanced IBM Rational Functional Tester, Java Scripting

29

Functional Tester API
• 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 contents for (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); } }

}

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API

Lab 2.2

Advanced IBM Rational Functional Tester, Java Scripting

30

Functional Tester API
Package: com.rational.test.ft.vp

ITestData

ITestDataText

ITestDataList

ITestDataTable

ITestDataTree

ITestDataElement

ITestDataElementList

ITestDataTreeNode ITestDataTreeNodes

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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

Advanced IBM Rational Functional Tester, Java Scripting

31

Functional Tester API
ITestDataList
Functional Tester Interfaces used with lists: – ITestDataList • getElementCount() • getElements() – ITestDataElementList • getElement(int) – ITestDataElement • getElement()

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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 ); }

Advanced IBM Rational Functional Tester, Java Scripting

32

Functional Tester API
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);

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API

Lab 2.3

Advanced IBM Rational Functional Tester, Java Scripting

33

Functional Tester API
Package: com.rational.test.ft.vp

ITestData

ITestDataText

ITestDataList

ITestDataTable

ITestDataTree

ITestDataElement

ITestDataElementList

ITestDataTreeNode ITestDataTreeNodes

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
ClassicsJavaA
Root Node Child nodes Leaf nodes

ClassicsJavaA TestObjects: tree()

Advanced IBM Rational Functional Tester, Java Scripting

34

Functional Tester API
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

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
ITestDataTree • Functional Tester Interfaces used with trees:
– ITestDataTree • getTreeNodes() – ITestDataTreeNodes • getRootNodes() • getNodeCount() – ITestDataTreeNode • getNode() • getChildCount() • getChildren() • getparent()

Advanced IBM Rational Functional Tester, Java Scripting

35

Functional Tester API
Capture Tree data
Coding tasks: 1. Cast ITestData to ITestDataTree 2. Use getTreeNodes() from ITestDataTree to return ITestDataTreeNodes 3. 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

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
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 ); }

Advanced IBM Rational Functional Tester, Java Scripting

36

Functional Tester API
• Implementation - selected data
– selected data is held as the complete path from the root node down to the selected branch:

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API
• Implementation - selected data
// Frame: ClassicsCD tree().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());

Advanced IBM Rational Functional Tester, Java Scripting

37

Functional Tester API
//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());

Advanced IBM Rational Functional Tester, Java Scripting

Functional Tester API

Lab 2.4

Advanced IBM Rational Functional Tester, Java Scripting

38

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

Advanced IBM Rational Functional Tester, Java Scripting

39

HelperSuper Classes
Functional Tester gives you the option of adding a HelperSuper Class to the hierarchy:
RationalTestScript

HelperSuper

"TestScriptHelper" Class

"TestScript“ Class

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes
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

Advanced IBM Rational Functional Tester, Java Scripting

40

HelperSuper Classes
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 or subfolder, or an external .jar file. 4. Every participating TestScriptHelper must inherit from the HelperSuper class 5. The actual TestScript class itself requires no modification to inherit from a HelperSuper

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes
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

Advanced IBM Rational Functional Tester, Java Scripting

41

HelperSuper Classes

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes

Choose Java folder and Class inside the folder in the wizard

Advanced IBM Rational Functional Tester, Java Scripting

42

HelperSuper Classes

Datastore Name Class Name Parent Name

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes
Functional Tester creates a stubbed superclass with the characteristics you have requested:

package util; import com.rational.test.ft.script.Rational.TestScript; public class MyHelperSuper extends RationalTestScript { //insert code here }

Advanced IBM Rational Functional Tester, Java Scripting

43

HelperSuper Classes
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'

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes
Implementing a HelperSuper
– Set MyHelperSuper inheritance for preexisting TestScript

Advanced IBM Rational Functional Tester, Java Scripting

44

HelperSuper Classes
The Functional Tester Execution Framework
Functional Tester performs housekeeping tasks, before and after testMain(), is called Execution Framework Among these tasks, two methods are called before and after testMain() The sequence is: • onInitialize(); • testMain(); • onTerminate();

Advanced IBM Rational Functional Tester, Java Scripting

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

Advanced IBM Rational Functional Tester, Java Scripting

45

HelperSuper Classes
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(); } } }

Advanced IBM Rational Functional Tester, Java Scripting

HelperSuper Classes

Lab 3.1

Advanced IBM Rational Functional Tester, Java Scripting

46

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 TestObject reference that refers to an object in the target application − These objects are termed 'Mapped objects' − This is the typical way to access target objects

Advanced IBM Rational Functional Tester, Java Scripting

47

Dynamic Object Handling
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 TestScript class. – Object Map data is persisted in datastore as XMLs.

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
Object Map Internals
Example 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 GuiTestObject Link_IslandAdventures(TestObject anchor, long flags) { return new GuiTestObject( getMappedTestObject("Link_IslandAdventures"), anchor, flags); }

Advanced IBM Rational Functional Tester, Java Scripting

48

Dynamic Object Handling
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 TestScript appear 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.

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
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>,<Cl ass>,<Role>,<Proxy>) – Object properties are held in <Prop> tags

Advanced IBM Rational Functional Tester, Java Scripting

49

Dynamic Object Handling
Object Map Internals
Sample 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

Dynamic Object Handling
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.

Advanced IBM Rational Functional Tester, Java Scripting

50

Dynamic Object Handling
Object Map Internals
Sample Script Definition XML
<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

Dynamic Object Handling
Unmapped Objects.
– Several Functional Tester methods return TestObject references that are unmapped. – These are called 'bound references', 'found references' or 'unmapped references'. – You can use these references to dynamically access objects

Advanced IBM Rational Functional Tester, Java Scripting

51

Dynamic Object Handling
Unmapped Objects
– Some TestObject methods that return bound references: – find(); – getChildren(); – getMappableChildren(); – getparent(); – getMappableParent(); – getTopParent(); – getTopMappableParent(); – getOwnedObjects(); – getOwner();

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
Comparing Mapped to Unmapped Objects
Every 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 ClassicsJavaA Composers 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

Advanced IBM Rational Functional Tester, Java Scripting

52

Dynamic Object Handling
Unmapped Objects
Coding 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.

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
Comparing Mapped to Unmapped Objects
You 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!

Advanced IBM Rational Functional Tester, Java Scripting

53

Dynamic Object Handling
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.

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
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.

Advanced IBM Rational Functional Tester, Java Scripting

54

Dynamic Object Handling
Nothing in the Object Map?
– getDomains() returns an array of DomainTestObjectS – DomainTestObject has a getTopObjects() method that returns an array of TestObjectS

Advanced IBM Rational Functional Tester, Java Scripting

Dynamic Object Handling
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); }
Domain: Java; Num wins: 1 Domain: Html; Num wins: 0 Domain: Process; Num wins: 0
Advanced IBM Rational Functional Tester, Java Scripting

55

Dynamic Object Handling

Lab 4.1 Lab 4.2

Advanced IBM Rational Functional Tester, Java Scripting

Module 5 Custom Verification Points

Advanced IBM Rational Functional Tester, Java Scripting

56

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 IFtVerificationPoint interface. • This interface has several methods for creating Verification Point behavior

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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

Advanced IBM Rational Functional Tester, Java Scripting

57

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

58

Custom Verification Points
Valid Data Types
you can pass vpManual: – ITestData – String – Primitive Wrapper – Vector – Hashtable – Array[] – Array[][]

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

59

Custom Verification Points
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

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

60

Custom Verification Points
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();

Passes

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Fails

Advanced IBM Rational Functional Tester, Java Scripting

61

Custom Verification Points
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();

Fails

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
Persisting Data with vpManual(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();

Advanced IBM Rational Functional Tester, Java Scripting

62

Custom Verification Points
Persisting Data with
vpManual(Name, data).performTest();
Hashtable props = tree().getProperties(); ITestDataProperties baseline = VpUtil.getTestData(props); vpManual("TreeProperties", baseline).performTest();

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
Selected IFtVerificationPoint methods:
– – – – – – performTest(); getActualData() getExpectedData(); compare(); compareAndLog(); getVPName();

Advanced IBM Rational Functional Tester, Java Scripting

63

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

64

Custom Verification Points
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();

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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();

Returns false

Advanced IBM Rational Functional Tester, Java Scripting

65

Custom Verification Points
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();

returns false

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
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 value IFtVerificationPoint vp = vpManual("User", act); boolean b = vp.compareAndLog(false);

Logs a pass

Advanced IBM Rational Functional Tester, Java Scripting

66

Custom Verification Points
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

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points
Log methods in RationalTestScript
– – – – logInfo(String info) logError(String error) logWarning(String warning) logTestResult(String headline, boolean passed, String additionalInfo)

Advanced IBM Rational Functional Tester, Java Scripting

67

Custom Verification Points
logTestResult()
signature: logTestResult(String headline, boolean passed, String additionalInfo); example: logTestResult("vp1", (exp.equals(act)), "addn1 info") ;

Advanced IBM Rational Functional Tester, Java Scripting

Custom Verification Points

Lab 5.1

Advanced IBM Rational Functional Tester, Java Scripting

68

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

Advanced IBM Rational Functional Tester, Java Scripting

69

Non-Java/Browser Windows
IScreen and IWindow
– Limited set of methods – The IScreen API has no methods that retrieve data – You cannot cast from IScreen to TestObject

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
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

Advanced IBM Rational Functional Tester, Java Scripting

70

Non-Java/Browser Windows
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

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
IScreen
Bad News There are no methods in IScreen that retrieve interesting information (properties, data) from a window
– isEnabled(), isShowing(), hasFocus() – getMousePosition(), getChildAtPoint()

Good News There are methods in IWindow that allow you get limited information about a window

Advanced IBM Rational Functional Tester, Java Scripting

71

Non-Java/Browser Windows
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);

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
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();

Advanced IBM Rational Functional Tester, Java Scripting

72

Non-Java/Browser Windows
IWindow
Getting 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

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
IWindow
GUI actions – If the IWindow is a TopLevelWindow, you can call these methods: • close() • activate() • maximize() • minimize() • contextHelp() - activates the window's contextsensitive Help mode.

Advanced IBM Rational Functional Tester, Java Scripting

73

Non-Java/Browser Windows
IWindow
Related 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();

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
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

Advanced IBM Rational Functional Tester, Java Scripting

74

Non-Java/Browser Windows
Accessing the Clipboard
Retrieve 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 ) { }

Advanced IBM Rational Functional Tester, Java Scripting

Non-Java/Browser Windows
Accessing the Clipboard
Send 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 );

Advanced IBM Rational Functional Tester, Java Scripting

75

Non-Java/Browser Windows

Lab 6.1

Advanced IBM Rational Functional Tester, Java Scripting

76