Automating Selenium IDE tests

Automating Selenium IDE

Author : Mikhail Pathikirikorale
Date : 6/16/2006
Version: 1.0
Change History:
20060616Mikhail: Created

Abstract: The aim of this tutorial is to teach the user how to automate Selenium IDE tests using the Selenium Testrunner. This tutorial should take 15 minutes to follow.

Automating Selenium IDE

To automate your tests there are a few things you need to do. First of all you need to make sure all the tests you made in Selenium IDE are saved as .html files. You can do this by going to each of your test files and renaming them to have a .html file extension. Or you can save your test as an html file when you create it.

Now, in the directory of all your tests, you need to make an html file called TestSuite.html (it can be called whatever you want but here I'm going to use TestSuite.html). This file should contain a simple array of links to each of your test html's. An example is shown below.

TestSuite.html

<table>
<tr>
<td>Test suite for the whole application</td>
</tr>
<tr>
<td><a target="testFrame" href="test_main_page.html" >Access main page</a></td>
</tr>
<tr>
<td><a target="testFrame" href="test_login.html" >Login to application</a></td>
</tr>
<tr>
<td><a target="testFrame" href="test_address_change.html" >Change address</a></td>
</tr>
<tr>
<td><a target="testFrame" href="test_logout.html" >Logout from application</a></td>
</tr>
</table>

Remember TestSuite.html should be kept in the same directory as all your tests. Obviously you will need to add new array rows, and change the html links as necessary, depending on your test html filenames and the number of tests you want to run.

Be sure to add the target="testFrame', or else Selenium won't be able to run your tests. This will force the tested pages to be opened in the bottom frame of the test window, so you can watch.

Now open Firefox, but not Selenium IDE. We are going to invoke Selenium Core, which runs as a sort of web application. In your browser, copy the following line and paste it into the address bar:

chrome://selenium-ide/content/selenium/TestRunner.html?baseURL=http://localhost&test=file:///dir/testsuite.html&auto=true

Read the url, and replace dir/testsuite.html with the true directory and filename where your test suite is. Also replace http://localhost with the baseURL of your server, that is http://deklarantT.ru in my case.

chrome://selenium-ide/content/selenium/TestRunner.html?baseURL=http://deklarantT.ru&test=file:///M:/Tests.html&auto=true

Now you will see a new screen with 4 frames. The leftmost one should display the tables as described in your TestSuite.html file. The middle should show the table values of the current test, and the rightmost should show the commands available. Now you can click on the links of your tests in the leftmost window and run them using 'run selected' or you can run all the tests. Bear in mind that if a test fails, you will have to run the test on its own to see exactly where it has failed. For this reason it is important to make tests that in the test teardown phase, nullifies all the changes made in the setup phase. This will allow your tests to run properly while leaving the state of the program in the same way that it was found. Any problems, see me.

Running Test Suite from command line

If you want to run a number of tests from the command line - for example, as an acceptance test step, or as a part of the checkin, you have a couple of options.

1) Selenium RC provides convenient command-line support for running HTML Selenese tests from the command-line or with Ant: http://www.openqa.org/selenium-rc/selenese.html

2) Create a batch file that launches Firefox pointed to the suite. For example, on Windows, my batch file looks like:

"C:\Program Files\Mozilla Firefox\firefox.exe" -chrome "chrome://selenium-ide/content/selenium/TestRunner.html?test=file:///C:/tests/AllTests.html&auto=true&baseURL=http://mysite.com" -height 900 -width 900

