Custom table mapping

On websites, tables can be constructed with a variety of HTML tags. Typically, these include tags such as <table>, <tr> for rows and <td> for columns. However, other tags such as <div> can be used to create the appearance of a table for a user. These permutations can make the testing of tables challenging.

If you attempt to test data within a table using simple locators for the individual cells, this will usually lead to brittle and high maintenance tests. The reasons for this include the following:

  • Tables can be re-sorted, resulting in the unique row of data in the table having a new locator
  • The data in the table can be unique each time you visit the web page, producing different HTML
  • Table HTML can be very repetitive, making it challenging to uniquely find an element

Defining a custom table is a one-time activity. Once completed, it can reduce a lot of future maintenance on brittle locators.

Access world-class customer support at the Provar Success Community


If you face any issues when mapping a particular table, please get in touch with us and we would be happy to help. To raise a case, simply log into the Provar Success Community and click View/Raise Case. Providing ongoing support is part of our promise to help you deliver robust, scalable and repeatable testing to achieve release agility, drive down system errors and get the maximum return on your Salesforce investment. Please contact us for more information.  

Add table mapping


To follow this example, first create a Selenium UI connection using UI Connect. The example below is taken from the HTML Tables page on w3schools.com.

To construct a custom table in Provar, start by selecting Add a Table Mapping from the Test Palette in Test Builder.

This will display a few fields which can be used to define a table.

How to complete the fields


There are two methods to complete the data to define a table. 

Option A: Choose the Start Selection button next to Table Locator. This is highlighted in red in the screenshot above.  

Option B: Inspect the HTML using right-click and Inspect in Chrome. 

Add Table Mapping Start Selection


Step 1: Launch Test builder and navigate to the table in your browser.

Step 2: Select the Start Selection option and the icon color will change to blue.

Step 3: Click on the first cell of the table and drag it to a cell on the outer limits. This does not need to be at the final row, but it should include the final column.

Step 4: If successful, you should see the cells in red. Some table XPaths cannot be worked out by Provar. You will need to inspect the HTML to fill out the fields. See the Understanding table mapping in page objects support article to help you define those types of tables.

Note: The fields for Add Table Mapping should not be populated with XPaths.

Step 5: If you are familiar with XPaths, you can now verify what Provar has derived. You may update the XPaths manually.

Step 6: Add a Table Name and click Add. Provar will now write this definition into the page object you have selected and no test step has been added. Ensure that the new page name is set to a unique name or select the existing page object if one exists already.

Add Columns to the table


It is necessary to select each column one at a time.

Step 1: Map the first column you want to reference in your test. Choose the data row, not the header row. If the table definition was successful, you will notice that the table is mentioned in Test Builder. If an incorrect page object is defaulted, select the correct existing one from the drop-down menu.

Step 2: Now we need to add the relative XPath for the column. The initial XPath presented will usually need amending so that it refers to all elements in that column. In the example below, this means removing the text from the XPath and also adding 1 to signify the first <td>.

Provar will assist using highlighting. If the column you are mapping is fully highlighted in red, then that is correct.

Before

After modifying the field locator

Step 3: Provide a Field Name and choose Add and Do. This will add a test step called With Row to the test case plus a nested test step referring to the column. You should expect to see a warning message that the XPath matches more than one element.

What does With Row do?


The With Row test step will identify which row to interact with. When you first add the step it will default to Row Number 1. You will most likely want to update this, otherwise you will always interact with the first row of the table. In order to update this you can edit the With Row test step in Test Builder or Provar Desktop.

In the image above, you’ll notice that 1 is listed in the Row Locator field. This can be replaced with a comparison statement which needs to be enclosed with curly braces {}. The comparison is typically:

{ColumnName = 'Island Trading'}

Or, if using a local variable use a dollar sign ahead of that variable.

{ColumnName = $IslandTrainingVariable}

When the With Row is executed, it will search the full table to match the criteria. Once located, it knows that all of the child test steps will only operate on that row of data. If you would like to test the comparison, update the Row Locator and choose Step Backwards to rerun the test steps.

To complete the table mapping, keep adding the columns you require.

Check out the Understanding Table Mappings support article to become familiar with the Java syntax Provar uses to persist the table definition.

Documentation library

Other available resources

Looking for something different?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.