requirements-testing-examples: Difference between revisions

From Microformats Wiki
Jump to navigation Jump to search
No edit summary
m (Reverted edits by AcelmOnouc (Talk) to last version by Brian)
 
(4 intermediate revisions by 3 users not shown)
Line 25: Line 25:
<pre>
<pre>
  <target name="login" >  
  <target name="login" >  
   <webtest name="normal" ></pre>
   <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>
</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>

Latest revision as of 22:10, 20 December 2008

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>