Do modify the test parameter of in the URL.
Note: I couldn't get this working with Selenium IDE 0.8.1; I had to use version 0.8.0.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 30, 2006

    Georg Jezersek says:

    How can I save this test to a local result file?

    How can I save this test to a local result file?

  2. Nov 01, 2006

    Al Chou says:

    I couldn't get Win XP Pro to interpret the command line correctly (it would open...

    I couldn't get Win XP Pro to interpret the command line correctly (it would open the Selenium TestRunner but wouldn't load my test suite HTML file). I resorted to using Cygwin's bash shell instead. Firefox 1.5.0.7 doesn't seem to respect the -height and -width switches, but my test does at least seem to run.

  3. Nov 09, 2006

    Matt says:

    How do I get feedback to my shell script or batch file that the tests passed or ...

    How do I get feedback to my shell script or batch file that the tests passed or failed?

  4. Dec 15, 2006

    Ted Ernst says:

    The site I'm attempting to test breaks out of frames, so this frame-based proced...

    The site I'm attempting to test breaks out of frames, so this frame-based procedure doesn't work. Any tips?

  5. Jan 10, 2007

    Ted Ernst says:

    I found that &multiWindow=true works here when frames aren't workable.

    I found that

    &multiWindow=true

    works here when frames aren't workable.

  6. May 30, 2007

    MOHA says:

    You can get the test running on Selenium IDEs after 0.8 if your test suit mark u...

    You can get the test running on Selenium IDEs after 0.8 if your test suit mark up is valid.

    The example given lacks tbody tag after table tag and before the first tr.

    Here is a sample of how the test suit file should look like to run on Selenium IDEs after 0.8

  7. Jul 22, 2007

    sharun says:

    I dont know why this happens and am hoping someone will explain it... I ran int...

    I dont know why this happens and am hoping someone will explain it...

    I ran into issues lauching multiple instances of firefox(running diff suites) from the command line. Looks like multiple instances of firefox cant be run with the same firefox profile(with selenium-ide). So if multple instances are started, and all use the same profile (and use the same chrome provider (selenium-ide) directory) weird things happen. All the instances start but windows do not appear.

    The hack I use to work around this is to create mulitple profiles and start each firefox instance with a unique profile.

    Steps:
    1. Create X profiles directories (copy of %appdata%Mozilla\Firefox\Profiles\xxxxxxxx.default with selenium-ide installed) where x = number of diff browser sessions to be run
    2. Modify extensions.ini in newly created profile directory with correct path info
    3. Launch each firefox instance with -profile <profile_X>

    dumb batch script to launch things
    @set PROFILE_ROOT=C:\Scripts
    @set TEMPLATE_SRC=C:\Scripts\TemplateProfile
    @set NAME_PREFIX=profile

    @for /L %%I in (1,1,%1) DO @call :MAIN %%I

    @GOTO :EOF

    :MAIN

    @set TMP_NAME=%PROFILE_ROOT%%NAME_PREFIX%_%1
    @set PROFILE_NAME=%NAME_PREFIX%_%1
    @xcopy /E /I %TEMPLATE_SRC% %PROFILE_NAME%

    @REM replace the dir in the extension.ini file
    @set INI_FILE=%TMP_NAME%\extensions.ini
    echo ini file = %INI_FILE%
    echo [ExtensionDirs] > %INI_FILE%
    echo Extension0=C:\Program Files\Mozilla Firefox\extensions\inspector@mozilla.org >> %INI_FILE%
    echo Extension1=%TMP_NAME%\extensions{a6fd85ed-e919-4a43-a5af-8da18bda539f} >> %INI_FILE%
    echo [ThemeDirs] >> %INI_FILE%

    start firefox.exe -no-remote -profile "%TMP_NAME%" -chrome
    "chrome://selenium-ide/content/selenium/TestRunner.html?test=file://c:/TestSuite_Whatever.html&multiWindow=true&auto=true&baseURL=http://host:port"

  8. Nov 14, 2007

    Dominik Sommer says:

    Here's a quick WinXP batch script to generate a TestSuite.html compiling all tes...

    Here's a quick WinXP batch script to generate a TestSuite.html compiling all tests stored with an .html extension in the current directory:

    @ECHO OFF
    del TestSuite.html
    echo ^<table^>^<tr^>^<td^>TestSuite for all tests^</td^>^</tr^> > TestSuite.html.tmp
    FOR /F %%i in ('dir /b /on *.html') do echo ^<tr^>^<td^>^<a target="testFrame" href="%%i"^>%%i^</a^>^</td^>^</tr^> >> TestSuite.html.tmp
    echo ^</table^> >> TestSuite.html.tmp
    ren TestSuite.html.tmp TestSuite.html
    
  9. Nov 27, 2007

    Gudlaugur Egilsson says:

    Hi I just downloaded Selenium IDE 0.8.7, and followed the instructions on this ...

    Hi

    I just downloaded Selenium IDE 0.8.7, and followed the instructions on this page. I am unable to get this to work, it seems like that test suites are no longer supported in chrome://selenium-ide, at least according to this post here:

    http://forums.openqa.org/thread.jspa?messageID=31620&#31620

    Can someone verify the status of this ? If this isn't supported anymore, this page shouldn't be here...

    My test suite html:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title> Test Suite</title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <tbody>
    <tr><td><b>Testing experiment</b></td></tr>
    <tr>
    <td>
    <a target="testFrame" href="testagentenable.html">Enable the agent</a></td>
    </tr>
    <tr>
    </tbody>
    </table>
    </body>
    </html>

    My test (testagentenable.html):
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
    testagentenable
    </title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <thead>
    <tr>
    <td rowspan="1" colspan="3">
    testagentenable</td>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>
    open</td>
    <td>
    /</td>
    <td></td>
    </tr>
    <tr>
    <td>
    clickAndWait</td>
    <td>
    link=Agents (1)</td>
    <td></td>
    </tr>
    </tbody>
    </table>
    </body>
    </html>

    Update

    I tried running test suites on a another computer, with Windows XP, same version of firefox, and this works fine there. Is this possibly an issue related to Windows Vista ?

  10. Jan 17, 2008

    Vikrant says:

    I am using selenium IDE 0.8.7. The suite file is not working at my end. I have f...

    I am using selenium IDE 0.8.7. The suite file is not working at my end. I have firefox version 2.0.0.11.

    The when I try to open the suite file using IDE it displays an error as no command found.

    Can anyone suggest me what I can do ?

    Suite file:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title> Test Suite</title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <tbody>
    <tr><td>Testing experiment</td></tr>
    <tr>
    <td>
    <a target="testFrame" href="paramCore.html">Enable the agent</a></td>
    </tr>
    <tr>
    </tbody>
    </table>
    </body>
    </html>

  11. Oct 08, 2008

    mark1900 says:

    Selenium IDE 1.0b2 The following will post the results to the remote url; "C:...

    Selenium IDE 1.0b2

    The following will post the results to the remote url;

    "C:\Program Files\Mozilla Firefox\firefox.exe" -chrome "chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?baseURL=http://www.google.com&test=file:///C:/TestSuite.html&auto=true&resultsUrl=http://remote.com/test/postOutput.php"

    I confirmed this behaviour by looking up the resultant text file at http://remote.com/test/postOutput.txt, before and after each test execution.

    *Note: The remote server name is fake and not http://remote.com.

    Below is the example TestSuite and TestCase I used;

    http://wiki.openqa.org/download/attachments/920/TestSuite.html http://wiki.openqa.org/download/attachments/920/TestCase1.html

  12. Oct 08, 2008

    mark1900 says:

    See also Selenium Core 0.8.3 documentation; http://selenium-core.openqa.org/usa...
  13. Jan 12, 2012

    Subhash Singh says:

    I couldn't get this working with Selenium IDE 0.8.1; I had to use version 0.8.0.

    I couldn't get this working with Selenium IDE 0.8.1; I had to use version 0.8.0.