How to automate Selenium scripts

Selenium is a test tool for web applications. Selenium tests run directly in a browser. I have put together a guide to show how to take many Selenium scripts and automate them using a single test.

Prerequisites

  • Download Firefox (i.e. Firefox Setup 2.0.0.13.exe)
  • Download Selenium IDE (Firefox plug-in) (i.e. selenium-ide-1.0-beta-1.xpi) and install by opening a Firefox window and dragging and dropping selenium-ide-1.0-beta-1.xpi onto a Firefox window.
  • Download Java Runtime Engine 1.6 (i.e. jre-6u5-windows-i586-p.exe)
  • Download Selenium Remote Control (i.e. selenium-remote-control-1.0-beta-1-dist.zip) and extract the zip file to a folder (i.e. D:\selenium-server-1.0-beta-1)

Note: This has been tested in a Windows environment; this however, is an operating system independent procedure.

Create Selenium Script(s)

selenium-02

  • Save the script with file extension .html (i.e. print.html)
  • Record several scripts, save each with the extension .html

Scripts folder

Automate Selenium Script(s)

  • Create an html file to batch the tests together (placed in the same folder) as the existing html tests. testsuite.html
    <table>
       <tr>
          <td>Test suite for the whole application</td>
       </tr>
       <tr>
          <td><a href="print.html" target="testFrame">Print: Test Plugin</a></td>
       </tr>
       <tr>
          <td><a href="categories.html" target="testFrame">Categories: Navigation Tests</a></td>
       </tr>
       <tr>
          <td><a href="pages.html" target="testFrame">Pages: Navigation Tests</a></td>
       </tr>
    </table>
    • Create a batch file to run the scripts and generate a results file, results.html
      For this example, autoRunSelenium.cmd

    java -jar "D:\selenium-server-1.0-beta-1\selenium-server.jar" -htmlSuite "*firefox" "https://it.megocollector.com" "D:\seleniumtests\testsuite.html" "D:\seleniumtests\results.html"

    Execute

    • Run autoRunSelenium.cmd from your desktop, a command windows will open and
    • a popup screen similar to this may appear.

    sshot-4

    • After the cmd window closes goto (D:\seleniumtests\results.html) for the results, done.

    Inspiration