Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Running Selenium HTML (Selenese) Test Cases in Parallel

4.29/5 (4 votes)
1 Dec 2009CPOL2 min read 39.1K   228  
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)