rational robotj field training advanced topics. confidential information agenda regular expressions...
TRANSCRIPT
Rational RobotJ Field TrainingRational RobotJ Field Training
Advanced TopicsAdvanced Topics
Confidential InformationConfidential Information
AgendaAgenda Regular Expressions Debugging Adding Libraries and Classes Data Driven Testing Modifying Options for Script Execution Querying Values of Object Properties Handling Ambiguous Recognition Handling Unexpected Active Windows Adding Manual and Dynamic VPs
Regular Expressions Debugging Adding Libraries and Classes Data Driven Testing Modifying Options for Script Execution Querying Values of Object Properties Handling Ambiguous Recognition Handling Unexpected Active Windows Adding Manual and Dynamic VPs
Regular ExpressionRegular Expression
Confidential InformationConfidential Information
Regular ExpressionsRegular Expressions Regular Expressions are often used for pattern
matching or text parsing (remember VU language – match function).
RobotJ uses a class RegEx which is implemented using org.apache.regexp.
Regular Expressions can be used within a script: Regex r = new Regex("a*b"); boolean matched = r.matches("aaaab");
Regular Expressions can be used to match attributes of VP, Recognition.
Regular Expressions are often used for pattern matching or text parsing (remember VU language – match function).
RobotJ uses a class RegEx which is implemented using org.apache.regexp.
Regular Expressions can be used within a script: Regex r = new Regex("a*b"); boolean matched = r.matches("aaaab");
Regular Expressions can be used to match attributes of VP, Recognition.
Right-ClickRight-Click
Confidential InformationConfidential Information
Regular ExpressionsRegular Expressions Characters
unicodeChar Matches any identical unicode character \ Used to quote a meta-character (like '*') \\ Matches a single '\' character \0nnn Matches a given octal character \xhh Matches a given 8-bit hexadecimal character \\uhhhh Matches a given 16-bit hexadecimal character \t Matches an ASCII tab character \n Matches an ASCII newline character \r Matches an ASCII return character \f Matches an ASCII form feed character
Character classes [abc] Simple character class [a-zA-Z] Character class with ranges [^abc] Negated character class
Characters unicodeChar Matches any identical unicode character \ Used to quote a meta-character (like '*') \\ Matches a single '\' character \0nnn Matches a given octal character \xhh Matches a given 8-bit hexadecimal character \\uhhhh Matches a given 16-bit hexadecimal character \t Matches an ASCII tab character \n Matches an ASCII newline character \r Matches an ASCII return character \f Matches an ASCII form feed character
Character classes [abc] Simple character class [a-zA-Z] Character class with ranges [^abc] Negated character class
Confidential InformationConfidential Information
Regular ExpressionsRegular Expressions Predefined Classes
. Matches any character other than newline \w Matches a "word" character (alphanumeric plus "_") \W Matches a non-word character \s Matches a whitespace character \S Matches a non-whitespace character \d Matches a digit character \D Matches a non-digit character
Boundary Matchers ^ Matches only at the beginning of a line $ Matches only at the end of a line \b Matches only at a word boundary \B Matches only at a non-word boundary
Predefined Classes . Matches any character other than newline \w Matches a "word" character (alphanumeric plus "_") \W Matches a non-word character \s Matches a whitespace character \S Matches a non-whitespace character \d Matches a digit character \D Matches a non-digit character
Boundary Matchers ^ Matches only at the beginning of a line $ Matches only at the end of a line \b Matches only at a word boundary \B Matches only at a non-word boundary
Confidential InformationConfidential Information
Regular ExpressionsRegular Expressions Greedy Closures (match as many elements as possible)
A* Matches A 0 or more times (greedy) A+ Matches A 1 or more times (greedy) A? Matches A 1 or 0 times (greedy) A{n} Matches A exactly n times (greedy) A{n,} Matches A at least n times (greedy) A{n,m} Matches A at least n but not more than m times
(greedy) Reluctant Closures (match as few elements as possible)
A*? Matches A 0 or more times (reluctant) A+? Matches A 1 or more times (reluctant) A?? Matches A 0 or 1 times (reluctant)
Greedy Closures (match as many elements as possible) A* Matches A 0 or more times (greedy) A+ Matches A 1 or more times (greedy) A? Matches A 1 or 0 times (greedy) A{n} Matches A exactly n times (greedy) A{n,} Matches A at least n times (greedy) A{n,m} Matches A at least n but not more than m times
(greedy) Reluctant Closures (match as few elements as possible)
A*? Matches A 0 or more times (reluctant) A+? Matches A 1 or more times (reluctant) A?? Matches A 0 or 1 times (reluctant)
Confidential InformationConfidential Information
Regular ExpressionsRegular Expressions Logical Operators
AB Matches A followed by B A|B Matches either A or B (A) Used for subexpression grouping
Backreferences \1 Backreference to 1st parenthesized subexpression ... (\2,\3,\4,\5,\6,\7,\8) \9 Backreference to 9th parenthesized subexpression
Logical Operators AB Matches A followed by B A|B Matches either A or B (A) Used for subexpression grouping
Backreferences \1 Backreference to 1st parenthesized subexpression ... (\2,\3,\4,\5,\6,\7,\8) \9 Backreference to 9th parenthesized subexpression
Confidential InformationConfidential Information
Regular Expressions - ExamplesRegular Expressions - Examples The simplest regular expression is a sequence of characters and
matches any string that contains the sequence. def matches abcdefg
Certain characters are treated specially by Regex. The period (.) matches any single character.a.c matches axcd
The asterisk or star (*) matches any repeating sequence (0 or more) of the previous pattern.a*d matches aaaaada*d matches d
The plus (+) matches any repeating sequence (1 or more) of the previous pattern.a+d matches aaaaada+d matches not d
The simplest regular expression is a sequence of characters and matches any string that contains the sequence. def matches abcdefg
Certain characters are treated specially by Regex. The period (.) matches any single character.a.c matches axcd
The asterisk or star (*) matches any repeating sequence (0 or more) of the previous pattern.a*d matches aaaaada*d matches d
The plus (+) matches any repeating sequence (1 or more) of the previous pattern.a+d matches aaaaada+d matches not d
Confidential InformationConfidential Information
Regular Expressions - ExamplesRegular Expressions - Examples The question mark (?) matches 0 or 1 of the previous pattern.ab?c matches acab?c matches abc
Parentheses can be used to group patterns.a(bc)+d matches abcbcbcbcd
You can indicate multiple choices using the vertical bar (|).red|green|blue matches redx(red|green|blue)*x matches xredblueredx
You can indicate a set of characters using square brackets ([]).x[ab]x matches xaxx[ab]x matches xbx[0-9]* matches 12378
The question mark (?) matches 0 or 1 of the previous pattern.ab?c matches acab?c matches abc
Parentheses can be used to group patterns.a(bc)+d matches abcbcbcbcd
You can indicate multiple choices using the vertical bar (|).red|green|blue matches redx(red|green|blue)*x matches xredblueredx
You can indicate a set of characters using square brackets ([]).x[ab]x matches xaxx[ab]x matches xbx[0-9]* matches 12378
DebuggingDebugging
Confidential InformationConfidential Information
DebuggingDebugging Integrated debugger supports
Debugging of RobotJ scripts
Debugging of [Local] Java Application Debugging of Remote Java Application
To playback script until a certain point use stop();
Integrated debugger supports Debugging of RobotJ scripts
Debugging of [Local] Java Application Debugging of Remote Java Application
To playback script until a certain point use stop();
Confidential InformationConfidential Information
Debugging PerspectiveDebugging Perspective
Debug controlsDebug controls Debug viewsDebug views
Outline View for navigation of sourceOutline View for navigation of sourceBreakpointBreakpoint
Confidential InformationConfidential Information
Basic Debugger ControlsBasic Debugger Controls Accessed via
Debug menu Debug perspective control panel
The debugger gives numerous controls to the developer Pause Resume Step Into – allows you to load any referenced code Step Over – skips referenced code
• e.g. skipping over println() calls in the code
Accessed via Debug menu Debug perspective control panel
The debugger gives numerous controls to the developer Pause Resume Step Into – allows you to load any referenced code Step Over – skips referenced code
• e.g. skipping over println() calls in the code
Confidential InformationConfidential Information
Working with breakpointsWorking with breakpoints Breakpoints are set directly
in the source via the context menu Shown along the left edge
Breakpoint view lists all breakpoints that exist Manipulation functions (e.g.
remove, disable, etc.) available via the context menu
Breakpoints are set directly in the source via the context menu Shown along the left edge
Breakpoint view lists all breakpoints that exist Manipulation functions (e.g.
remove, disable, etc.) available via the context menu
Confidential InformationConfidential Information
Inspecting variablesInspecting variables The stack contents
Displayed automatically in the variables view as you step through code
To inspect variables at a given point Highlight in source editor
in debug perspective Choose inspect from the
context menu
The stack contents Displayed automatically in
the variables view as you step through code
To inspect variables at a given point Highlight in source editor
in debug perspective Choose inspect from the
context menu
Confidential InformationConfidential Information
Evaluating expressions and code snippetsEvaluating expressions and code snippets
The display view allows you to evaluate expressions interactively Useful for experimenting and
testing ideas, , etc. e.g. results of some calculation
that is not in the source Similar to an interpreter
To evaluate an expression: Type it in the display view Highlight and choose display
from the context menu
The display view allows you to evaluate expressions interactively Useful for experimenting and
testing ideas, , etc. e.g. results of some calculation
that is not in the source Similar to an interpreter
To evaluate an expression: Type it in the display view Highlight and choose display
from the context menu
Adding Libraries and Classes Adding Libraries and Classes
Confidential InformationConfidential Information
Adding libraries to the build pathAdding libraries to the build path To add external JARS,
folders, etc. to the build path Open Project Properties Select Libraries tab Navigate and add
appropriate folders, libraries, etc.
To add external JARS, folders, etc. to the build path Open Project Properties Select Libraries tab Navigate and add
appropriate folders, libraries, etc.
Confidential InformationConfidential Information
Bringing in Java code into the projectBringing in Java code into the project To bring in existing
Java code to a project: Use File>Import Select File system option
for importing source files Select Zip File option
for importing Jar files Navigate to folder or file(s) Select individual elements Finish
To bring in existing Java code to a project: Use File>Import Select File system option
for importing source files Select Zip File option
for importing Jar files Navigate to folder or file(s) Select individual elements Finish
NOTE: Import is a “copy” operation. Copy is located in the project folder.
After the import, two versions of the imported resources exist in the environment.
NOTE: Import is a “copy” operation. Copy is located in the project folder.
After the import, two versions of the imported resources exist in the environment.
Data Driven TestingData Driven Testing
Confidential InformationConfidential Information
Data Driven TestingData Driven Testing Data-driven tests play back user input from a file
rather than using the input taken interactively during recording
Possible Source of Data: Flat files Database files Rational TSS datapools
- incl. all .jar-files Java knowledge is required
(no this is not the PM of RobotJ!)
Data-driven tests play back user input from a file rather than using the input taken interactively during recording
Possible Source of Data: Flat files Database files Rational TSS datapools
- incl. all .jar-files Java knowledge is required
(no this is not the PM of RobotJ!)
Confidential InformationConfidential Information
Data Driven TestingData Driven Testing Record a test as usual, which generates a RobotJ script. Add the Java code necessary to load the data file before the
startApp command. Create an indexed loop around the test that reads the data
source record by record. Replace the commands in the RobotJ script where the data
was entered interactively with commands that read from the data source.
Play back the RobotJ script to ensure that the data is read correctly.
Record a test as usual, which generates a RobotJ script. Add the Java code necessary to load the data file before the
startApp command. Create an indexed loop around the test that reads the data
source record by record. Replace the commands in the RobotJ script where the data
was entered interactively with commands that read from the data source.
Play back the RobotJ script to ensure that the data is read correctly.
Confidential InformationConfidential Information
Data Driven Testing - ExampleData Driven Testing - Example JavaClassicsA - UC
1. The user selects a CD and clicks on the Place Order button.2. The user enters a name and password and clicks on the OK button3. The user places an order specifying quantity, credit card number, and
credit card expiration date and clicks on the Place Order button.4. The user click on the OK button of the confirmation dialog.5. The user selects the View Existing Order Status menu option.6. The user enters name and password again to view the status of the
order and clicks on the OK button.7. The user selects the order and clicks on the Cancel Selected Order
button. Clicks on Close button8. The user closes the application.
JavaClassicsA - UC1. The user selects a CD and clicks on the Place Order button.2. The user enters a name and password and clicks on the OK button3. The user places an order specifying quantity, credit card number, and
credit card expiration date and clicks on the Place Order button.4. The user click on the OK button of the confirmation dialog.5. The user selects the View Existing Order Status menu option.6. The user enters name and password again to view the status of the
order and clicks on the OK button.7. The user selects the order and clicks on the Cancel Selected Order
button. Clicks on Close button8. The user closes the application.
Confidential InformationConfidential Information
Data Driven TestingData Driven Testing
Script Overview:New import directives:
Restructured testMain:
Script Overview:New import directives:
Restructured testMain:
New function for main test caseNew function for main test case
File, DB or DPFile, DB or DP
Container for data recordsContainer for data records
Confidential InformationConfidential Information
Data Driven Testing - ExampleData Driven Testing - Example
Before vs. AfterBefore vs. After
Recorded ValuesRecorded Values
Replaced ValuesReplaced Values
Confidential InformationConfidential Information
Data Driven Testing - ExampleData Driven Testing - Example
Loading Test Data - FileLoading Test Data - File
See Advanced Topics
in RobotJ Help!
See Advanced Topics
in RobotJ Help!
Java programming
knowledge needed!
Java programming
knowledge needed!
Modifying Options for Script ExecutionModifying Options for Script Execution
Confidential InformationConfidential Information
Modifying Options for Script ExecutionModifying Options for Script Execution Options specified with UI can be changed Method calls to change options during playback
Object x = getOption(IOptionName.option); setOption(IOptionName.option,value); resetOption(IOptionName.DELAY_BEFORE_KEY_DOWN); Values can be found at
• RobotJ API Reference com.rational.test.ft.script.IOptionName
Only valid during playback
Options specified with UI can be changed Method calls to change options during playback
Object x = getOption(IOptionName.option); setOption(IOptionName.option,value); resetOption(IOptionName.DELAY_BEFORE_KEY_DOWN); Values can be found at
• RobotJ API Reference com.rational.test.ft.script.IOptionName
Only valid during playback
Querying Values of Object PropertiesQuerying Values of Object Properties
Confidential InformationConfidential Information
Querying Values of Object PropertiesQuerying Values of Object Properties Accessing object property UC:
You may want to compare previous versions of a value to the current value and to do so would require a calculation .
Sometimes objects have methods that return other objects and you may need to test on the value of a property of the returned object.
You also may want to branch in your RobotJ script based on the current value of a property.
Methods GET/SET Object getProperty(String propertyName); void setProperty(String , ...)
Accessing object property UC: You may want to compare previous versions of a value to the
current value and to do so would require a calculation . Sometimes objects have methods that return other objects
and you may need to test on the value of a property of the returned object.
You also may want to branch in your RobotJ script based on the current value of a property.
Methods GET/SET Object getProperty(String propertyName); void setProperty(String , ...)
Confidential InformationConfidential Information
Querying Values of Object PropertiesQuerying Values of Object Properties Example Example
Handling Ambiguous Recognition Handling Ambiguous Recognition
Confidential InformationConfidential Information
Handling Ambiguous RecognitionHandling Ambiguous Recognition Ambiguous recognition can happen when more than
one instances a Java application is used/started during recording.
Ambiguous recognition can happen when more than one instances a Java application is used/started during recording.
Confidential InformationConfidential Information
Handling Ambiguous RecognitionHandling Ambiguous Recognition Using ProcessTestObjects to identify the application
Manual coding required!
Using ProcessTestObjects to identify the application
Manual coding required!
Ambiguous RecognitionAmbiguous Recognition
Non Ambiguous RecognitionNon Ambiguous Recognition
Handling Unexpected Active Windows Handling Unexpected Active Windows
Confidential InformationConfidential Information
Handling Unexpected Active windows Handling Unexpected Active windows RobotJ has no standard mechanism (vs. Robot)! There is no out-of-the-box approach!
1. Code can be added to test script Pros: Easy to do Cons: Has to be added wherever it is need!
2. Code can be added to a custom helper class(the dark side of RobotJ)
Pros: More general Cons: Not trivial!
RobotJ has no standard mechanism (vs. Robot)! There is no out-of-the-box approach!
1. Code can be added to test script Pros: Easy to do Cons: Has to be added wherever it is need!
2. Code can be added to a custom helper class(the dark side of RobotJ)
Pros: More general Cons: Not trivial!
again NO
, this is not the PM of R
obotJagain N
O, this is not the PM
of RobotJ
New helper super class is NOTgenerated!! User has to create the class!!
New helper super class is NOTgenerated!! User has to create the class!!
Confidential InformationConfidential Information
Handling Unexpected Active windows Handling Unexpected Active windows Add code to script – Example
Some browsers show a dialog when switching between secure/non-secure pages
Some browsers don‘t
Or will not do aftermore than 5 seconds
Add code to script – Example Some browsers show a dialog when switching between
secure/non-secure pages
Some browsers don‘t
Or will not do aftermore than 5 seconds
Confidential InformationConfidential Information
Handling Unexpected Active windows Handling Unexpected Active windows Create new helper class before next recording
Recorder preferences• Every script recorded after
this change will use the newhelper super class!
Change script template• all scripts in DataStore will be using
the new helper super class!
Create new helper class before next recording Recorder preferences
• Every script recorded afterthis change will use the newhelper super class!
Change script template• all scripts in DataStore will be using
the new helper super class!
New helper super class is NOTgenerated!! User has to create the class!!
New helper super class is NOTgenerated!! User has to create the class!!
Confidential InformationConfidential Information
Super Helper Class Super Helper Class
RationalTestScript
- onObjectNotFound
RationalTestScript
- onObjectNotFound
ATestScriptHelperATestScriptHelperATestScriptHelperATestScriptHelper
ATestScriptATestScriptATestScriptATestScript
CustomHelper
- onObjectNotFound
CustomHelper
- onObjectNotFound
After recording you will see the scriptAfter recording you will see the script
DefaultDefault Added custom helperAdded custom helper
Confidential InformationConfidential Information
Handling Unexpected Active windows Handling Unexpected Active windows Override onObjectNotFound – Method
in new super helper class
Sample codewill be provided!
Override onObjectNotFound – Method in new super helper class
Sample codewill be provided!
Adding Manual and Dynamic VPs Adding Manual and Dynamic VPs
Confidential InformationConfidential Information
Adding Manual VPs – 3 Different Kinds Adding Manual VPs – 3 Different Kinds
Static (Recorded) - Verification points created at record time that are ready to play back at the appropriate time during execution of test script.
Manual - Verification points in which the data supplied by the script developer. The verification point interface only compares and logs the result with persistence as appropriate.
Dynamic - Verification points that are created at playback time, the first time that the script is run. These verification points act like recorded scripts after the baseline for the verification point is established.
Static (Recorded) - Verification points created at record time that are ready to play back at the appropriate time during execution of test script.
Manual - Verification points in which the data supplied by the script developer. The verification point interface only compares and logs the result with persistence as appropriate.
Dynamic - Verification points that are created at playback time, the first time that the script is run. These verification points act like recorded scripts after the baseline for the verification point is established.
Confidential InformationConfidential Information
Adding Manual VPs Adding Manual VPs UC1:
Verify base lined data during execution. This can also be non GUI-based data like e.g. data base record field, any data available in application or a result of calculation/transformation.
UC2: Compare dynamic data during execution. This can also be non GUI-
based data like e.g. data base record field, any data available in application or a result of calculation/transformation.
Important Information: All data types or objects that should be used have to be supported
VALUE types! – Extensibility is possible but not within the first release!
UC1: Verify base lined data during execution. This can also be non GUI-
based data like e.g. data base record field, any data available in application or a result of calculation/transformation.
UC2: Compare dynamic data during execution. This can also be non GUI-
based data like e.g. data base record field, any data available in application or a result of calculation/transformation.
Important Information: All data types or objects that should be used have to be supported
VALUE types! – Extensibility is possible but not within the first release!
Confidential InformationConfidential Information
Adding Manual VPs Adding Manual VPs Manual VPs
IFtVerificationPoint vpManual (java.lang.String vpName, java.lang.Object actual)
IFtVerificationPoint vpManual (java.lang.String vpName, java.lang.Object expected, java.lang.Object actual)
vpName must be unique in a script!
Before performTest() is executed the first time a baseline is created.
Manual VPsIFtVerificationPoint vpManual (java.lang.String vpName,
java.lang.Object actual)IFtVerificationPoint vpManual (java.lang.String vpName,
java.lang.Object expected, java.lang.Object actual)
vpName must be unique in a script!
Before performTest() is executed the first time a baseline is created.
Confidential InformationConfidential Information
Adding Manual VPs Adding Manual VPs Before execution
Log viewer (HTML)
After execution ! no manual2!
Before executionLog viewer (HTML)
After execution ! no manual2!
New!New!
Confidential InformationConfidential Information
Adding Dynamic VPs Adding Dynamic VPs UC: Insert verification point into script.
Specify line of script by adding dynamic VP, without specifying the object. At runtime the object will be select with the object finder dialog.
Specify line and object of script by adding a dynamic VP, with specifying the object. At runtime the object will already be selected but user has to finish verification point dialogs.
After first run, those VPs behave like static VPs.
UC: Insert verification point into script. Specify line of script by adding dynamic VP, without
specifying the object. At runtime the object will be select with the object finder dialog.
Specify line and object of script by adding a dynamic VP, with specifying the object. At runtime the object will already be selected but user has to finish verification point dialogs.
After first run, those VPs behave like static VPs.
Confidential InformationConfidential Information
Adding Dynamic VPs Adding Dynamic VPs Dynamic VPs
IFtVerificationPoint vpDynamic (java.lang.String vpName) IFtVerificationPoint vpDynamic (java.lang.String vpName, TestObject
objectUnderTest)
vpName must be unique in a script!
Dynamic VPsIFtVerificationPoint vpDynamic (java.lang.String vpName) IFtVerificationPoint vpDynamic (java.lang.String vpName, TestObject
objectUnderTest)
vpName must be unique in a script!
11
22
Confidential InformationConfidential Information
Adding Dynamic VPs Adding Dynamic VPs First execution of statement starts VP dialog
Select objectto verify
First execution of statement starts VP dialog
Select objectto verify
11
11
Confidential InformationConfidential Information
Adding Dynamic VPs Adding Dynamic VPs First execution of statement starts VP dialog, with
object already selected
Object alreadyselected!
First execution of statement starts VP dialog, with object already selected
Object alreadyselected!
22
22
Confidential InformationConfidential Information
Adding Dynamic VPs Adding Dynamic VPs
Before executionLog Viewer (HTML)
After execution
Before executionLog Viewer (HTML)
After execution
New!New!
Confidential InformationConfidential Information
QuestionsQuestions