Dashboard > Selenium Remote Control > Home > Selenium-RC and Continuous Integration
Selenium Remote Control Log In View a printable version of the current page.
Selenium-RC and Continuous Integration
Added by Adam Feuer, last edited by Harlan on May 08, 2007  (view change) show comment
Labels: 
(None)

This page is about using Selenium-RC in a continuous integration system- running Selenium tests from a commandline, from Ant, or TestNG.

Currently, we gather informations. Then we will try to organize it in a didactic and non-redundant way. The point is that there is a lot of way to launch the tests and gather the results,  so you have to be coherent with the tools you are using (ANT, TestNG, CC, ...)

There are a couple of things to know about using Selenium-RC in this way:

  • The Selenium server (selenium-server.jar) is the thing that actually starts the web browser. This is important, because if you need to pass parameters to the browser through commandline parameters, you do it by changing the server's environment.
  • Use Xvfb (X Windows Virtual Frame Buffer): If you want to run Selenium on a Unix server- without an X Windows display- or if you just don't want to see the web browser windows popping up, use xvfb. This is an X server that just runs in memory, without a display.

ANT

A target to start the server : 

<java jar="${selenium-server.jar}" fork="true" spawn="true" />

 A target to stop the server (from Forum thread) :

<target name="stop-server">
    <get taskname="selenium-shutdown" src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"
        dest="result.txt" ignoreerrors="true" />
    <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
</target>

A target to launch Selenese tests (from Forum thread) : 

<target name="runSeleniumTests">
    <java jar="${acceptanceTestLibDir}/selenium-server.jar" fork="true">
        <arg line="-htmlSuite &quot;${firefox}&quot;"/>
        <arg line="&quot;${baseURL}&quot;"/>
        <arg line="&quot;${acceptanceTestListDir}/testSuite.html&quot;"/>
        <arg line="&quot;${acceptanceTestReportDir}/results.html&quot;"/>
        <arg line="-timeout 30"/>
    </java>
</target>

A complete example :

<?xml version="1.0" encoding="UTF-8"?>
<project name="Run Test" default="run_test" basedir=".">

    <property name="test.dir" value="src\test" />

    <property name="testLibDir" value="lib" />

    <path id="run.cp">
        <pathelement path="build"/>
        <fileset dir="build/">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="lib"/>
        <fileset dir="lib/">
            <include name="*.jar"/>
        </fileset>
    </path>

    <target name="run_test" description="Start Proxy ; Run TestNG ; stop Proxy">
        <parallel>
            <antcall target="start-server"></antcall>
            <sequential>	
                <echo taskname="waitfor" message="Wait for proxy server launch" />
                <waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
                    <http url="http://localhost:4444/selenium-server/driver/?cmd=testComplete"/>
                </waitfor>
                    <antcall target="run_testNG"></antcall>
                    <antcall target="stop-server"></antcall>
            </sequential>
        </parallel>
    </target>

    <target name="run_testNG" description="Run TestNG">	
        <testng classpathref="run.cp" haltOnfailure="false">
            <xmlfileset dir="." includes="testng.xml" />
        </testng>
    </target>

    <target name="start-server">
        <java jar="lib/selenium-server.jar" fork="true" spawn="true">
            <arg line="-timeout 30"/>
            <jvmarg value="-Dhttp.proxyHost=proxy.corporate.com"/>
            <jvmarg value="-Dhttp.proxyPort=3128"/>
        </java>
    </target>

    <target name="stop-server">
        <get taskname="selenium-shutdown" 
            src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"	
            dest="result.txt" ignoreerrors="true" />
        <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
    </target>

    <taskdef resource="testngtasks" classpath="lib/testng-5.0-jdk15.jar" />

</project>

ANT users (feedback welcome) : jattardi ; alxdark ; mustaphakhan ; jmheneman. ANT+CC : paulocheque ; lance.li2005 ...

MAVEN 2

To start/stop Selenium RC before/after integration tests, edit the pom.xml to include the following stanzas (from this post on Maven users list).

<?xml version="1.0"?>
<project>
    <dependencies>
        <dependency>
            <groupId>org.openqa.selenium.client-drivers</groupId>
            <artifactId>selenium-java-client-driver</artifactId>
            <version>${selenium-version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.openqa.selenium.server</groupId>
            <artifactId>selenium-server</artifactId>
            <version>${selenium-version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>dependency-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.openqa.selenium.server</groupId>
                                    <artifactId>selenium-server</artifactId>
                                    <version>${selenium-version}</version>
                                    <type>jar</type>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>selenium-server.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-selenium</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <tasks>
                                <echo taskname="selenium" message="---------------------------------------------------------"/>
                                <echo taskname="selenium" message=" Starting Selenium Remote Control                        "/>
                                <echo taskname="selenium" message=" Please make sure that FireFox executable is on the PATH "/>
                                <java jar="${project.build.directory}/selenium-server.jar" fork="yes" spawn="true"/>
                                <echo taskname="selenium" message="---------------------------------------------------------"/>                                
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-selenium</id>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <tasks>
                                <echo taskname="selenium" message="---------------------------------------------------------"/>
                                <echo taskname="selenium" message=" Shutting down Selenium Remote Control                   "/>
                                <echo taskname="selenium" message=" DGF Errors during shutdown are expected                 "/>
                                <get taskname="selenium"
                                     src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"
                                     dest="result.txt" ignoreerrors="true"/>
                                <echo taskname="selenium" message="---------------------------------------------------------"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>  
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>openqa</id>
            <url>http://maven.openqa.org</url>
        </repository>
    </repositories>

    <properties>        
        <selenium-version>0.8.1</selenium-version>
    </properties>
</project>

Maven2 users: Binil Thomas

A complete example on how to use Selenium, Cargo, TestNG and Maven can be found here

JAVA

Another way to launch the server (from Forum thread) :

Sure, just add selenium-server.jar to your classpath, create a new SeleniumServer object, and .start() it.

 This is typically used in SetUp() in TestNG.

LINUX 

Here are a couple of Unix commands that might be helpful:

 Starting Xvfb as display 1:

% startx -- `which Xvfb` :1 -screen 0 1024x768x24 2>&1 >/dev/null &

Starting a Selenium server that will launch web browsers on this display (display 1):

% DISPLAY=:1 java -jar selenium-server.jar

Taking a snapshot of what is happening in the xvfb display (useful for debugging):

% DISPLAY=:1 import -window root /tmp/xvfb_snapshot.png

Note: the '%' is the Unix shell prompt. The 'DISPLAY=:1" is an environment variable being set on the same commandline. You can just as easily set DISPLAY to something like foo.bar.com:2, which would make Selenium's web browser appear on foo.bar.com's second X Windows display.

Note2: if you have no startx available, try something like 'sudo apt-get install xserver-xorg' (worked for me on Ubuntu)

A Linux user : obinho.


This information is adapted from the following pages:

There is a simple plugin that lets you use Selenium-IDE HTML tests in your maven webapp project and integrates in maven's build life cycle, stopping it whenever a test fails.

Upload to the maven central repository pending.

http://mavenium.sourceforge.net/

Posted by David at Dec 08, 2006 14:40

When running with Ant and CruiseControl it's important to both fork and spawn the selenium-server. Not doing so caused our selenium-shutdown target to hang indefinetly.

Ant 1.7.0
CruiseControl 2.6.2
Selenium-RC 0.9
Java 1.5.0_11

FYI, you can use the selenium-maven-plugin to automate the configuration of the Selenium RC server when using Maven 2.

And you can also automate configuration/execution of Xvfb to allow tests to run on headless unix systems too.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators