Locators and Variables

Updated 1 month ago by Copado Solutions

Locators 

Locators are expressions that select the HTML element to which a command refers. Selenium uses them to find and match the elements of the page it needs to interact with. 

The format of a locator is:

 locatorType=argument

Using the right locator will allow you to ensure tests are faster, more reliable or have lower maintenance through the releases. For this purpose, and in addition to the standard Selenium locators (listed in the  Selenese command reference), we offer the Copado locators with the following format:

copado=type:value

Locators in Test Cases

From the Copado Selenium Testing app, click on the Test Cases tab. Select one from the list, or create a new one. To learn how to record a test case, see the article Selenium Test Cases.

When you record a test case, all the actions you perform are stored in the test case record. Locators are generated also in every recording step. As you can see in the next picture from a test case screen, they are stored in the "PARAM 1/TARGET" column. 

Here is a list of the locators that can be found depending on the type:

  • copado=field:*Project Name
  • copado=link#2:{!RUN_ID} Test Project
  • copado=button:Save
  • copado=tab:Projects
  • copado=app:Copado Change Management
  • copado=detail:Git Snapshot Name
  • copado=popup:Project

Locators are easy to edit from the Copado Selenium Recorder or just by clicking on the Edit button in the test case. In case the element is not detected by the test, select another one from the drop-down menu:

In different environments, elements may have different identifiers, so the locators' list is useful when you need to select a more specific one and ensure it works on every environment.

Locators Tab

You can access locators also from the Selenium Locators tab. From the Copado Selenium Testing app, navigate to the Selenium Locators tab. Once there, select one locator and click on Related. There you can see the test case where the locator is being used.

Locators can also be used in a test case as {!Locator.LOCATOR_ID}. This allows you to name/manage locators across multiple test cases in a central location. To assign an ID to the locator, go to the locator's Edit screen and create it.

Variables

Variables represent text strings to be replaced at the time of the execution of a test case.

We have predefined variables ready to be used:

  • {!NS} Namespace defined in the  Copado Environment record.
  • {!RUN_ID} Unique number per Test Run, useful to generate unique name values.
  • {!BLANK} If you need to execute a command with a blank value (to set a field as empty, for example), you can use this variable.
  • Date and datetime variables: {!TODAY}, {!TODAY-1} (yesterday), {!NOW},  {!NOW+1}.
  • Group variables, defined in a  Selenium Test Group{!Group.VARIABLE}.

You can also create variables for you to use, as needed, from the Copado Recorder page. To do so, follow the steps below:

  •  In the command column, you can use the store commands listed in the Selenese Command Reference to create new variables.
  • In the param 1/target column, we will assign a value to the variable.
  • In the param 2/value column, we will provide its name. Variable names must start with a letter and cannot contain blank spaces or non-alphanumeric characters except for _).

The picture below shows an example of this process:

In order to use a variable, the syntax can be any of the below:

  • {!variablename}
  • ${variablename}
  • storedVars.variablename


How did we do?