requirements-testing-examples

From Microformats Wiki
Jump to navigation Jump to search

Requirements Testing Examples

The XUnit framework approach to writing test cases is still the most common way of implementing automated tests, but there are already a number of examples of mini languages and formats for web testing:

Feed Parser Test Suite

The XML files from the Feed Parser Test Suite created by Mark Pilgrim are prefixed with a comment containing a description and expectation, decoupling the test assertions from imperative code:

<!--
Description: Atom namespace (official)
Expect:      bozo and feed['title'] == u'Example Atom'
-->

<!--
Description: entry contributor homepage
Expect:      bozo and entries[0]['contributors'][0]['url'] == u'http://example.com/'
-->

Canoo WebTest

Canoo WebTest runs test steps defined in the Ant XML format:

 <target name="login" > 
  <webtest name="normal" >
    &config;
    <steps>
      <invoke        description="get Login Page"
        url="login.jsp"   />
      <verifyTitle   description="we should see the login title" 
        text="Login Page" />
      <setInputField description="set user name" 
        name="username"
        value="scott"     />
      <setInputField description="set password" 
        name="password"
        value="tiger"     />
      <clickButton   description="Click the submit button" 
        label="let me in" />
      <verifyTitle   description="Home Page follows if login ok"
        text="Home Page"  />
    </steps>
  </webtest>
</target>

Selenium

Selenium is a Javascript based testing agent that runs a set of commands on a target website using a mini language for binding actions and assertions to page elements and DOM selections. Basic commands include:

open
click
clickAndWait
verifyTitle
verifyValue

Selenium test commands are defined using arbitrary HTML tables. This example is from the basic tests shipped with the framework, and shows how to specifiy assertions against an HTML select element:

 <table cellpadding="1" cellspacing="1" border="1">
  <tbody>
    <tr>
      <td rowspan="1" colspan="3">Test Select<br>
      </td>
    </tr>
    <tr>
      <td>open</td>
      <td>./tests/html/test_select.html</td>
      <td> </td>
    </tr>
    <tr>
      <td>select</td>
      <td>theSelect</td>
      <td>index=4</td>
    </tr>
    <tr>
      <td>verifySelected</td>
      <td>theSelect</td>
      <td>Fifth Option</td>
    </tr>
  </tbody>
 </table>

There are no specific semantic attributes used - the test tool simply extracts commands from the columns of the table.

Watir

Watir is a testing tool, written in Ruby that implements a domain specific language for driving web tests with Internet Explorer.

Example (using the browser):

 ie = IE.new
 ie.goto("http://microformats.org")
 ie.contains_text("Designed for humans first")

Example (clicking a link):

 ie.link(:text, "Microformats").click

Would click the hyperlink:

 <a href="http://microformats.org">Microformats</a>