Posted by gherget on Thursday, July 15th, 2010 at 1:50 pm to Best Practices

Depending on the technology of your application under test, your controls may have dynamic identifiers. You could of course adapt the path for each repository item, but you would have to do this every time a new item is added. The RxPathWeights plug-in enables you to filter out those identifiers and use an even better attribute to identify your application under test.

Ranorex 3.X comes with a RanoreXPath Weights Editor (available in the Ranorex Spy) which will help you to change/set-up rules.

Have a look at our new blog post “Automated Testing and Dynamic IDs” for further information.

Set up your RxPathWeights configuration file (Ext-JS example)

Let’s assume we would like to automate a website which is built on the Ext JS framework (a cross-browser JavaScript library).

The picture below shows the RanoreXPath of an ext-js input field on following ext-js example page.

extjs-ranorex-spy

You can see containers in the path which are identified by the id, beginning with “ext-comp-” and ending with a numeric value. These ids are dynamically generated and they may change.

We would like to set up a filter mechanism which should eliminate id attributes beginning with “ext-gen” or “ext-comp-” and ending with a numeric value.

  1. Open the Ranorex Spy and analyze you application under test
  2. Navigate to the element which has the dynamic identifier
  3. Write down the attribute name and the capability to which the attribute belongs to
    ranorex-spy-attribute-capability
  4. Download and extract the “RxPathWeights.zip” to following location (only needed for the system on which you will record your test scripts):
    “C:\Documents and Settings\All Users\Application Data\Ranorex2\Plugins” (for Windows XP) or “C:\ProgramData\Ranorex2\Plugins” (for Vista, 7)
  5. Open the “Ranorex.Plugin.RxPathWeights.config” file in a text editor program

The configuration file consists of a rule element and an underlying condition element. The rule element enables you to change the weight of an attribute. By setting the weight to zero, the element will not be used in the RanoreXPath as an identifier anymore.

The condition element enables you to specify a rule for the attribute. In our sample, we would like to filter out ids which match following regular expression syntax
“(ext-gen|ext-comp-)[0-9]*”. (Read more about regular expression syntax here…)

<rxpathweights>
 <rule capability="webelement" attribute="id" setweight="0" conditionsoperator="or">
  <condition source="self" attribute="id"
        match="(ext-gen|ext-comp-)[0-9]*" negate="false"/>
  </rule>
</rxpathweights>

Save the config file and restart the Ranorex tools to load the RxPathWeights plug-in.

RxPathWeights plug-in documentation

Role parameters:

  • capability/attribute: define the target capability/attribute of the rule
  • setweight: the weight to set if all the conditions evaluate to true
  • conditionsoperator: defines the operator (“and” / “or”) that is used to combine the outcomes of multiple conditions in a rule

Condition parameters:

  • source: can be self/parent/toplevel
  • attribute: the attribute name to match. Can be different from the rule attribute name
  • match: a regular expression. If you don’t specify the match value, the value of the attribute needs to be null to match
  • negate: the outcome of the condition is the negated outcome of the match, e.g. if negate=”true” and the match fails, the condition evaluates to true
Share

Tags: , , , ,

2 comments

  1. Ralf Gerstenberger

    What values should be used for setweight?

  2. ahoisl

    For transient values Ranorex uses a weight below 100. For all other attributes Ranorex defines a weight between 100 and 200 depending on how unique the attribute usually is.
    Consequently, you should use a weight smaller than 100 (e.g. zero) if you don’t want the attribute to be used in RanoreXPath and a weight greater than 200 for attributes that should definitely be used.

    See the API documentation for the attribute weight:
    http://www.ranorex.com/Documentation/Ranorex-2.0/html/P_Ranorex_Core_AttributeDescriptor_Weight.htm

    Regards!

Leave a Reply