In this second part of a three-part article series on acceptance testing with Ruby on Rails, you will learn the various commands that are performed during this process, and start your first acceptance test. This article is excerpted from chapter 11 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Commands for Acceptance Testing - Element Locators (Page 3 of 4 )
Element locators tell Selenium which HTML element a command should be performed against. For example, you can tell Selenium to locate a link where the id attribute equals xyz. Some of the element locators that Selenium supports are listed in Table 11-4.
Table 11-4. Some Selenium Element Locators
Name
Description
id=element id
Finds the element with the specified id attribute
name=element name
Finds the element with the specified name attribute
identifier=element id
Finds the element that has a matching id attribute; if no match is found, finds the element whose name attribute matches the specified id
dom=JavaScript expression
Finds the element using a JavaScript DOM expression; for example, document.forms['someForm'].someButton
xpath=XPath expression
Finds the element based on an XPath expression; for example, //a[@href='http://google.com']
link=text pattern
Finds the link that matches the specified pattern
Selenium Test Formats
Selenium acceptance tests can be written in various ways. The default is HTML format. Selenium on Rails also offers the Selenese and RSelenese formats.
HTML Format
Tests using this format are written as normal HTML documents that contain a table:
Selenium parses the table and executes the commands in the order they appear.
There is one downside to using HTML tables to write acceptance tests: they are difficult to maintain and write.
Note You can write dynamic tests by using RHTML templates containing ERB code. However, like HTML, these tests are hard to maintain and write.
Selenese Format
The Selenese format is the easiest to write and maintain. Acceptance tests written using this format contain a table where columns are separated by the pipe character: