Difference between revisions of "requirements-testing-examples"

From Microformats Wiki
Jump to navigation Jump to search
(moved test language examples to separate page)
 
Line 25: Line 25:
 
<pre>
 
<pre>
 
  <target name="login" >  
 
  <target name="login" >  
   <webtest name="normal" >
+
   <webtest name="normal" ></pre>
    &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>
 
</pre>
 
 
 
=== Selenium ===
 
 
 
[http://selenium.thoughtworks.com/ 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:
 
 
 
<pre>
 
open
 
click
 
clickAndWait
 
verifyTitle
 
verifyValue
 
</pre>
 
 
 
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:
 
 
 
<pre>
 
<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>&nbsp;</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>
 
</pre>
 
 
 
There are no specific semantic attributes used - the test tool simply extracts commands from the columns of the table.
 
 
 
=== Watir ===
 
 
 
[http://wtr.rubyforge.org 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):
 
 
 
<pre>
 
ie = IE.new
 
ie.goto("http://microformats.org")
 
ie.contains_text("Designed for humans first")
 
</pre>
 
 
 
Example (clicking a link):
 
 
 
<pre>
 
ie.link(:text, "Microformats").click
 
</pre>
 
 
 
Would click the hyperlink:
 
 
 
<pre>
 
<a href="http://microformats.org">Microformats</a>
 
</pre>
 

Revision as of 01:22, 6 July 2007

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" >