When you record a test script in Rapise, it uses locators to determine how to find a specific learnt object when playing back the script.

The locator for each object is specified in the saved_script_objects dictionary in the Objects.js file in your test script folder. The locator information is highlighted in the TwoDialogs generic library example below:

 "locations": [
  {
   "locator_name": "Location",
   "location": {
    "location": "4.4",
    "window_name": "param:window_text",
    "window_class": "param:window_class"
   }
  
},

 "window_text": "Inflectra Rapise Two Dialogs Sample",
 "window_class": "#32770",
 "object_text": "",
 "object_role": "ROLE_SYSTEM_WINDOW",
 "object_class": "Edit",
 "version": 0,
 "object_type": "Win32Text",
 "object_flavor": "Text",
 "object_name": "Please enter someone else's name:",
 "object_library": "Generic",

 "window_name": "Inflectra Rapise Two Dialogs Sample"

When recording an application who's window name changes or who's object name changes, you may need to adjust this locator. For example you may have different localized text in the name of the window depending on the language that the user has selected.

You have two main options for changing the locators:

  1. You can replace the static window/object name with a wildcard or regular expression. This works if all the possible combinations of window name share some common text.
  2. You can override the locators through code inside your test script. This works for situations where the regular expression / wildcard option will not work because the different combinations of window/object name do not share any comment text.

We shall discuss each in turn:

Using a Regular Expression / Wildcard

Simply open up the Objects.js file in the Rapise editor and do a global search for the hard-coded window/object name and replace it with the appropriate regular expression. In the example above we shall change the name from "Inflectra Rapise Two Dialogs Sample" to match any window that has "Two Dialogs" in it. That way it would work for "MyCompany MyProduct Two Dialogs Demo" as well. To do this we replace the text with the regular expression:

regex:.*Two Dialogs.*

(for more details please refer to Regular Expressions documentation topic)

This would change our locator code to:

"window_text": "regex:.*Two Dialogs.*",
"window_class": "#32770",
"object_text": "",
"object_role": "ROLE_SYSTEM_WINDOW",
"object_class": "Edit",
"version": 0,
"object_type": "Win32Text",
"object_flavor": "Text",
"object_name": "Please enter someone else's name:",
"object_library": "Generic",
"window_name": "regex:.*Two Dialogs.*"

Overriding the Locator through Code

You can override any of the locators in code. This process is described in more detail in Object Locators documentation topic.

However for our example, lets change the object name to something different. To do that we'd simply use the following code:

//Call the first text box using the explicit name 'Please enter your name:'
SeS('Please_enter_your_name_', {object_name:"Please enter your name:"}).DoSetText("Roger");

this allows you to specify the explicit object name when you use the variable instead of just using SeS('<object name>').

If the change affects all objects, you can use the g_locatorParams["property"] collection instead:

g_locatorParams["window_name"] = 'MyCompany Two Dialogs Demo';

We've also attached some sample code to this article as well.