Running IDE scripts with Selenium RC

From MozillaWiki
Jump to: navigation, search

Selenium IDE scripts may be run in Selenium RC by running them directly on the server with a -htmlSuite parameter. The Selenium RC doc is here.

These notes are based on Selenium RC 1.0.1.

Create a test suite file

RC operates on SIDE test suite files, rather than test case files.  The test suite contains the file names of the test case(s) to run.  A test suite file exists in the same directory as the test case file(s).

  1. Create an empty test suite file as follows: In SIDE select File > New Test Suite. Select Save Test Suite As and save the file with an html extension in the same directory as the test case(s).
  2. In a text editor open the test suite file and find the line <tr><td><a href="../../..">Untitled</a></td></tr>.  Copy the line for each test case the suite will run.
  3. Replace ../.. in the href with the test case file name.  The directory name can be omitted or be ./ (dot slash) since the test case and suite are in the same directory.
  4. Change the text from "Untitled" to the test case title.
  5. Above the test cases find the lines <tr><td><b>Test Suite</b></td></tr> and <title>Test Suite</title>.  Replace "Test Suite" with an appropriate test suite title.
  6. Confirm the test suite file works by running it in SIDE: File > Open Test Suite.  Run the entire test suite using the run icon with three dark green bars.

( If there's a an easier way to create the full test suite from IDE let's include it. )


Set Up Selenium RC

  1. Download the Selenium RC zip from the Selenium HQ downloads page.  Unzip to a convenient location.
  2. In the Selenium Remote Control folder open the selenium-server-* subfolder and check that it contains selenium-server.jar.
  3. Create a file that contains all user extensions required by the tests.  Name the file user-extensions.js and save in the directory containing selenium-server.jar.  If the tests require only one user extension the user extension file may be copied and renamed.  If multiple user extensions are needed copy/append them into one file.  If the sequence in which they are listed is significant in the Selenium Core Extensions option in IDE, they must appear the same sequence in the user-extensions.js file.
IMPORTANT: The user extension goto_sel_ide that defines the While and Goto commands does not 
work with Selenium RC.  Include the user extension goto_sel08.js instead.
(let's include a link here to the flow control user extensions when someone finds it)


Running an IDE Test Suite

  1. Open a Windows command line window and set the current directory to the location of selenium-server.jar.
  2. Enter the command java -jar selenium-server.jar with the necessary options on one line.  Below, the options are displayed on multiple lines for readability.
     java 
        -jar selenium-server.jar 
        -userExtensions user-extensions.js
        -htmlSuite 
           "*chrome" 
           "<base URL>" 
           "<Selenium test suite file>" 
           "<results log file>"  
       -timeout nnnn
Selenium Server Options
-user Extensions
 user-extensions.js is the only option
-htmlSuite
displays help text if no parameters are provided

1st parameter is the browser to run the script in. In RC 1.0.1 *chrome = Firefox, *iehta = Internet Explorer.  (options in RC 1.0.2 are expected to be *firefox and *iexplore, respectively)

2nd parameter is base URL, same as in IDE.  Required but may be a dummy URL if not relevant to the script.

3rd parameter is absolute path of the Selenium test suite file.

4th parameter is absolute path of the results log.  see below for more information
-timeout
time limit in seconds for the script to run.  Default is 1800 seconds (~30 minutes).  If the timeout is reached selenium-server terminates with the error HTML suite exception seen: org.openqa.selenium.server.SeleniumCommandTimedOutException


Results Log File

  • File is created in XML format and name should use .html file extension.
  • The upper section lists the script commands and outputs from some executions of echo commands.
  • The lower section is the command execution runtime log.
  • After the script finishes RC immediately creates the first part of the log file. There may be a long delay while the remainder of the log is created.
Echo Command  Output

Output from an echo command is not displayed as a separate line as in IDE.  Instead it appears as the command's 2nd parameter which is otherwise unused for echo.  One of two scenarios result:

An echo command is executed only once:

  • The output appears with the echo command in the command listing (upper section).
  • In the execution log (lower section) the echo's 2nd parameter is empty.

An echo command is executed multiple times, such as in a while-loop.

  • In the execution log an echo's first execution does not show output.  Each following execution of the same echo command displays the output from the previous execution.
  • The output from the echo's last execution appears in the command listing.

The overall pattern is consistent across the two scenarios: Attempt to store an echo's output in the command listing, unless a previous output exists.  If there is a previous output, copy it to the current line in the execution log before saving the current output in the command listing.

For a sequence of commands in a script that are executed in order, the echo outputs in either the command listing or execution log are in the same order that the outputs were generated.  When flow control (nested while-loops, goto-If ) affects execution order, the echo outputs may not be the order that they were generated.