Example of how to test table sorting using the JavaScript substring function

This is an example of how to:

  • Test the sorting of column data (ASC|DESC)
  • Use the javaScript substring function to trim a string variable to a desired length

In the example application, the user can sort both columns ("Fac No" and "Fac Name") ascendingly or descendingly by clicking on the column header:

Here are the two Selenium IDE scripts I used to verify that the Facility Name column was in fact sorting properly:

We simply:

  1. Store how many table rows we have
  2. Store the value of the first row Facility Name
  3. Use the JavaScript function substring to remove all of the string characters in the variable ${top} except the first. So in this case, the variable ${top} first contained the string "Aigburth Engineering Building". Then after the substring function was executed, the ${top} variable was manipulated to "A".
  4. Store the value of the last row Facility Name, using the variable ${currentTableRows} from step 1 in the storeText command to ensure we actually get the last value in the table.
  5. Use the JavaScript function substring to remove all of the string characters in the variable ${bottom} except the first. So in this case, the variable ${bottom} first contained the string "Woodmoor Elementary". Then after the substring function was executed, the ${bottom} variable was manipulated to "W".
  6. Then, just use the verifyEval command to check that ${top} < ${bottom}. This takes care of verifying the sort is ascending.
  7. To prove it works descendingly, simply click the table header link to resort descendingly, grab to top and bottom values again and substring thier data, then use the verifyEval command, but this time: ${top} > ${bottom}.

Easy! Note that the verifyEval command operators work the same way for numeric or alphabetic characters. :)