We are beginning to use the
Selenium IDE at work to do some UI based testing. One thing that I wanted to test is the sorting of columns in a table. If you are like me, I like to test with the most simple implementation that I can.
While the
assertTextPresent command is good to assert that a particular string
is present, it does not assert the location of the string. Upon doing
a little reading on the OpenQA site I found that the assertText
command, along with an xpath target provides the ability to assert a
string’s location.
The
Selenium
Core reference provided the insight. The documentation
stated that the assertText method signature is: assertText ( locator,
pattern ). The documentation goes on to explain, "Element Locators
tell Selenium which HTML element a command refers to. The format of a
locator is: locatorType = argument." Concerning the pattern input parameter, "Patterns are used for various reasons, e.g. to specify the expected value of an input field, or identify a select option.
Here is the HTML of a test page.
I want to assert that the first cell is
a1. I then want to assert that the cell below a1 is
b1. Finally, I want to assert that the cell to the right of the a1 is
a2.
I did this using the xpath locator for the first cell.
xpath=//table[1]//tr[1]/td[1]. I could have also used
xpath=//table[@id='firstTable']//tr[1]/td[1].
Here is the code of the Selenium IDE test:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>sel</title>
</head>
<body>
<table cellpadding="1"
cellspacing="1" border="1">
<thead>
<tr><td rowspan="1"
colspan="3">sel</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>file:///home/mark/html/test.html</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=//table[1]//tr[1]/td[1]</td>
<td>a1</td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=//table[1]//tr[2]/td[1]</td>
<td>b1</td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=//table[1]//tr[1]/td[2]</td>
<td>a2</td>
</tr>
</tbody></table>
</body>
</html>
When running the test, here is the result:
Finally, since I was able to pass the test with the most simple implementation, now I will
utilize the assertText assertion command to check the value of the first cell of a column before and after the sort action is called to verify that the sort worked as expected.