520 likes | 532 Views
Learn advanced topics in Rational RobotJ, including regular expressions, debugging, adding libraries and classes, data-driven testing, and more.
E N D
Rational RobotJ Field Training Advanced Topics
Agenda • 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 • 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-Click
Regular 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
Regular 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
Regular 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)
Regular 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
Regular 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
Regular 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
Debugging • 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();
Debugging Perspective Debug controls Debug views Breakpoint Outline View for navigation of source
Basic 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
Working 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
Inspecting 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
Evaluating 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
Adding 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.
Bringing 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 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 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 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.
Data Driven Testing - Example • JavaClassicsA - UC • The user selects a CD and clicks on the Place Order button. • The user enters a name and password and clicks on the OK button • The user places an order specifying quantity, credit card number, and credit card expiration date and clicks on the Place Order button. • The user click on the OK button of the confirmation dialog. • The user selects the View Existing Order Status menu option. • The user enters name and password again to view the status of the order and clicks on the OK button. • The user selects the order and clicks on the Cancel Selected Order button. Clicks on Close button • The user closes the application.
Data Driven Testing Script Overview: New import directives: Restructured testMain: Container for data records File, DB or DP New function for main test case
Data Driven Testing - Example Before vs. After Recorded Values Replaced Values
Data Driven Testing - Example Loading Test Data - File See Advanced Topics in RobotJ Help! Java programming knowledge needed!
Modifying 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 Referencecom.rational.test.ft.script.IOptionName • Only valid during playback
Querying 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 , ...)
Querying Values of Object Properties • Example
Handling Ambiguous Recognition • Ambiguous recognition can happen when more than one instances a Java application is used/started during recording.
Handling Ambiguous Recognition • Using ProcessTestObjects to identify the application • Manual coding required! Ambiguous Recognition Non Ambiguous Recognition
Handling Unexpected Active windows • RobotJ has no standard mechanism (vs. Robot)! • There is no out-of-the-box approach! • Code can be added to test script • Pros: Easy to do • Cons: Has to be added wherever it is need! • 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 RobotJ New helper super class is NOTgenerated!! User has to create the class!!
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
Handling Unexpected Active windows • 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 usingthe new helper super class! New helper super class is NOTgenerated!! User has to create the class!!
Super Helper Class Added custom helper Default RationalTestScript - onObjectNotFound CustomHelper - onObjectNotFound ATestScriptHelper ATestScriptHelper ATestScript ATestScript After recording you will see the script
Handling Unexpected Active windows • Override onObjectNotFound – Method in new super helper class • Sample codewill be provided!
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.
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!
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.
Adding Manual VPs • Before execution Log viewer (HTML) • After execution • ! no manual2! New!
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.
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! 1 2
Adding Dynamic VPs 1 • First execution of statement starts VP dialog Select objectto verify 1
Adding Dynamic VPs 2 • First execution of statement starts VP dialog, with object already selected Object alreadyselected! 2