How to automate Selenium scripts

Selenium is a test tool for web applications. Selenium tests run directly in a browser. This guide will demonstrate how to take many Selenium scripts and automate them using a single test using a Microsoft Windows workstation.

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)

Selenium Scripts

Create

  • Execute Firefox
  • Go to Tools > Selenium IDE
  • Set your Base URL, i.e. https://it.megocollector.com
  • Record your script. (Note: Details http://selenium-ide.openqa.org/)
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

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" rel="noopener">Print: Test Plugin</a></td>
   </tr>
   <tr>
      <td><a href="categories.html" target="testFrame" rel="noopener">Categories: Navigation Tests</a></td>
   </tr>
   <tr>
      <td><a href="pages.html" target="testFrame" rel="noopener">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.

Source(s)

  • http://wiki.openqa.org/display/SIDE/Automating+Selenium+IDE+tests
  • http://selenium-rc.openqa.org/selenese.html