Home arrow Ruby-on-Rails arrow Page 3 - Commands for Acceptance Testing
RUBY-ON-RAILS

Commands for Acceptance Testing


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).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
July 29, 2010
TABLE OF CONTENTS:
  1. · Commands for Acceptance Testing
  2. · Accessor Commands
  3. · Element Locators
  4. · The First Acceptance Test

print this article
SEARCH DEVARTICLES

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:

<table>
 
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
 
</tr>
 
<tr>
    <td>verifyTitle</td>
    <td>Home</td>
    <td></td>
  </tr>
</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:

|open|/help|
|assertTextPresent|The Forgotten Soldier| |goBack||

The only downside to the Selenese format is that the tests are static. This is why Selenium on Rails also supports the RSelenese format.

RSelenese Format

RSelenese scripts are written in Ruby and allow you to use the full power of the Ruby language, as shown in the following example:

setup :fixtures => :all
open '/'
assert_title 'Home'
(1..10).each {|i| open :controller => 'catalog', :action => 'list', :page => i }

The biggest benefit of using RSelenese is that it allows you to create dynamic tests.


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials