We're here to help

Label locator strategies

In Provar version 1.9.7 and later, there is a new feature which lets the user define their own label strategy to identify web elements. This is designed to help Provar recognize a custom field labeling schema on a web page. This is useful for testing generic websites as well as custom Salesforce features such as Lightning Flow and custom Communities.

Label Locator Strategies are stored as java files. Inside the file, lists of XPaths can be defined that tell Provar how to identify the label elements on a page and how to identify the control (or input) elements on the page.

Strategy files include the following information:

  • title: from the @LabelLocatorStrategy annotation
  • priority: from the @LabelLocatorStrategy annotation, defaulting to Integer.MAX_VALUE
  • labelLocators: list of StrategyLocator for the annotations labelLocators
  • controlLocators: list of StrategyLocator for the annotations controlLocators list

 

In turn the StrategyLocator has the following information:

  • name
  • findByType: always “xpath”
  • findByValue: the XPath value (relative XPath: it should always be relative to the same node for which we are defining the label Strategy)
  • preceding: if label is preceding the control default false

 

There can be multiple strategy files each for different pages of the application. These files are kept in /src/labellocators and the compiled classes are in /bin/labellocators:

Once the strategy file is in place and we map the corresponding web page, the following information is shown in Test Builder when mapped as a Page Object:

  • Matching strategy files in Field Locator type dropdown in By Label section in following format {locatorValue} ({strategy title}), e.g. ‘Shipping Method (Lightning Flow)’
  • Locator Value
  • Label Locator name and XPath, with the name in a green bubble
  • Control Locator name and XPath, with the name in a red bubble

Also, in Chrome browser, the corresponding field label gets highlighted in green and the control locator in red, as below:

In case of multiple matching strategy files, the files will be displayed in Test Builder in order of priority:

Once we add the locator in a page object, its gets stored in the following format:

@FindByLabel(label = “Shipping Method”, controlLocator = “input2”, labelLocator = “label2”, strategy = LightningFlow.class)

Where strategy identifies the Label Locator Strategy to be used, labelLocator gives the name of the label XPath to be used and controlLocator gives the name of the control XPath to be used.

For example:

Note that, when changes are made to a strategy file, Provar’s Test Plug-ins should be restarted by clicking the ‘Stop’ icon at the top of the Test Plug-ins view and then the ‘Start’ icon. In addition, when any new strategy file is added, Provar needs to be refreshed and recompiled (from the top menu in Provar, click the ‘Tools’ dropdown and then select ‘Refresh and Recompile’).

Once you have defined a label strategy in Provar, it can be used across the project and also outside the project.