Escolar Documentos
Profissional Documentos
Cultura Documentos
Copyright 2013 Ranorex GmbH Created on: August 8, 2013 Ranorex Version: 4.1 Authors: Roland Enzinger, Christoph Preschern, Tobias Walter Special Thanks to: Michael Gissing, Alexander Hoisl
Contents
Ranorex Studio - The Layout #1 - Project View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #2 - Module Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #3 - File View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lesson 1: Getting Started Preparing to Record User Actions . . . . . System Under Test: KeePass Password Safe Recording a Test . . . . . . . . . . . . . . Analyzing Recorded Steps . . . . . . . . . . Executing the Test . . . . . . . . . . . . . Lesson 2: Ranorex Modules - Test Actions Lesson 3: Data-Driven Testing Using Variables within Recordings . . Using Variables within the Repository Creating Test Data . . . . . . . . . . Combining Variables with Test Data . Combining Variables with Parameters Invoking Actions: Selection . . . . . . Executing Data Driven Tests . . . . . 1 1 2 2
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
5 . 5 . 5 . 6 . 16 . 16 19 21 21 22 24 28 28 31 34 36 36 42 47 52 53 56 58 61 64 67 71 77 80 83 87 94 109 114 115 122 128 132 135 138 140 143 143 146 148
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
Lesson 4: Ranorex Test Suite Test Suite Editor . . . . . . . . . . . . . . . Module Group Editor . . . . . . . . . . . . . General Structure of a Test Suite and its Test Running a Test Suite . . . . . . . . . . . . . Running Tests without Ranorex Studio . . . . Test Suite Settings . . . . . . . . . . . . . . Test Case Settings . . . . . . . . . . . . . . Using Data in Test Suites . . . . . . . . . . . Lesson 5: Ranorex Recorder Before Starting to Record . During Recording . . . . . After Recording . . . . . . Replay and Debug Actions Recorder Variables . . . . . User Code Actions . . . . . Additional Editing Options Image-Based Automation .
. . . . . . . . Cases . . . . . . . . . . . . . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
Lesson 6: UI Mapping with Ranorex Repository Adapting an Existing Repository . . . . . . . . Adding Repository Items . . . . . . . . . . . . Waiting for UI Elements - Repository Timeouts Editing RanoreXPath . . . . . . . . . . . . . . Repository Separation . . . . . . . . . . . . . . Repository Settings Dialog . . . . . . . . . . . Repository Item Properties . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
Lesson 7: Code Modules Creating Code Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Repository within Code Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Screen Shots within Code Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Variables with Code Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Using Code Modules within Test Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Lesson 8: Reporting Reading Ranorex Reports . . . . . . Report Levels . . . . . . . . . . . . Logging Individual Information . . . Updating the Custom Report Format Create a Custom Report Template . 154 154 156 158 164 165 168 171 172 176 178 181 201 204 205 207 208 208 208 209 210 210 212 213 214 214 215 216 216 217 218 219 219 222 222 225 226 228 229 232 233 235 237 240 244 247 251 254 257
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Lesson 9: Ranorex Spy Short Introduction to the Structure of RanoreXPath . Capture Screenshot Files for Image-Based Search . . Tracking UI Elements . . . . . . . . . . . . . . . . . RanoreXPath Edit Mode . . . . . . . . . . . . . . . The Path Editor . . . . . . . . . . . . . . . . . . . . Creating Ranorex Snapshot Files . . . . . . . . . . . General Ranorex Settings General settings . . . . . Advanced Settings . . . . Recorder Settings . . . . Repository Settings . . . Imaging Settings . . . . . Plug-In Specific Settings
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Code Examples Using Repository in Code . . . . . . . . . . . . . . . . . Wait for UI Elements Using Repository . . . . . . . . . . Create Adapters to Access More Properties and Methods Create a List of Adapters From a Repository Element . . Using Validate Class . . . . . . . . . . . . . . . . . . . . Forcing a Test Case to Fail . . . . . . . . . . . . . . . . Set Up Automation Speed . . . . . . . . . . . . . . . . Accessing Test Case & Test Suite Context . . . . . . . . Advanced Code Examples . . . . . . . . . . . . . . . . . How to do image based automation . . . . . . . . . . . How to find and compare images . . . . . . . . . . . . . Handling unexpected Dialogs . . . . . . . . . . . . . . . Data Connectors Manage Data Sources . . Kind of Data Connectors Simple Data Table . . . CSV File . . . . . . . . . SQL Connector . . . . . Excel File . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Instrumentation Wizard Running Instrumentation Wizard from the Command Line Java AWT/Swing . . . . . . . . . . . . . . . . . . . . . . Adobe Flash/Flex . . . . . . . . . . . . . . . . . . . . . . Mozilla Firefox . . . . . . . . . . . . . . . . . . . . . . . . Google Chrome . . . . . . . . . . . . . . . . . . . . . . . Apple Safari . . . . . . . . . . . . . . . . . . . . . . . . . Android . . . . . . . . . . . . . . . . . . . . . . . . . . . iOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
II
Working with 2.X Projects in 3.X Test Suites Adding 2.X Projects to 3.X Projects . . . . . Using 2.X Recording Modules . . . . . . . . . Adapting 2.X Data-Driven Recording Modules Using 2.X Code Modules . . . . . . . . . . . Breaking Changes . . . . . . . . . . . . . . . Technology Instrumentation Flash/Flex Testing . . . . . . Testing of Java Applications . Qt Testing . . . . . . . . . . . Testing of Legacy Applications Testing of SAP Applications . General Troubleshooting . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
260 260 261 261 262 263 265 266 271 272 274 277 278
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
RanoreXPath 283 RanoreXPath Syntax Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Advanced RanoreXPath Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 RanoreXPath with Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Ranorex UI Adapter 289 Multiple Adapters for one GUI element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 Android Testing Infrastructure . . . . . . . . . . . . Getting Started . . . . . . . . . . . Record your Android test . . . . . . Run your test on any Android device Manage Devices . . . . . . . . . . . Troubleshooting . . . . . . . . . . . Instrumentation with Source Code . iOS Testing Infrastructure . . . . . . . . . . Getting Started . . . . . . . . . Record your iOS Test . . . . . . Run your test on any iOS device Testing of mobile web sites . . . Web Testing Architecture of Websites in the Find or filter Web Elements . . Cross-Browser Testing . . . . Recordings & Repositories . . Samples . . . . . . . . . . . . 295 295 295 303 308 315 325 327 328 328 328 346 353 356 358 358 359 360 361 363 367 368 378 381 383 385 386 388 391 392 395
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Ranorex Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Source Control Add a Solution to Source Control . . . . . . . . . . . . . . Check Out a Solution from Source Control . . . . . . . . . Open an existing Ranorex TFS Solution with Visual Studio Open existing Visual Studio TFS Solution with Ranorex . . Ranorex Studio IDE Create . . . . . . Build . . . . . . . Run . . . . . . . Adding New Items Solution Explorer
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
III
Debugging . . . . Code Completion Code Conversion . Code Navigation . Code Generation . Refactoring . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Visual Studio Integration 408 Create a new Visual Studio project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408 Add Ranorex core assemblies as references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408 Write some Ranorex automation code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 System Requirements 64-bit Platforms Remotely Working with Ranorex Do not Automate via Remote Desktop Window . . . . . . Do not Close or Minimize the RDP Window . . . . . . . . Disable Mouse/Keyboard Activities . . . . . . . . . . . . . Use same Color and Resolution Settings . . . . . . . . . . Increase Timeouts on Virtual Machines . . . . . . . . . . . Disable Asynchronous Dispatching of Mouse and Keyboard 411 412 413 413 413 413 414 414 414
. . . . . . . . . . . . . . . . . . . . Events
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Silent Installation of Ranorex 416 Installation Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Installation Command Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Install Ranorex License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Licensing License Registration . . . . . . . Installing a Node Locked License Installing a Floating License . . . Transfer Licenses . . . . . . . . Uninstall License . . . . . . . . . 418 418 418 420 423 425 428 428 428 428 429 429 429 429 429 430 430 430 430 430 430
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
FAQ How does Ranorex identify UI elements? . . . . . . . . . . . . . . . . . . . . . . . . . Is it possible to run the same Ranorex test code on Vista and XP? . . . . . . . . . . . Is it required to use RanoreXPath for test automation? . . . . . . . . . . . . . . . . . Does Ranorex support data driven testing? . . . . . . . . . . . . . . . . . . . . . . . . What to do when items cant be found during Ranorex test execution? . . . . . . . . . Is it possible to extend recordings with user specified code actions? . . . . . . . . . . . What is the difference between Adapter and Element? . . . . . . . . . . . . . . . . . Is it possible to trigger Ranorex tests from an existing test or build environment? . . . Can I use Ranorex libraries within Visual Studio? . . . . . . . . . . . . . . . . . . . . What shall I do with unexpected dialogs and popup windows during test automation? . Is it possible to test Silverlight applications with Ranorex? . . . . . . . . . . . . . . . Is it possible to automate a webpage without moving the mouse pointer? . . . . . . . What are the system requirements for developing and running Ranorex tests? . . . . . Are there known incompatibilities with other software? . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
IV
#1 - Project View
A Ranorex Studio project is based on files and uses the same project file format as Microsoft Visual Studio 2008/2010. The project view shows all files and references currently associated with the project. A Ranorex Studio project can have the following type of items: Test Suite Module Group Repository Recording Code Files Represents the projects test suite (*.rxtst) Represents the projects module groups (*.rxtmg) Used to manage UI elements (*.rxrep) Represents an automation module based on capture/replay (*.rxrec) Any type of C# or VB.NET code; typically used to create code based automation modules
The project view is mainly used to add new items like Lesson 5: Ranorex Recorder, Lesson 6: UI Mapping with Ranorex Repository, Module Groups, or Lesson 7: Code Modules.
#2 - Module Browser
The Module Browser view lists all available modules (Lesson 7: Code Modules & Lesson 5: Ranorex Recorder) based on the projects code files and module groups based on the projects module group file. In addition it shows all the variables defined by a module or module group. The view is mainly used to drag and drop and to reuse automation modules and module groups within the test suite view. Specify folders (e.g. for recording files) within the projects view to group modules. In order to find already existing modules use the module browsers search field.
#3 - File View
When double-clicking a file in the Project View or a module in the Module Browser, the associated file will be opened in the Studios file view. This view is mainly used for the actions shown below.
Note: Read more about how to activate mouse movement recording in Lesson 5: Ranorex Recorder - Recorder Hotkeys.
Figure 8: Open source tool KeePass Since version 3.3, KeePass is included with Ranorex Studio along with a sample database file.
On the start screen of Ranorex Studio youll find a Sample button which also includes a sample test suite project that handles some test cases within the KeePass application. You can have a closer look at that in Lesson 4: Ranorex Test Suite - General Structure of a Test Suite and its Test Cases.
Recording a Test
In the following section you will create a new Ranorex Test Solution and record the process for adding an entry to KeePass.
Figure 9: Ranorex Studio Start Page - creating a new test solution In the categories box select C# and in the templates box select the Ranorex C# Test Suite item. Next specify a name and a location for your new test suite project.
Note: Because of possible performance and security impacts, projects should not reside on a network drive (neither should Ranorex itself be installed on a network drive). Its recommended to use a version control system (VCS) instead.
Click the Create button and a new test suite project opens.
Figure 11: New Ranorex Test Suite containing one test case using an empty recording Within the test suite view, the template already contains a single test case which uses an empty recording. In order to start recording simply open Recording1 by double-clicking the recording within the test suite view.
Note: Its recommended to copy the KeePass application folder from the sample directory within the Ranorex installation folder (<Ranorex Installation Folder>\Samples\KeePassSample\C#\KeePassTestSuite\KeePass) to your projects folder as by default you do not have write access to the program folder which is necessary to save the database handled by KeePass.
You can open the project folder by right-clicking the project in the Projects view and choosing Open Folder in Explorer from the context menu
Figure 13: Open project folder in explorer to copy the sample application to the project folder
Click the Record button in order to start. The Recorder assists you in preparing the application under test. Simply select Run an Application and specify the directory and file name of the application under test. After copying the KeePass application folder to your project folder, you can set the File Name by choosing the file KeePass.exe using the Browse button.
Figure 14: New Recording dialog - Ranorex automatically starts the specified application Click on Start in order to record the test. The KeePass application opens and the Ranorex Recorder starts running.
10
Figure 17: KeePass application with sub menu Edit (Menu item Add Entry is selected)
11
12
13
Figure 21: KeePass form with highlighting frame for validation At the first step of the validation you can choose the UI element you want to validate. Verify that the correct element is selected and click on the Next button. At the second step, all available attributes for the given UI element to check are shown. Just click the OK button in order to accept the preselected Text attribute.
14
Figure 24: Screenshot indicating the save button in the tool bar Stop the recording by pressing the Stop button in the recorder tool bar.
15
Figure 25: Recorded steps shown within the actions table You can read more about different action types within Ranorex Recorder in Lesson 5: Ranorex Recorder - Additional Editing Options.
Reporting
After executing the test, Ranorex Studio automatically opens the generated test report file (*.rxlog) which shows whether the test run was successfully or not.
16
Figure 28: Test run failed In order to force an error as shown in the picture above, simply modify the expected value used in the validation step of the recording (e.g. Typo3Demo instead of WordPressDemo).
Figure 29: Force an error by changing the expected value of the validation step Now the test automation executable is also available within your project folder. To run the test suite without starting Ranorex Studio, simply double-click the executable file.
Note: In order to run the test suite project on an external machine it is required to have the executable (*.EXE) as well as the test suite file (*.RXTST) in the same directory at the target machine. If your Ranorex Studio solution consists of more than one project, you need to ensure that the library (*.DLL) files are also part of the same directory. In short, it is best to copy the complete output folder (e.g. bin/debug) to the target machine.
17
Figure 30: MyFirstTestProject.exe located within the build folder of the project By default the report files are also generated within the same directory. Further information on changing the report folder can be found in Lesson 4: Ranorex Test Suite - Test Suite Settings. Read more about alternative ways to run the test suite from the command line or with the standalone test suite runner in Lesson 4: Ranorex Test Suite - Running Tests without Ranorex Studio.
18
Identifying Modules
In your first recording, you did the following from a keyword driven perspective:
Started the application KeePass Logged in Added a new entry
Set the attributes for title, username, password, URL Chose an icon Set the expiration value
Validated the existence of the newly created entry in the grid Deleted the entry Saved the changes Closed the application
In order to split recordings into smaller automation modules, select related actions and use the context menu item Move to new Recording Module. Within the underlying recording, the three actions performing the log-in should be selected and moved into a new recording named LogIn. These three actions are a click on the password field, a key sequence on the password field and finally a mouse click on the OK button.
19
Figure 32: Create a new recording named LogIn Then, select and move all items used to add a new entry to the database to a new recording named AddEntry.rxrec. Repeat the previous steps to create modules for ValidateEntry, DeleteEntry, SaveDB and for CloseSUT. Also rename the initial recording file (with only one recorded item left for starting the application) from Recording1.rxrec to StartSUT.rxrec. In the end you should have seven separate new recording modules. After splitting the initial recording into smaller test actions, the Ranorex Module Browser also contains the new modules. Now simply use the drag and drop feature to combine these modules within the test case.
Figure 33: Use the drag and drop feature to specify your test case within the test suite view Separating a recording into smaller modules is the first step in building robust and reusable automation modules. In addition replace constant values used within these modules with variables in order to enable parameterization. Read more about how to use variables in Lesson 3: Data-Driven Testing.
20
All these input actions are done within the AddNewEntry recording. You need to open the recording file and identify the actions which have to be variable. To make the input of the title variable, open the combo box as shown below and select As new Variable to create a new variable.
Figure 34: Create a new variable for a key sequence action item
21
Figure 35: Create a new variable Specify the variable name and the default value which is automatically set to the same value as it was recorded initially. If you want to alter the name or the default values, simply open the variables dialog as described in section Using Variables within the Repository.
Note: Please do not use variable names which are already in use by a recording or code module.
Repeat the previous step which makes the key sequence action used to set the value of the title field variable, and also create the variables varPassword, varUsername and varURL for the specific actions.
Figure 36: Make Item Variable menu item from context menu in Recorder
22
Typically the menu item for the Expires Date in the KeePass application is identified by the accessible name attribute. Now you can define a new variable for the attribute text by clicking the button on the right.
Figure 37: Create a new variable for the expires menu item When looking at the repository, you can see that the item pointing to the menu item is now using the variable within the path expression specified previously.
Figure 38: Variable repository item Also rename the repository item MenuItem1Year to MI Expires to clarify that this repository element is not pointing to a specific menu item anymore but instead uses a variable to choose one of the menu items in a data-driven way. Repeat the same procedure to add a new variable varIconIndex into the repository item which is connected to the icon list view. The recording AddNewEntry now uses six variables. Four of them are used for key sequences directly within the recording while the others are used within the repository. To get an overview of all variables used within the recording simply click the Variables button as shown below.
23
24
Figure 41: Open the Manage data sources . . . dialog Assuming someone is keeping his/her passwords in an excel-file, the following example could be helpful in more safely managing the information. This Excel file contains the fields Title, Username, Password, URL, Expires and IconIndex.
Note: The top row is handled as a header. Therefore the cells of the first row will be interpreted as captions for the current column.
Figure 42: Use an Excel file for data-driven testing Now create a new data connector by clicking on Use Excel file. . . .
25
26
27
For further information about different Ranorex data connector types have a look at Data Connectors.
Note: Please assure that the ExcelConnector is chosen in the Data Source tab sheet (drop down in the middle of the dialog).
Now you can connect each column specified within the data table with variables used by the test case. You can also map multiple variables to one data column. You currently only have variables specified within the AddNewEntry module.
In addition to typical test data specified within data tables as shown before, a test suite and its test cases allow you to declare global and local parameters. These parameters can also be bound to module variables. This type of data driven execution can help with environment-related attribute values and similar issues as the following example describes. The test case starts with a recording module called StartSUT. The recording only contains a single action item used to start the KeePass application. Open the recording and create a new variable called varApplicationPath.
Figure 47: Create a new variable for the execution path of system under test The execution path of the system under test has to be declared as a global parameter on the test suite level in order to combine it with multiple test cases of the test suite. Use the context menu within the test suite view and open the parameters dialog as shown below.
29
Figure 49: Define a new global parameter for the test suite Specify a new parameter name by clicking in the first cell of the column Name. Now specify a value for the new parameter. Just copy and paste the execution path from the default value shown within the variables dialog of the recording StartSUT. Click OK to apply the changes and to close the dialog. Read more about how to open a recordings variable dialog in Lesson 5: Ranorex Recorder - Recorder Variables. Now you are ready to combine the global parameter with the variable created within the recording before. Open the test cases data binding dialog the same way you did previously for combining variables with the data table.
30
Figure 50: Bind global parameter to the variable used within recording StartSystemUnderTest Before you execute the data driven test case, you have to make sure that the values specified within the Excel file can be used correctly within the AddNewEntry recording. The values for the title, username, password, URL and expiration will not cause any problems during automation. Considering a more advanced situation such as selecting an item from a list view which is not visible by default; there will be a problem because of the current visibility state of the item. This situation will be handled in the next section.
31
32
Icons with an index of 0 to 49 are visible without using the scroll bar so icons with indexes lower than 49 could even be accessed easily when using a data-driven approach. In order to select an icon with a higher index (e.g. 66 for the US dollar icon) in an automated way, a simple click on an invisible item would fail. It is recommended to add an Invoke Action to select the icon regardless of the visibility of the item in the listview. First of all an additional action should be added to the recording right before the action representing the click on the icon. Select one action before the click action (#5) and click the Add New Action button as shown below.
Figure 53: Adding a new Invoke Action to the recording After adding the new item you need to specify for which repository element the invoke action should be used. Simply open the Select Repository Item dialog as shown below and select IconItem.
Figure 54: Open the Select Repository Item dialog by clicking on the highlighted button and choosing ListItem-Icon from the repository After assigning the repository item to the invoke action, the recorder presents the methods suitable for the role list item. The role ListItem shows a Select method which you can chose as seen in following figure.
33
Figure 55: Choose Select method Also delete the initially recorded mouse click action (action item #7 shown in previous figure) because now the recording uses the new invoke action to select the list item instead of the click action.
Now switch back to the test suite view and start your data driven test by clicking the Run button.
34
Figure 56: Report file showing two iterations of the test case After executing the test suite the report file shows the results for each iteration. The summary chart counts each iteration as a single test case run.
35
36
Figure 57: Ranorex Test Suite file Using the project created during the lessons 1 through 3 you can now create a new test case based on the existing modules. To open up the test suite, you can double-click the *.rxtst file or use the View Test Suite button shown in the toolbar panel.
Select the Test Case item to create a new test case at the current position.
37
Note: Within a test suite, test cases can be added at different levels. A test case can also be added as a child to an existing test case or to a folder item.
The newly created test case will be used for validating the correctness of KeePass version number so the name of the test case should be changed. Select and click on the test case and rename it to TC ValidateVersionNumber.
38
39
Press OK to add the record module to the test case. Repeat the steps to add the record items LogIn and CloseSUT to the test case.
Figure 63: Insert a new recording module Before starting the new recording, you should confirm that KeePass is running - you could start the application manually if it is not running. The new recording module ValidateVersionNumber should cover the following steps:
open the about dialog validate the version number close the about dialog
Keep in mind that you need to select the Global Recording option because the system under test will be started by the reused recording module StartSUT.
40
Figure 64: Newly created recording scenario During the validation step, Ranorex automatically created a new repository item for the cell holding the version number from KeePass - the text itself is used for identification of the cell (path). Since the content of the cell (KeePass version number) is used for identification, a higher version number would cause the test case to fail because the cell cant be found anymore - independent from the match of version number in the validation step itself. To avoid this, the path to this cell should be modified to be more robust. The path can be edited using The Path Editor. Additionally it should not use the version number itself for identification.
Figure 65: Click the Edit in Spy button open the path editor
41
Figure 66: Change attributes for identification: deselect text attribute and select column- and row-index attributes Using the index for identification assures the accessibility of the cell even if a new version is released. To complete this recording you could modify the validation action to use a new variable called varCurrentKeePassVersion with a default value 2.20.1 instead of matching against the constant value. This module variable could be bound to a new global variable GlobalCurrentKeePassVersion. Now the test case ValidateVersionNumber is ready to be executed. Use the context menu item Run Selected Test Case to run it and see whether it works or not.
Figure 68: Open module group editor After creating a new solution an empty module groups file is created.
43
Figure 69: Module group editor You can add module groups to your project in the following ways:
Press the New Module Group button in the module group editor Use the context menu in the test suite editor to add a module group to a test case Use the context menu in the test suite editor to group selected modules into a module group
Figure 70: Adding a module group to a test case using the context menu in the test suite editor
44
Figure 71: Grouping existing modules into a new module group using the context menu in the test suite editor By grouping existing modules into a module group, the module group will be filled with the selected modules. When adding a new module group, the module group is empty and can be filled with modules by using the context menu in the module group and then adding a new or existing module.
Figure 72: Adding an existing module to a module group using the context menu Next to adding existing modules it is possible to add folders to module groups to add additional hierarchical levels. An existing module can also be added using drag and drop from the module browser or project view into the module group in the module group editor.
45
Figure 73: Drag and drop module into a module group To allow for a data driven approach as described in Lesson 3: Data-Driven Testing, it is necessary to pass values from data sources or parameters through the module group to the modules contained in that module group. You can define data binding for modules in the module group by using the context menu item Data Binding. . . which appears by right-clicking a module group.
Figure 74: Open the data binding dialog for module group The data binding dialog allows you to specify which of the module variables should be changeable from outside the module group and which of the module variables should have constant values inside the module group.
Note: The mechanism for using constant values within module groups allows hiding module variables. This can reduce the complexity and increases the clarity of module groups because it is not always necessary to set each module variable individually.
46
Figure 75: Define which module variables should get their values passed from outside the module group and which module variables should have constant value After defining a module group and its data binding, it can be added to a test case the same way a module is added. The data binding for module groups works exactly the same way as it works for modules. Further details about working with modules and data binding can be found in Lesson 2: Ranorex Modules - Test Actions and Lesson 3: Data-Driven Testing.
47
Figure 77: Opening the sample test suite project KeePassTestSuite This sample includes different types of elements which can be used within a test suite and covers all possible combinations.
48
#1 Folder #2 Test case #3 Setup region #4 Module group #5 Teardown region #6 Code module #7 Recording module
Used to group multiple test cases Represents a test case which can contain modules, a setup or teardown region or other test cases Groups modules used to prepare a test case (e.g. start system under test, initialize a database, etc.) Used to group several modules into a reusable set Groups modules used to clean up a test case (e.g. deleting files generated during test execution, closing application, etc.) Automation module written in code Automation module generated by recording
49
Note: If you want to define one setup and one teardown region for a set of test cases, simply nest your test cases as shown in the following picture
50
Figure 80: Nested test case for a general setup and teardown region
Note: In order to define global setup and teardown regions click on Show Setup/Teardown in context menu of the test suite node and drag and drop the wanted modules or module groups to displayed the setup and teardown regions.
Figure 81: Show setup and teardown region for test suite node
51
Figure 82: Drag and drop modules to global setup region In order to quickly deactivate a certain module, instead of deleting it from the test case, use the context menu item Disable.
52
For example one test suite run configuration can be defined where the data driven tests stored in your test suite will be executed and one test suite run configuration can be defined where they wont.
53
Figure 86: External Ranorex Test Suite Runner You can use the Ranorex Test Suite Runner to run the test suite, execute certain test cases or just run a specific automation module. Additionally one can create new run configurations the same way as is done within a Ranorex Studio Project.
54
zipreportfile|zrf:<zip report file path> When used with /zipreport|zr, sets the name (and path) of the compressed report file. If no path is provided, the path of the report file is used. If the file extension is not .rxzlog, the extension will be replaced with .rxzlog. By default, the report filename specified in the rxtst file or the value of reportfile|rf is used with an .rxzlog extension (for example: %S %Y%M%D %T.rxzlog). reportlevel|rl: Debug|Info|Warn|Error|Success|Failure|<any integer> Sets the minimum report level that log messages need to have in order to be included in the log file. Specify None to completely disable reporting. These levels correspond to the following integer values:
Debug=10 Info=20 Warn=30 Error=40 Success=110 Failure=120
listglobalparams|lp Lists all global parameters and their values. listtestcaseparams|ltcpa:<name or guid of test case> Lists all testcase parameters and their values. testcase|tc:<name or guid of test case> Runs this test case only. testsuite|ts:<path to test suite file> Runs the test cases defined by the test suite (rxtst) file. By default
the rxtst file with the same name as the <TestSuiteExe> is used or the first rxtst file in the same folder as <TestSuiteExe>.
runconfig|rc:<configuration name> Runs the test cases of the specified configuration defined by the rxtst file. Configurations can be edited using Ranorex Studio or TestSuiteRunner. By default, the currently selected run config is used. module|mo:<module name or guid> Runs the module with the specified name or guid. Assemblies loaded by <TestSuiteExe> and assemblies referenced in the rxtst file are searched.
55
param|pa:<global parameter name>=<value> Creates or overrides values for global parameters specified in the test suite. testcaseparam|tcpa:<name or guid of test case>:<parameter name>=<value> Creates or overrides values for testcase parameters specified in the test suite. runlabel|rul:<custom value> Sets a custom runlabel for the test run. testcasedatarange|tcdr:<name or guid of test case>=<data range> Sets the data range for a testcase.
Note: Compressed report files (*.rxzlog) can be extracted by right-clicking them in explorer and choosing Extract from context menu. Report files (*.rxlog) can be compressed by right-clicking them in explorer and choosing Compress from context menu.
56
57
Name Description Show Progress Dialog Capture Tracing Screenshots Report Level Warn for unbound variables
Specifies the name of the test suite (same as shown within the test suite editor) Description of the test suite (same as shown within the description column of the test suite editor) Specifies whether a progress dialog should be shown during test suite execution Specifies whether tracing screenshots should be captured or not in the case of an error Specifies the minimum report level of messages shown with the report file Specifies whether a warning should be shown for unbound variables
Additional Report Settings Report Enabled Report File Directory Report File Compressed Copy Report Template Folder Auto Save Interval Place screenshots in folder Specifies whether a test report should be generated Specifies the directory for the generated report files Specifies the filename generated by the report; move the mouse over the Description label to see available placeholder values Specifies whether the report should be generated as compressed folder Specifies the directory holding customized style files used instead of the Ranorex default style to present the reports; a new template can be created by pressing the button Create Custom Template as explained in Create a Custom Report Template Specifies how often the report file is saved during execution Specifies whether the created screenshots will be stored in a specific folder for each report or directly in the report folder
Global Parameters Globally specified parameters can be accessed and used by every test case within the test suite. The KeePassTestSuite example project uses a global parameter to specify the directory path for the application under test. You can easily connect global parameters with variables as shown in the test case TC AddEntry. In addition you can use the global parameter to transfer values or states between test cases.
59
Figure 93: Test case properties dialog Use the context menu to change the report level or the error behavior for multiple test cases.
60
After building up the test suite with its test cases as described in the previous sections, the included module variables can be bound to group variables, constant values, data columns, or parameters. Constant Values: Constant values can be used in module groups to hide module variables outside a module group. This can help to reduce the complexity and increases the clarity of module groups. For further details have a look at the section about the Module Group Editor. Group Variables: In module groups, group variables are the interface between the nested modules and the nesting test case. 61
For further details have a look at the section about the Module Group Editor. Data Columns: The columns of a data connector are called Data Columns and specify the columns from external data sources. Have a look at the data connectors section (Data Connectors) to get an overview about the different kinds of data connectors. Data columns can be connected to variables in the data binding dialog of a test case as described in section Combining Variables with Test Data. Parameters: Module variables can also be bound to parameters. A distinction is made between local parameters, which are part of a specific test case and are available in the test case and all child test cases, and global parameters which are available in the whole test suite. Unlike local parameters, global parameters can be set from the command line as explained in section Running Tests via Command Line. Have a look at the section Combining Variables with Parameters to see how parameters can be connected to variables.
Figure 95: Scope of data containers The green rectangle illustrates the scope of global parameters, the blue rectangle the scope of local parameters and data columns of the test case named Parent Test Case 1 and the red rectangle the scope of local parameters and data columns of the test case named Test Case 1. This means, in Test Case 1 you can bind all global parameters as well as all local parameters and data columns of itself and its parent test case Parent Test Case 1, as illustrated in the following figure.
62
Figure 96: Data binding dialog of Test-Case-1 The green rectangle illustrates a global parameter, the blue rectangle a local parameter and a data columns of the test case named Parent Test Case 1 and the red rectangle a local parameter and data column of the test case named Test Case 1.
63
Figure 98: Ranorex Recorder as standalone tool Within Ranorex Studio you can add a new recording in different ways. Use the project view to add a new recording by clicking the Add Recording Module button on the toolbar.
64
Figure 99: Add a recording module by clicking the button on the toolbar Alternatively you can also add a recording directly to a test case within the test suite editor.
65
Figure 101: Add a new recording to the selected test case During the next chapters you learn about the following:
Before Starting to Record During Recording After Recording Replay and Debug Actions Recorder Variables User Code Actions Additional Editing Options Image-Based Automation
66
Prepare to Record
Before you start recording, you need to ensure that your system under test is ready to start with the manual test execution. In addition, consider the following points in order to avoid too much effort in cleaning up the recording and the repository afterwards.
Do not run multiple instances of your application under test if that is not part of the test case itself By default, mouse movements are not recorded; for this reason please also perform mouse clicks in situations such as navigating through menus (or use Recorder Hotkeys to record mouse movements) Think about which steps should be part of the final test Try to keep recordings small in order to make them modular
67
Current Recording
This tab primarily contains configuration parameters for code generation specific to the current recording. All settings on this tab page are stored within each recording. Recording namespace: Specifies the namespace used for the generated code. Recording class name: Specifies the class name used for the generated code. Replay speed factor (%): The speed factor is used to increase or decrease the replay overall speed by a specific factor value. Replay repeat count: The repeat count is used to specify the number of iterations. Recorder UI mode: By specifying the recorder UI mode the set of actions available in the actions table will be adapted (Global: all actions, Desktop & Web: no mobile actions, Mobile: no mouse and keyboard actions). Enable turbo mode for replay and generated code: Is used to specify whether recorded delays between actions should be part of the generated code. Generate replay reports: This setting is used to turn the generation of reports during replay on and off. Use item logging by default:
68
Activate this setting to turn on a default logging message for each action item.
Recorder Defaults
In this tab you can specify global default values for every newly created recording. The settings are divided into three sections: Recording Capture a screenshot for each step: Specifies whether a screenshot of the current action should be made during the recording. Highlight clicked elements: Specifies whether objects clicked during a recording should be highlighted. Coordinate recording mode: Specifies the way coordinates will be recorded. Following options are available:
None: Actions will always be invoked on the center of the recognized elements Pixel: Relative coordinates within a recognized element are recorded in pixels Proportional: Relative coordinates within a recognized element are recorded in percent
Timings for new actions Note: Please note that the following settings only affect newly created actions, not existing actions.
Use timings also for recorded actions: When enabled, the specified timings below will be taken instead of the recorded durations. Key sequence split time (ms): Use this setting to specify the maximum time between key presses in a key sequence during recording. If this time is exceeded, the sequence is split into multiple key sequences. Mouse move time per action (ms): Specifies the time in milliseconds used to move the mouse to the UI object related to the action. Mouse/Pointer-related action time (ms): Specifies the overall time in milliseconds used for a manually created mouse action. The value set for this setting is only taken into account for manually created actions, when the time of an action cannot be determined during recording or when Use timings also for recorded actions is activated. Keyboard-related action time (ms): Specifies the default overall time in milliseconds used for a manually created keyboard action. The value set for this setting is only taken into account for manually created actions, when the time of an action cannot be determined during recording or when Use timings also for recorded actions is activated.
69
Code Generation Recording namespace: Specifies the namespace used for the generated code. Recording class name: Specifies the class name used for the generated code. Generate replay reports: This setting is used to turn the generation of reports during replay on or off. Use item logging by default: Activate this setting to turn on a default logging message for each action item.
70
During Recording
Click the Record button to trigger a new recording.
Figure 104: Click Record to start recording After clicking the record button youre assisted in running an application, opening a browser to navigate to a particular URL or starting an app on a mobile device before recording any actions. Therefore its not necessary to record actions like double clicking a shortcut on the desktop. By choosing the option global recording its on you to start the application under test.
Figure 105: New recording dialog After clicking the Start button, the Recorder or Ranorex Studio will be minimized. A running recording session is indicated in the Ranorex Recorder tool bar.
71
Figure 106: Ranorex Recorder toolbar Now perform all the actions you want to be part of the automated test. You can also pause the recording session at any time by clicking the Pause button.
Note: The Recording can be stopped either by using the keyboard shortcut <SHIFT>+<ESC> or by pressing the Stop button.
Validation
The Ranorex Recorder provides two different types of validation during a running recording session:
Validation based on attribute values of a UI element Image-based validation
Validating States or Attributes The Ranorex Recorder tool bar can be used to validate states or attributes of GUI elements during a running recording session. Click the Validate button to pause the recording in order to start the validation.
Figure 107: Validation mode is active Recording is now paused. Move your mouse pointer over a specific UI element. Wait a moment to ensure that the highlight frame is surrounding the intended UI element indicating that it is ready to be validated. Click on the element to open the validation dialog.
72
Figure 108: The highlight frame specifies the element to validate In the Validation dialog you can check if you have chosen the right UI element to validate. By clicking Next button you can define the attributes and their values you want to validate.
73
Figure 110: Select the attributes of the UI element to validate To validate UI elements of pop-up windows like menus, use the shortcut key V to turn on validation mode without clicking the Validate button. Read more about how to enable hotkeys in the section Recorder Hotkeys later on in this lesson.
Validating Images In addition to validating attribute values of a UI element, it is also possible to validate images or screen regions of an application. Simply switch to validation mode as described above and select a UI element. To validate the elements image, open the Image tab in the validation dialog.
74
Figure 112: Validate whether a specific listitem contains a specified image or not
Recorder Hotkeys
Ranorex Recorder provides useful hot keys for triggering special features like validation or the recording of simple mouse movements. When you start a new recording session, the hot key functionality is turned off. To activate the Recorders hot keys simply click on the Enable Hotkeys checkbox or press the master hot key <SCROLL>. The recorders toolbar will then show which shortcuts are available.
75
Figure 113: Available hot keys during a recording session V: Press the hot key V to turn on Validation - especially useful for validating elements of a pop-up window like menu items and drop-down lists. M: Use the hot key M to record simple mouse movements. Simply move the mouse pointer to a certain position and press the hot key to record the mouse movement in relation to the underlying UI element. T: Its easy to validate the content of a tooltip by pressing the hot key T after the tooltip box appears. Ranorex Recorder automatically captures a mouse move action in relation to the underlying item and validates the current content of the tooltip. I The hot key I is used to turn on/off Image-Based Automation - used for pop-up windows, menu items or drop-down lists. Roll Mouse Wheel Roll the mouse wheel during validation mode to change the level of UI element selection.
76
After Recording
After pressing the Stop button on the Recorder toolbar, the recorder represents all low level actions like clicking on a button or typing text within the actions table.
Figure 114: Recorded actions listed in the recorders actions table By default each recorded action has an additional screenshot shown on the right. Depending on the type of action, each row shows additional action-related information. Whereas a mouse related action provides more information about the type of mouse action (Click, Double-Click, Move, etc.) or which button was used (Left, Right, etc.) a key sequence action only stores the keystrokes made during a recording.
Figure 116: Recorded mouse click action Additionally each action can be connected to a UI element represented by the repository view below. For each UI element used during a recording session the recorder generates an item in the given repository.
Note: In case an item already exists in the repository or if the UI element is used twice during a recording session the recorder reuses this element.
77
By default the repository is not part of the recording file and only refers to the main repository used within a project. In comparison to the integrated Recorder, the standalone Recorder tool embeds the repository by default. You can also unlink and refer to another file or embed the repository into the recording file. Read more about how to do that in Lesson 6: UI Mapping with Ranorex Repository - Repository Separation.
Figure 117: Key sequence action (at password textfield) refers to the repository item Password
Action Cleanup
After finishing the recording, it is advisable to look at each recorded action item in detail. The recorder offers some editing features to clean up the sequence, for example merging key sequence actions.
Figure 118: Merging selected keyboard items By default the recorder records the mouse click location performed by the user relative to a button or a text field. Its possible to turn that off in advance within the Recorders settings dialog. Alternatively, you can also change the click location afterwards within the properties dialog.
78
Figure 119: Changing click location for all mouse related action items to Center
Repository Cleanup
Each item within the repository refers to one RanoreXPath expression necessary to identify the object. The names used for the items and folders of the repository are generated automatically. It is recommended to rename them if its helpful. Additionally the structure of the repository is generated automatically and depends on the internal UI hierarchy given by the application under test. To rename items of the repository simply click in the cell or press <F2> at the selected item.
Figure 121: New structured and renamed repository Use logical folders to create additional structure, for example to group input fields, buttons or a log on form with user name and password text boxes. Also, already existing rooted folders can be used for grouping as well. Learn more about how to work with Ranorex repositories in Lesson 6: UI Mapping with Ranorex Repository.
79
Note: To set the Turbo Mode for more than one module select the desired modules in the Module Browser and set the option Enable Turbo Mode in the properties pane.
Figure 123 During execution, the progress box shown at the right lower corner gives information about the current automation state. Press the <Pause> key to stop execution. Press <SHIFT> + <PAUSE> to skip delays during replaying.
80
Figure 124: Test run progress If the option Generate replay reports is set to true, a report is shown after replay has finished. By default, each action item logs one message to the report.
Figure 125: Report after replay Within Ranorex Studio, the report is shown as a new file view whereas the standalone Recorder opens the report viewer to show the result. Learn more about how to use Ranorex reporting in Lesson 8: Reporting. As shown in the picture above, each log entry allows one to quickly jump to the source action item. This is helpful in quickly debugging single actions in case of an error. Within the Recorders actions table, you can then fix a step causing an error and quickly re-run single or selected steps using the context menu. Additionally, you can play to and play from the selected item
81
82
Recorder Variables
As described in Lesson 3: Data-Driven Testing a recording can have variables instead of static string values generated during the recording session. In particular key sequence actions used to type in such things as log-in data into a form are commonly used action items which have to be data driven in many cases. At any position within the actions table where you can change or set values in a cell it is possible to use variables instead.
Figure 127: Variables used for key sequence actions The variables in the table above are shown in green. All variables used within the recording can be connected to a Ranorex data connector or to local/global parameters provided by the the entire test suite or a single test case. Creating Variables There are different ways to create new variables for a recording. During Lesson 3: Data-Driven Testing you learned how to create variables directly within the actions table.
Figure 129: Create a new variable Most action types can make use of variables. To make a click action data driven - for example selecting an icon for password entry - you need to define a repository variable used for identification within a RanoreXPath expression. 83
Select the context menu item Make Item Variable. . . to create a new repository variable in order to have a data driven mouse click action.
Figure 130: Creating a new variable for use within the path of the repository item
84
Figure 131: Create a new variable for selecting a menu item Another option is to open the variables dialog where you can add new or change existing variables already used by the recording. Moreover, you can see which variables are In use, Not in use or In use from Repository.
85
Figure 133: Variable dialog of a recording with different levels of usage Use the toolbar to add, remove or copy a variable from the repository. Change the name of the variable and set a default value by clicking in the cells of the table. Press the Copy Variable from Repository button in the tool bar to make variables defined in the given repository available for the recording. Read more about variables specified in repositories in Lesson 3: Data-Driven Testing - Using Variables within the Repository.
86
Looking at a recording file in the projects view you will see that each recording has two associated code files.
Note: User code actions are not available within the standalone Recorder.
Within Ranorex Studio, each recording manages two types of source code files:
Automatically generated main recording source code file <RecordingName>.<CodeFileExtension> User specific source code file <RecordingName>.UserCode.<CodeFileExtension>
You can jump to the generated code of a recorded action by right-clicking the action and choosing View Code from the context menu.
87
Figure 135: Jump to generated code of a recorded action Every time you change and save a recording, the main code file AddNewEntry.cs is newly generated. Any change of code should always be made within the recordings UserCode.cs file.
88
Figure 137: Specify method name used for user code item
Figure 138: Use the context menu item View Code to jump into the code After the creation of a new user code action within the actions table, a new method is added to the partial class of the recording. If youre converting an existing action item, the code generated for the main recording file is transferred to the new user code method. C#
namespace MyFirstTestProject { public partial class AddEntry { // / < summary > // / This method gets called right after the recording has been started . // / It can be used to execute recording specific initialization code . // / </ summary > private void Init () { // Your recording specific initialization code goes here . } public void ClickOnPasswordField () { Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Left Click item FormAdd_Entry . TabPageList . InputFields . TextPassword at 175;9. " , repo . FormAdd_Entry . TabPageList . InputFields . TextPasswordInfo ) ; repo . FormAdd_Entry . TabPageList . InputFields . TextPassword . Click ( " 175;9 " ) ; } } }
89
VB.NET
Namespace MyFirstTestProject Public Partial Class AddNewEntry < summary > This method gets called right after the recording has been started . It can be used to execute recording specific initialization code . </ summary > Private Sub Init () Your recording specific initialization code goes here . End Sub Public Sub ClickOnPasswordField () Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Left Click item FormAdd_Entry . TabPageList . InputFields . TextPassword at 175;9. " , repo . FormAdd_Entry . TabPageList . InputFields . TextPasswordInfo ) repo . FormAdd_Entry . TabPageList . InputFields . TextPassword . Click ( " 175;9 " ) End Sub End Class End Namespace
Figure 139: User Code Action with a parameter To enhance flexibility, you can use variables instead of hardcoded values. This can be done in the usual way.
Figure 140: Create a new variable to be used as a parameter Of course you are also able to use more than one parameter for each action. If there are no more columns available (maximum of three in the GUI), you can use the browse button to access the Ranorex Argument Editor.
Figure 141: Browse button to access the Ranorex Argument Editor Youll find an overview of existing parameters in the Ranorex Argument Editor. Here you can also name existing parameters and add additional parameters.
90
Figure 142: Ranorex Argument Editor for handling user code parameters After declaring the parameters with values or variables, you can switch to the user code method and use the passed parameters.. C#
public void AddEntryWithParams ( string aTitle , string aUsername , string aPassword , string aURL ) { MyFirstTestProjectRepository MyRepo = MyFirstTestProjectRepository . Instance ; // Set text fields MyRepo . AddEntry . TabSheetAddEntry . Title . TextValue = aTitle ; MyRepo . AddEntry . TabSheetAddEntry . UserName . TextValue = aUsername ; MyRepo . AddEntry . TabSheetAddEntry . Password . TextValue = aPassword ; MyRepo . AddEntry . TabSheetAddEntry . Repeat . TextValue = aPassword ; MyRepo . AddEntry . TabSheetAddEntry . URL . TextValue = aURL ; }
VB.NET
Public Sub AddEntryWithParams ( aTitle As String , aUsername As String , aPassword As String , aURL As String ) MyFirstTestProjectRepository MyRepo = MyFirstTestProjectRepository . Instance Set text fields MyRepo . AddEntry . TabSheetAddEntry . Title . TextValue = aTitle MyRepo . AddEntry . TabSheetAddEntry . UserName . TextValue = aUsername MyRepo . AddEntry . TabSheetAddEntry . Password . TextValue = aPassword MyRepo . AddEntry . TabSheetAddEntry . Repeat . TextValue = aPassword MyRepo . AddEntry . TabSheetAddEntry . URL . TextValue = aURL End Sub
Additionally to creating method calls in Ranorex Recorder you are able to define your methods in code and just select the intended method in the Recorder Table. Here you are also able to choose overloaded methods.
91
Figure 144: Ranorex Argument Editor with arguments and variable binding from overloaded method
Conditions in Code
Another reason for writing user code is to read text values from UI elements like text boxes and to reuse them for conditional automation steps.
Note: Only create small and easy to maintain user code actions for a recording. If an implemented method should also be available for other test cases, create a code module (see Lesson 7: Code Modules) instead.
Within the DeleteEntry recording that was created in Lesson 3: Data-Driven Testing, there are three simple actions for deleting the selected entry (selecting the item, opening the context menu and choosing the context menu item). As you can see it is meaningful to only delete an entry if it is selected. To accomplish this, code with a condition can be used. As a first step, open the DeleteEntry recording and select the last two items as only they should be executed if the entry is selected. Click on the Merge Items to User Code Item menu item in the context menu.
Figure 145: Context menu item to Merge Items to User Code Item After doing this, these two actions are merged into one user code action. Give this method a meaningful name (e.g. DeleteItemIfFocused). Switch into the code view by clicking on the context menu item View User Code. Now change the converted code so it is only executed if the cell is focused on. C#
92
public void DeleteItemIfFocused () { if ( repo . MainForm . Entry . HasFocus ) { Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Right Click item MainForm . Entry at 127;1 . " , repo . MainForm . EntryInfo ) ; repo . MainForm . Entry . Click ( System . Windows . Forms . MouseButtons . Right , " 127;1 " ) ; Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Left Click item KeePass . DeleteEntry at 168;14. " , repo . KeePass . DeleteEntryInfo ) ; repo . KeePass . DeleteEntry . Click ( " 168;14 " ) ; } }
VB.NET
Public Sub DeleteItemIfFocused () If repo . MainForm . Entry . HasFocus Then Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Right Click item MainForm . Entry at 127;1 . " , repo . MainForm . EntryInfo ) repo . MainForm . Entry . Click ( System . Windows . Forms . MouseButtons . Right , " 127;1 " ) Report . Log ( ReportLevel . Info , " Mouse " , " Mouse Left Click item KeePass . DeleteEntry at 168;14. " , repo . KeePass . DeleteEntryInfo ) repo . KeePass . DeleteEntry . Click ( " 168;14 " ) End If End Sub
93
To add a new action item, open the Add New Action drop-down menu as
Figure 146: Add a new action item to the actions table By selecting one of the items a new action is added after the current selection within the actions table.
94
Figure 147: New mouse move action added Depending on the type of action item, you may be able to configure each action individually. Before doing that, you should first assign a repository item to this action - this might affect the available options for the specified action. You should click the small button framed in red in the graphic above and chose the Repository item related to the newly created action. The items listed within the Select Repository Item dialog are the same as within the recordings repository. You can use the Search text box to filter the elements. You can read more about how to use repository search and how to add new UI elements in Lesson 6: UI Mapping with Ranorex Repository - Searching For Elements. Confirm your selection by clicking OK.
Figure 148: Select a repository item to be used by the action Alternatively it is possible to assign the repository item to the action by dragging and dropping a repository item directly onto the newly created action in the column Repository Item.
95
Figure 149: Assign a repository item to the action via drag and drop To modify the newly created action, use the drop down menus available within the cell, for example you can change the action from Click to Move.
Drag and drop repository item to initiate adding a new action Alternatively to the method presented above, you can also drag and drop repository items into a new line in the actions table of a recording as shown in following graphic.
96
Figure 151: Use drag and drop to create a new action for a specific repository item You are asked to specify the type of action after dropping the element into the actions table. For more information about the available actions, see below. Types of Action Items Mouse Mouse Wheel Touch Event Key Shortcut Key Sequence Mobile Key Press Validation Invoke Action Get Value Set Value Open Browser Run Application Run Mobile App Deploy Android/iOS App Close Application Wait For Not Exists Adds a new mouse action item at the current position Adds a new mouse wheel action item Adds a new touch event action item at the current position Adds a new key shortcut action item (e.g. CTRL+C or CTRL+V) Adds a new key sequence action item (e.g. Hello) Adds a new mobile key press action (e.g. {BACK}, {MENU}) Adds a new validation action item Adds a new invoke action item (e.g. call method Select for a UI element of type list item) Adds a new get value action item (e.g. get Text for a UI element of type button) Adds a new set value action to set an attribute value (e.g. Text for a UI element of type text) Opens a browser and navigates to the given URL Runs an application at the given directory and file path Runs an application on a mobile device Instruments the given Android application and deploys it on the given mobile device or deploys the already instrumented iOS application on the given mobile device Closes an application or web site containing the given repository item Waits for given repository item to disappearance Note: This action can be used for any type of UI element
97
Adds a new report action item Note: In addition to the standard report levels, you can define custom report levels by changing the level from Info to Custom Inserts a separation line on the currently selected position in the actions table Adds a new delay action item Adds a new user code action item which is used, for example to implement a user specific validation in code
Note: Keep in mind that most types of actions can handle module variables.
Note: Based on the Recorder UI Mode there will be different sets of actions available. You can change the Recorder UI Mode in the Current Recording tab in the settings dialog.
Note: Next to the parameters as described in the next paragraphs there might be additional options for each action which can be accessed in the properties pane. You can open this pane by clicking the context menu item Properties on any action item.
Mouse This mouse action can be used for Up, Down, Click, Double-Click and Move-actions. This action is typically used for button clicks so a repository item assignment is required.
Mousewheel This mousewheel action can be specified as Vertical or Horizontal direction. You are also able to specify a wheel-delta, which is 120 by default.
Touch Event A touch event can be used to perform different kinds of touch events on mobile devices as well as on Windows 8 desktops.
Key Shortcut This action can be used for executing key shortcut actions. Aside from the shortcut itself, it is possible to specify the events Press, Up and Down. For this action, a repository item assignment is not required.
Key Sequence This action makes it possible to execute or to simulate a key sequence. This action is typically recorded in a form filling scenario (e.g. username field in login process). For this action a repository item assignment is not required. Mobile Key Press This action can be used for pressing mobile keys like {BACK} and {MENU}. For more detailed information please have a look at Android Testing - Record your Android test.
98
Validation The validation action is typically used for validating states, text or images of specific repository items. Every validation action leads to a specific entry in the report file and, depending on the type of validation and the validated element, there may be different validation results (success, failure). After assigning a repository item, you are able to choose one of the following validation-types: Exists: The validation checks for the existence of the repository item and expects an existing item. Example: A user can validate whether a button exists with a resulting success if the button actually exists. NotExists: The validation checks for the existence of the repository item and expects the item not to exist. Example: A user can validate whether an error dialog does not exist with a resulting success if the dialog does not exist. AttributeEqual: This validation checks whether an attribute (column Match Name) is equal to a specific value (column Match Value). The matching attributes depend on the assigned repository item and therefore an assignment of a repository item is assumed. For example a WinForms button may be validated on the Text, on the Valid state, on the Pressed state and also on AccessibleName, AccessibleValue etc.. The matching value can either be a constant, a self-defined value or a module variable. Example: A user can validate whether a button has the text OK with a success result if the button text is OK. AttributeRegEx: This validation is for matching a match value (self-defined match value or the content of a module variable) against a specific attribute (column Match Name) using a regular expression. Because the attribute itself (column Match Value) depends on the assigned repository item, assignment of a repository item is recommended prior to choosing a match value. If you plan to use a variable within this type of validation, you can easily implement your regular expression in the value of that variable. Example: One can validate whether the title of the KeePass application ends with the text KeePass Password Safe and could therefore use the Match Name containing the regular expression .+KeePass\Password\Safe$. The validation would lead to success if the attribute (column Match Name) has any character (this is defined as a .+ in the regular expression) followed by the constant KeePass Password Safe. For more information about Regular Expressions see RanoreXPath - RanoreXPath with Regular Expressions. AttributeContains: This validation checks whether a specific attribute (column Match Name) of a specific repository item contains a match value. The match value can either be a user-defined constant value or it can also be the content of a module variable. As above this validation assumes the assignment of a repository item. Example: A user can validate whether the title of the KeePass application contains the constant value kdbx, which is the file extension of the database used by KeePass. The match name would thus be set to Title and the match value would be set to kdbx. As a result the validation would succeed if the title actually contains the constant kdbx. AttributeNotContains: This validation can be thought of as the opposite of AttributeContains. It checks whether an attribute (column Match Value) does not contain a match value. Example: One can validate whether the content of a specific cell (URL) in KeePass does not contain the constant value http://. Match Name would therefore be set to Text and Match Value would be set to http://. This validation would lead to a positive result if the URL does not contain the constant value http://. ContainsImage: This validation checks whether the assigned repository item contains a specified screenshot. This screenshot can be easily created within the Edit Image Validation dialog which can be accessed via a button in the Screenshot column. For more information about image-based validation please have a look at the section entitled Image-Based Automation later in this chapter. Example: Its possible to validate whether the user-defined list of icons (for a KeePass entry) contains a specific icon. This could be done using image-based validation. The repository item would therefore hold the list of icons and the screenshot would be a picture of the specified icon. The validation would lead to a result if the list contains the specified icon. CompareImage: This validation checks whether a specified repository item is equal to a specific screenshot. This screenshot can be easily created within the Edit Image Validation which can be accessed via a button in the Screenshot column. For more information about image-based validation please see Image-Based Automation later in
99
this chapter. Example: To validate whether the toolbar of the KeePass application contains the intended icons you can compare the repository item with a screenshot of the toolbar in its initial state.
Invoke Action Used for invoking actions on the specified repository item. For example a WinForms button provides functionality for Ensuring Visibility, Focusing and Pressing. More important, this action can be used to easily select items in lists and drop-downs. No mouse movement and click is simulated but nevertheless the item itself is selected. This is a more powerful and smarter action than simulating the selection via mouse actions. Invoking a select action on a specific item also works if the item itself is not visible by default because there are too many elements in the list. Invoking user-defined (dynamic) actions: In addition to access actions delivered by default, you can also invoke user-defined actions (see Invoking User-Defined Actions) in your System Under Test.
Get Value As the action name indicates, this method can be used for getting values from repository items. Depending on the assigned repository item, the available attributes can be different. The value obtained can be assigned to a module variable. Depending on the available adapters for the assigned repository item, the attributes are divided into several sections (see figure below).
100
Figure 152: Submenu for Get-Value action Parse strings with regular expressions: In the Capture Regex column of the GetValue action you can specify a regular expression. For additional information on regular expressions please consult the corresponding MSDN web site: http://msdn. microsoft.com/en-us/library/az24scfc.aspx With this regular expression it is possible to easily parse a string out of the specified field. The matched string will be saved to the chosen module variable for further use. So far there is no need to write a single line of code. If the regular expression delivers more than one match, the first match will be stored in the module variable. Example: If you have a string Count: 42 and you want to return the digits only (42) you can use the following regular expression: Count: ([0-9]*)$ The first non-trivial group matched by the regular expression is returned. If there are no groups captured the full match will be returned. In case that there are more grouping constructs in the regular expression, you can mark the requested group using the following construct ?<1>.
101
Example: If you have a string Rows: 23, Columns: 42 and you want to return the number of columns you can use following regular expression: Rows: ([0-9]*), Columns: (?<1>[0-9]*)$ User-defined methods and attributes: In addition, it is also possible to call user-defined methods defined in your system under test. As is described in the next section (see Invoking User-Defined Actions), a simple application could have a public function that returns a string value holding the text of a protected text field. If the application is running during the creation of the GetValue-Action, there is a submenu for Dynamic methods. Public attributes can also be accessed and returned through the Dynamic submenu.
Note: To get access to the dynamic methods and attributes, the repository item has to be available. This can be verified by highlighting the specific element by right clicking the element in repository and choosing Highlight Element from the context menu.
Reuse values from the GUI in other modules: Using a Get Value action allows one to store an attribute value of a UI element to a module variable. Doing so makes the value available within this module.
Figure 153: Text value of a button stored in a variable To make the value stored in the module variable available to other modules, its necessary to bind the variable to a parameter. By doing so, it can then be bound to variables in other modules.
Figure 154: Two variables are bound to one parameter for passing a variable value from one module to another
Set Value As the action name indicates, this method can be used for setting the attribute values of repository items. Depending on the assigned repository item, the available attributes might be different. Depending on the available adapters for the assigned repository item, the attributes can be divided into several sections as shown below.
102
Figure 155: Submenu for Set Value Action User-defined attributes: In addition, it is also possible to set user-defined attributes. If the application is running during the creation of the Set Value action then there is a submenu for Dynamic methods holding dynamic attributes.
Note: To get access to the dynamic methods and attributes, the repository item has to be available. This can be verified by highlighting the specific element by right clicking the element in repository and choosing Highlight Element from the context menu.
Open Browser This action can be used for opening a browser. For preparation you are able to use the parameter URL for directly opening a website. The parameter browser can be used for choosing a browser (e.g. IE, Chrome, Safari or Firefox).
Note: You can use a module variable inside the column Browser which can be used for cross-browser testing. For an extensive description including an example see Cross-Browser Test Automation with Ranorex.
Additionally there is a parameter Maximized. When this parameter is set to false, the URL is opened in the default browser window size which can nevertheless be in maximized state. With the maximized-parameter set to true, the browser will be opened in maximized window state. Run Application This action can be used to run an application with the filename specified in the column File Name. You can also pass some arguments (column Arguments) and define whether the application should be started in maximized window state (column Maximized, see explanation for open browser action to find out more about this parameter). Run Mobile App When using this action you can specify a Device and an App. For more information see Android Testing - Record your Android test. Deploy Android App When using this action, you can specify a Device and an APK file. The given Android application will be instrumented and deployed to the given Android device. Close Application This action can be used for closing applications and web sites. If the Close Method is set to CloseWindow, the application is attempted to be closed. If the parameter Grace Period is set to a value greater than 0 ms, the process will be killed after the Grace Period if closing the application failed. If Close Method is set to KillProcess the applications process is killed immediately and the grace period is ignored. 103
Wait For Not Exists You can use the Wait for not exists action to wait until the assigned repository item does not exist anymore. You can also specify a Timeout.
Report
The Report action is typically used for providing information related to the test report.
You are able to choose one of the following action types: Log: This action adds a line of text holding a given value to the test report. Example: One could report the current value of a variable or UI element. Screenshot: This action adds a screenshot of a specific repository item and some user-defined text to the test report. If no repository item is assigned, a screenshot of the whole desktop is created and will be passed to the report. Example: One could report a screenshot to make the report file clarify the current state of the system under test in the report file. Snapshot: This action adds a snapshot file of a specific repository item and some user-defined text to the test report. The snapshot file can be opened directly from the report file. Please mind that the assignment of a repository item is obligatory for this type. Example: One could report a snapshot file of the application under test if an automation problem occurs in order to analyze this automation problem. In addition to the specification of the action type you are also able to deliver a Message and to specify a Report Level. For more information about the Report Level see Lesson 8: Reporting.
Separator A separator can be used to visually separate recordings into smaller sections to get a clearer view of thematically related actions. You can specify a Header Text to name or describe the following group of actions.
Delay A delay action can be used to pause test automation execution for a specific time (column Duration).
Note: This time delay is not scaled with the speed factor and is also present in Turbo Mode
User Code User code actions can be used to execute custom class methods defined in the recording user code file. User code actions are described extensively in User Code Actions
104
Figure 156: Example (in initial state) with public functionality which will be invoked C#
public void MyInvokedAction ( string MyMessage ) { edProtectedText . Text = MyMessage ; } private void btSetValue_Click ( object sender , EventArgs e ) { edProtectedText . Text = " This text was set from GUI " ; }
The protected text can only be set by clicking the button. The application then sets the text field to a constant value.
Figure 157: Example after clicking the button without using custom invoke functionality Ranorex provides the functionality for accessing methods that are declared as public directly within the actions table. The public method MyInvokedAction can easily be called using a custom argument value. When adding the new action it is recommended to keep the application (InvokeExample) open because accessible functionality is determined dynamically.
105
Figure 158: Submenus for available invoke actions Even parameters can be easily set in the Ranorex Recorder table.
Figure 159: Setting a parameter for an invoked action You can also access an attribute editor using the Browse (. . . ) button in the last argument column to get an overview of available parameters.
106
Figure 160: Browsing available arguments Invoking this method causes the text fields content to be set to the desired value.
Figure 162: Disabled actions are grayed out while Continue-On-Fail is indicated by an italic font style
Note: In case of an error the particular action logs a warning to the report.
107
Splitting Recordings
The more recorded actions you have after finishing a new recording, the less clear each single action becomes. As was already mentioned in Lesson 2: Ranorex Modules - Test Actions, identifying reusable steps within a newly created recording is recommended. Use the context menu item Move to New Recording Module to create a new recording module.
Figure 163: Creates a new Recording from the selected items Use the test suite editor as described in Lesson 2: Ranorex Modules - Test Actions and Lesson 4: Ranorex Test Suite to combine multiple recording modules into one test case.
Figure 164: Change referring repository Select Open From Disk if you want to open and refer to a repository which is currently not part of your Ranorex Studio projects. If you want to use a repository exclusively for a single recording, simply embed it into the recording file. In this case all the repository items are saved to the recording file. Creating a new repository for your recording automatically adds a new repository file to the current project.
108
Image-Based Automation
In some situations, required information for automation is not available as text but only as pixel image. Ranorex provides image-based automation to bypass this lack of accessibility. Sometimes you need to automate a click action based on image information. For this reason, Ranorex Recorder provides an optional way to capture image related mouse actions. To activate image-based recording, simply check the Image based checkbox in the Recorders toolbar during a recording session.
Figure 165: Image based recording activated Now move the mouse pointer over a certain GUI element. Ranorex highlights the last accessible UI element and also highlights a recognized image region within the GUI element. To turn off image-based recording, uncheck the checkbox or press the shortcut key I.
Note: Hotkey functionality has to be activated by first using the master hot key SCROLL. Read more about hotkey usage in the current lesson in the section entitled Recorder Hotkeys.
Introductive Example
In KeePass, there is a way to include some user specific icons for password entries (e.g. someone could use the WordPress logo for his WordPress password entry). For automation of a click on a custom icon, it might be necessary to use image-based automation because the order and in addition the index of the icon can change because icons with a lower index can be deleted.
109
Figure 166: KeePass Icon Picker dialog containing two custom icons To prepare image-based automation for a click on a custom icon, activate image-based recording. Move the mouse pointer to the listview for custom icons in KeePass and wait until the whole listview frame is highlighted. Execute a mouse click on the listview (take care to not click on a custom icon). The click has to be done on the listview control in contrast to a click on an (icon) element itself because this click defines the region in which the prospective image has to searched. Thus the image is searched in the entire list control. After stopping the recording, the actions table contains an image-based mouse click action. At the time of recording the mouse click, a screenshot of the control was created and is now listed as a child element of the correspondending repository item.
Figure 167: The Ranorex Studio Image Editor In order to automate the image-based click on the custom icon, you have to tell Ranorex which image (or part of the image in this case) you want to find and click within the figure of the listview. Open the image editor by clicking on the button in the location cell (see graphic above). In this dialog use the Select image find region toolbar button to
110
define the user-defined icon which should be clicked. Additionally use the Select click location functionality to tell Ranorex at which position the mouse click should be executed. This features will be described in more detail later on in the Image Editor section.
Figure 168: Select image find region and Select click location in Ranorex Image Editor In this example, Ranorex has been used to automate a mouse click on the custom WordPress logo within the entire listview of all available custom icons. If found, this icon is clicked regardless of the position of the icon. Again, Ranorex is not searching for any index or any list item at a specific position but for a specific figure within a region (which is a screenshot of the listview in this case). To check it, delete the KeePass icon with the index 0 and execute the recording again. The WordPress icon will be found and will be clicked although the position and the index changed in comparison to the time of recording. To alter the settings of an image-based automation action, open the property group Image-Based Location in the property grid. Image-based Location Settings Use the property group to set advanced image search options like Clipping or Best Match If Best Match is set to true, the result position with the highest similarity is used for validation. If is set to false, the first available result position will be used for the validation. The first is more accurate and the second is faster. Defines preprocessing steps that can be performed on an image before search.
None: No preprocessing Grayscale: Convert the image to a grayscale image. Edges: Detect object edges in the image using the Laplace edge detection algorithm (includes Grayscale).
Advanced Options
Preprocessing
EdgesSobel: Detect object edges in the image using the Sobel edge detection algorithm (includes Edges). Downsize: Downsize the image. Threshold: Convert the image to a black/white image using a threshold (includes Grayscale).
Specifies the name of the screenshot used in the search. Defines the image selection region (= what to search for). Specifies the minimum similarity (0.0-1.0), that the image region to search for needs to have in common with the image in order to be considered a match.
111
To set up the default values for image-based recording, open up the Settings dialog and continue with activating the Imaging tab.
Image Editor
Use the context menu item Edit Location. . . to open the image editor and to change the click location options. The editor provides a more detailed view of the captured image information. In addition, it offers some useful features for changing the image rectangle to be searched for.
Figure 170: Click location dialog to change the settings of image-based mouse actions
112
Image Editor Functionality Image Based Select Image Find Region Select Click Location Autoselect Image Find Region Zoom Out Zoom 100% Zoom In Capture New Screenshot Specifies whether the click is based on image information or not Specifies the region to search within the image Defines the click position in relation to the searched region Helps to specify the search region within the image Zooms out Switches to 1:1 view Zooms in Captures a new screenshot from the related repository item
Use the drop-down combo boxes to specify whether a mouse action should be performed relative or absolute to the currently defined Image Find Region. Absolute location means the distance from the upper left corner of the Image Find Region to the click location (in pixels). Relative location offers a couple of pre-defined location settings (e.g. Center, CenterLeft . . . ) relative to the Image Find Region. Its also possible to define relative position statements for the click location. Therefore the click-location inside the Image Find Region is defined by a value between 0 and 1 for both directions (X and Y-Axis). A relative click location of 0.9;0.9 defines a click near the bottom right corner of the specified region. Values greater than 1 (or negative values) mean locations outside the defined region relative to the size of the region.
Figure 171: Set relative or absolute mouse action location If the captured screenshot has to be updated, click the Capture New Screenshot toolbar button. Every newly created screenshot is also automatically added to the image list of the related repository item so its available for other image-based validation or automation actions.
Figure 172: Add a new image or select an existing image to specify the location/graphic to search
113
114
Figure 174: Integrated repository view within the Recorder You can access and edit the repository (directly) in the recorder view by double clicking the file (MyFirstTestProjectRepository.rxrep) in the projects view as shown in the figures above. Renaming Repository Items Each UI element within the repository can have a logical user-defined name. The more logical names you use the easier it is to understand test automation code and report files. In order to rename an item in the repository, first select it and then click the item to enter edit mode. Optionally you can use the keyboard shortcut <F2> to edit the names.
115
Figure 175: Renaming of repository items Creating Logical Folders The more objects you have in a repository the more structured and organized it should be. For this reason you can structure and group UI elements which logically belong together. Add a new Simple Folder using the drop-down button in the repository toolbar.
Figure 177: Repository using two logical folders to group input fields and buttons
Repository Structure - Types of Elements A repository can have the following types of items:
116
Represents a top level application, a dialog or a context menu Contains GUI elements having the same parent (i.e. RanoreXPath prefix) Used to group items Represents a Ranorex adapter (Button, ListItem, TextBox, ComboBox, etc.)
Use the Add New Item button in the toolbar to add new items manually.
Figure 179: Specify whether to search in Names, Paths or to Search All elements
117
Figure 180: Search result for text button used in names and paths
Repository Cleanup
The repositorys Cleanup button is used to search for currently unused items and to delete these items afterwards. Unused items mean they are neither used by recording modules nor by code modules. Considering the situation that a user clicked unintentionally on some desktop icons during the recording, these icons would have been added to the repository as well. Cleaning up would be beneficial in that case. Another situation where cleaning up is helpful is when UI elements which are still linked from the repository are no longer part of the software under test. In order to keep your repositories as tidy as possible, use the Cleanup functionality from time to time to avoid disorder.
Figure 181: The Cleanup button In the Cleanup dialog unused repository items are listed and checked automatically. Uncheck items if you do not want to delete them.
118
Figure 182: After clicking the Cleanup button a dialog is shown with the repository elements currently not in use by any of recording or code modules within the project
119
Figure 184: Search result - simply double-click a result item to open the code file Next to finding repository items in code you can also search all test modules.
Figure 185: Search for references of a repository item in all test modules
120
Figure 186: Search result - simply click a result to open the test module
121
Figure 187: Open Ranorex Spy to track and add items to the repository Next track the Find button in KeePass using the Track button in Ranorex Spy. Successful identification is indicated by a highlight frame around the button.
Figure 188: Track and identify the Find button with Ranorex Spy As a third step, add the button to the repository as shown in following figure.
122
Note: Alternatively you can drag and drop the item from Ranorex Spy directly into the repository from Ranorex Studio.
123
Note: It is also possible to track UI elements directly from the repository using the Track button.
Figure 191: Tracking directly from the repository Now the Find button is part of the repository and is ready to be used by code or recording modules. Create a new recording module in order to handle the Search scenario. Use the Add New Action drop-down button in the toolbar of the Ranorex Recorder and add a new Mouse action. There is more than one way to connect the repository item to this action:
Drag and drop the item from the repository directly into the recording grid or Click on the browse repository button in the recording grid (column for repository item)
Figure 192: Connect repository item to action using the browse repository button Alternatively you can also drag and drop a repository item into the recording grid and create a new action this way (you will be asked which type of action you want to create when dropping the item into the grid).
124
Figure 193: Context menu for choosing action type when creating a new recording action directly using drag and drop A new recording module was already created containing a single action for clicking on the Find button in KeePass. This recording module should be able to simulate entering text into the search form and clicking on the OK button to start the search. We still need more elements in our repository and some more actions in our recording table. Please carry out the following steps, which are quite similar to the steps already done in this section.
Open the Ranorex Spy tool (if not already opened) Track the Find What text field in KeePass using the Track button in Ranorex Spy Add the tracked text field to the repository (either with the context menu or with drag and drop) Rename this repository item to something meaningful (e.g. FindText) Add a new action (Mouse) to the recording in Ranorex Studio Connect this action to the repository item FindText Add a new action (Key Sequence) to the recording Change the value in the column Sequence to a text phrase that you want to search for (e.g. WordPressDemo) Connect this action to the repository item FindText Open the Ranorex Spy tool (if not already opened) Track the Find button from KeePass Search form using the Track button in Ranorex Spy Add the tracked button to the repository (choosing one of the already mentioned methods) Add a new action (Mouse) to the recording in Ranorex Studio Connect this action to the repository item Button Find
Note: This long list of steps shows the manual method of creating a recording. Of course these steps could be also done as a normal recording without worrying about assigning repository items.
125
You can easily execute a single action and multiple actions within the recorder by using the context menu item Play Selected Item/s, Play To Here or Play From Here.
Figure 194: Execute a single action to simulate a key sequence on the edit field FindText Now your manually created recording consists of four actions including opening the form, clicking on the text field, entering a key sequence and finally clicking on the Find button. This simple recording can now easily be embedded in your test case and can be made use of in any (suitable) position.
Note: It is also possible to add a recording module two or more times to a test case. See the following example for more details.
Figure 195: Example of an advanced test case using different code modules multiple times To explain the test case it should be mentioned that after the setup region (StartAndLogin) this test case tries to find a value (WordPressDemo) and to validate the results. If KeePass is started with an empty database, this validation will intentionally fail. After adding the entry (AddEntry) the second instance of the Find module with the subsequent ValidateEntry module would succeed if the previous adding action succeeded. The ongoing test case continues with the deletion of the item and tries to find and to validate again, which now intentionally fails again. The final teardown region containing the SaveAndClose module group is executed anyway.
Note: To prevent the recorder from stopping the run on failing the validation (intentional) please have a look at Lesson 5: Ranorex Recorder - Continue On Fail and Disable and enable continuing on fail.
Use the Ranorex Spy to prepare a RanoreXPath with multiple result elements and add it to the repository as described in the previous section.
Figure 196: RanoreXPath delivering multiple results (All buttons from the toolbar in KeePass) Repository items delivering a list of elements can be used in code modules as described in Create a List of Adapters From a Repository Element.
127
Figure 197: KeePass application opening a new database from a URL Depending on the speed of the internet connection and on the size of the database, the action of loading a database from a FTP server can take up to 10 seconds. After the download has finished, the log in dialog appears. To handle a scenario like that in Ranorex Recorder (or in the repository), every repository item has its own specific timeout value. Use the context menu item Properties to open the properties for the application folder for the Log In dialog.
128
Figure 198: Open properties of LoginWindow application folder In order to see what happens when the timeout value does not match the situation, set the dialogs search timeout to 10 milliseconds in order to force an error when executing the test case again. Even without loading the database from the external data store (e.g. FTP server) it takes some time to open the file and to bring up the dialog. A timeout of 10 milliseconds is not enough and the LogIn recording module fails.
129
Figure 199: Test case execution failed - LoginWindow was not found within the specified timeout of 10ms
Note: In order to restore your repository into a working condition, reset the search timeout value for the login dialog to 30 seconds.
Figure 200: Insert a new recording module after the LogIn recording After confirming that KeePass is in a suitable state (opened, logged in, containing one data set) use the record button from Ranorex Studio (choose Global Recording and complete the following steps) 130
Because until now there was no need to access the status text, there is no repository item holding this UI element. The validation action was accompanied with the creation of a repository item pointing to the status text which is identified by the text value Ready. After recording these simple actions, change the order in the recording table and move the validate action (#1) to the last position (#5).
Note: You can easily rearrange the order of recording actions by dragging and dropping them in the recording table.
131
Editing RanoreXPath
The RanoreXPath is used for identifying objects and elements on the screen. Each repository item refers to a RanoreXPath used to identify the corresponding UI element. In order to reduce work required for maintaining path expressions, repository items like buttons, text fields and list items are automatically grouped within application folders holding the base path for each child item.
Figure 201: RanoreXPath separation Press <ENTER> to change the RanoreXPath expression of an item using the edit mode or open the Path Editor by clicking the Edit button.
132
Figure 203: Path Editor to to change attributes used for identification Use the path editor to select alternative attributes or to combine multiple attributes for unique UI element identification. Additionally, you can create variables to be used instead of static string values for data driven identification (for more information see Lesson 3: Data-Driven Testing - Using Variables within the Repository). Learn more about how to work with the path editor in Lesson 9: Ranorex Spy - The Path Editor. After changing the identification attribute from AccessibleName to Text you can quickly verify the new RanoreXPath using Highlight element as shown below.
Figure 204: Highlight the modified element to check the modified path
133
134
Repository Separation
By default each Ranorex Studio project contains one repository file which is automatically used for each newly created recording. You can manage all UI elements of a test suite project in a single repository file, but there are several reasons for having multiple repositories within a test automation project:
Testing Different User Interfaces Common Repositories for Common Modules Advanced RanoreXPath Repositories for Complex Identification Multiple Testers Working on the Same Test Automation Project
Testing Different User Interfaces If your test suite contains, for example test cases for a web application and tests for a user interface of a client application, it might be useful to have two repositories. One is used to manage the UI elements of the web application while the other exclusively stores the elements from the client hosted application. Although you can separate things within one repository using simple folders for grouping, it makes sense to divide it up - especially when working in teams. Common Repositories for Common Modules Repositories can (and should) be modularized and reused in the same way recordings and code modules are. For example when you think about a rich client application using main menus, ribbons or toolbars you would create small reusable recordings for clicking on the main menu File |Open |Handle the Open File Dialog |etc. All these reusable modules work with a main menu, a main tool bar or similar, commonly available controls, and should be based on a repository which exclusively represents commonly used controls on the user interface. Advanced RanoreXPath Expressions Another reason to build a separate repository could be to store advanced RanoreXPath expressions which should exclusively be used to create new actions manually instead of recording them. Multiple Testers on the Same Project As long as youre working alone on a test automation project its not a problem to work with one single repository. When working in teams and everyone in the team only clicks the Record button to create test automation modules, it is recommended to keep in mind who is responsible for the main repository. Who is allowed to rename objects and to re-structure the repository? The main reason to separate repositories is to avoid accidental damage to repository items which are used by other team members.
135
Figure 207: New repository representing the complex options dialog in KeePass
Note: Its crucial to understand that repositories are essential in working with Ranorex and that the basic principle does not depend on the technology used.
Note: There are some differences in the way the elements in different technologies are identified so the RanoreXPath is a bit different for different technologies. Once your repository is able to identify the elements in a robust way, it doesnt matter which technology is behind your test cases. Of course, different technologies can be tested and combined within one test automation project in Ranorex Studio.
Using Multiple Repositories in Code Modules Now your test project contains two repository files. While a recording module can only have one repository assigned, a code module can use multiple repositories. C#
136
[ TestModule ( " C5B C 11 -274 A -4 E54 -83 DB - CE28DB955 9 " , ModuleType . UserCode , 1) ] public class OptionsCodeModule : ITestModule { // Repository object to access UI elements of KeePass Application MyFirstTestProjectRepository repo = MyFirstTestProjectRepository . Instance ; // Repository object to access UI elements of KeePass Options Dialog KeePassOptionsRepository OptionsRepo = KeePassOptionsRepository . Instance ; // / < summary > // / Constructs a new instance . // / </ summary > public OptionsCodeModule () { // Do not delete - a parameterless constructor is required ! } // / < summary > // / Performs the playback of actions in this module . // / </ summary > // / < remarks > You should not call this method directly , instead pass the module // / instance to the < see cref =" TestModuleRunner . Run ( ITestModule ) " > method // / that will in turn invoke this method . </ see > </ remarks > void ITestModule . Run () { Mouse . DefaultMoveTime = 3 ; Keyboard . DefaultKeyPressTime = 1 ; Delay . SpeedFactor = 1. ; // Click the Save - Button in KeePass MainForm repo . KeePass . ButtonSave . Click () ; // Check the option to AutoClear the Clipboard OptionsRepo . FormOptions . TabSecurity . CheckBoxClipboard_auto_clear . Checked = true ; } }
VB.NET
< testmodule ( " baa6 b6c -5 dd1 -4 eb5 - bc39 - fdfd65775742 " , moduletype . usercode ,= " " 1) = " " > _ Public Class UserCodeModule1 Implements ITestModule Repository object to access UI elements of KeePass Application Private repo As MyFirstTestProjectRepository = MyFirstTestProjectRepository . Instance Repository object to access UI elements of KeePass Options Dialog Private OptionsRepo AS KeePassOptionsRepository = KeePassOptionsRepository . Instance < summary > Constructs a new instance . </ summary > Public Sub New () Do not delete - a parameterless constructor is required ! End Sub TestRepository repo = TestRepository . Instance ; < summary > Performs the playback of actions in this module . </ summary > < remarks > You should not call this method directly , instead pass the module instance to the < see cref =" TestModuleRunner . Run ( Of ITestModule ) " > method that will in turn invoke this method . </ see > </ remarks > Sub Run () Implements ITestModule . Run Mouse . DefaultMoveTime = 3 Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. Click the Save - Button in KeePass MainForm repo . KeePass . ButtonSave . Click Check the option to AutoClear the Clipboard OptionsRepo . FormOptions . TabSecurity . CheckBoxClipboard_auto_clear . Checked = true End Sub End Class </ testmodule ( " baa6 b6c -5 dd1 -4 eb5 - bc39 - fdfd65775742 " ,>
137
Figure 209: Open Settings from Spy Within the Current Repository tab you can specify the class name and the namespace of the automatically generated source code for the current repository. On the Repository Default tab page you can specify defaults for the class name and namespace of newly created repositories. Additionally, the timeouts used for newly created repository folders and items can be changed in the Timings for new entries group box. The setting Enable folder caching can be unchecked to turn off folder caching for all items by default. Uncheck the checkbox Enable folder autogeneration to prevent the repository from creating rooted folders automatically.
138
139
140
Figure 213: Repository item properties Within the properties tab the following properties are available: Absolute Path Adapter Type Effective Timeout Comment Live Element Name Search Timeout Use Ensure Visible The Absolute Path represents the path to the repository item including the paths of all parent folders. This property is read-only. With the Adapter Type property the adapter type of the repository item can be changed. The best fitting adapter will be chosen by setting this property to default. The Effective Timeout property represents the sum of the search timeouts for the specific repository item and all its parent folders. This property is read-only. Using the comment property, the repository item can be described textual. The Live Element represents the element specified by the repository item found in the live system as it is shown in Ranorex Spy. The Name property defines the name of the repository item. The Search Timeout property defines the amount of time an element will be searched for before an exception is thrown. The Use Ensure Visible property specifies whether the repository item should be forced to become visible before automation or not.
Additionally to the properties mentioned in the table above, a rooted folder or an app folder has the following property:
141
Use Cache
The Use Cache property will either enable or disable caching for the specific folder. The chapter Repository Troubleshooting - Folder Caching will give more information about folder caching.
142
Figure 214: Adding a new code module with the toolbar button Alternatively you are able to add a new code module by using the context menu in the Test Suite.
143
Figure 215: Adding a new code module using the context menu
Figure 216: Specifying the name used for the code module
144
After clicking the Create button a new file is added to the project and automatically opened in the file view. Ranorex Studio creates a new test module class which contains a Run method that is ready to be extended with test automation code.
C#
namespace KeePass { // / < summary > // / Description of AddCredentialEntry . // / </ summary > [ TestModule ( " 3 F56 3B - DDC -49 AA -8 C26 -4 D8 8826 C66 " , ModuleType . UserCode , 1) ] public class AddCredentialEntry : ITestModule { // / < summary > // / Constructs a new instance . // / </ summary > public AddCredentialEntry () { // Do not delete - a parameterless constructor is required ! } // / < summary > // / Performs the playback of actions in this module . // / </ summary > // / < remarks > You should not call this method directly , instead pass the module // / instance to the < see cref =" TestModuleRunner . Run ( ITestModule ) "/ > method // / that will in turn invoke this method . </ remarks > void ITestModule . Run () { Mouse . DefaultMoveTime = 3 ; Keyboard . DefaultKeyPressTime = 1 ; Delay . SpeedFactor = 1. ; } } }
VB.NET
Namespace KeePass < summary > Description of AddCredentialEntry . </ summary > < TestModule ( " 3 F56 3B - DDC -49 AA -8 C26 -4 D8 8826 C66 " , ModuleType . UserCode , 1) > _ Public Class AddCredentialEntry Implements ITestModule < summary > Constructs a new instance . </ summary > Do not delete - a parameterless constructor is required ! Public Sub New () End Sub < summary > Performs the playback of actions in this module . </ summary > < remarks > You should not call this method directly , instead pass the module instance to the < see cref =" TestModuleRunner . Run ( ITestModule ) "/ > method that will in turn invoke this method . </ remarks > Private Sub ITestModule_Run () Implements ITestModule . Run Mouse . DefaultMoveTime = 3 Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. End Sub End Class End Namespace
145
C#
public class AddCredentialEntry : ITestModule { // Repository object to access UI Elements MyFirstTestProjectRepository MyRepo = MyFirstTestProjectRepository . Instance ; // / Constructs a new instance . public AddCredentialEntry () { // Do not delete - a parameterless constructor is required ! } void ITestModule . Run () { Mouse . DefaultMoveTime = 3 ; Keyboard . DefaultKeyPressTime = 1 ; Delay . SpeedFactor = 1. ; // Click Add Entry Button MainMenu MyRepo . MainForm . Edit . Click () ; MyRepo . KeePass . AddEntry . Click () ; // Set text fields MyRepo . AddEntry . TabSheetAddEntry . Title . TextValue = " WordPressDemo " ; MyRepo . AddEntry . TabSheetAddEntry . UserName . TextValue = " admin " ; MyRepo . AddEntry . TabSheetAddEntry . Password . TextValue = " demo123 " ; MyRepo . AddEntry . TabSheetAddEntry . Repeat . TextValue = " demo123 " ; MyRepo . AddEntry . TabSheetAddEntry . URL . TextValue = " bitly . com / wp_demo " ; // Choose an icon MyRepo . AddEntry . TabSheetAddEntry . MBtnIcon . Click () ; MyRepo . IconPicker . LI_Icon . Click ( Location . CenterLeft ) ; MyRepo . IconPicker . ButtonClose . Click () ; // Set Expires MyRepo . AddEntry . TabSheetAddEntry . MBtnStandardExpires . Click () ; MyRepo . KeePass . MI_Expires . Click () ; // Save Credential Entry MyRepo . AddEntry . ButtonOK . Click () ; } }
VB.NET
Public Class AddCredentialEntry Implements ITestModule Repository object to access UI Elements Private MyRepo As MyFirstTestProjectRepository = MyFirstTestProjectRepository . Instance Constructs a new instance . Do not delete - a parameterless constructor is required ! Public Sub New () End Sub Private Sub ITestModule_Run () Implements ITestModule . Run Mouse . DefaultMoveTime = 3 Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. Click Add Entry Button MainMenu MyRepo . MainForm . Edit . Click () MyRepo . KeePass . AddEntry . Click () Set text fields MyRepo . AddEntry . TabSheetAddEntry . Title . TextValue = " WordPressDemo " MyRepo . AddEntry . TabSheetAddEntry . UserName . TextValue = " admin " MyRepo . AddEntry . TabSheetAddEntry . Password . TextValue = " demo123 " MyRepo . AddEntry . TabSheetAddEntry . Repeat . TextValue = " demo123 " MyRepo . AddEntry . TabSheetAddEntry . URL . TextValue = " bitly . com / wp_demo "
146
Choose an icon MyRepo . AddEntry . TabSheetAddEntry . MBtnIcon . Click () MyRepo . IconPicker . LI_Icon . Click ( Location . CenterLeft ) MyRepo . IconPicker . ButtonClose . Click () Set Expires MyRepo . AddEntry . TabSheetAddEntry . MBtnStandardExpires . Click () MyRepo . KeePass . MI_Expires . Click () Save Credential Entry MyRepo . AddEntry . ButtonOK . Click () End Sub End Class
Note: By default the class name of a repository is the same as the repository file name (*.rxrep) shown in the projects view.
Now the class uses a private member to refer to the repository in order to reuse some of the objects (Title, Username, Password, PasswordRepeat and URL) within the Run method.
Figure 217: Repository used within code example Depending on the structure of your repository, accessing items in code might become more and more complex. To reduce complexity - especially when UI elements are used more than once - you should use local variables instead of coding the whole structure of your repository everytime you need to automate a UI element.
C#
var ButtonOK = MyRepo . FormAdd_Entry . ButtonOK ; ButtonOK . Click () ;
VB.NET
Dim ButtonOK = MyRepo . FormAdd_Entry . ButtonOK ButtonOK . Click ()
To create local variables as shown in the code above, simply drag and drop elements from the repository browser directly into the code. 147
Note: If the repository itself is not already part of the class (e.g. newly created code modules), a local variable for the repository is generated too.
C#
// get the screenshot from the repository Bitmap MyScreenshot = MyRepo . IconPicker . LI_IconInfo . GetScreenshot_Icon () ; // create FindOptions with similarity set to 95% Imaging . FindOptions MyFindOptions = new Imaging . FindOptions ( .95) ; // compare the captured screenshot with the actual list item Validate . CompareImage ( MyRepo . IconPicker . LI_Icon , MyScreenshot , MyFindOptions ) ;
VB.NET
get the screenshot from the repository Dim MyScreenshot As Bitmap = MyRepo . IconPicker . LI_IconInfo . GetScreenshot_Icon () create FindOptions with similarity set to 95% Dim MyFindOptions As New Imaging . FindOptions ( .95) compare the captured screenshot with the actual list item Validate . CompareImage ( MyRepo . IconPicker . LI_Icon , MyScreenshot , MyFindOptions )
Note: Using the FindOptions, you can set custom values like similarity. This option allows you to define the minimum similarity that the image region to search for needs to have in common with the screenshot in order to be considered a match. For further details have a look at Lesson 5: Ranorex Recorder - Image-Based Automation.
Figure 220: Specify the variable name and the default value By adding a new variable Ranorex Studio inserts a new code fragment at the current cursor position. A variable implementation consists of a public property <VariableName> and a private member <VariableName>.
C#
string _varTitle = " Wordpress Credentials " ; [ TestVariable ( " 9348 A7E6 -8 B6 -4 A2B -9 CBF - 276 A236AA3E " ) ] public string varTitle { get { return _varTitle ; } set { _varTitle = value ; } }
VB.NET
Private _varTitle As String = " Wordpress Credentials " < TestVariable ( " 9348 A7E6 -8 B6 -4 A2B -9 CBF - 276 A236AA3E " ) > _ Public Property varTitle () As String Get Return _varTitle End Get Set _varTitle = value End Set End Property
149
Now create additional variables for the Username, Password and URL. All the module variables will appear immediately in the module browser.
Accessing Repository Variables with the Use of Setter Methods To bind repository variables to external data when accessing the repository element via the code module, you have to create a new module variable to act as a bridge. You can use the setter method for the public variable to also set the repository variable. Variables used by the repository (e.g. varExpires for the Menu Item in the context menu of KeePasss Add Entry Dialog) are easily accessible via the repository, even from code. In order to bind these variables to external data (e.g. one row in our Excel file) in a code module you have to create a new module variable to act as a bridge between external data and repository variables. Following such an approach, it is obviously best to use the setter methods for public variables. A public variables setter method is called every time the value of this variable is set; i.e. assigning the value to the private variable holding the information for the public property. This method can easily be extended in order to set the repository variable as well. First two new module variables, varExpires and varIconIndex, have to be created the same way as was shown for varTitle, varPassword. After that, a simple code line has to be inserted into the setter method for each variable. This code line is used for assigning the passed value to the repository variable and facilitates binding to external data.
C#
string _varRepoIconIndex = " 1 " ; [ TestVariable ( " EF 9BC93 -3447 -4 AC2 -9 DEB - FE3D78ED5538 " ) ] public string varRepoIconIndex { get { return _varRepoIconIndex ; } set { _varRepoIconIndex = value ; // Additionally set the Repository Variable in Setter - Method MyRepo . varIconIndex = _varRepoIconIndex ; } } string _varRepoExpires = " 1 Year " ; [ TestVariable ( " D A54427 -68 FF -4 B9D - B861 -4882 BCEC846B " ) ]
150
public string varRepoExpires { get { return _varRepoExpires ; } set { _varRepoExpires = value ; // Additionally set the Repository Variable in Setter - Method MyRepo . varExpires = _varRepoExpires ; } }
VB.NET
Private _varRepoIconIndex As String = " 1 " < testvariable ( " ef 9bc93 -3447 -4 ac2 -9 deb - fe3d78ed5538 " ) > _ Public Property varRepoIconIndex () As String Get Return _varRepoIconIndex End Get Set _varRepoIconIndex = value Additionally set the Repository Variable in Setter - Method MyRepo . varIconIndex = _varRepoIconIndex End Set End Property Private _varRepoExpires As String = " 1 Year " < testvariable ( " d a54427 -68 ff -4 b9d - b861 -4882 bcec846b " ) > _ Public Property varRepoExpires () As String Get Return _varRepoExpires End Get Set _varRepoExpires = value Additionally set the Repository Variable in Setter - Method MyRepo . varExpires = _varRepoExpires End Set End Property </ testvariable ( " d a54427 -68 ff -4 b9d - b861 -4882 bcec846b " ) > </ testvariable ( " ef 9bc93 -3447 -4 ac2 -9 deb fe3d78ed5538 " ) >
Thus the two columns in the Excel file can be bound to these module variables. This binding causes the variables to be set for each iteration in the test case. When setting those variables, the extended functionality also sets the repository variable assuring that the correct icon will be used and clicked in our example.
151
Figure 222: Drag and drop the code module into a test case and combine it with recordings Now you can reuse the existing data connector created during Lesson 3: Data-Driven Testing with your new test case.
Figure 223: Reuse the existing data connector by choosing the item from the drop-down
152
Figure 224: Bind the newly created variables to the data connectors columns, i.e. columns from the Excel file
153
Lesson 8: Reporting
Lesson 8: Reporting
By default, each run of a test suite, test case or single module generates a report file (*.rxlog) which tells you if the run was successful or not. In the following lesson you will learn about the following:
Reading Ranorex Reports Report Levels Logging Individual Information Updating the Custom Report Format Create a Custom Report Template
154
Lesson 8: Reporting
The report shown after running a test suite provides a general overview of how many of the test cases have been executed successfully, have failed or have been blocked. Each executed test case and all its child modules can be analyzed in depth by expanding a particular test case. In addition to that, a test suite report also informs you about the following:
System information like execution time, machine name, operating system, screen dimensions, language, duration, total errors, total warnings Global parameter values
If a test case uses local parameter values or external test data, the report shows the values used during automation as shown below.
Figure 226: Detailed view of a test case report The detailed log messages generated by a recording or by a code module shown in the figure above consist of a time stamp, a report level, a category and message text. By default logging is turned on for recordings. Use the Recorder Settings Dialog to change the default value and to turn off logging for new recordings. In order to turn logging off or on for a particular action item, open the properties and set the Use Default Logging attribute to false.
Figure 227: Debug a test run with quick links Jump to Item and Open in Spy Click at Jump to Item to open the module and to select the correspondending action. Use the quick link Open in Spy to analyze the RanoreXPath expression used for the particular action item. This is especially useful in situations when a test run fails with the message Failed to find item. . . error message. Move the mouse cursor over a testcase and click on Jump to Testcase to select the correspondending test case in the test suite.
155
Lesson 8: Reporting
Report Folder
For each run of a test suite, a single test case or a recording a new log file (*.rxlog) is generated and saved in the projects Report folder. You can open older report files by double-clicking the file in the project view. Specify the file names used for the report files within the Test Suite Settings.
Note: It is not required to run Ranorex Studio to open a report file. You can also open the report file from Windows Explorer. If youre going to copy or send the file by email, it is recommended to use the zipped report as described in Test Suite Settings.
Report Levels
Within Ranorex you are able to use different levels of reporting information importance, from a debug message to a failure information. In addition to predefined report levels, you can also easily define your own levels. Report Levels describe the importance of a message that is delivered to the report. Using different kinds of report levels can help you keep your reports short and better readable. Within a test suite or even within a test case, you are able to define a report level that describes the minimum level of reporting information (see Lesson 4: Ranorex Test Suite - Test Suite Settings for more information). Report information with a lower level of importance is ignored and does not fill up your report, whereas decreasing a test cases report level could assist you in finding errors in your testing scenario.
156
Lesson 8: Reporting
Predefined Report Levels Ranorex provides the following predefined report levels - the level itself is indicated by integer values (which are written in parenthesis):
Debug (10) Info (20) Warning (30) Error (40) Success (110) Failure (120)
The first five items describe different levels of importance for report messages. For instance an error message in the report indicates a logical test step error whereas a warning message should only get your attention but not indicate an error. From report levels Debug to Success, the result of the current module is still classified as a success whereas the Failure report level classifies the module result as a failure; this is indicated by a red mark in the report.
Figure 230: Report indicating a failed module Additionally, at the top of a test case, warnings are indicated using a message with a yellow background.
Figure 231: A message indicating the existence of warning messages inside a test case
Note: A test cases failure depends on the success of its child elements which can either be modules or nested test cases. A module fails when an exception is thrown or a failure message is being logged. Exceptions are typically thrown by failed validation actions, by searching for nonexistent elements or by an explicit call at code level.
User-defined Report Levels In addition to predefined report levels, you are able to define your own report level with a custom importance value. You can do that either from code or within the Recorder (see Logging Individual Information for detailed information). 157
Lesson 8: Reporting
Category These methods can be used with a single parameter, the message text. Alternatively they can be used with an additional parameter indicating the category which is set to the default value User in the first overload of such methods. The default category can also be set via code by assigning the Ranorex.Report.DefaultCategory property. The category can be seen in a distinct column in the report. The following code lines demonstrate different reporting methods (and different reporting categories), resulting in the report shown after the code example.
C#
// Reporting information ( debug , info ) using default Category " User " Ranorex . Report . Debug ( " This is a Debug Information " ) ; Ranorex . Report . Info ( " This is a Information " ) ; // Setting Parameter Category to specific value and report a warning and an error Ranorex . Report . Warn ( " Specific Category " ," This is a Warning Information " ) ; Ranorex . Report . Error ( " Specific Category " , " This is an Error Information " ) ; // Setting the Default Category Ranorex . Report . DefaultCategory = " My new default category " ; // Reporting information ( success , failure ) using the new default category Ranorex . Report . Success ( " This is a success information " ) ; Ranorex . Report . Failure ( " This is a failure Information " ) ;
VB.NET
Reporting information ( debug , info ) using default Category " User " Ranorex . Report . Debug ( " This is a Debug Information " ) Ranorex . Report . Info ( " This is a Information " ) Setting Parameter Category to specific value and report a warning and an error Ranorex . Report . Warn ( " Specific Category " , " This is a Warning Information " ) Ranorex . Report . Error ( " Specific Category " , " This is an Error Information " ) Setting the Default Category Ranorex . Report . DefaultCategory = " My new default category " Reporting information ( success , failure ) using the new default category Ranorex . Report . Success ( " This is a success information " ) Ranorex . Report . Failure ( " This is a failure Information " )
158
Lesson 8: Reporting
Figure 232: Report with different reporting methods and categories indicating the different levels of importance
Note: Please consider that the report information at the failure level provides a screenshot automatically (if tracing screenshots is enabled). In order to visually retrace the last steps that lead to the current error, screenshots will be provided for the last three actions.
User-defined Report Levels You are able to define your own report levels with a custom name and a value for the level:
C#
Ranorex . ReportLevel MyNewReportLevel = new ReportLevel ( " My low Report Level " , 25 , null ) ; Ranorex . Report . Log ( MyNewReportLevel , " This is unimportant information " ) ;
VB.NET
Dim MyNewReportLevel As Ranorex . ReportLevel = New ReportLevel ( " My low Report Level " , 25 , Nothing ) Ranorex . Report . Log ( MyNewReportLevel , " This is unimportant information " )
Depending on the current Report Level (see next chapter), the report information with the user-defined report level should appear in the report as follows:
159
Lesson 8: Reporting
Figure 233: Report with information for a user-defined level Current Report Level Report information only appears in the report if the parent test case has a report level setting lower than or equal to the current report information level. The current report level can also be set using code:
C#
Ranorex . Report . CurrentReportLevel = Ranorex . ReportLevel . Parse ( " Only Highest Importance ;9 " ) ;
VB.NET
" Ranorex . Report . CurrentReportLevel = Ranorex . ReportLevel . Parse ( " Only Highest Importance ;9 " )
This assignment causes the inclusion of reporting information only at a level greater the or equal to 90, which is Success and Failure. The resulting report, which is caused by the same code from above but with a different current report level, can be seen below.
Note: The current report level can always be overridden by logging information with the report level Always.
C#
Ranorex . Report . Log ( Ranorex . ReportLevel . Always , " User " , " Any - Case message " ) ;
160
Lesson 8: Reporting
VB.NET
Ranorex . Report . Log ( Ranorex . ReportLevel . Always , " User " , " Any - Case message " )
Reporting Screenshots Screenshots of the current state of the system under test or any UI element can be easily sent to the report.
C#
Ranorex . Report . Screenshot ( MyRepo . KeePass . Toolbar . Self ) ;
VB.NET
Ranorex . Report . Screenshot ( MyRepo . KeePass . Toolbar . Self )
Figure 235: Screenshot of KeePass toolbar opened directly in Ranorex report If you call the screenshot method without any arguments, a screenshot of the whole desktop will be available in your report.
Note: Screenshots from UI elements can only be made if the element is visible at the time a screenshot is made. Controlling your application using code does not necessarily bring your application to the front and make it visible. To ensure the visibility of UI elements, use the EnsureVisible method which is provided by any element that is derived from Ranorex Adapter class (e.g. Text, RadioButton, Button, etc.). Consequently, rooted folders from repository or even application folders do not ensure visibility. Alternatively you can ensure visibility by using the Self property from that object types (rooted folder or application folder).
161
Lesson 8: Reporting
Reporting System Summary The Ranorex reporting class provides a way to simply report a system summary:
C#
Ranorex . Report . SystemSummary () ;
VB.NET
Ranorex . Report . SystemSummary ()
Logging Information from Recorder The Ranorex Recorder provides a way to send information directly to the report. Just use the Add New Action button from the toolbar and add a Report Action.
162
Lesson 8: Reporting
163
Lesson 8: Reporting
Predefined Report Level Just like a call from code, you can specify one of the predefined report levels directly within the recorders actions table.
Custom Report Level Report messages with a custom report level can also be submitted. Simply choose the Custom report level in the drop-down.
Screenshots and Snapshots Since Ranorex Version 3.3, you can send screenshots and even snapshots to your report directly from the recorders actions table. These two actions require a connection to a repository item in order to specify from which object the screenshot or snapshot should be made.
Figure 240: Usage of the report action using the screenshot and the snapshot action type
164
Lesson 8: Reporting
Figure 241: ReportXmlFile is no longer supported Clicking on the warning will open a resolve dialog. In this dialog you can choose to either copy the custom report to a template folder and use this folder as report template, or to use the default report template.
165
Lesson 8: Reporting
Figure 243: Create a custom report template A new report template folder has automatically been created at <Project Folder>\NewCustomTemplate. The newly created files can be shown in project view by pressing the Show All Files button.
Note: Press the Refresh button to ensure that the new created folder will be shown.
Figure 244: Show all files in project view Open the file RanorexReport4.css to edit the style of the report according to your wishes.
Open the file RanorexReport4.xsl to edit the structure of the report according to your wishes. 166
Lesson 8: Reporting
Open the file View.rxlog to get a preview of your customizations using some sample data.
167
The element browser tree shown on the left side represents the computers desktop with all currently opened applications. The name of the root node is set to the machines host name. By selecting one of the elements from the browser tree, the Spy provides more detailed information about the selected item in the tabs Overview, Detail and Screenshot shown on the right. Ranorex recognizes over 30 of the most commonly known types of UI elements. In Ranorex vocabulary they are called adapters. Every element shown within the element tree of Ranorex Spy is represented by an adapter as described in Ranorex UI Adapter. If Ranorex is not able to specify the type of adapter of a UI element, it will be displayed as Unknown. The Overview tab provides the most important view into the details of a UI element. The available attributes and their values are divided into the following sections:
General Logical adapters like Form, Button or Text Technology related adapters like Control, Accessible or NativeWindow
168
Figure 247: Ranorex Spy Overview tab divided into three attribute sections
General
Regardless of what type of UI element is currently selected the General section provides information about whether the element is enabled, valid or visible.
attribute values at Create Adapters to Access More Properties and Methods. In addition all attributes can be used within the RanoreXPath. By default the attribute in the overview tab written in bold is automatically used to identify the UI element.
Figure 248: Attribute controlname is used to identify the button The RanoreXPath expression shown in the figure above can be seen as a navigation path through the element browser tree used to identify a UI element. You can use the The Path Editor to change element identification or edit the path expression directly within the text boxs RanoreXPath Edit Mode.
Note: You are able to access common text functionality like Select All (<CTRL>+A), Copy (<CTRL>+C), Cut (<CTRL>+X), Paste (<CTRL>+V), Undo (<CTRL>+Z) or Delete (<DEL>) in RanoreXPath.
Another way to navigate through the element tree is to use the image navigator which can be found at the bottom of the Overview/Detail tab.
170
Figure 249: Image navigator At the top of the image navigator you can see the adapter type and the name of the currently selected UI element. By moving the mouse over a specific child element of the currently selected element, you will see the adapter type and its name. Double-clicking a UI element selects it, double-clicking outside the selected element selects the parent.
171
Figure 250: Abstract illustration of the structure of RanoreXPath Attribute comparisons may also be combined with and and or operators (e.g. button[@text=OK and @enabled=true]).
172
Figure 251: Capture a screenshot from a UI element to save as PNG file Specify the image region using the toolbar button Select Image Region and click the Save button to save the selected region as a PNG file.
173
Toolbar shortcuts Browse Local Host Connect to a Mobile Device Refresh Load from Snapshot Save as Snapshot Highlight Elements Update Path Shows currently running host applications Opens the Manage Devices dialog Updates the current state of applications Loads an existing Ranorex snapshot file Saves the currently selected node and all its descendants to a Ranorex snapshot file When switched on, highlights selected UI elements on the users desktop Sets the path from the currently selected element
174
Context menu Update Path Set Element as Root Highlight Element Add to Repository Add to Repository (incl. Children) Add Matching Children to Repository Update Element Data Save as Snapshot. . . Capture Screenshot. . . Expand All Collapse All Sets the path from the currently selected element Sets the currently selected element as root element Highlights the current element Adds the current element to a Ranorex Repository Adds the current element and the elements children to a Ranorex Repository Adds all UI elements matching the given RanoreXPath to the Repository Updates all attributes of the specified UI element Saves the current UI element including the child structure to a Ranorex snapshot file Captures a screenshot from the current element to be used for further image-based validation Expands all child elements of the selected UI element in the element browser Collapses all child elements of the selected UI element in the element browser Specifies whether the elements class or process name should use the GDI plug-In to turn on text-based object recognition Based on the type of the UI element a list of different actions to perform on the UI element is available
Actions to perform
Note: Saved screenshots can also be used for image comparison in code, for example for finding and comparing images or image-based automation. For more information about this, please have a look at How to do image based automation and How to find and compare images.
175
Tracking UI Elements
You can navigate manually through the Ranorex Spys element tree or use element tracking to identify UI elements in your application under test. The Ranorex Spy supports two ways of tracking UI elements:
Using the TRACK Button Instant Tracking
Note: To abort the tracking session press <ESC> or click the TRACK button again.
Note: Holding the <F12> key temporarily disables the tracking mechanism.
In some cases it might be necessary to track UI elements which are currently behind the Ranorex Spy window. Simply uncheck the Always On Top checkbox to cause Ranorex Spy to minimize during the tracking process.
176
Instant Tracking
When tracking menu or pop-up items, you use the Instant Tracking method by using a shortcut to select a UI element. Simply move your mouse pointer over a menu item and press the <CTRL> + <Win> key combination to instantly track the UI element. Instant Tracking is not only available for popup items, it can be used for any UI element.
177
Figure 256: RanoreXPath auto completion The RanoreXPath editor mode is indicated by a yellow background color. In edit mode, RanoreXPath is used as a query to filter UI elements as follows:
Figure 257: Use of RanoreXPath as a filter to search for buttons The result is presented directly within the Ranorex Spy tree. All matching items are highlighted in yellow. In addition the result can easily be added to a repository by selecting the menu item Add Matching Children to Repository.
178
Figure 258: Add matching items to the repository To stop the edit mode, click the red cancel button which is located in the RanoreXPath edit box or press the <ESC> key.
179
180
As you might know, the RanoreXPath expression is a powerful identifier of UI elements for desktop and Web applications. To learn more about the RanoreXPath have a look at the section RanoreXPath.
Figure 260: Click the Edit button to open the path editor In Ranorex Spy, the path editor can be accessed by simply switching to the PATH EDITOR tab.
181
182
Figure 262: Overview of path editor Additionally you can see the number of identified UI elements using the given RanoreXPath in the status bar. Buttons to refresh and to highlight the identified elements can be found right above the tree view and the original RanoreXPath can be found at the top of Ranorex Spy, right below the modified one. As you can see, the whole path is shown in this tree structure with each path element being a node of the tree. In the left section of the editor, you can access each of these path elements to alter the attribute comparisons in the right section on which the path is based. After altering the RanoreXPath, you can review the effects by pressing the refresh and highlight buttons and apply the changes using the Apply button next to the RanoreXPath at the top of Ranorex Spy. Of course you can change the RanoreXPath by using the Track button, too. To simplify tracking, the tracking area is limited to the parent folder of the selected repository item (grayed out in RanoreXPath at the top of Ranorex Spy), which will be indicated with a yellow border.
183
Figure 264: KeePass with one cell being tracked by Ranorex Spy
184
Figure 265: RanoreXPath structure in path editor for a cell in second row
What we can see in the RanoreXPath structure (in path editor) as well as in the RanoreXPath itself is that the row (adapter) is identified by its index attribute (row[@index=1]). This means that the cell Ranorex is only recognized if it is located in the second row. This cell would not be found if an additional row was inserted above and the index was changed. Sorting by a column (e.g. column username) could easily lead to another row index. To avoid a problem concerning the row index, you could change the path with the use of the path editor to be row independent by unchecking the index attribute checkbox in the row node.
185
/ form [ @controlname = MainForm ]/ container [ @controlname = m \ _splitHorizontal ] // table [ @controlname = m \ _lvEntries ]/ row / cell [ @text = Ranorex ]
This path leads to any cell in any row containing the text Ranorex. Concerning our validation of the success of adding an entry, it would be more meaningful if the path would lead to the text value Ranorex in any row but only in the column UserName. Therefore add the column index attribute by checking it.
186
/ form [ @controlname = MainForm ]/ container [ @controlname = m \ _splitHorizontal ] // table [ @controlname = m \ _lvEntries ]/ row / cell [ @text = Ranorex and @columnindex = 1 ]
If another KeePass entry is added which has the same username (Ranorex), this path would lead to multiple results. You can easily check the result of your RanoreXPath in path editor by having a look at the text in the bottom left corner.
187
Figure 268: The current path leads to two elements To find out which elements are found with the current RanoreXPath, simply click on the Highlight button on the bottom of path editor.
188
Figure 269: The underlying path leads to two elements in KeePass As you can see, building up a robust and unique path is a crucial task which always depends on the characteristics of your application.
Types of Comparisons
Ranorex provides a set of comparisons which can be used to build up or to modify a RanoreXPath. These comparison operators can be accessed via a drop-down in path editor.
Textual Comparisons The following types of comparisons are defined for textual comparisons (case sensitive):
=: The value of the attribute must be equal to the given value : The value of the attribute must match the given regular expression !: The value of the attribute must not match the given regular expression !=: The value of the attribute must not be equal to the given value >: The value of the attribute must start with the given string
The following types of comparisons are defined for numerical comparisons (starting with
>: The (numerical) value of the attribute must be greater than the given value >=: The (numerical) value of the attribute must be greater than or equal to the given value <: The (numerical) value of the attribute must be less than the given value <=: The (numerical) value of the attribute must be less than or equal to the given value
Note: Since the > operator is used for textual and for numerical comparisons as well, it depends on the type of the values you are trying to compare; i.e. whether the textual Starts with or the numerical Greater than functionality is used.
Example for Regular Expression The following example shows how to use a regular expression operator ().
189
Figure 270: Matches all entries ending with the text fragment rex using a regular expression
Note: For more details about regular expressions, see RanoreXPath - RanoreXPath with Regular Expressions.
Example for Not Equal The following example shows how to use the not equal operator (!=).
Figure 272: Matches all entries that are not equal to Ranorex
190
Figure 273: Result from the comparison above Example for Starts With The following example shows how to use the starts with operator (>).
Example for Numerical Comparisons The following examples demonstrates how numerical operators (>, >=, <and <=) can be used in the path Editor.
191
Figure 276: Matches all rows matching index > 2 and index <= 3
Relationship Operators
After exploring the comparison operators, you are going to learn more about the relationship operators. Relationship operators define the relationship between the nodes (elements of the path). It is therefore not necessary to always use a directed path. One element in the path can also be defined by using another relationship to its parent other than being the child of a parent node. The following relationship operators are available in the context menu of a node.
192
The following example describes,how to change the common parent-child relationship in the path using relationship operators (Axis), e.g. if you want to refer to a table row containing any cell with the text Amazon. Using the common, directed way of building up a path, this wouldnt be possible. We start with the path referring to the cell:
/ form [ @controlname = MainForm ]/ container [ @controlname = m \ _splitHorizontal ] // table [ @controlname = m \ _lvEntries ]/ row [ @index = 2 ]/ cell [ @text = Amazon ]
We can now move back to the cells parent using the parent relationship operator. The parent element is a row, therefore we have to add a new level manually using the row adapter. 193
/ form [ @controlname = MainForm ]/ container [ @controlname = m \ _splitHorizontal ] // table [ @controlname = m \ _lvEntries ]/ row [ @index = 2 ]/ cell [ @text = Amazon ]/ row
In the path editor we choose the relationship operator parent in the Axis submenu.
Figure 279: Contextmenu for defining the relationship operator for currently selected node This path first describes the way to a cell containing the text Amazon and moves up one level of hierarchy to the parent of this cell, which is a row. Highlighting the element leads to the result shown in following figure.
Figure 280: Highlighting the element from the newly created path
Adapter Types
Adapters describe the type of element that is referred to. In the path editor you are able to change the adapter type easily. Adapters used within a path which are automatically suggested by Ranorex, can also be changed using the context menu. 194
Figure 281: Changing the adapter to a specific type of element If you do not want to use a specific adapter, you can use the asterisk adapter (*) which is an undefined container for all types of elements. This might be useful if your application has dynamically created elements and if for some parts of the path, the adapter should not be specified.
195
Figure 282: Windows node located at the root level (left) or. . .
Figure 283: . . . in a sub-node of the tree (right) in KeePass In general, the path to the Windows node on the left side of the figure would not include the General folder because this folder can be seen as a sibling. The path to the Windows node on the right side, which can be seen as child element of the General node, would therefore include this element in the path. Thus, the General folder can be seen as optional if you want to access the Windows node in both cases. Here, the General folder could be marked as optional which means that regardless whether the Windows folder is a child of the General folder (and therefore is part of the path) or is a sibling of the General folder (which is not part of the path) the element will be found.
196
/ form [ @controlname = MainForm ]// treeitem [ @accessiblename = NewDatabase ]/ treeitem ?[ @accessiblename = General ]/ treeitem [ @accessiblename = Windows ]
Defining Variables
In the RanoreXPath you are able to use variables which can be used for such things as data-driven testing. Variables can be created and assigned in the path editor. If you start the path editor from an existing repository, there is an additional button for each (selected) attribute comparison. With these buttons you are able to define variables which can be used for data driven object identification.
197
Figure 285: Buttons for creating a new variable for every selected attribute
Figure 286: Variables can also be created using the As new Variable entry in the dropdown menu
198
The variables you have added are placed in the repository you are working on. Each of the variables held by the repository can be used as a value for attribute comparison. For more details about variables used within the repository, please have a look at Lesson 3: Data-Driven Testing - Using Variables within the Repository.
Figure 287: Path editor window in live view having dynamic capabilities
199
Note: Dynamic capabilities can only be accessed for certain types of technologies (WinForms, Flash/Flex, Web and Java).
200
201
Figure 289: Ranorex Spy tool with opened snapshot file from KeePass Use the context menu item Save as Snapshot within Ranorex Spy to store all elements, dialogs and applications, including their sub-items into a single Ranorex snapshot file.
Note: In order to save screenshot information correctly, activate the desired application for which you wish to create a snapshot before saving.
Snapshots from pop-up windows, drop-down combo boxes or drop-down menus For creating a snapshot from the File menu pop-up of KeePass, you can use the <SCROLL> key (keyboard) in combination with the instant tracking feature of Ranorex Spy: 1. Open Ranorex Spy and activate Highlight Elements. 2. Start the KeePass application and open the File menu. 3. Track the parent menu container window of the menu items: Track the pop-up frame by positioning the mouse over the edge of the window and pressing <CTRL>+<Win>. 4. Press the <SCROLL> key to cache the current elements including their underlying items for Ranorex Spy. 5. Lastly save the current view as snapshot. Another possibility of creating a snapshot from the File menu pop-up of KeePass is to use the TRACK button in combination with the <F12> key which temporarily disables the tracking mechanism: 1. Open Ranorex Spy and activate Highlight Elements. 2. Start the KeePass application.
202
3. Press the TRACK button. 4. In the KeePass application open the File menu while holding the <F12> key. 5. After releasing the <F12> key track the parent menu container window of the menu items using the mouse wheel to change the recognition level. 6. Reopen the menu and press the <SCROLL> key to cache the current elements including their underlying items for Ranorex Spy. 7. Lastly save the current view as snapshot.
Figure 290: Track menu container window using instant tracking (<CTRL>+<Win>)
203
204
Figure 294: Start external Settings executable from Ranorex installation bin folder
General settings
205
Figure 295: General Ranorex settings Use Ensure Visible by default Specifies whether a UI element used as Ranorex adapter should be forced to become visible before automation or not. By default this value is automatically used for each repository item. Enable search by unique ID (if available) Specifies whether web elements should be identified using their unique id or not. On mouse/pointer move check if location is within visible desktop bounds Specifies whether an exception should be thrown if the mouse/pointer tries to move outside the visible desktop bounds or not. Maximum length of text values in RanoreXPaths Specifies the maximum length of attribute values used within RanoreXPath. The factor that all timeouts of find operations are multiplied with Multiplies all repository timeouts with the specified value to prevent test cases from failing in case of different timing behavior. This is especially useful when executing tests on different system configurations.
Note: The value can also be set at the time of executing a test suite using the Running Tests without Ranorex Studio or by directly using the Ranorex.Core.Configuration.Current.Adapter.TimeoutFactor property in code.
Resets the Do not show again checkbox used to suppress the assistance dialog for technology limitations. Click Reset to show the dialog again for not instrumented technologies or applications. GDI Capture Settings. . . Opens the dialog to change the current GDI capture list. More information about the Ranorex GDI plug-In can be found at Testing of Legacy Applications. Mobile Devices. . . Opens the Manage Devices dialog as described in the sections iOS Testing and Android Testing.
Note: Click the button Restore Defaults to reset all values to their default values. Use the Import. . . and Export. . . buttons to save and load user-specific configurations.
Advanced Settings
Figure 296: Advanced Ranorex settings Most of the settings shown in the Advanced tab are used to configure Ranorex object recognition and RanoreXPath generation. Please be careful when changing these settings. Enable 32/64 Bit Bridge Use the checkbox Enable 32/64 Bit Bridge to turn off the bit bridge required to handle 32/64 bit based applications on 64 bit operating systems automatically. Use hidden screenshot capturing (if possible)
207
Tries to capture screenshots used by recordings, repositories or Ranorex snapshot files, even from application windows which are not in the foreground. If disabled, Ranorex tries to make the application window visible before capturing a screenshot. Let snapshot contain complete ancestor subtree When checked, the subtree containing the whole application will be stored when saving a snapshot file. If not checked, only the direct subtree to the selected item will be stored. Use asynchronous dispatching of mouse and keyboard events This setting is used to turn on or off asynchronous dispatching of mouse and keyboard events during recording. With enabled asynchronous dispatching mouse and keyboard events will not be forwarded to an application before Ranorex has finished processing the event. Disable expensive attribute in tools This setting instructs plug-ins not to evaluate computationally intensive attributes for Ranorex Spy, Recorder, and Ranorex Studio. If checked, attributes like Row.Index do not have a value for certain technologies when shown in Ranorex Spy. This improves performance is some cases. Use UiaLauncher to elevate privileges for processes started by tools Specifies whether test execution is started with elevated privileges or not. Delay before pressing a key sequence (ms) Specifies the time to wait in milliseconds before performing a key sequence simulation. RanoreXPath generation mode: Defines how RanoreXPaths will be build during recording actions or tracking elements using the Ranorex tools (by default, the mode StepCostReduce is selected). Edit Path Weights. . . In order to get assistance with editing RanoreXPath weights, have a look at the blog post Automated Testing and Dynamic IDs. Edit Path Build Options Specifies the parameters for StepCostReduce RanoreXPath generation mode.
Recorder Settings
The description of the settings regarding the Ranorex Recorder can be found in the Recorder Settings Dialog in Lesson 5: Ranorex Recorder.
Repository Settings
The description of the settings regarding the Ranorex Repository can be found in the Repository Settings Dialog in Lesson 6: UI Mapping with Ranorex Repository.
Imaging Settings
The Imaging settings are explained in the section Image-Based Automation in Lesson 5: Ranorex Recorder.
208
Figure 297: Plug-in specific settings Plug-in specific settings can be used to alter the behavior of individual Ranorex plug-ins, for example, to achieve backwards compatibility with older versions. For more information on each setting, read the description shown when you click on a particular setting in the property grid.
209
Code Examples
Code Examples
The following code examples explain how to use Ranorex API in order to write code modules or to extend recording modules with user specific code.
Using Repository in Code Wait for UI Elements Using Repository Create Adapters to Access More Properties and Methods Create a List of Adapters From a Repository Element Using Validate Class Forcing a Test Case to Fail Set Up Automation Speed Accessing Test Case & Test Suite Context Advanced Code Examples How to do image based automation How to find and compare images Handling unexpected Dialogs
210
Code Examples
// Read and log value of Text attribute Report . Info ( repo . MyApp . Buttons . ButtonAdd . Text ) ; // Press button repo . MyApp . Buttons . ButtonAdd . Press () ; // Read and log value of Enabled attribute Report . Info ( repo . MyApp . Buttons . ButtonAdd . Enabled . ToString () ) ; // Using Ranorex . RadioButton adapter // represented by GenderOption // Select radio button repo . MyApp . GenderOption . Select () ; // Accessing listitems of Ranorex . List adapter // represented by CategoryList IList < ranorex . listitem > listItems = repo . MyApp . CategoryList . Items ; foreach ( Ranorex . ListItem item in listItems ) { Report . Info ( item . Text + " is member of CategoryList " ) ; } // Using Ranorex . MenuItem to open File menu repo . MyApp . MenuItemFile . Select () ; // Selecting sub menu item Connect repo . FileMenu . Connect . Select () ; // Read and log Enabled state of menu item Connect Report . Info ( repo . FileMenu . Connect . Enabled . ToString () ) ; } }
VB.NET
Public Class UsingRepository Implements ITestModule Repository object to access UI elements Private repo As MyFirstTestProjectRepository = MyFirstTestProjectRepository . Instance < summary > Constructs a new instance . </ summary > Do not delete - a parameterless constructor is required ! Public Sub New () End Sub < summary > Performs the playback of actions in this module . </ summary > < remarks > You should not call this method directly , instead pass the module instance to the < see cref =" TestModuleRunner . Run ( ITestModule ) " > method that will in turn invoke this method . </ see > </ remarks > Private Sub ITestModule_Run () Implements ITestModule . Run Mouse . DefaultMoveTime = 3 Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. Using Ranorex . Form adapter represented by MyApp MyApp is used as a folder within the repository ; the Self property returns a Ranorex . Form object Activates application repo . MyApp . Self . Activate () Log Active state Report . Info ( repo . MyApp . Self . Active . ToString () ) Maximize , Minimize and Restore repo . MyApp . Self . Maximize () repo . MyApp . Self . Minimize () repo . MyApp . Self . Restore () Closes application repo . MyApp . Self . Close () Using Ranorex . Button adapter represented by ButtonAdd Read and log value of Text attribute Report . Info ( repo . MyApp . Buttons . ButtonAdd . Text ) Press button repo . MyApp . Buttons . ButtonAdd . Press () Read and log value of Enabled attribute Report . Info ( repo . MyApp . Buttons . ButtonAdd . Enabled . ToString () ) Using Ranorex . RadioButton adapter
211
Code Examples
represented by GenderOption Select radio button repo . MyApp . GenderOption .[ Select ]() Accessing listitems of Ranorex . List adapter represented by CategoryList Dim listItems As IList ( Of Ranorex . ListItem ) = repo . MyApp . CategoryList . Items For Each item As Ranorex . ListItem In listItems Report . Info ( item . Text & " is member of CategoryList " ) Next Using Ranorex . MenuItem to open File menu repo . MyApp . MenuItemFile .[ Select ]() Selecting sub menu item Connect repo . FileMenu . Connect .[ Select ]() Read and log Enabled state of menu item Connect Report . Info ( repo . FileMenu . Connect . Enabled . ToString () ) End Sub End Class
C#
// Use the Info object to check existence of the // SaveDialog item ; Method Exists uses the timeout // specified for the SaveDialog in the repository Report . Info ( " Exists = " + repo . SaveDialog . SelfInfo . Exists () . ToString () ) ; // Use the Info object to check existence of the // TextOnline item which uses the following RXPath : // statusbar / text [ @accessiblename = Online ] // This way you can wait with the timeout specified for // the item within the repository for the text Online bool statusTextConnected = repo . MyApp . TextOnlineInfo . Exists () ; // Using Info objects for validation // Throws a Ranorex . ValidationException if validation // fails . Automatically reports success or failed message // to log file Validate . Exists ( repo . SaveDialog . ButtonOKInfo ) ; // Validates the existence of the repository item , // but does not throw any exception Validate . Exists ( repo . SaveDialog . ButtonOKInfo , " Check Object { } " , false ) ;
VB.NET
Use the Info object to check existence of the SaveDialog item ; Method Exists uses the timeout specified for the SaveDialog in the repository Report . Info ( " Exists = " & repo . SaveDialog . SelfInfo . Exists () . ToString () ) Use the Info object to check existence of the TextOnline item which uses the following RXPath : statusbar / text [ @accessiblename = Online ] This way you can wait with the timeout specified for the item within the repository for the text Online Dim statusTextConnected As Boolean = repo . MyApp . TextOnlineInfo . Exists () Using Info objects for validation Throws a Ranorex . ValidationException if validation fails . Automatically reports success or failed message to log file
212
Code Examples
Validate . Exists ( repo . SaveDialog . ButtonOKInfo ) Validates the existence of the repository item , but does not throw any exception Validate . Exists ( repo . SaveDialog . ButtonOKInfo , " Check Object { } " , False )
C#
// Creating adapter of type NativeWindow using the "\ dots Info " object Ranorex . NativeWindow nativeWnd = repo . MyApp . SelfInfo . CreateAdapter < Ranorex . NativeWindow >( false ) ; // \ dots and read value of attribute ProcessName Report . Info ( " Process name of VIP Database : " + nativeWnd . ProcessName ) ; // Using Control Adapter to access properties and methods of // . NET WinForms control Ranorex . Control winFormsControl = repo . MyApp . SelfInfo . CreateAdapter < Ranorex . Control >( false ) ; // Set background color of VIP application to Color . Black using the // exposed property BackColor winFormsControl . SetPropertyValue ( " BackColor " , Color . Black ) ; // Report screenshot after changing the background color Report . Screenshot ( repo . MyApp . Self ) ; // Closes VIP Database by invoking the Close method // exposed by the System . Windows . Forms . Form class winFormsControl . InvokeMethod ( " Close " ) ;
VB.NET
Creating adapter of type NativeWindow using the "\ dots Info " object Dim nativeWnd As Ranorex . NativeWindow = repo . MyApp . SelfInfo . CreateAdapter ( Of Ranorex . NativeWindow ) ( False ) \ dots and read value of attribute ProcessName Report . Info ( " Process name of VIP Database : " & nativeWnd . ProcessName ) Using Control Adapter to access properties and methods of . NET WinForms control Dim winFormsControl As Ranorex . Control = repo . MyApp . SelfInfo . CreateAdapter ( Of Ranorex . Control ) ( False ) Set background color of VIP application to Color . Black using the exposed property BackColor winFormsControl . SetPropertyValue ( " BackColor " , Color . Black ) Report screenshot after changing the background color Report . Screenshot ( repo . MyApp . Self ) Closes VIP Database by invoking the Close method exposed by the System . Windows . Forms . Form class winFormsControl . InvokeMethod ( " Close " )
Note: In order to access properties or methods exposed by a WinForms control you need to know their names. If youre not familiar with the controls API ask the developer of your application for assistance.
213
Code Examples
C#
// Create a list of adapters using the " Info " object IList < Ranorex . Button > buttonList = repo . MyApp . EnabledButtonsInfo . CreateAdapters < Ranorex . Button >() ; // Move the mouse pointer to each button of the list // and add a screenshot for each to the report foreach ( Ranorex . Button button in buttonList ) { button . MoveTo () ; Report . Screenshot ( button ) ; }
VB.NET
Create a list of adapters using the " Info " object Dim buttonList As IList ( Of Ranorex . Button ) = repo . MyApp . EnabledButtonsInfo . CreateAdapters ( Of Ranorex . Button ) () Move the mouse pointer to each button of the list and add a screenshot for each to the report For Each button As Ranorex . Button In buttonList button . MoveTo () Report . Screenshot ( button ) Next
Learn more about how to create repository items delivering multiple elements here: Repository Items Representing Multiple Elements
C#
// Validate for Existence // Using Info objects for validation // Throws a Ranorex . ValidationException if validation // fails . Automatically reports success or failed message // to log file Validate . Exists ( repo . SaveDialog . ButtonOKInfo ) ; // Validates the existence of the repository item , // but does not throw any exception bool exists = Validate . Exists ( repo . SaveDialog . ButtonOKInfo , " Check Object { } " , false ) ; // Check whether an application form exists using a RanoreXPath Validate . Exists ( " / form [ @controlname = formVipApplication ] " ) ; // Check whether an application does not exists // for the time specified as timeout for the given repository item Validate . NotExists ( repo . MyApp . SelfInfo ) ; // Validate Enabled attribute of button Delete Validate . Attribute ( repo . MyApp . Buttons . ButtonDeleteInfo , " Enabled " , false ) ;
214
Code Examples
VB.NET
Validate for Existence Using Info objects for validation Throws a Ranorex . ValidationException if validation fails . Automatically reports success or failed message to log file Validate . Exists ( repo . SaveDialog . ButtonOKInfo ) Validates the existence of the repository item , but does not throw any exception Dim exists As Boolean = Validate . Exists ( repo . SaveDialog . ButtonOKInfo , " Check Object { } " , false ) Check whether an application form exists using a RanoreXPath Validate . Exists ( " / form [ @controlname = formVipApplication ] " ) Check whether an application does not exists for the time specified as timeout for the given repository item Validate . NotExists ( repo . MyApp . SelfInfo ) Validate Enabled attribute of button Delete Validate . Attribute ( repo . MyApp . Buttons . ButtonDeleteInfo , " Enabled " , false )
Note: Each method provided by the Validate class allows to suppress exceptions thrown in case of a failed validation. The code snippet above uses only a few validation methods. For further and more detailed explanation of the Ranorex.Validate class see the API documentation.
C#
Ranorex . Cell cellObject = null ; // Try to find a cell object using two // different RanoreXPath expressions bool found = false ; found = Host . Local . TryFindSingle < Ranorex . Cell >( " / form // table / row / cell [3] " , 2 , out cellObject ) ; found = Host . Local . TryFindSingle < Ranorex . Cell >( " / form // table / row / cell [4] " , 2 , out cellObject ) ; // If none of the expressions returns an object // throw new ElementNotFoundException and test case fails if (! found ) { throw new Ranorex . ElementNotFoundException ( " Both RanoreXPath with no return " , null ) ; } else { // If the value of attribute Text does not equal to the expected value // throw new ValidationException to break the test case if ( cellObject . Text == " MyExpectedTextValue " ) { Report . Success ( " User Specific Validation " ," Text validation of cell object succeeded " ); } else { throw new Ranorex . ValidationException ( " Text validation of cell object succeeded failed " ) ; } }
215
Code Examples
VB.NET
Dim cellObject As Ranorex . Cell = Nothing Try to find a cell object using two different RanoreXPath expressions Dim found As Boolean = Host . Local . TryFindSingle ( Of Ranorex . Cell ) ( " / form // table / row / cell [3] " , 2 , cellObject ) found = Host . Local . TryFindSingle ( Of Ranorex . Cell ) ( " / form // table / row / cell [4] " , 2 , cellObject ) If none of the expressions returns an object throw new ElementNotFoundException and test case fails If Not found Then Throw New Ranorex . ElementNotFoundException ( " Both RanoreXPath with no return " , Nothing ) Else If the value of attribute Text does not equal to the expected value throw new ValidationException to break the test case If cellObject . Text = " MyExpectedTextValue " Then Report . Success ( " User Specific Validation " , " Text validation of cell object succeeded ") Else Throw New Ranorex . ValidationException ( " Text validation of cell object succeeded failed " ) End If End If
C#
void ITestModule . Run () { Mouse . DefaultMoveTime = 3 ; Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. ; }
VB.NET
Private Sub ITestModule_Run () Implements ITestModule . Run Mouse . DefaultMoveTime = 3 Keyboard . DefaultKeyPressTime = 1 Delay . SpeedFactor = 1. End Sub
216
Code Examples
C#
// ----------------- Code Block used by Code Module A ----------------// Click Save button to open SaveDialog repo . MyApp . Buttons . ButtonSave . Click () ; // Read text message shown with SaveDialog // and assign it to the variable varDialogTextA bound to a test case parameter varDialogTextA = repo . SaveDialog . TextMessage . TextValue ; // -------- Code Block used by User Code Action of recording B -------// Read value of module variable varDialogTextB in other code module // or recording module using a user code action Report . Info ( varDialogTextB ) ; // Get the current data context and log // the current row index of a data driven run Report . Info ( TestCase . Current . DataContext . CurrentRow . ToString () ) ;
VB.NET
----------------- Code Block used by Code Module A ---------------- Click Save button to open SaveDialog repo . MyApp . Buttons . ButtonSave . Click () Read text message shown with SaveDialog and assign it to the variable varDialogTextA bound to a test case parameter varDialogTextA = repo . SaveDialog . TextMessage . TextValue -------- Code Block used by User Code Action of recording B ------- Read value of module variable varDialogTextB in other code module or recording module using a user code action Report . Info ( varDialogTextB ) Get the current data context and log the current row index of a data driven run Report . Info ( TestCase . Current . DataContext . CurrentRow . ToString () )
C#
// Create Ranorex . Button adapter using FindSingle method // from Host . Local ( starting at root node ) with absolute RanoreXPath // Note : ElementNotFound exception is thrown if item is not found within // the specified timeout of 2 ms . Ranorex . Button addButtonVar1 = Host . Local . FindSingle < Ranorex . Button >( " / form [ @controlname = formVipApplication ]/ button [ @controlname = btAdd ] " ,2 ); addButtonVar1 . MoveTo () ; // Alternatively you can use the TryFindSingle method to prevent // a test case from failing because of an exception thrown if // the element is not found within the specified timeout of 2 ms Ranorex . Button addButtonVar2 = null ; bool found = Host . Local . TryFindSingle < Ranorex . Button >( " / form [ @controlname = formVipApplication ]/ button [ @controlname = btAdd ] " , 2 , out addButtonVar2 ) ; // Move mouse pointer to button addButtonVar2 . MoveTo () ; // Request a list of buttons shown from the VIP Database application // and create a screenshot for each button in the report file IList < Ranorex . Button > buttonList = Host . Local . Find < Ranorex . Button >( " / form [ @controlname = formVipApplication ]/ button " ,5 ) ; foreach ( Ranorex . Button bt in buttonList ) {
217
Code Examples
Report . Screenshot ( bt ) ; } // Using find methods in combination with existing Ranorex repository items Ranorex . Button btAdd = repo . MyApp . Self . FindSingle < Ranorex . Button >( " button [ @controlname = btAdd ] " ,2 );
VB.NET
Create Ranorex . Button adapter using FindSingle method from Host . Local ( starting at root node ) with absolute RanoreXPath Note : ElementNotFound exception is thrown if item is not found within the specified timeout of 2 ms . Dim addButtonVar1 As Ranorex . Button = Host . Local . FindSingle ( Of Ranorex . Button ) ( " / form [ @controlname = formVipApplication ]/ button [ @controlname = btAdd ] " , 2 ) addButtonVar1 . MoveTo () Alternatively you can use TryFindSingle method to prevent a test case from failing because of an exception thrown if the element is not found within the specified timeout of 2 ms Dim addButtonVar2 As Ranorex . Button = Nothing Dim found As Boolean = Host . Local . TryFindSingle ( Of Ranorex . Button ) ( " / form [ @controlname = formVipApplication ]/ button [ @controlname = btAdd ] " , 2 , addButtonVar2 ) Move mouse pointer to button addButtonVar2 . MoveTo () Request a list of buttons from the VIP Database application and create a screenshot for each button in the report file Dim buttonList As IList ( Of Ranorex . Button ) = Host . Local . Find ( Of Ranorex . Button ) ( " / form [ @controlname = formVipApplication ]/ button " , 5 ) For Each bt As Ranorex . Button In buttonList Report . Screenshot ( bt ) Next Using find methods in combination with existing Ranorex repository items Dim btAdd As Ranorex . Button = repo . MyApp . Self . FindSingle ( Of Ranorex . Button ) ( " button [ @controlname = btAdd ] " , 2 )
C#
// Create bitmap to search for // within application form and // click it Bitmap bmp = Ranorex . Imaging . Load ( @ " ..\..\ Green Sea Turtle Small . bmp " ) ; // Performs a right click on the image found // within the application window based on // the image location myRepo . WinFormsApp . Self . Click ( MouseButtons . Right , bmp ) ; // You can also search for images that are slightly different to the // loaded image by specifying the minimum Similarity for a match (95% = .95) . myRepo . WinFormsApp . Self . Click ( new Location ( bmp , new Imaging . FindOptions ( .95) ) ) ; // OR Set the default Similarity value for all following image operations Imaging . FindOptions . Default . Similarity = .95; myRepo . WinFormsApp . Self . Click ( bmp ) ; Report . Success ( " Image found and clicked successfully " ) ;
218
Code Examples
VB.NET
Create bitmap to search for within application form and click it Dim bmp As Bitmap = Ranorex . Imaging . Load ( " ..\..\ Green Sea Turtle Small . bmp " ) Performs a right click on the image found within the application window based on the image location myRepo . WinFormsApp . Self . Click ( MouseButtons . Right , bmp ) You can also search for images that are slightly different to the loaded image by specifying the minimum Similarity for a match (95% = .95) . myRepo . WinFormsApp . Self . Click ( new Location ( bmp , new Imaging . FindOptions ( .95) ) ) OR Set the default Similarity value for all following image operations Imaging . FindOptions . Default . Similarity = .95 myRepo . WinFormsApp . Self . Click ( bmp ) Report . Success ( " Image displayed successfully " )
C#
// Create bitmap Bitmap bmp = Ranorex . Imaging . Load ( @ " ..\..\ Green Sea Turtle Small . bmp " ) ; // Search for it within the application window if ( Ranorex . Imaging . Contains ( myRepo . WinFormsApp . Self , bmp ) == true ) { Report . Success ( " Image found within WinForms application " ) ; }
VB.NET
Create bitmap Dim bmp As Bitmap = Ranorex . Imaging . Load ( " ..\..\ Green Sea Turtle Small . bmp " ) Search for it within the application window If Imaging . Contains ( myRepo . WinFormsApp . Self , bmp Then Report . Success ( " Image found within WinForms application " ) End If
Note: Both examples load an uncompressed file (BMP or PNG format) in order to carry out a one-to-one comparison. Use the FindOptions class to configure similarity, preprocessing and other search settings.
219
Code Examples
Figure 298: Update-Check dialog To overcome this issue, you can use the PopupWatcher class. Using this class you can add watches for each dialog which might pop up during test execution. In this watches you can specify a RanoreXPath or a Repository item the PopupWatcher should keep watching for, as well as a method which should be triggered or a repository item which should be clicked.
C#
void ITestModule . Run () { // Create PopupWatcher PopupWatcher myPopupWatcher = new PopupWatcher () ; // Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog myPopupWatcher . Watch ( " / form [ @controlname = UpdateCheckForm ]/ button [ @controlname = m_btnClose ] " , CloseUpdateCheckDialog ) ; // Add a Watch using the info object of a button and triggering the Method CloseUpdateCheckDialog // myPopupWatcher . Watch ( repo . UpdateCheckDialog . btCloseInfo , CloseUpdateCheckDialog ) ; // Add a Watch using the info object of the dialog and the info object of the button to click // myPopupWatcher . WatchAndClick ( repo . UpdateCheckDialog . SelfInfo , repo . UpdateCheckDialog . btCloseInfo ); // Add a Watch using a repository folder object and the info object of the button to click // myPopupWatcher . WatchAndClick ( repo . UpdateCheckDialog , repo . UpdateCheckDialog . btCloseInfo ) ; // Start PopupWatcher myPopupWatcher . Start () ; } public static void CloseUpdateCheckDialog ( Ranorex . Core . Repository . RepoItemInfo myInfo , Ranorex . Core . Element myElement ) { myElement . As < ranorex . button >() . Click () ; } public static void CloseUpdateCheckDialog ( Ranorex . Core . RxPath myPath , Ranorex . Core . Element myElement ) { myElement . As < ranorex . button >() . Click () ; }
VB.NET
220
Code Examples
Private Sub ITestModule_Run () Implements ITestModule . Run Create PopupWatcher Dim myPopupWatcher As New PopupWatcher () Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog myPopupWatcher . Watch ( " / form [ @controlname = UpdateCheckForm ]/ button [ @controlname = m_btnClose ] " , AddressOf CloseUpdateCheckDialog ) Add a Watch using the info object of a button and triggering the Method CloseUpdateCheckDialog myPopupWatcher . Watch ( repo . UpdateCheckDialog . btCloseInfo , CloseUpdateCheckDialog ) ; Add a Watch using the info object of the dialog and the info object of the button to click myPopupWatcher . WatchAndClick ( repo . UpdateCheckDialog . SelfInfo , repo . UpdateCheckDialog . btCloseInfo ) ; Add a Watch using a repository folder object and the info object of the button to click myPopupWatcher . WatchAndClick ( repo . UpdateCheckDialog , repo . UpdateCheckDialog . btCloseInfo ) ; Start PopupWatcher myPopupWatcher . Start () End Sub Public Shared Sub CloseUpdateCheckDialog ( myInfo As Ranorex . Core . Repository . RepoItemInfo , myElement As Ranorex . Core . Element ) myElement .[ As ]( Of Ranorex . Button ) () . Click () End Sub Public Shared Sub CloseUpdateCheckDialog ( myPath As Ranorex . Core . RxPath , myElement As Ranorex . Core . Element ) myElement .[ As ]( Of Ranorex . Button ) () . Click () End Sub
221
Data Connectors
Data Connectors
In this section you learn about how to define different types of external data sources to be used for test automation.
Simple Data Table CSV File SQL Connector Excel File
Figure 299: Open Manage Data Sources dialog from test suite view
222
Data Connectors
Figure 300: Manage Data Sources dialog In this dialog you can add new data connectors of the types described in the next chapters and rename or delete existing data connectors.To add an existing data connector or create a new data connector to one of your test cases, select the desired test case from test suite view and open the data source dialog by pressing the Data Source. . . button.
223
Data Connectors
Figure 302: Test case properties dialog shows the currently used data source In this new opened dialog you can create a new data connector by selecting one of the data connector types described in the next chapters from the combo box marked in green. You can also choose an existing data connector by selecting one of the data sources from the combo box marked in red. By pressing the blue marked button, labeled Manage Data Sources the data source management dialog, explained before, will be opened. By pressing the yellow marked button labeled Refresh, the data of the actual selected data source will be updated from its source file or database. You can limit the data of your data source by selecting a data range in the area marked orange. To open a dialog showing you the effective data set limited by a range (area marked in orange, e.g. 1-2,4), press the purple marked button, labeled Preview effective data set. . . .
224
Data Connectors
Figure 303: Preview the effective data set In this dialog you can update the effective data set from the data file or database by pressing the green marked button labeled Refresh. You can also export the effective data set to a CSV file by pressing the red marked button, labeled Export CSV.
225
Data Connectors
226
Data Connectors
Figure 305: Add new test data directly to a table of type Simple Data Connector
227
Data Connectors
CSV File
You can also use a CSV file to provide data for your test suite by choosing this type of data connector. After adding a CSV file data connector, the data source management dialog will be opened. You can edit the name of the data connector in the text box marked in red and choose the CSV file by selecting a file in the green marked area. By checking or un-checking the check box marked blue you can decide either to include or to exclude the selected CSV file to your test suite. By checking this check box, a copy of the file will be placed in your solutions folder. By checking the yellow marked check box, the first line of your CSV file will be added as the header of all rows.
Figure 306: Set up CSV file as external data source CSV data connectors are, like simple data connectors, not read-only. You can add rows and columns in the same way as described in chapter Simple Data Table. The changes to your table will be applied to the CSV file. If you have chosen the option Include File in Test Suite in the data source management dialog, the changes will be applied to the local copy of your CSV file.
228
Data Connectors
SQL Connector
The third type of data connector is the SQL connector. This connector allows you to access a SQL database and get the desired data using a SQL query. After adding a SQL connector, the data source management dialog will be opened. You can edit the name of the data connector in the text box marked yellow. To generate a connection string to connect to your database, press the red marked Create button. After establishing a connection to the database by generating a connection string, you can add an SQL query by pressing the green marked Create button.
229
Data Connectors
Figure 308: SQL connector - Connection Properties dialog The appearance of this dialog depends on the data source which can be chosen by pressing the Change button marked red. In this screenshot, a Microsoft Access Database File is chosen as data source. You can choose the database file by pressing the Browse button marked green and set the user name and the password in the area marked yellow. But as explained before, the kind and number of properties will depend on the chosen data source. By pressing the orange marked button labeled Advanced. . . the advanced property dialog will be opened. In this dialog you can edit the advanced options of your database connection. After configuring all relevant options, you can check if the database connection is working by pressing the purple marked button labeled Test Connection.
Create Query
By pressing the green marked Create button in the data source management dialog the query design dialog will be opened.
230
Data Connectors
Figure 309: SQL Query Designer used to create SQL queries You can add a column by double clicking an attribute of a table in your database. These attributes can be found in the area marked green. These attributes will be added to the area marked red, keeping the column headings shown in your data connector, as well as in the area marked blue, with the SQL query. Pressing the button marked yellow will add a GROUP BY statement to the SQL query. Pressing the button marked orange will allow you to add advanced settings to your SQL query. Pressing the purple button will check SQL syntax. Pressing the light blue button will show you a preview of the data set retrieved by the SQL query. Pressing the button marked brown will reset the SQL query.
231
Data Connectors
Excel File
The last type of data connector is the Excel file connector. This connector allows you to use an Excel file to provide data for your test suite. After adding an Excel file connector, the data source management dialog will be opened. You can edit the name of the data connector in the text box marked red and choose the Excel file by selecting a file in the green marked area. By checking or un-checking the check box marked blue you can decide either to include or to exclude the selected Excel file to your test suite. By checking this check box, a copy of the file will be placed in your solutions folder. Additionally you can define the worksheet and the range of the worksheet which will provide the data for the Excel file connector in the yellow marked area.
232
Instrumentation Wizard
Instrumentation Wizard
Ranorex supports the testing of many different UI technologies, however some technologies need to be instrumented correctly to guarantee the best possible automation results. The Ranorex Instrumentation Wizard is a tool which helps you instrumenting these technologies to ensure optimal object recognition and consequently robust test automation projects. The Ranorex Instrumentation Wizard can be started either from Tools menu in Ranorex Studio, from the pop-up dialog triggered by a technology limitation, from the start menu, or directly from the binary folder of your Ranorex installation (<Ranorex Installation Folder>\bin\Ranorex.InstrumentationWizard.exe). The last method is useful if you are going to automatically instrument a technology. Have a look at the section Running Instrumentation Wizard from the Command Line for further details. The wizard is used to instrument the following technologies:
Java AWT/Swing Adobe Flash/Flex Mozilla Firefox Google Chrome Apple Safari Android iOS
233
Instrumentation Wizard
Figure 313: Start Instrumentation Wizard from installation folder By starting the wizard from the Tools menu, from the start menu or from the bin folder, you can choose which kind of technology you want to instrument, whereas the technology limitation pop-up leads you directly to the instrumentation of the technology with limited identification capabilities.
234
Instrumentation Wizard
p|pagename:
Default is Select. Set this option to directly navigate to a specific page. Is also required for automated command line based instrumentation. Pages are: android, chrome, firefox, flex, ios, java and safari.
?|help:
Default is False. Displays command line arguments help.
235
Instrumentation Wizard
dm|deploymode: Possible Values: WiFi, Usb, NoDeploy. Default is WiFi. Specifies how the apk file will be deployed. Set to NoDeploy if the file should not be deployed to the device. chrome a|activate: Required. Enable this switch to activate the Chrome browser addon. If the switch is disabled the addon will be deactivated. firefox a|activate: Required. Enable this switch to activate the Firefox browser addon. If the switch is disabled the addon will be deactivated. flex pl|preloader: Required. Enable this switch to enable the Ranorex preloader. If the switch is disabled the preloader will get deactivated. ie: Required. Enable this switch to enable Internet Explorer Flash debug player installation. If the switch is disabled Internet Explorer Flex debug player will not be installed. o|others: Required. Enable this switch to enable Firefox/Chrome/Safari Flash debug player. If the switch is disabled FireFox/Chrome/Safari Flash debug player will not be installed. ft|flextrace: Default is False. Enable this switch to enable the flash tracelog. If the switch is disabled flash trace log will be deactivated. ios u|udid: Required. The unique device identifier for the device where the application should be installed. ip|inputpath: The path to the application archive (*.ipa). ai|appid: The application Id (bundle identifier of the app). This is required so that an application can be uninstalled prior to installing the new archive. java jp|javapath : Required. System path to the JRE that shall be instrumented. e|enable: Default is True. Tells Ranorex if the instrumentation shall be enabled or disabled. safari a|activate: Required. Enable this switch to activate Safari browser addon. If the switch is disabled the addon will be deactivated.
236
Instrumentation Wizard
Java AWT/Swing
The Java AWT/Swing technology limitation will pop up if your Java installation or application is not instrumented correctly.
Figure 315: Java AWT/Swing Technology Limitation The Instrumentation Wizard tries to add the Plug-In specific files to the Java Runtime Environment (JRE) of your choice and to activate the Java Plug-In for Ranorex. You have 3 different choices:
Select a JRE from a list of running Java applications: Here you can choose the Java runtime based on the application you want to instrument. This is the preferred method, as you can determine exactly which Java runtime is being used by your application under test. Select a JRE from a list of installed Java runtimes: Here you can choose the Java Runtime Environment you want to be instrumented from a list of all installed Java runtimes on your machine. Specify a custom Java runtime directory: Here you can specify the folder holding the Java runtime you want to be instrumented.
237
Instrumentation Wizard
Figure 316: Java Instrumentation Wizard After activating the Java AWT/Swing instrumentation, Ranorex will not be limited in recognizing UI elements of your Java application. Restart your application under test and your Ranorex tools to ensure that the newly added instrumentation works correctly.
Figure 317: Finished Java Instrumentation If you are using Windows XP SP2, please also make sure that the Windows Update KB884020 is installed, which resolves problems with the local network communication. If the activation of the Java Plug-In was not successful, please make sure that you have installed Ranorex correctly, that you have chosen the right directory of your JRE, and if you have started the Instrumentation Wizard from the bin folder that it has been started with admin rights.
238
Instrumentation Wizard
239
Instrumentation Wizard
Adobe Flash/Flex
The Flash/Flex technology limitation will pop up if your Flash/Flex application is not instrumented correctly.
Note: If you need to automate an Adobe AIR application, please read Methods for loading the Automation Lib chapter.
The instrumentation Wizard tries to install either the Flash Debug Player for Internet Explorer or the Flash Debug Player for Mozilla Firefox, Google Chrome and Safari or both Flash Debug Players if you like. Moreover, you can enable the Ranorex Preloader Instrumentation. This allows you in combination with the Flash Debug Player to instrument your application under test without the need to alter your application. Additionally, you can enable logging for the Flash Debug Player. This might be helpful if you have any problems with this kind of instrumentation. In such case you can then simply provide this logging information to our support team.
240
Instrumentation Wizard
Figure 320: Flash/Flex Instrumentation Wizard After installing the Debug Players and activating the Ranorex Preloader, Ranorex should be able to recognize your Flash and Flex applications without any limitations. Restart your application under test and your Ranorex tools to ensure that the newly added instrumentation works correctly.
Figure 321: Finished Flash/Flex Instrumentation If you still have problems within recognition of Flash/Flex applications, please make sure that your applications are not double instrumented, i.e. make sure that you do not use any Ranorex Library or Ranorex Module within your Flash/Flex application.
Google Chrome
To use the preloader method with Google Chrome, you have to disable the internal Flash Player. This can be done by performing following steps: 241
Instrumentation Wizard
Open Chromes plugins overview (chrome://plugins/):
242
Instrumentation Wizard
243
Instrumentation Wizard
Mozilla Firefox
The Mozilla technology limitation will pop up if the Ranorex Add-On for you Mozilla Browser is not installed or enabled. This technology limitation should only occur if you install Firefox after successfully installing Ranorex. If Mozilla Firefox has been installed before installing Ranorex, the Mozilla Browser Add-On will be installed and activated automatically.
Figure 325: Mozilla Firefox Technology Limitation The Instrumentation Wizard tries to install the Mozilla Firefox Add-On when checking the checkbox Activate Mozilla Firefox Add-On and tries to uninstall the Add-On when unchecking the mentioned checkbox.
Figure 326: Mozilla Firefox Instrumentation Wizard After installing the Add-On, Ranorex should not have any limitation recognizing UI elements within your web document. Restart your application under test and your Ranorex tools to ensure that the newly added instrumentation works correctly.
244
Instrumentation Wizard
Figure 327: Finished Mozilla Firefox Instrumentation If the activation of the Add-On was not successful, please make sure that you have installed Ranorex correctly and if you have started the Instrumentation Wizard from bin folder that it has been started with admin rights.
Figure 328: Failed Mozilla Firefox Instrumentation If you still get a limitation when tracking web elements, please assure that the Mozilla Firefox Add-On is enabled in the Firefox Add-On settings.
Note: To successfully activate the Ranorex Add On for Firefox 8 and greater, it is necessary to confirm its installation.
245
Instrumentation Wizard
246
Instrumentation Wizard
Google Chrome
The Chrome technology limitation will pop up if the Ranorex Extension for the Chrome Browser is not installed or enabled.
Figure 330: Google Chrome Technology Limitation The Instrumentation Wizard tries to activate the Google Chrome Extension when checking the checkbox Activate Google Chrome Addon and tries to deactivate the Extension when unchecking the mentioned checkbox.
Figure 331: Google Chrome Instrumentation Wizard After activating the Extension, Ranorex should not have any limitation recognizing UI elements within your web document. Restart your application under test and your Ranorex tools to ensure that the newly added instrumentation works correctly.
247
Instrumentation Wizard
Figure 332: Finished Google Chrome Instrumentation If the activation of the Add-On was not successful, please make sure that you have installed Ranorex correctly and if you have started the Instrumentation Wizard from bin folder that it has been started with admin rights.
Figure 333: Failed Google Chrome Instrumentation If you still get a limitation when tracking web elements, please assure that the Ranorex Automation Extension is enabled in the Chrome Extensions settings (chrome://settings/extensionSettings).
248
Instrumentation Wizard
Figure 334: Enable Ranorex Automation Extension If you have removed the Ranorex Automation Extension manually, you have to manually re-add the Extension. Therefore you have to open the file RanorexAutomation.crx, which can be found in the binary folder of your Ranorex installation (..\Ranorex 3.2\bin\RanorexAutomation.crx ), in Chrome and install by following the instructions.
Note: If you want to test cross domain iframe scripting with Google Chrome, you have to start Chrome with the command line argument --disable-web-security
Note: If you want to test file URLs, you have to enable Allow access to file URLs for the Ranorex Automation Extension.
249
Instrumentation Wizard
Note: if the NotScript Chrome Extension is installed it has to be disabled to allow from point tracking with Ranorex.
250
Instrumentation Wizard
Apple Safari
The Safari technology limitation will pop up if the Ranorex Extension for the Safari Browser is not installed or enabled.
Figure 337: Apple Safari Technology Limitation The Instrumentation Wizard tries to activate the Safari Extension when checking the checkbox Activate Apple Safari Addon and tries to deactivate the Extension when unchecking the mentioned checkbox.
Figure 338: Apple Safari Instrumentation Wizard After activating the Extension, you have to confirm the installation in Safari.
251
Instrumentation Wizard
Figure 339: Confirm installation of Ranorex Automation Extension After activating the Extension and confirming the installation, Ranorex should not have any limitation recognizing UI elements within your web document. Restart your application under test and your Ranorex tools to ensure that the newly added instrumentation works correctly.
Figure 340: Finished Apple Safari Instrumentation If the activation of the Extension was not successful, please make sure that you have installed Ranorex correctly and if you have started the Instrumentation Wizard from bin folder that it has been started with admin rights.
252
Instrumentation Wizard
Figure 341: Failed Apple Safari Instrumentation If you still get a limitation when tracking web elements, please assure that the Apple Safari Extension is enabled in the Safari Extensions settings (Preferences->Extensions).
Note: Testing file URLs with Apple Safari is currently not supported.
Note: Testing cross domain iframe scripting with Apple Safari is currently not supported.
253
Instrumentation Wizard
Android
To make an Android app automatable by Ranorex, it is necessary to instrument this application using the Instrumentation wizard.
Note: Have a look at Getting Started to learn how to automate Android applications.
Figure 343: Android instrumentation wizard Choose the APK file of the app and the device, the instrumented APK file will be deployed to. More information about setting up a mobile device can be found in section Manage Devices. If the APK is already instrumented and only needs to be deployed on a mobile device, the checkbox Instrument the APK under test before deployment can be unchecked. After processing the instrumentation and deploying the instrumented APK file to the selected device, the installation has to be confirmed on the device.
254
Instrumentation Wizard
Figure 344: Finished Android instrumentation The instrumented APK file can be found at location referenced by the link Open instrumentation File location. After instrumenting the APK file, the app is available in the Mobile Recording section of Record Setting dialog.
Figure 345: Instrumented APK in Record Settings The Ranorex Service App installed on the mobile device shows an overview of instrumented apps installed on the device.
255
Instrumentation Wizard
Note: If you have problems with instrumenting your APK using the instrumentation wizard or if you want to integrate the instrumentation into your build process, please have a look at the Instrumentation with Source Code section.
256
Instrumentation Wizard
iOS
To make an iOS app automatable by Ranorex, it is necessary to instrument this application and deploy it to a device. The Instrumentation wizard can be used to deploy the instrumented app to the device.
Note: Deployment only works for USB connected iOS devices.Have a look at Getting Started to learn how to instrument iOS applications.
Figure 347: Android instrumentation wizard Choose the instrumented IPA file of the app and the device, the app will be deployed to. More information about setting up a mobile device can be found in section Getting Started. To delete the existing version of the app on your device before deploying a new one, check the corresponding check box.
257
Instrumentation Wizard
Figure 348: Finished Android instrumentation After deploying the IPA file, the app is available in the Mobile Recording section of Record Setting dialog.
258
Instrumentation Wizard
259
2. Make a backup of your existing 2.X project and add it to the Test Suite Project
260
1. Open your recording file and click on the Variables. . . Recorder view
261
3. Open the UserCode file of your recording and remove your existing properties 4. Remove the static keyword from your UserCode methods
Now you are able to bind your module variables to a data column or parameter within a test case.
262
1. Select your project in the projects view and click on Add Code Module
Now you can add your code module to a test case. Please see following pages for more information about code modules:
Creating Code Modules Using Repository within Code Module Accessing Screen Shots within Code Modules Using Variables with Code Modules Using Code Modules within Test Cases
Breaking Changes
A few changes had to be introduced that can break existing Ranorex 2.X projects when updating to Ranorex 3.X. If your automation project does not work any more after updating to 3.X, please see the following list that explains what has changed and how you need to update your project to make it work with 3.X again: 263
C#
using Ranorex ;
VB.NET
imports Ranorex
The IReportLogger interface has been extended. In particular, the signature of the LogText and LogData methods changed and the PreFilterMessages property was added. If you get compile errors after updating stating that your classes do not correctly implement the IReportLogger interface, please update the implementing classes accordingly. See following blog on how to implement the new IReportLogger interface: Customizing Ranorex Reports The tree structure for MSAA elements has changed under certain circumstances and potentially includes more levels and elements now. If you do not want to use the new elements, set the MSAA Filter compatibility level setting in the Plugins tab of the Ranorex settings to V2X. Otherwise, please, update broken RanoreXPaths accordingly. Text nodes which consist only of white-spaces are no longer appended to Mozilla WebElement.InnerText. Please, update RanoreXPaths and validations that depend on this property and fail accordingly. Some Win32 controls in the tree no longer have the role Form, but a more appropriate role instead. If you want Ranorex to not use the new role, set the Win32 Use legacy Form role setting in the Plugins tab of the Ranorex settings to True. Otherwise, please, update broken RanoreXPaths accordingly. Control.Get/SetPropertyValue now use Reflection instead of the ComponentModel. If a property cannot be found, please check that the used name correctly reflects the API name of the property. The ControlNet11 capability is no longer used as the preferred capability for .NET 1.1 controls. As a consequence, the generated path to items with that capability can change (existing paths will still work). With version 3.0.1 Ranorex added basic support for Delphi controls resulting into different RanoreXPaths being generated for many Delphi controls. If you do not want to use the new functionality, set the Win32 Enable basic Delphi support setting in the Plugins tab of the Ranorex settings to False.
264
Technology Instrumentation
Technology Instrumentation
Ranorex supports testing of many different UI technologies. Although some of them need to be instrumented correctly to ensure optimal object recognition and furthermore to built robust test automation projects. If an application under test requires additional manual instrumentation, a pop-up dialog is shown when using a Ranorex tool.
Figure 356: Technology limitation box shown for not instrumented application Learn more about technology dependent instrumentation and how to troubleshoot object recognition issues using the information below:
Flash/Flex Testing Testing of Java Applications Qt Testing Testing of Legacy Applications Testing of SAP Applications General Troubleshooting
265
Technology Instrumentation
Flash/Flex Testing
The Flash/Flex Test Automation Plugin provides a smooth integration with the Ranorex Automation Framework and its tools. You can easily filter, access and validate Flex controls easily using RanoreXPath. You have full access to all the properties and attributes of Flash and Flex elements.
Prerequisites
The automation of Flash/Flex applications requires inclusion of the Ranorex Flex Automation Lib.
Using the Ranorex PreLoader OR including the Ranorex Lib into Adobe Flex: Adobe Flex: Load the Ranorex Lib into your Flex applicationinto Adobe Flash: Adobe Flash: Load the Ranorex Lib into your Flash application
Samples
A flash/flex test sample project is included with the Ranorex installation package (shown on the startpage of Ranorex Studio).
How to read/set attributes and styles
Adobe Flex: Load the Ranorex Lib into your Flex application The AutomationLib swc file has to be included into your flash/flex application (by adding a compiler argument).
AutomationLib will be loaded in background (will not affect the functionality of your flash/flex application) No modifications to your website needed
How to load the Ranorex Module into your Flash application The Module swf file has to be loaded by adding a code snippet to your How to load the Ranorex Module into your Flash application or to your How to load the Ranorex Module into your Flex/AIR application.
Module will be loaded in background (will not affect the functionality of your flash/flex application) No modifications to your website needed
266
Technology Instrumentation
Module swf has to be copied to the web server
The following table shows you the different instrumentation options available for the supported versions of flash/flex:
* Support for Adobe AIR 2 Release in combination with Flex 3.5 and Flex 4 Release = supported = recommended
Technology Instrumentation
// Set the checked state with the property " Checked " repo . FlexTestPageDom . CheckBox_Control_Example . CheckBoxEggs . Checked = true ;
To access custom attributes and styles, you first have to load your Flex item as a FlexElement in order to read your attributes. Heres an example:
// Load the slider as a Flex element to access flex attributes FlexElement sliderFlex = repo . FlexTestPageDom . ContainerHSlider_Control . SliderHSlider . As < flexelement >() ; sliderFlex [ " value " ] = " 1 " ; FlexElement containerFlex = repo . FlexTestPageDom . Self . FindSingle ( " .// container [ @caption = Tree Control ] " ) ; containerFlex . SetStyle ( " borderColor " ," # ee "); </ flexelement >
Figure 358: Flash/Flex Instrumentation Wizard The wizard will execute following steps for you: 1. Install the Adobe Debug Flash Player on the machine on which you would like to record and execute Ranorex test scripts and for all browsers you would like to test with. The installers are available on Adobes download page; the following are the links to the Debug Player for Internet Explorer (Windows 8 x86 and Windows 8 x64)and Firefox/Chrome/Safari. 2. Open your user profile directory %UserProfile%, e.g. by opening Windows Explorer and copying the string %UserProfile% into the address bar. 3. Create a new file called mm.cfg in your user profile directory and insert the following line of code, where C:\FlashFlex\RanorexAutomation.swf needs to be replaced by the preloader location of your Ranorex installation: PreloadSwf= C:\Program Files\Ranorex X.X\Bin\RanorexAutomation.swf Additional to this configuration entry you can enable the logging mechanisms of the Adobe Debug Flash Player, which might be helpful if you have any problems with this kind of instrumentation. In such a case you can then
268
Technology Instrumentation
simply provide this logging information to our support team. To enable logging you have to add the following line of code to your mm.cfg file: TraceOutputFileEnable=1 This additional configuration entry forces the Debug Player to create a log file at following location: C:\Users\username\AppData\Roaming\Macromedia\Flash Player\Logs 4. If you run your application from the local drive, add your output directory to the trusted locations of Flash Player as follows: (a) Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings manager04.html#119065 (b) Add your project output directory
Adobe Flex: Load the Ranorex Lib into your Flex application
1. Start Adobe Flex Builder and open your workspace 2. Right-click on your project and choose Properties 3. Under Flex Compiler add theRanorexAutomation.swc file (located in the Bin directory of your Ranorex installation) to the the compiler argument as follows:
- include - libraries " C :/ Program Files / Ranorex X . X / Bin / RanorexAutomation . swc "
5. Save and compile your application 6. Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari) 7. If you run your Flex application from the local drive, add your output directory to the trusted locations of Flash Player as follows: (a) Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings manager04.html (b) Add your project output directory
Adobe Flash: Load the Ranorex Lib into your Flash application
1. Start Adobe Flash CS4/CS5 and open your application 2. Open the Publish Settings dialog (File->Publish Settings) 3. Include the Ranorex Flash Library in your Flash application under Flash->Script->Settings. . . ->Library Path and choose Browse to SWC file 4. Select RanorexAutomation.swc file in the browse dialog (RanorexAutomation.swc is located in the Bin directory of your Ranorex installation) 5. Insert following code to your ACTIONS (by pressing F9):
import Ranorex . RxAutomation ; RxAutomation . InitFromApp ( stage ) ;
269
Technology Instrumentation
mx . controls .*; flash . events .*; flash . display .*; flash . ui . Keyboard ; flash . geom . Rectangle ; fl . events . SliderEvent ; Ranorex library Ranorex . RxAutomation ; class Simple extends MovieClip public function Simple () { // Add to your constructor RxAutomation . InitFromApp ( stage ) ; }
6. Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari) 7. If you run your Flash application from the local drive, add your output directory to the trusted locations of Flash Player as follows: (a) Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings manager04.html (b) Add your project output directory
270
Technology Instrumentation
Figure 359: Java Instrumentation Wizard If you are using Windows XP SP2, please also make sure that the Windows Update KB884020 is installed, which resolves problems with the local network communication. Manual Setup of Ranorex Java Plug-In 1. First of all close all Ranorex Tools. 2. Now you have todetermine the path of your active Java runtime Environment to know where to copy the necessary files to. Open the Java Runtime Environment Settings which can be found in Java Control Panel (Control-Panel -> Java). There you can see the path of your Java Runtime Environment. If you have more than one Java Runtime Environment installed on your machine, check which one will be used to execute your Java applications by determining which one is activated. 3. After identifying the path you have to copy each of the following files to its corresponding directory based on the root folder of your java runtime installation (e.g. C:\Program Files (x86)\Java\jre6\). The given files are located in the Ranorex installation folder (e.g. C:\Program Files\Ranorex 3.2\Bin)
accessibility.properties to \lib RanorexAutomation.jar to \lib\ext JavaHelper32/64.dll to \bin
After restarting you Java application you should be able to use the Ranorex for your Java application under test.
271
Technology Instrumentation
Qt Testing
The Ranorex Automation Framework fully supports test automation of Qt based applications. To ensure that Ranorex can access UI elements and properties in the Qt application, MSAA (Microsoft Active Accessibility) support for your Qt application must be enabled. This provides additional information on Qt UI elements to automation software like Ranorex and can be accomplished by shipping and loading the Accessible Plug-in included in the Qt SDK (Software Development Kit) with the Qt application under test (see below). Loading Accessible Plug-in for your Qt application: 1. Copy the accessibledirectory(and all its contents)from the Qt SDK (used to build the application under test) installation folder to the folder of the automated application (e.g. Program Files/Your-Application/plugins). If you do not have access to the Qt SDK which the Qt application is developed with, please contact the developer of the application and request the accessible directory from him. 2. Create a file called qt.conf (or append if the file already exists) in the root directory of the automated application (e.g. Program Files/Your-Application) with following content (copy and paste the following two lines): [Paths] Plugins = plugins
272
Technology Instrumentation
273
Technology Instrumentation
Figure 362: Add class name to GDI capture list The pictures below show the different object recognition for a MFC-based menu bar control before and after GDI activation.
274
Technology Instrumentation
Figure 364: . . . and after GDI activation You can also add a process name to the GDI capture list by right-clicking on the parent form element of a control in the Ranorex Spy tree.
275
Technology Instrumentation
Figure 365: GDI Capture Settings dialog shows currently observed processes and class names Simply delete class or process names which have been added via the context menu from the text boxes shown above.
276
Technology Instrumentation
Figure 366: SAP GUI options dialog SAP support is not included in the Ranorex standard developer licenses. sales@ranorex.com for further details. Please contact our sales team at
277
Technology Instrumentation
General Troubleshooting
This section provides an overview of possible reasons for a limited object recognition with Ranorex tools and recommends ways to correct a malfunction.
.NET WinForms .NET Silverlight Flash/Flex Applications Win32 Based Applications Browser (Mozilla Firefox, Google Chrome, Apple Safari) Image Related Automation or Validation Geometry Related Issues Windows Apps (aka Windows 8 UI Apps) Other Software
.NET WinForms
Ranorex failed to load the assemblies containing the definition of this control. UI element identification capabilities for this control are limited. There might be several reasons for limited support of .NET WinForms based applications or controls: Reason #1: The automating process (Ranorex executable) and the automated application (AUT) are not started with the same security rights, i.e. not as the same Windows user. Solution: Try starting both applications as the same user. Reason #2: Either the automating executable or the AUT are started from a network drive or encrypted folder and consequently do not have the required security rights. Solution: Try copying both applications to a folder on your hard disk. Reason #3: The controls that cannot be identified are implemented in a mixed-mode EXE file (not DLL). This can be the case with some obfuscating applications or assembly merging utilities that create mixed-mode EXE files. The .NET Framework does not support loading such mixed-mode executables in other processes and thats why Ranorex cannot recognize controls implemented within them. Solution: As a workaround, you can try to automate the non-obfuscated version of your application.
278
Technology Instrumentation
Reason #4: The controls that cannot be identified are implemented in an assembly that targets a particular platform/processor and the automating executable targets a different platform/processor. This can cause problems on 64 bit operating systems, since such assemblies cannot be loaded by the automating process. Solution: Try changing the Target CPU (Ranorex Studio) or Platform Target (Visual Studio) option in the automation project settings to match the target of the automated application as described in 64-bit Platforms. If you dont know the target CPU/platform of the automated application, first try to change the option to Any processor or Any CPU, respectively, then try the remaining options. Reason #5: The .NET Framework 4.0 Extended package is needed but not installed. An indication for this problem typically is that controls can correctly be identified by the standalone Ranorex Spy application, but not by the integrated Ranorex Spy or Recorder in Ranorex Studio.The application under test uses the .NET Framework 4.0 and you may get Technology Limitation pop-ups saying that specific assemblies cannot be loaded. Solution: Either install the .NET Framework 4.0 Extended or if that is not possible always use the standalone Ranorex Spy and Recorder tools instead of the integrated ones in Ranorex Studio. Reason #6: If the application under test is built with the .NET Framework 4.0, a <executableName >.exe.config file (where <executableName > has to be replaced by the name of the Ranorex executable) needs to reside in the same folder as the automating Ranorex executable and it needs to contain the configuration below. Solution: Create and add an app.config file with the below content to your project. Make sure that after compiling and when executing the executable there is a <executableName >.exe.config file in the same folder as the Ranorex executable with following content:
< configuration > < startup useLegacyV2RuntimeActivationPolicy = " true " > < supportedRuntime version = " v4 . " / > < supportedRuntime version = " v2 . .5 727 " / > </ startup > </ configuration >
.NET Silverlight
Ranorex is not able to access UI objects inside your Silverlight application. Solution: Please make sure that the Windowless property of your Silverlight application is set to False.
Flash/Flex Applications
After activating the Flash/Flex Plug-In for your application using the instrumentation wizard Ranorex is still not able to recognize Flash/Flex elements within your application.
279
Technology Instrumentation
Reason #1 The AllowScriptAccess parameter in the HTML code that loads a SWF file controls the ability to perform outbound URL access from within the SWF file. Solution: Set this parameter inside the PARAM or EMBED tag to always. Reason #2 Your Flash/Flex application was instrumented twice using different versions of Ranorex Flash components. Solution: Ensure that only one of the recommended Flash/Flex Testing approaches for Flash/Flex is used.
Technology Instrumentation
refer to the Mozilla Firefox for more information. Google Chrome: UI element identification capabilities for Google Chrome are limited. Solution:Please make sure that you have installed and activated the Ranorex Extension in your Goggle browser. Please refer to the Google Chrome for more information. Apple Safari: UI element identification capabilities for Apple Safari are limited. Solution: Please make sure that you have installed and activated the Ranorex Extension in your Apple browser. Please refer to the Apple Safari for more information.
Technology Instrumentation
Solution #1: Start the test suite using the TestSuiteRunner. Solution #2: Use the Ranorex UiaLauncher (<Ranorex Installation Folder>\bin\Ranorex.UiaLauncher32.exe) to start the test executable by passing the executable name as the first argument. E.g. Ranorex.UiaLauncher32.exe <Solution Folder>\bin\debug\<Project Executable>.exe . Solution #3: Add the following lines of code to the Program.cs/Program.vb of the main (executable) project: C#
if ( Ranorex . Core . Util . IsRestartRequiredForWinAppAccess ) return Ranorex . Core . Util . RestartWithUiAccess () ;
VB.NET
If Ranorex . Core . Util . IsRestartRequiredForWinAppAccess Then Return Ranorex . Core . Util . RestartWithUiAccess () End If
Other Software
Running some antivirus or security software might lead to a limited object recognition with Ranorex tools. Reason #1: The antivirus or security software blocks certain Ranorex functionality. Solution: Add an exception for the appropriate Ranorex process or temporarily switch off the specific security application.
282
RanoreXPath
RanoreXPath
A RanoreXPath expression is primarily used to uniquely identify UI elements within a desktop or web application. Generally, a RanoreXPath expression consists of:
Adapters Attributes and Values
Figure 367: Main components of a RanoreXPath expression The adapter type specifies the type or classification of a UI element to search for (button, form, text field, listbox, etc.). Looking at the first part of the RanoreXPath expression /form[@title=Form 1] the
/form string specifies a search for a UI element of adapter type form. A Ranorex.Form adapter represents top-level windows such as dialogs or messageboxes on the Windows desktop system. The attribute value comparison [@title=Form 1] specifies the UI element in detail.
As an example the first part of the RanoreXPath expression shown in the pictures will look for a UI element which is of type form and has an attribute called title with the value Form 1. This form holds a container witch caption Container 1, which holds a button with text Button 1.
Figure 368: Hierarchical structure of a RanoreXPath Use the Tracking UI Elements tool to get the RanoreXPath for a particular UI object. To edit a RanoreXPath use the text box in Ranorex Spy or change the path value of a repository item directly in the repository view. A more comfortable way to edit RanoreXPath is provided by the The Path Editor.
283
RanoreXPath
Note: Use the <CTRL> key in combination with the arrow keys to navigate to the previous or the next token in RanoreXPath. Use the <CTRL> key and the <SHIFT> key in combination with the arrow keys for selecting specific parts of the RanoreXPath. Use the <SHIFT> key in combination with the <UP> arrow key to select the current token of the RanoreXPath (tokens can be a values, identifiers, operators . . . ).
Axes /form/button ./button //button .//button ../button absolute path identifying all buttons that are children of a form relative path identifying all buttons that are children of the current element identifies all buttons that are descendants of the root element, i.e. all buttons in all levels of the element tree identifies all buttons that are descendants of the current element, i.e. all buttons in the subtree of the current element identifies all buttons that are descendants of the parent of the current element optional location step fitting a container adapter between form and button; identifies both, /form/container/button and /form/button optional location step fitting every adapter between form and button
/form/container?/button
/form/?/button
Attributes /form /form[@title=Calculator] /form[@title=Calculator and @instance=2] /form[@title=Calculator or @class=SciCalc] /form/button identifies a top level application identifies a top level application with the title Calculator identifies a top level application with the title Calculator and an attribute of instance with value two identifies a top level application with the title Calculator or by its class identifies a button in the application 284
RanoreXPath
identifies the second button in the application identifies the second-to-last button in the application identifies a button with a text attribute value of 7 identifies a button with a text attribute value that is not 7 identifies a button using a RanoreXPath with Regular Expressions identifies a button not matching a RanoreXPath with Regular Expressions identifies a WinForms control using cascaded attribute names. The identified control has an Items property that has a Count property which returns the value 100 identifies any element with a text attribute value of 7 optional location step fitting a container adapter between form and button; identifies both, /form/container[@caption=Container 1]/button and /form/button identifies button with any attribute containing the substring add (case-insensitive) identifies a button where the attribute text is not null identifies a progress bar with value greater than or equal 13.5 (following comparison operators are also available: >, <=, <) identifies a top level application with title attribute value set to value stored in variable $var identifies the button with index equals the value stored in the variable $var identifies an input element on a web document with unique id search (supported for web testing)
Functions /form/table/row/cell[first()=True] /form/table/row/cell[last()=True] /form/table/row/cell[index()=2] /form[x()>100 and y()>100] /form/button[cx()>10 and cy()>10] /form[width()>100 and height()>100] identifies the first cell of a row identifies the last cell of a row identifies the second cell of a row identifies a top level application with screen coordinates greater than 100 identifies a button with client coordinates (coordinates of an element relative to its parent) greater than 10 identifies a top level application with width and height greater than 100.
285
RanoreXPath
2. Select the corresponding checkbox with a relative path from the name (highlighted red)
/../../ td / input [ @type = checkbox ]
3. Get the full path to the checkbox by combining the two paths.
matches the following button elements: sample0, sample1, . . . sample9, My sample26 matches all elements starting with text value sample matches all elements ending with text value sample matches text value gray or grey matches sample 123 (use backslash to escape special characters like space) matches the regular expression case-insensitive, e.g. mytext, MYTEXT, mYTeXT, . . . 286
listitem[@text(?i:MyTeXt)]
RanoreXPath
The following are special characters that need to be escaped when used in a regular expression by prefixing them with a backslash \. E.g. when you want to match the text Sample. (with a dot at the end), the dot needs to be escaped: Sample\..
287
RanoreXPath
Character
. $
Description The dot will match any single character. For example Sample. matches Sample1, Samplex, etc. The dollar sign will match the end of the string. The expression abc$ will match the sub-string abc only if it is at the end of the string. The alternation character allows either expression on its side to match the target string. The expression gr(a|e)y can match gray or grey. The asterisk indicates that the character to the left of the asterisk in the expression should match zero or more times. For example go*gle matches ggle, gogle, google, gooogle, etc. The plus is similar to asterisk but there must be at least one match of the character to the left of the + sign in the expression. For example go+gle matches gogle, google, gooogle, etc. The question mark (?) matches the character to its left 0 or 1 times. For example, colou?r matches both color and colour. Beginning of the string. The expression A will match an A only at the beginning of the string. The parenthesis affects the order of pattern evaluation. Brackets enclosing a set of characters indicate that any of the enclosed characters may match the target character. The caret immediately following the left-bracket has a different meaning. It is used to exclude the remaining characters within brackets from matching the target string. The expression [0-9] indicates that the target character must not be a digit.
? () []
[ -9]
For additional information on regular expressions please consult the corresponding MSDN web site: http://msdn. microsoft.com/en-us/library/az24scfc.aspx
288
Ranorex UI Adapter
Ranorex UI Adapter
When tracking single UI elements with Lesson 9: Ranorex Spy, Ranorex tries to specify the role and technology of the element. Ranorex recognizes over 30 of the most commonly used types of UI elements. In Ranorex vocabulary these types are called adapters. Every single element shown within the element tree of Lesson 9: Ranorex Spy can be accessed using the Ranorex UI adapters that the element supports. If Ranorex is not able to assign a more specific type of adapter to a UI element, it will be displayed as Unknown. Ranorex adapters provide more convenience when creating automated tests. Here is an example: A Ranorex Text adapter provides text box related properties like Text or SelectionText. In comparison to a simple Text adapter, a Ranorex TreeItem adapter provides tree item specific properties and methods like expand or collapse. Ranorex Spy shows all adapter related properties in the Overview tab.
289
Ranorex UI Adapter
Figure 371: Properties of a Ranorex TreeItem Adapter The section General in Lesson 9: Ranorex Spy shows the general properties which are available for any type of UI element. All the other information within the Overview tab is related to the type of adapter supported by the element. The following example accesses properties of a Ranorex Text adapter:
C#
// Create Text adapter from RanoreXPath Text textBox = " / form [ @controlname = TestedApp ]/ text [ @controlname = label3 ] " ; // Set text value of text box textBox . TextValue = " 12 " ; // Check on of the General properties if ( textBox . Enabled ) Report . Info ( " Text is enabled " ) ;
VB.NET
Create Text adapter from RanoreXPath Dim textBox As Text = " / form [ @controlname = TestedApp ]/ text [ @controlname = label3 ] " Set text value of text box textBox . TextValue = " 12 " Check on of the General properties If textBox . Enabled Then Report . Info ( " Text is enabled " ) End If
C#
290
Ranorex UI Adapter
// Create TreeItem adapter from RanoreXPath TreeItem treeItem = " / form [ @title = TreeView Test ]/?/?/?/ treeitem [ @text = TreeItem ] " ; // Collapse and expand tree item if ( treeItem . Expanded ) treeItem . Collapse () ; else treeItem . Expand () ;
VB.NET
Create TreeItem adapter from RanoreXPath Dim treeItem As TreeItem = " / form [ @title = TreeView Test ]/?/?/?/ treeitem [ @text = TreeItem ] " Collapse and expand tree item If treeItem . Expanded Then treeItem . Collapse () Else treeItem . Expand () End If
291
Ranorex UI Adapter
Figure 372: Button of calculator application which provides a Ranorex Button and a Ranorex NativeWindow Adapter
292
Ranorex UI Adapter
Figure 373: Button of a .NET WinForms application which provides an additional Ranorex Control adapter
293
Ranorex UI Adapter
The Control adapter, which is available for .NET WinForms applications, allows Ranorex to access more properties in the application under test, like the background color or font size of the displayed text. Simply convert a standard Button adapter to a WinForms Control adapter as follows:
C#
// Create Button adapter with RanoreXPath Ranorex . Button button = " / form [ @controlname = TestedApp ] / button [ @controlname = button1 ] " ; // Convert Button adapter to Control adapter Ranorex . Control winFormsButton = new Ranorex . Control ( button ) ; // Call GetPropertyValue method provided by the Control adapter Color color = winFormsButton . GetPropertyValue < Color >( " BackColor " ) ;
VB.NET
Create Button adapter with RanoreXPath Dim button As Ranorex . Button = " / form [ @controlname = TestedApp ] / button [ @controlname = button1 ] " Convert Button adapter to Control adapter Dim winFormsButton As New Ranorex . Control ( button ) Call GetPropertyValue method provided by the Control adapter Dim color As Color = winFormsButton . GetPropertyValue ( Of Color ) ( " BackColor " )
It is not required to work with Ranorex adapters. Its also possible to write automation code using Ranorex Element instances (which are used internally by Ranorex adapters) - its just more difficult.
Note: UI objects managed within Ranorex repositories always use Ranorex adapters.
294
Android Testing
Android Testing
Learn how to automate your Android app testing for different devices and languages. The following sections will explain how to set up an environment for Android testing, how to generate and execute a test and what to do if any problems occur. The Android app KeePassDroid is taken as an example how to automate mobile applications using Ranorex.
Infrastructure Getting Started Record your Android test Run your test on any Android device
Infrastructure
Before getting started with Android test automation, its necessary to make sure that the system under test (the mobile devices) and the machine running the tests (where Ranorex is installed) are in the same network.
Figure 374: Automated Android app testing over Wi-Fi As the recording and executing of tests is processed via the network, there is no need for an USB connection between the system under test and the machine running the test. But it is recommended to have your system under test plugged into a power supply during test recording and execution.
Note: To automate on a device connected via USB instead of Wi-Fi, have a look at Add a device connected via USB.
Getting Started
This quick start guide will show you how easy it is to record your Android test and execute the test on different devices and Android languages. 295
Android Testing
Start your first recording by pressing the record button in Ranorex Recorder. Next to starting a Global Recording, Run an Application or Open a Browser it is also possible to start a Mobile Recording.
Add Device
Open the Manage Device dialog by pressing the Devices button from the Record Settings dialog. If no devices have been added yet, the Add new Device dialog will be shown. Choose Android and follow the instructions to install the Ranorex service on your Android device.
296
Android Testing
Figure 377: Install Service App By using the QR code with a bar code reader app or by entering the URL mentioned in the description, the Ranorex Service app can be downloaded and installed on the mobile device.
297
Android Testing
298
Android Testing
Note: If you have more than one user account activated on your Android device, make sure hat the Ranorex Service app is only installed and running on the owners user account.
Note: If you do not have an internet connection on your device, download the Service app from the Add New Device dialog, connect your device via USB and copy the apk file to the SD card of the device. Open the copied apk file using a file explorer to install it (Make sure to allow installation of non-Market apps by enabling Settings -> Security -> Device Administration -> Unknown Sources).
Note: Another possible way to install the service apk is to download the Service app from the Add New Device dialog, open the command line and switch to the Ranorex Android Tools directory (<Ranorex Installation Folder>\bin\RxEnv\Android\tools). Type adb devices to connect your device followed by typing adb install <Download Folder>/<Name of App>.apk to install the app. After performing these steps, start the installed service app on your device.
After downloading and installing, the Ranorex Service app will be started on the device which can now be added to the list of devices by choosing Network as device connection, selecting your discovered device and clicking on the Add button.
299
Android Testing
Figure 381: Add Android device If you would like to add an USB connected device, an emulator or if you have problems with a device, have a look at the Manage Devices and the Troubleshooting section.
300
Android Testing
Note: The Instrumentation Wizard can be started from command line. For further details have a look at the section Running Instrumentation Wizard from the Command Line.
Note: Make sure to have JRE 1.6 installed on your machine as this is requested by the system requirements of Android SDK.
Note: You can also instrument and deploy your APK in a recording or from code. For further details have a look the chapter Types of Action Items and the API documentation of the InstrumentAndDeployAndroidApp method.
As mentioned before, the Android app KeePassDroid is taken as an example how to automate mobile applications using Ranorex. The APK file can be downloaded at http://keepassdroid.googlecode.com/files/KeePassDroid-1.9.9.apk. After choosing a device to deploy and an APK file to instrument, the process will be started by pressing the Next button.
301
Android Testing
Figure 383: Android Instrumentation Wizard After the instrumentation of the APK file, it will be automatically deployed to the selected device.
Figure 384: Successfully finished instrumenting and deploying APK To finish the instrumentation and deployment process, the installation has to be confirmed on the mobile device.
302
Android Testing
Note: If you have problems with instrumenting your APK using the instrumentation wizard or if you want to integrate the instrumentation into your build process, please have a look at the Instrumentation with Source Code section.
Figure 386: Mobile Recording with chosen device and app By pressing the Start button, the instrumented app will be automatically started on the mobile device and a notification on the desktop will inform the user, that actions will be recorded directly on the mobile device.
303
Android Testing
Figure 387: Record notification During the recording process, the action table of the Ranorex Recorder will give a good overview over the performed steps, as the table is updated live.
Note: The recommended way to add a value to a text box is to tap on the text box before typing.
Note: Its recommended to wait a short period of time before operating on list elements after scrolling the list.
Note: Its recommended to touch the text of a list element and not the empty space next to the text when operating a list element.
304
Android Testing
During recording its possible to add validations using the Validation button. By pressing the button, a dialog will open where the element which should be validated can be chosen.
Figure 389: Select element to validate After choosing an element, the Validate Element dialog will pop up. In this dialog, the attributes which should be validated can be selected.
305
Android Testing
Figure 390: Choose attribute to validate Additionally to recording actions, its also possible to add actions to the action table after the recording process. This can be done by dragging a repository item to the action table and choosing the action which should be performed from the menu.
Figure 391: Adding actions manually After recording and adding actions manually, the action table might look something like the following.
306
Android Testing
Figure 392: Action table Action #1 is a Run Mobile App action which starts the instrumented APK file on the selected device. Action # 2 is a Touch Event on a button. There are 5 different kinds of touch events recognized by Ranorex:
a normal Touch which is equivalent to a mouse click on a desktop machine, a Long Touch which typically opens a context menu and Touch Start, Touch Move and Touch End for simulating a drag gesture.
Action # 4 is a Set Value action, which is typically used for keyboard input. Action # 6 is a Wait For Not Exists action, which is useful when having for example an item indicating a loading process and the automation should go ahead when the item has disappeared. Action # 7 is a Validate action as described before. Action # 8 is a Get Value action, which can be used to write back an attribute value of a control to a variable for further processing. Action # 9 is a Report action, which is used to add information to the test report. Action # 10 is a Invoke Action which performs a scroll action on a list control to its index 0. Invoke Actions directly call the corresponding method of the selected control. Action # 11 is a Mobile Key Press action. Mobile Key Press actions simulate the physical buttons Back and Menu of the mobile device. Action # 12 is a Close Application action. Close Application actions stop the selected application on the mobile device.
Note: Make sure to add a Close Application action, when running your test on different devices, because if the app will not be closed on the devices, the app on the first identified device will be automated.
Stop Recording
After performing the test on the mobile device, the recording process can be stopped by pressing the Stop button.
307
Android Testing
Run Test
After recording and altering the action table, the test can be executed on the mobile device by pressing the Run button.
Note: Make sure to add a Close Application action, when running your test on different devices, because if the app will not be closed on the devices, the app on the first identified device will be automated.
Figure 394: Add a Close Application action to ensure that the recording will be executed on the right device After doing so, make the Device Display Name of the Run Mobile App action in your recording variable.
308
Android Testing
Figure 395: Make the Device, the test will be executed, variable After making the device variable, open the Data Source dialog of the test case holding your recording and add a new simple data table holding the names of the devices you want to run the test on.
309
Android Testing
Figure 398: And add the device names to the simple data table
310
Android Testing
After doing so, switch to the Data Binding tab and bind the data source to the variable in your recording.
Figure 399: Bind the data source to the variable Have a look at Lesson 3: Data-Driven Testing if you want to learn more about the data-driven approach of testing. Now, the test suite is prepared for running the recording on different devices. After successfully running the test, the test report should look something like the following.
311
Android Testing
Figure 401: Disable data source Add a global parameter and bind it to the variable varMobileDevice.
312
Android Testing
Figure 403: Bind variable to global parameter Have a look at Lesson 3: Data-Driven Testing for further details about global parameters and data binding. In the repository open the RanoreXPath of the mobile app folder using the path editor in Ranorex Spy.
313
Android Testing
Figure 404: Open advanced RanoreXPath editor Additional to the title add the device name to the RanoreXPath and choose the variable varMobileDevice as value.
Figure 405: Add variable device name to RanoreXPath After performing these steps you can build your test suite and execute the test case from command line using the command line arguments to set the mobile device name as described in section Running Tests without Ranorex Studio: start MobileTest.exe /pa:globalMobileDevice=Galaxy Nexus start MobileTest.exe /pa:globalMobileDevice=GTP7500
314
Android Testing
Manage Devices
Within the Manage Devices dialog, new Android devices can be added to make them automatable by Ranorex.
Add a device Add a device manually Add an emulator Add a device connected via USB Show device information
Add a device
The Manage Device dialog can be opened from the Devices pane or from the Record Settings dialog. If no devices have been added yet, the Add new Device dialog will be shown. Choose Android and follow the instructions to install the Ranorex service on your Android device.
315
Android Testing
Figure 407: Install Service app By using the QR code with a bar code reader app or by entering the URL mentioned in the description, the Ranorex Service app can be downloaded and installed on the mobile device.
316
Android Testing
317
Android Testing
After downloading and installing, the Ranorex Service app will be started on the device which can now be added to the list of devices by choosing Network as device connection, selecting your discovered device and clicking on the Add button.
318
Android Testing
319
Android Testing
Figure 414: New added device Devices can be disabled by pressing the Disable button. By disabling devices, they will not be available in devices pane and Record Settings dialog until they are enabled again. The name, IP address and port of a device can be changed by pressing the Edit button. By pressing the Remove button, the selected device will be removed for the list of devices. Pressing the Reconnect/Retry button will try to connect to the device over the network.
Add an emulator
To add an emulator, choose Emulator as device type/connection, select the emulator from the list of discovered devices and set a more readable name.
320
Android Testing
321
Android Testing
322
Android Testing
323
Android Testing
324
Android Testing
Troubleshooting
If you have connection problems try to consider following potential sources of error:
Make sure that the system under test (the mobile devices) and the machine running the tests (where Ranorex is installed) are in the same network. After changing Wi-Fi settings on the device, make sure to restart the device. Try to increase the Discovery Timeout at the Mobile section in the Plugins tab of general settings. Try to find out more about the connection problem by moving your mouse over the device in Manage Devices dialog.
325
Android Testing
326
Android Testing
3. Add permissions to your manifest file (if not already in place): XML
< uses - permission android:name = " android . permission . INTERNET " / > < uses - permission android:name = " android . permission . INJECT_EVENTS " / >
4. Add the actual Ranorex version number in the manifest so your app is found by the Ranorex service app. Alter following code: XML
< manifest xmlns:android = " http: // schemas . android . com / apk / res / android " package = " YOUR PACKAGE " android:versionCode = " YOUR CODE VERSION " android:versionName = " YOUR VERSION NAME " >
To: XML
< manifest xmlns:android = " http: // schemas . android . com / apk / res / android " package = " YOUR PACKAGE " android:versionCode = " YOUR CODE VERSION " android:versionName = " YOUR VERSION NAME ( RxInstrumented $ < RANOREX - VERSION >) " >
327
iOS Testing
iOS Testing
Learn how to automate your iOS app testing for different iPhone/iPad devices and languages. The following sections will explain how to set up an environment for iOS testing, how to generate and execute a test and what to do if any problems occur. The iPhone/iPad app MiniKeePass is taken as an example how to automate mobile applications using Ranorex (RXMiniKeePass.zip).
Infrastructure Getting Started Record your iOS Test Run your test on any iOS device Testing of mobile web sites
Next to native iOS apps, its also possible to automate mobile web testing directly on your iOS device or simulator. For more information on how to get started with mobile web testing, have a look at the section Testing of mobile web sites.
Infrastructure
Before getting started with iOS test automation, its necessary to choose the connection type fitting to your needs. The following overview helps you to find out which connection type works best for you. Record USB (debug mode) USB WiFi Replay Start/Stop App Install IPA Deploy (unattended)
Note: To make an iOS app testable with Ranorex, it is necessary to instrument the app using Xcode on a Mac for all three connection types as described later. When choosing USB Debug Mode as connection type, Xcode is also necessary once for bringing the device into debug mode. Choosing the connection type WiFi, the application under test has to be deployed via Xcode on a Mac.
Using the USB debug mode allows you to start and stop the application under test on the device. This is required when following the continuous integration approach.USB Requirements: iTunes is necessary to establish a USB connection (debug mode and non-debug mode), because iTunes installs the USB driver on the Windows machine to connect to iOS devices. Network Requirements: When choosing WiFi as connection type, it is recommended to have your system under test plugged into a power supply during test recording and execution. Additionally make sure that the system under test (the mobile devices) and the machine running the tests (where Ranorex is installed) are in the same network.
Getting Started
This quick start guide will show you how easy it is to record your iOS test and execute the test on different iOS devices. 328
iOS Testing
329
iOS Testing
330
iOS Testing
331
iOS Testing
Note: As XCode does not automatically update all necessary files, you have to rename them manually. You have to alter the target itself, the targets .plist file (in workspace as well as in Build Settings -> Packaging), the targets project name (Build Settings -> Packaging) and the schemes name (Product -> Manage Schemes).
Add the previously downloaded automation lib to your newly created target.
332
iOS Testing
333
iOS Testing
Figure 432: Choose the lib file and specify the target, the lib will be added to
334
iOS Testing
After doing so, the automation lib will be listed in the Linked Binary With Libraries list in the Build Phases pane of the test target.
335
iOS Testing
336
iOS Testing
In the Build Settings pane of the test add the switches -ObjC -all load to the option Other Linker Flags.
Figure 436: Set the switches -ObjC and -all-load After performing these steps, your project can be built using the newly created target and scheme for your iOS devices as well as simulators.
Note: If you see the debug output RxAutomationEngine init in the console pane, your app has been instrumented successfully.
Note: Because the Ranorex automation lib uses non-public APIs, make sure, that you do not submit a Ranorex instrumented app to the app store , as your app might be rejected and you might get banned from submitting apps to the app store for a period of time.
337
iOS Testing
Note: To add your device via WiFi its necessary that the application under test is started on your iOS device or simulator.
Note: To improve the object recognition of your app under test set the accessibility label attribute of your controls.
Debug Mode: In order to enable starting and stopping of the application under test on the device, it is necessary to establish a debug session. This can be accomplished by simply deploying any app to the device in debug scheme from Xcode. As long as the device is not restarted, the debug session will remain alive.
Note: Only one debugger can be attached at the same time. If you have problems with the debugger session, please try to close all opened apps. If closing all apps does not help, restart the device and establish a debug session again, as described above.
Figure 438: Deploy from Xcode to start debug session In order to deploy the application under test from a Windows machine its required to use a USB connection. The app has to be built on a Mac and archived as iOS App Store Package (IPA) file. Have a look at the section Create an iOS App Store Package to learn how such an IPA file can be created.
Note: When using WiFi as connection type, make sure that your iOS device or simulator is reachable over Wi-Fi. Also make sure, that the application under test is started, active and visible on the device or simulator if you do not start the app from a recording (USB debug mode).
338
iOS Testing
Figure 439: WRONG: The app might be started, but is not active
339
iOS Testing
340
iOS Testing
Start your first recording by pressing the record button in Ranorex Recorder. Other than starting a Global Recording, Run an Application or Open a Browser, it is also possible to start a Mobile Recording. Open the Manage Device dialog by pressing the Devices button from the Record Settings dialog.
Figure 441: Open Devices dialog Choose iOS (iPhone, iPad) and start your instrumented app on your device.
341
iOS Testing
Figure 443: Choose connection type When choosing USB as connection type, the connected device should be discovered automatically. Choose the device from the list to finish the process.
Figure 444: Add new device If the device cannot be found automatically click the The device isnt listed button. Enter a name of the device and choose the corresponding device serial.
342
iOS Testing
Figure 445: Add device manually When choosing WiFi as connection type, make sure that the app is started and active on the device. The device should be visible in the list of devices. Choose the device to add it to your list of devices. If the device cannot be found automatically click the The device isnt listed button. Enter a name and IP address of the device and click Finish to add the device manually.
343
iOS Testing
344
iOS Testing
345
iOS Testing
Figure 451: Mobile Recording with chosen device and app By pressing the Start button a notification on the desktop will inform you, that actions will be recorded directly on the mobile device.
346
iOS Testing
Figure 452: Record notification During the recording process, the action table of the Ranorex Recorder will give a good overview over the performed steps, as the table is updated live.
Figure 453: Action table updates during recording process During recording it is possible to add validations using the Validation button. By pressing this button, a dialog will open where the element which should be validated can be chosen.
347
iOS Testing
Figure 454: Select element to validate After choosing an element, the Validate Element dialog will pop up. In this dialog, the attributes which should be validated can be selected.
348
iOS Testing
Figure 455: Choose attribute to validate To automatically start and stop an iOS app, a USB debug session is necessary. To not make your test fail when not running in USB debug mode its recommended to make the Run Mobile App action optional by enabling continue on fail in context menu.
349
iOS Testing
350
iOS Testing
In addition to recording actions directly, it is also possible to add actions to the action table at a later time. This can be done by dragging a repository item to the action table and choosing the action which should be performed from the menu.
Figure 458: Adding actions manually If your device is connected via USB you can additionally add a Deploy iOS App action to automatically deploy the current version of your application under test for each test run. Choose the device, the file location of the app archive and the app id to enable automated deployment.
Figure 459: Add Deploy iOS App action After recording and adding actions manually, the action table might look something like the following.
351
iOS Testing
Figure 460: Action Table Action #1 is a Deploy iOS App action which deploys the given app to the selected device. Action #2 is a Run Mobile App action which resets the instrumented app on the selected device. Action #3 is a Touch Event on a button. There are 2 different kinds of touch events recognized by Ranorex:
a normal Touch which is equivalent to a mouse click on a desktop machine, and a Long Touch which can be compared to a right click.
Action #4 is a Set Value action, which is typically used for keyboard input. Action #5 is a Mobile Key Press action. With a Mobile Key Press action you can simulate the Enter button on your devices keyboard. Action #6 is a Wait For Not Exists action, which is useful for cases where an item indicates a loading process and the automation should continue after the item has disappeared. Action #7 is a Validate action as described before. Action #8 is a Get Value action, which can be used to write back an attribute value of a control to a variable for further processing. Action #9 is a Report action, which is used to add information to the test report. Action #10 is an Invoke Action which performs a scroll action on a table control to its index 0. Invoke Actions directly call the corresponding method of the selected adapter. Action #12 is a Close Application action. Close Application actions stop the selected application on the mobile device.
Stop Recording
After performing the test on the mobile device, the recording process can be stopped by pressing the Stop button.
352
iOS Testing
Run Test
After recording and altering the action table, the test can be executed on the mobile device by pressing the Run button.
Figure 462: Make the device name value variable After making the device name value variable, open the Data Source dialog of the test case holding your recording and add a new simple data table containing the names of the devices you want to run the test on.
353
iOS Testing
Figure 464: Add the device names to the simple data table
354
iOS Testing
After doing so, switch to the Data Binding tab and bind the data source to the variable in your recording.
Figure 465: Bind the data source to the variable Have a look at Lesson 3: Data-Driven Testing if you want to learn more about the data-driven approach of testing.The test suite is now prepared for running the recording on different devices. After successfully running the test, the test report should look like the following figure.
355
iOS Testing
Note: If you want to run one test on multiple devices at the same time, have a look at the section Run Tests in parallel.
356
iOS Testing
Figure 467: Build and deploy the project to your iOS device or simulator After performing the mentioned steps its possible to access the RXBrowser app as any other instrumented native iOS app. Continue by following the instructions in the Add your iOS device section.
Note: To add your device via WiFi, its necessary that the RXBrowser app is started on your iOS device or simulator.
357
Web Testing
Web Testing
The Ranorex Web Plugins (for Microsoft Internet Explorer, Mozilla Firefox, Google Chrome and Apple Safari) allow you to test the UI of web applications in the same way you would automate standard desktop applications.
Architecture of Websites in the Ranorex Framework Handling of AJAX Find or filter Web Elements List elements of a table and set css style Cross-Browser Testing Set inputs, tag attributes and perform a click without mouse Recordings & Repositories Execute javascript code Handling of layer menus
Figure 469: RanoreXPath example The web document and its HTML structure can be identified using RanoreXPath. Similar to XPath in HTML, the RanoreXPath provides a simple search mechanism for finding single or multiple web elements within a web page. 358
Web Testing
WebDocument Adapter
The WebDocument Adapter creates a representation of the complete web-site including all tags (e.g. the header tag, body tag, etc.). Furthermore it offers useful ways to make your test scripts more effective. The following sample shows how to use these features:
C#
// Identify a web document by its title WebDocument webDocument = " / dom [ @caption = Ranorex Test Page ] " ; // Open a website webDocument . Navigate ( " http :// www . ranorex . com " ) ; // Wait until the document is loaded webDocument . WaitForDocumentLoaded () ; // Execute a javascript code webDocument . ExecuteScript ( " history . back () ; " ) ;
VB.NET
Identify a web document by its title Dim webDocument As WebDocument = " / dom [ @caption = Ranorex Test Page ] " Open a website webDocument . Navigate ( " http :// www . ranorex . com " ) Wait until the document is loaded webDocument . WaitForDocumentLoaded () Execute a javascript code webDocument . ExecuteScript ( " history . back () ; " )
C#
// Start IE with a specific website System . Diagnostics . Process . Start ( " iexplore . exe " , " www . ranorex . com / web - testing - examples " ) ; // Identify the webdocument by its title WebDocument webDocument = " / dom [ @caption = Ranorex Test Page ] " ; // Find a link by its link text ( innertext ) ATag link = webDocument . FindSingle ( " .// a [ @innertext = simple link ] " ) ; link . Click () ;
VB.NET
Start IE with a specific website System . Diagnostics . Process . Start ( " iexplore . exe " , " www . ranorex . com / web - testing - examples " ) Identify the webdocument by its title Dim webDocument As WebDocument = " / dom [ @caption = Ranorex Test Page ] " Find a link by its link text ( innertext ) Dim link As ATag = webDocument . FindSingle ( " .// a [ @innertext = simple link ] " ) link . Click ()
359
Web Testing
Cross-Browser Testing
During the installation of Ranorex the setup package automatically installs add-ins for all supported browsers, which enable the communication between the Ranorex Browser Plug-In and the specific browser. If you have problems with instrumenting a specific browser use the Ranorex Instrumentation wizard as explained Instrumentation Wizard. Creating tests for Firefox does not differ to creating tests for Internet Explorer or any other supported browser. All web UI elements are specified through RanoreXPath, which uses HTML attributes and values for identification. For this reason a single web repository can be used for testing all supported types of web browsers. Learn more about how to test multiple browsers with a test case based on one single repository introduced by our web testing example project, which is part of the Ranorex setup package.
C#
// Click the OK button in popping up dialog of one of the supported browser // If the current browser is Internet Explorer if ( webDocument . BrowserName == " IE " ) { Button okIE = " / form [ @processname ( iexplore | IEXPLORE ) ]// button [ @text = OK ] " ; okIE . Click () ; } // If the current browser is Mozilla Firefox else if ( webDocument . BrowserName == " Mozilla " ) { Button okFF = " / form [ @processname = firefox ]// button [ @text = OK ] " ; okFF . Click () ; } // If the current browser is Google Chrome else if ( webDocument . BrowserName == " Chrome " ) { Button okChrome = " / form [ @processname = chrome ]// button [ @text = OK ] " ; okChrome . Click () ; } // If the current browser is Apple Safari else if ( webDocument . BrowserName == " Safari " ) { Button okSafari = " / form [ @processname = Safari ]// button [ @text = OK ] " ; okSafari . Click () ; }
VB.NET
Click the OK button in popping up dialog of one of the supported browser If the current browser is Internet Explorer If webDocument . BrowserName = " IE " Then Dim okIE As Button = " / form [ @processname ( iexplore | IEXPLORE ) ]// button [ @text = OK ] " okIE . Click () If the current browser is Mozilla Firefox ElseIf webDocument . BrowserName = " Mozilla " Then Dim okFF As Button = " / form [ @processname = firefox ]// button [ @text = OK ] " okFF . Click () End If
360
Web Testing
If the current browser is Google Chrome ElseIf webDocument . BrowserName = " Chrome " Then Dim okChrome As Button = " / form [ @processname = chrome ]// button [ @text = OK ] " okChrome . Click () End If If the current browser is Apple Safari ElseIf webDocument . BrowserName = " Safari " Then Dim okSafari As Button = " / form [ @processname = Safari ]// button [ @text = OK ] " okSafari . Click () End If
361
Web Testing
C#
// Load repository ProjectRepository repo = ProjectRepository . Instance ; // Open a website repo . WebPage . Self . Navigate ( " http :// www . ranorex . com " ) ; // Wait until the document is loaded repo . WebPage . Self . WaitForDocumentLoaded () ;
VB.NET
Load repository Dim repo As ProjectRepository = ProjectRepository . Instance Open a website repo . WebPage . Self . Navigate ( " http :// www . ranorex . com " ) Wait until the document is loaded repo . WebPage . Self . WaitForDocumentLoaded ()
362
Web Testing
Samples
The following web testing examples show how to access typical web elements of a web page.
Handling of AJAX List elements of a table and set css style Set inputs, tag attributes and perform a click without mouse Execute javascript code Handling of layer menus
The Ranorex web site provides a small page especially for web testing purposes: http://www.ranorex.com/web-testing-examples/ All examples are available in the Web Test Sample Ranorex Studio and Visual Studio project located within your installation folder (..\Samples\WebTestSample)
Handling of AJAX
C#
GlobalRepository repo = GlobalRepository . Instance ; WebDocument webDocument = repo . WebPage . Self ; // Fill out the AJAX form InputTag input1 = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = value1 ] " ) ; input1 . EnsureVisible () ; input1 . Value = " Size " ; InputTag input2 = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = value2 ] " ) ;
363
Web Testing
input2 . Value = " Weight " ; InputTag checkbox = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = checkbox2 ] " ) ; checkbox . Checked = " true " ; SelectTag selectColor = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // select [ @name = color2 ] " ) ; selectColor . TagValue = " blue " ; // Submit data InputTag submit = webDocument . FindSingle ( " .// form [ @id = ajax - form ]// input [ @id = submit - ajax ] " ) ; submit . Click () ; // Wait for the ajax request for max 1 seconds (1 milliseconds ) PreTag result = webDocument . FindSingle ( " .// div [ @id = ajax_response ]/ div / pre " , 1 );
VB.NET
Dim repo As GlobalRepository = GlobalRepository . Instance Dim webDocument As WebDocument = repo . WebPage . Self Fill out the AJAX form Dim input1 As InputTag = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = value1 ] " ) input1 . EnsureVisible () input1 . Value = " Size " Dim input2 As InputTag = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = value2 ] " ) input2 . Value = " Weight " Dim checkbox As InputTag = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // input [ @name = checkbox2 ] " ) checkbox . Checked = " true " Dim selectColor As SelectTag = webDocument . FindSingle ( " .// form [ @id = ajax - form ]/ fieldset // select [ @name = color2 ] " ) selectColor . TagValue = " blue " Submit data Dim submit As InputTag = webDocument . FindSingle ( " .// form [ @id = ajax - form ]// input [ @id = submit - ajax ] " ) submit . Click () Wait for the ajax request for max 1 seconds (1 milliseconds ) Dim result As PreTag = webDocument . FindSingle ( " .// div [ @id = ajax_response ]/ div / pre " , 1 )
364
Web Testing
VB.NET
Dim repo As GlobalRepository = GlobalRepository . Instance Dim webDocument As WebDocument = repo . WebPage . Self List all elements of a table For Each row As TrTag In repo . WebPage . DivTagContent . TableTagSimpletable . Find ( " ./ tbody / tr " ) Dim rowInfo As String = " " Dim rowNameCell As TdTag = row . FindSingle ( " ./ td [2] " ) rowInfo += " Row index : " & rowNameCell . PreviousSibling . InnerText & " , " rowInfo += " Row name : " & rowNameCell . InnerText & " , " rowInfo += " Row value : " & rowNameCell . NextSibling . InnerText & " , " Get all cells from the row rowInfo += " All Cells : " For Each cell As TdTag In row . Find ( " ./ td " ) rowInfo += cell . InnerText & " , " Move the mouse to each cell element cell . MoveTo () Set css style cell . SetStyle ( " background - color " , " #33 ff " ) Next Report . Info ( rowInfo ) Next
VB.NET
Use mouse and keyboard to set Name repo . WebPage . TestForm . InputTagTestname . Click () Keyboard . Press ( " Test Name " ) Set email address directly via Value repo . WebPage . TestForm . InputTagTestemail . Value = " test@ranorex . com " Open calendar form repo . WebPage . TestForm . ButtonTagCalendar . Click () Select the 22 th of the current month repo . WebPage . TdTag_22nd . Click () Select each item of list box For Each [ option ] As OptionTag In repo . WebPage . TestForm . SelectTagTestmultiple . Find ( " .// option " ) [ option ]( " selected " ) = " selected " Next Perform a click without moving the mouse to the button repo . WebPage . TestForm . InputTagSubmit . PerformClick ()
365
Web Testing
VB.NET
webDocument . ExecuteScript ( " history . back () ; " )
VB.NET
Dim webDocument As WebDocument = " / dom [ @caption = Ranorex Test Page ] " Dim topMenuDiv As DivTag = webDocument . FindSingle ( " .// div [ @id = top - menu ] " ) Bring the main menu to the front topMenuDiv . EnsureVisible () Automating a dropdown menu For Each item As LiTag In topMenuDiv . Find ( " .// li [ @visible = true ] " ) Mouse . MoveTo ( item ) Move the mouse to each submenu item For Each subitem As LiTag In item . Find ( " .// li [ @visible = true ] " ) Mouse . MoveTo ( subitem ) Next Next
366
Source Control
Source Control
Ranorex Studio comes with the integration of the two source control systems Subversion and Team Foundation Server. Have a look at the SVN Book to get more information about Subversion.
Note: Open the Ranorex Options (Tools->Options) to change Subversion settings. With Ranorex 4.0 the setting Automatically add new files is checked by default (which was unchecked by default before).
Figure 472: Subversion settings For further details about Team Foundation Server have a look at the related MSDN site.
Note: The MSSCCI interface supports single byte character sets (SBCS) only. Here you can find a description on how to change the code page. This means there is no MBCS support.
Note: To work with Team Foundation Server as source control system either a Microsoft Visual Studio or a Team Explorer for Microsoft Visual Studio installation is required.
367
Source Control
Figure 473: Add a new project to source control Or by right-clicking an existing solution and choosing Source Control -> Add Solution to Source Control in context menu.
368
Source Control
Figure 474: Add an existing project to source control With adding the solution to source control, the Source Control Wizard will be started and you are prompted to choose a source control tool.
369
Source Control
Note: If the chosen tool is not installed on your machine, follow the link to download the installation package and install the tool.
370
Source Control
SVN
Enter the URL of the repository.
Figure 479: Authentication dialog Choose the folder you want to add your solution to.
371
Source Control
Figure 480: Choose folder Check the files you want to have under source control and uncheck the files you dont want to have under source control respectively.
372
Source Control
Figure 481: Add specific files to source control The chosen files will be added to source control.
Figure 482: Add finished Now, the changes have to be committed to the SVN server.
373
Source Control
374
Source Control
After performing these steps, your solution is under source control and your local copy is up to date.
Figure 485: Solution under source control Icon overlays Normal Conflicted Modified Added Not locally modified, no changes waiting for commit. Indicates a conflict. Modified, changes are waiting to be committed. Marked for addition, waiting to be committed.
TFS
Select your Team Foundation Server.
Figure 486: Connect to a TFS Choose the folder you want to add your solution to.
375
Source Control
Figure 487: Choose folder Select the files you want to have under source control and deselect the files you dont want to have under source control respectively and perform a check in.
376
Source Control
Figure 488: Add specific files to source control After performing these steps, your solution is under source control.
377
Source Control
Icon overlays Checked In Checked out Checked out Modified Added File under source control, not checked out for editing. File under source control, checked out, not dirty. File under source control, checked out, dirty. File added to project, not checked in.
Figure 490: Check out existing solution The Source Control Wizard will be started and you are prompted to choose a source control tool.
SVN
Enter the URL of your repository and specify the checkout directory.
378
Source Control
Figure 492: Check out solution The chosen project will be checked out.
TFS
Specify the local check out directory.
379
Source Control
Figure 494: Select local project path Select your Team Foundation Server.
Figure 495: Connect to a TFS Choose the folder you want to check out from server.
380
Source Control
Figure 496: Choose folder The chosen solution will be checked out.
381
Source Control
382
Source Control
383
Source Control
384
385
Create
The chapter Recording a Test already explains how to create a new Ranorex Solution. Within a Ranorex Solution different kinds of projects can be created.
A project holding a Ranorex Test Suite which may contain recordings and code modules. This might be your first choice when starting with Ranorex Studio A project holding recordings and code modules which can be shared and reused A project for creating classes which are used in other applications A project that creates a command line application A project that creates an application with a windows interface
Ranorex Test Suite Module Library Ranorex Class Library Ranorex Console Application Ranorex Windows Application
After choosing a project type and a name for the project, a project will be created in the solution and Ranorex Studio is ready for you to start developing.
386
387
Build
After creating your application, it can be built using the Build menu.
Figure 505: Build Menu Within this menu, either the whole solution, or a specific project in the solution can be built, rebuilt or cleaned. Build messages will be shown in the Output window.
Figure 506: Output window Build Errors and Warnings will be displayed in the Errors window.
Figure 507: Errors window Project specific settings can be defined in the Project Options dialog, which can be accessed from the Project menu.
388
Figure 508: Opening Project Options menu item To name some of these settings, you can set the name or the type of the generated assembly in the Application tab, for example.
Figure 509: Project Options Application tab You can also set the target CPU and framework or the output path in the Compiling tab.
389
390
Run
After building the project successfully, it can be executed from the Debug menu either with or without debugger.
391
392
Figure 513: Adding new item through Project Explorer context menu
393
After adding a Form its possible to use a forms designer which allows to visually design the UI as described explicitly in the article Visually Designing Forms posted at SharpDevelop Community Blog.
394
Solution Explorer
Besides adding new items to the project, the Solution Explorer allows to perform some other assistant options to edit your solution. For example adding folders to organize projects by separating recording modules from user code modules.
Figure 515: Add new folder to a project in solution browser Additionally you are able to delete unused files. This feature is useful especially to delete outdated log files. Alternatively, unused files can be excluded from the project without deleting them from the solution.
395
Figure 516: Delete file from project Its also possible to redefine the Start Up Project of a solution.
396
397
Debugging
Ranorex provides the possibility to debug code directly in the development environment. To make the Debugger stop at a specific position in your code, you can set breakpoints. Breakpoints can either be set
by clicking on the left margin at the line you want to set it, or
Figure 519: Toggle breakpoint By setting a breakpoint, a red circle will be added at the margin and the line of code will be highlighted red. The breakpoint can be removed in the same way as it has been added. After setting a breakpoint the debugger can be started by executing your application as described in the chapter Run.
Note: To run an application with debugger, its necessary to not choose Run without Debugger from menu.
398
The application will start and Ranorex Studio will switch to the Debug Layout which causes the following menu items to be available from Debugger menu and toolbar: Continue Debugging Stop Process Step Over Step Into Step Out Continues execution Forces the process to stop Executes the statement on the current line but it will not step into Executes the statement on the current line and stops at the first line of code inside the method Finishes executing the current method and returns to its parent method
399
Figure 521: Debugging toolbar items To skip several lines of code and continue debugging on a specific line, the context menu item Set Current Statement can be chosen by right-clicking on the line and choosing Set Current Statement from the context menu.
Figure 522: Context menu Set Current Statement In paused mode, the actual state of the individual objects can be diagnosed. The following windows can be activated in the sub-menu Debug which is part of the View menu.
400
Shows method calls currently on stack. Shows variables defined in the function currently being executed, arguments passed into the current function and fields and properties of the class where the function is defined. Shows all expressions added to the watch list. Expressions can be added by right-clicking on the window, choosing Add from context menu and entering the expression. Expressions can also be added by selecting them in code and dragging them into the Watch window.
Watch
Additionally to the different views its also possible to diagnose individual objects directly in code using the tool tips popping up when moving the mouse over them.
401
Note: If Visual Studio 2010 is installed on the machine running Ranorex Studio, debugging might be slow. To overcome this issue it is recommended to search the key LowLevelHooksTimeout in the registry and delete all occurrences.
402
Code Completion
Ranorex supports code completion as you type.
Figure 525: Code Completion in Ranorex Further details about how this works can be found in the article Code Completion posted at SharpDevelop Community Blog .
403
Code Conversion
With Ranorex Studio it is possible to convert a single code file as well as whole projects from C# to VB.NET and vice versa. This can be performed by right-clicking on the specific element in the Project Explorer and choosing Convert from the context menu.
404
Code Navigation
With Ranorex Studio several features for an intuitive and quick navigation in code are supported. Further details can be found in the article Code Navigation posted at SharpDevelop Community Blog .
405
Code Generation
Ranorex Studio can help you saving time with providing you auto generated code and code templates as described in the article Code Generation posted at SharpDevelop Community Blog .
406
Refactoring
Ranorex Studio supports several mechanisms to refactor code. Further details can be found in the article Refactoring posted at SharpDevelop Community Blog .
407
Note: The sample works with both Microsoft Visual Studio 2005 and 2008.
Figure 527: Create a new Console Application with Microsoft Visual Studio
408
C#
using System . Drawing ; using Ranorex ;
VB.NET
Imports System . Drawing Imports Ranorex
Mark the main thread with the attribute [STAThread] and change the return value of the Main function to int.
C#
[ STAThread ] static int Main ( string [] args )
409
VB.NET
< STAThread > _ Public Shared Function Main ( args As String () ) As Integer
Add the following code lines to the Main routine of the class Program:
C#
int error = ; try { System . Diagnostics . Process . Start ( " calc . exe " ) ; Form form = Host . Local . FindChild < Ranorex . Form >( " Calculator " ) ; form . Activate () ; Button button = form . FindSingle < Ranorex . Button >( " .// button [ @controlid = 132 ] " ) ; button . Click () ; button = form . FindSingle < Ranorex . Button >( " .// button [ @controlid = 92 ] " ) ; button . Click () ; button = form . FindSingle < Ranorex . Button >( " .// button [ @controlid = 133 ] " ) ; button . Click () ; button = form . FindSingle < Ranorex . Button >( " .// button [ @controlid = 121 ] " ) ; button . Click () ; } } catch ( RanorexException e ) { Console . WriteLine ( e . ToString () ) ; error = -1; } return error ;
VB.NET
Dim returnError As Integer = Try System . Diagnostics . Process . Start ( " calc . exe " ) Dim form As Form = Host . Local . FindChild ( Of Ranorex . Form ) ( " Calculator " ) form . Activate () Dim button As Button = form . FindSingle ( Of Ranorex . Button ) ( " .// button [ @controlid = 132 ] " ) button . Click () button = form . FindSingle ( Of Ranorex . Button ) ( " .// button [ @controlid = 92 ] " ) button . Click () button = form . FindSingle ( Of Ranorex . Button ) ( " .// button [ @controlid = 133 ] " ) button . Click () button = form . FindSingle ( Of Ranorex . Button ) ( " .// button [ @controlid = 121 ] " ) button . Click () Catch e As RanorexException Console . WriteLine ( e . ToString () ) returnError = -1 End Try Return returnError
410
System Requirements
System Requirements
Supported Operating Systems
All versions (32 and 64 bit, except those for Itanium-based systems) of the following operating systems are supported by Ranorex:
Windows XP Windows Server 2003 (R2) Windows Vista Windows Server 2008 (R2) Windows 7 Windows 8 Windows Server 2012
Software Prerequisites
The following software prerequisites are required to run all Ranorex components (Runtime, Spy, Recorder, License Server). All needed prerequisites are usually automatically installed when running the Ranorex setup:
Microsoft Windows Installer 3.1 or higher Microsoft Visual C++ 9.0 x86 Microsoft Visual C++ 9.0 x64 (required for 64 bit Windows versions only) Microsoft Visual C++ 10.0 x86 Microsoft Visual C++ 10.0 x64 (required for 64 bit Windows versions only) Microsoft .NET Framework 2.0 SP2 or higher
Additionally, for running Ranorex Studio the following prerequisites are required:
Microsoft .NET Framework 3.5 SP1 or higher
Hardware Requirements
The hardware requirements depend on the version of the .NET Framework that needs to be installed for the respective Ranorex package. Ranorex (Runtime, Spy, Recorder, License Server) requires at least the .NET Framework 2.0 to be installed, Ranorex Studio requires the .NET Framework 3.5. Consequently: The minimum system requirements for running Ranorex (Runtime, Spy, Recorder, License Server) are the same as those for the .NET Framework 2.0: http://msdn.microsoft.com/en-us/library/ms229070.aspx The minimum system requirements for running Ranorex Studio are the same as those for .NET Framework 3.5: http://msdn.microsoft.com/en-us/library/bb882520.aspx
64-bit Platforms
64-bit Platforms
Ranorex handles testing of 32/64 bit based applications on 64 bit operating systems automatically. It is possible, but recommended only for advanced users, to turn off the bit bridge feature within the Ranorex Settings dialog. If you disable the bit bridge feature (not recommended!) or your Ranorex version does not support the bit bridge (versions prior to V2.3), follow these guidelines to make 32/64 bit automation interoperable: On 64 bit versions of Windows, processes may run using 64 bit or 32 bit (also called x86) architecture. Applications that are started as 32 bit processes are marked with *32 or (32 bit) in the Windows Task Manager, all others use the 64 bit architecture.
Figure 530: Task manager showing 64 and 32 bit calculator application Ranorex can as well run as a 32 bit or 64 bit process, both versions are included in the setup. In general, one should use the Ranorex version that matches the bit architecture of the automated application. I.e. if you automate a 32 bit application, use Ranorex Spy (32bit) (formerly Ranorex Spy (x86)) and Ranorex Recorder (32bit) (formerly Ranorex Recorder (x86)), otherwise use Ranorex Spy and Ranorex Recorder (64 bit versions). When you compile your own Ranorex executables, be sure to specify the right target architecture in your project settings. In Ranorex Studio this setting is on the Compiling tab in the project properties. .NET applications are by default started as 64 bit processes on 64 bit operating systems unless the target CPU is explicitly set to the 32 bit (x86) architecture. Consequently, set the Target CPU property to Any processor for automating 64 bit applications and to 32-bit Intel-compatible processor for 32 bit applications.
412
413
C#
Keyboard . Enabled = false ;
and
C#
Mouse . Enabled = false ;
in the Program.cs file. But again be careful when using these properties because when you set both to false you cannot abort the test without an AbortKey set. So also set
C#
Keyboard . AbortKey = System . Windows . Forms . Keys . Pause ;
in Program.cs to abort the test if something unexpected (e.g. an endless loop) happens. You can also use this technique for one recording only. In this case you have to enable/disable the mouse and keyboard controls in user code directly before executing specific actions. As always, dont forget to enable controls again at the end of your recording and to set an AbortKey.
414
Figure 532: Use asynchronous dispatching of mouse and keyboard events option This should fix the shaking mouse behavior.
415
Installation Packages
Ranorex uses the Microsoft/Windows Installer (MSI) for its setup. Consequently, all standard MSI command line arguments can be used. The command line arguments work both with the self-extracting zip file (Ranorex-x.x.x.exe) and the setup.exe and Ranorex-x.x.x.x.msi files contained in the Ranorex-x.x.x.zip file. System administrators may use the Ranorex MSI package for installation. You can download the Ranorex-x.x.x.zip containing the MSI package from our homepage; the download link is the same as for the self-extracting zip file (Ranorex-x.x.x.exe). Just replace the file ending exe with zip. When installing Ranorex using the MSI package you have to make sure that all Ranorex prerequisites are installed before executing the MSI package (please see the README.txt included in the ZIP archive or the System Requirements). If you are unsure, please use the setup.exe or self-extracting zip file Ranorex-x.x.x.exe to start the installation, which will also install all required prerequisites.
Ranorex-
416
For more installation options see the help for the MsiExec program by typing (/v is needed for the *.exe files): msiexec /help or: setup /v /help or: Ranorex-x.x.x.exe /v /help
417
Licensing
Licensing
In general Ranorex provides two different types of licenses to install:
Installing a Node Locked License Installing a Floating License
The node locked license type is bound to the machines host name. After registration each license can be used perpetually on the registered machine. A floating user license can be shared between different machines, but can only be used by one machine (and user) at a time. Both license types are available for Ranorex Runtime, Professional, and Premium Edition. If you are going to transfer a license to another machine, have a look at the section Transfer Licenses. SAP support is not included in the Ranorex standard developer licenses. sales@ranorex.com for further details. Please contact our sales team at
License Registration
In order to register a Ranorex license, start the Ranorex Licensing tool, which is available in the Ranorex start menu folder.
Figure 533: License installation dialog The license installation tool is used to install both types of licenses.
418
Licensing
419
Licensing
Figure 535: Error Dialog - No internet connection available The web site address used to authenticate the license key is part of the licensing email delivered after purchasing licenses. Simply open a browser and navigate to the authentication page. Fill in your license key and the machines host name. After clicking the Authenticate button youll be able to download the license file. Load the downloaded file within the Ranorex licensing tool in order to finish the license installation process on the target machine.
420
Licensing
Note: To prevent firewalls from blocking communication between license server and client, it is required to open port 7266 for TCP and UDP access on the server.
Note: By installing a Ranorex license server its required to use a Ranorex license server installation package which is at least as actual as your Ranorex client installation.
Figure 537: License server dialog - one premium licenses in use Open the Ranorex license server configuration tool. Add the floating license keys to the text box and press Install. These licenses are now ready to use. To get more information about the clients leasing a license you can select the specific license in license server configuration tool and open the Clients tab. Using the Save Server Log button allows you to export all actions processed by the license server as CSV- or XML-file for further processing.
Note: It is recommended to have an internet connection available in order to install a new license.
421
Licensing
Figure 538: No internet connection available - license needs to be registered on a computer with internet connection If there is no internet connection available, authenticate the floating license using the license authentication web site. The web site address used to authenticate the license key is part of the licensing email delivered after purchasing licenses. Simply open a browser and navigate to the authentication page. Fill in your license key and the machines host name. After clicking the Authenticate button youll be able to download the license file. Load the downloaded file within the Ranorex licensing tool in order to finish the license installation process on the target machine.
Figure 539: Using license server for Ranorex Premium edition Press the button Detect to request a list of the currently available license servers within the local network. The license type specifies which license (Runtime, Professional, Premium) should be used on the client. By selecting Auto, the client automatically requests the appropriate license. In case of running Ranorex tests via the standalone test suite runner or from command line, only a Runtime floating license will be used. When starting Ranorex Spy tool a Professional floating license will be leased on the server. After pressing the Install button the client is assigned to
422
Licensing
the selected license type. To switch the currently installed license type, simply select another one from the list and click Install again. Every time a Ranorex test, a Ranorex tool, or Ranorex Studio is started the client sends a license request to the server. If the type of the required license is available, it will be assigned to the requesting client. By closing Ranorex Studio or finishing a test run the license will be automatically released and can then be used by other clients. For this reason a reliable network environment is required when working with floating licenses.
Note: If a floating license has not been released correctly (based on a network problem for example), it will be locked for a time-out of 5 minutes.
Transfer Licenses
In order to transfer a license from one machine to another, you have to follow the instructions below. To transfer a node-locked license, open the Ranorex License Tool and press the Transfer License button.
Figure 540: Transfer a node locked license If you are going to transfer a floating license, open the Ranorex License Server Tool, right-click the license you are going to transfer and choose Transfer License(s) from the context menu.
423
Licensing
Figure 541: Transfer a floating license Confirm the license transfer for the specific license and the specific machine.
Figure 542: Confirm the license transfer A dialog will pop up, informing you about the success of your license transfer. If the license transfer was successful, the license has been uninstalled from the machine you transferred it from and can be installed on another machine as described in Installing a Node Locked License or Installing a Floating License.
424
Licensing
Figure 543: Succeeded license transfer If the license transfer has failed, you can manually transfer your license by sending a prepared mail to our support mail box.
Note: When performing a manual license transfer, the license cannot be used until the manual license transfer has been completed.
Uninstall License
In order to uninstall a license from a machine, please either use the uninstall button in the Ranorex License Tool for node-locked licenses, or right-click the license you are going to uninstall and choose Uninstall License(s) from the context menu in the Ranorex License Server Tool for floating licenses.
425
Licensing
426
Licensing
427
FAQ
FAQ
How does Ranorex identify UI elements? Is it possible to run the same Ranorex test code on Vista and XP? Is it required to use RanoreXPath for test automation? Does Ranorex support data driven testing? What to do when items cant be found during Ranorex test execution? Is it possible to extend recordings with user specified code actions? What is the difference between Adapter and Element? Is it possible to trigger Ranorex tests from an existing test or build environment? Can I use Ranorex libraries within Visual Studio? What shall I do with unexpected dialogs and popup windows during test automation? Is it possible to test Silverlight applications with Ranorex? Is it possible to automate a webpage without moving the mouse pointer? What are the system requirements for developing and running Ranorex tests? Are there known incompatibilities with other software?
Is it possible to run the same Ranorex test code on Vista and XP?
Yes. All identification information is stored within a RanoreXPath expression and is therefore separated from the test automation code. The following RanoreXPath expression finds a button both on Windows XP and on Windows Vista: /form[@title=WordPad]/.//button[@text=&No or @text=Do&nt Save] The RanoreXPath searches for a button, whether it contains the text &No or Do&nt Save.
428
FAQ
A general description of how to create data driven test cases can be found here: Lesson 3: Data-Driven Testing
FAQ
What shall I do with unexpected dialogs and popup windows during test automation?
Ranorex recognizes and specifies whether an application still has the top level characteristic or not. In case of totally unexpected dialogs, the Ranorex.Report class provides a simple way to log screen shots of the current desktop status. Read more about how to handle popup dialogs within Ranorex test automation code in the section Handling unexpected Dialogs.
What are the system requirements for developing and running Ranorex tests?
The following link to our online documentation shows what is needed to develop or to simply run Ranorex tests. System Requirements
430