Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Desktop

Home Page > Knowledge Base > Rapise > Rapise Web

Article Dynamically changing object locators for WPF/Silverlight applications

by Adam S on Friday, May 24, 2013

Sometimes you will have controls in a WPF or Silverlight application which use dynamic lists.

Depending on certain settings, the widgets in the list will appear in different places.

This means that a Learned Rapise object which works fine if its in the original ListBox[0] location position is then played-back when it's displayed in another position, it will be ListBox[1] or [2].

Unlike the XPath option with web testing, Rapise doesn't currently allow regular expressions (Regex) in locators stored inside the objects.js file. This article describes a way around the problem:

The solution is to override the built-in UIAutomation locator functionality (used when testing WPF/Silverlight applications) and modify the locator on the fly. The following simple example will change the location of a checkbox in the sample application to be a different position:

function Test()
 //Specify the customized locator behavior



function overrideLocators()
 UIAutomationLocator.fromLocationDef = UIAutomationLocator.fromLocation;
 UIAutomationLocator.fromLocation=function(objLocation, objInfo)
     // Do something here if needed
  if (objInfo.location == 'tabControl1/tabItem1/checkBoxX')
   objInfo.location = 'tabControl1/tabItem1/checkBox1';
     // and/or call default locator
     return UIAutomationLocator.fromLocationDef(objLocation, objInfo);

Article Info
Last Updated: 5/24/2013
Article ID: KB50
# Views: 3180
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.