Selenium Tutorial: Test Cases And Test Suites

4. Test-Cases and Test-Suites

4.1. Selenese

  • Selenium IDE produces tests that are written in a DSL (Domain Specific Language) called Selenese.
  • Selenese tests are simple xHTML tables of 3 columns and as many rows that there are steps in your test.

    The rule for these commands is:

    • A method on the first column: the action to perform
    • A locator on the second column: the subject of the method (ie: what element is acted upon)
    • A value on the third one: the value to be passed to the method (what to type in a text field for instance)

      Table 1. Selenese test-case

      Pizza Test

      open

      / (1)

      type

      q (2)

      pizza

      click (3)

      btnG

      assertTextPresent (4)

      glob:*pizza*



      1. The subject of the command open: the root of the application here
      2. q is the locator referring to the text field in which type will write pizza
      3. click doesn’t need a second argument, we just click on an element (which locator is btnG)
      4. assertTextPresent doesn’t need a locator since it searches on the entire page: we just need what to look for

And the corresponding source below - usually you don’t have to touch it, Selenium IDE will do it for you:

Selenese test-case source. 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 1

<head profile="http://selenium-ide.openqa.org/profiles/test-case"> 2
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link rel="selenium.base" href="" />
  <title>Pizza Test</title> 3
</head>
<body>
  <table cellpadding="1" cellspacing="1" border="1"> 4
   <thead>
     <tr><td rowspan="1" colspan="3">Pizza Test</td></tr>
   </thead>
    <tbody>
      <tr> 5
        <td>open</td> 6
        <td>/</td> 7
        <td></td>
      </tr>
      <tr>
        <td>type</td>
        <td>q</td>
        <td>pizza</td> 8
      </tr>
      <tr>
        <td>click</td>
        <td>btnG</td>
        <td></td>
     </tr>
      <tr>
        <td>assertTextPresent</td>
        <td></td>
        <td>regexp:*pizza*</td>
      </tr>
    </tbody>
  </table>
  </body>
</html>

1

XML declaration, DTD and xHTML namespace

2

The profile attribute specifies this is a test-case

3

The html <title> tag corresponds to the test title

4

The test case in itself is enclosed in an HTML table

5

Each row of the table corresponds to a step in the test

6

The first cell of the row contains the command to execute, it is mandatory

7

The second cell is the target of the command (a locator). Here, open targets /, the root of the webapp

8

The third cell is the value that may be used by a command. Here, the command type is instructed to type pizza in the element located by the name q.
[Note]Note

The url of the website to be tested is not specified. It is up to the Selenium engine to run the test against a specific ‘base url’ that you provide for testing on different servers.

4.2. Test Suites

You can assemble test-cases into a test-suite

  • They are also expressed as HTML files
  • The test-suite only references test-case files as anchor elements
  • The anchors are nested inside a table of 1 column and as many rows as there are test-cases in the test-suite

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
      <title>Test Suite</title> 1
    </head>
    
    <body>
      <table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"> 2
        <tbody>
          <tr><td><b>Test Suite</b></td></tr>
          <tr><td><a href="pizza.html">pizza</a></td></tr> 3
          <tr><td><a href="selenium-search.html">selenium-search</a></td></tr>
        </tbody>
      </table>
    </body>
    </html>

    1

    The title of the test-suite is specified here

    2

    As a test-case, the test-suite is also enclosed within an HTML table

    3

    Each test of the test suite is a relative link to the test-case file

Copyright © 2020 ProTech. All Rights Reserved.

Sign In Create Account

Navigation

Social Media