Click here to Skip to main content
15,885,757 members
Articles / Web Development / HTML

Running Selenium HTML (Selenese) Test Cases in Parallel

Rate me:
Please Sign up or sign in to vote.
4.29/5 (4 votes)
1 Dec 2009CPOL2 min read 38.5K   228   8   8
This article will explain how to reduce time for the execution of Selenium HTML test cases without using Selenium Grid.

Introduction

This article explains how to run Selenium HTML (Selenese) based test suites in parallel reducing the execution time without using Selenium Grid.

Background

Currently Selenium Grid offers running Selenium tests written in C#, Java, Ruby, and PHP. But there are no client drivers available for Selenese test cases. The idea presented in this article is a workaround for running the Selenese test cases in parallel for reducing the execution time.

Real Scenario: Before this approach, we executed our Selenese tests in Selenium Functional Test Runner and it took almost 2 hours to execute 8 test suites parallel in a browser. With this approach, we have reduced the time to 15 minutes to execute the same 8 test suites.

Using the Code

The attached zip file is a sample ANT build script that executes the test suites by initializing them in different Selenium Remote Controls in parallel. To setup the environment, you need the following tools to be installed on your machine :

  • ANT
  • Psexec
  • Selenium Remote Control
  • Subversion (optional: if the test cases are in subversion repository)

The following snippet sets the required paths according to your environment. E.g. path to Selenium Server, base URL, path to Selenium tests and path to save generated Selenium reports:

XML
<!-- Path to Selenium Server Binaries-->
<property name="SeleniumServerPath" value="C:\Path-to-Selenium-Server" />
<!--Path to base url-->
<property name="baseURL" value="https://url-to-your-application"/>
<!--<Path to Selenium Tests-->
<property name="SeleniumTestsPath" value="C:\Path-to-SeleniumTests"/>
<!--Path to Selenium Results-->
<property name="SeleniumReports" value="C:\Path-to-Reports" />

The following snippet updates the test files from subversion and calls the target for FirstTestSuite file:

XML
<!-- This target will be used to update your selenium tests from Subversion -->
<target name="svn">
<exec dir="${SeleniumTestsPath}" executable="svn">
<arg line="update --username usr --password pwd" />
</exec>
<antcall target="FirstTestSuite">
</antcall>
</target>

The following snippet initializes the first Selenium Server on port 4444 and second Selenium Server on port 4445 to execute the first and second test suite file in parallel. (Note: Place the user extension file in the same folder where test suite file is located.)

Please observe that Selenium Server is initialized using psexec so that ant can get the control back to initialize the second Server. Moreover, a sleep time of 15 seconds is included in order to have sufficient time for first Selenium Remote control to prepare the new Firefox profile before initializing the second Selenium Remote Control. Otherwise, it will throw an error that Firefox profile cannot be created.

XML
<target name="FirstTestSuite">
<exec dir="${SeleniumServerPath}" executable="psexec.exe" spawn="true">
<arg line="-d -i java -jar
selenium-server.jar -port 4444 -singlewindow -htmlSuite *firefox ${baseURL}
${SeleniumTestsPath}\FirstTestSuite.html
${SeleniumReports}\Results_FirstTestSuite.html" /> 
</exec>
<sleep seconds="15" />
<antcall
target="SecondTestSuite"/>
</target>
<target name="SecondTestSuite">
<exec dir="${SeleniumServerPath}" executable="psexec.exe" spawn="true">
<arg line="-d -i java -jar
selenium-server.jar -port 4445 -singlewindow -htmlSuite *firefox ${baseURL}
${SeleniumTestsPath}\SecondTestSuite.html
${SeleniumReports}\Results_SecondTestSuite.html" /> 
</exec>
<sleep seconds="15" />
<antcall
target="ThirdTestSuite"/>
</target>

Points of Interest

Large test suite files can be divided into smaller parts in order to execute them in parallel. This approach helps until Selenium Grid comes with an HTML client driver to execute the Selenese test cases in parallel.

History

  • 1st December, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 4 Pin
psamagal6-Dec-12 10:12
psamagal6-Dec-12 10:12 
Questionwhat is the way to run it? Pin
Tanvir Afzal14-Nov-12 22:47
Tanvir Afzal14-Nov-12 22:47 
QuestionCant get multiple windows opened Pin
krishnam_selenium9-Jul-12 23:25
krishnam_selenium9-Jul-12 23:25 
Questionerror in IE Pin
Member 827595922-Nov-11 11:37
Member 827595922-Nov-11 11:37 
QuestionOnly single browser session is created Pin
Member 840431916-Nov-11 5:16
Member 840431916-Nov-11 5:16 
QuestionRunning Selenium HTML (Selenese) Test Cases in Parallel Pin
Member 830905511-Oct-11 8:10
Member 830905511-Oct-11 8:10 
QuestionBrilliant, Pin
just_do_it_5728-Sep-11 4:39
just_do_it_5728-Sep-11 4:39 
GeneralMy vote of 1 Pin
santoshnagp99914-Dec-09 2:56
santoshnagp99914-Dec-09 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.