You want to use selenese-runner-java (SRJ).
Features
- Run test cases or test suites created with Selenium IDE
- Run tests from Java code directly
- Run tests from command line
- Support the most common drivers (firefox (default), chrome, ie, phantomjs ...)
- Support of custom drivers through WebDriverFactory
- Can be embedded in a maven build process (useful also for continouous integration process)
Since 1.7.0
: Support custom commands with the use of an implementation of CommandFactory
Sample usage
Firstly create your test (case and/or suite) with selenium IDE and save them on your disk.
1) Run tests from command line
java -jar selenese-runner.jar \
--driver chrome \
--chromedriver path/to/chrome-driver \
path/to/my-test.html
2) Run tests programmatically
public static void main(String[] args) {
String[] myArgs = new String[] { //
//
"--driver chrome", //
"--chromedriver path/to/chrome-driver", //
"path/to/my-test.html"
};
jp.vmi.selenium.selenese.Main.main(myArgs);
}
3) Run selenium tests as part of a Maven build process
Selenium tests are typically run during the integration-test
phase. Moreover, selenese-runner-java must be part of the pom.xml
dependencies.
...
<properties>
<exec.maven.plugin.version>1.3.2</exec.maven.plugin.version>
<selenese.runner.java.version>x.y.z</selenese.runner.java.version>
<speed>0</speed><!-- Tests speed in milliseconds (Fast: 0, Slow: 5000) -->
</properties>
...
<dependency>
<groupId>jp.vmi</groupId>
<artifactId>selenese-runner-java</artifactId>
<version>${selenese.runner.java.version}</version>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.maven.plugin.version}</version>
<executions>
<execution>
<id>Execution Tests Selenium</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<includePluginDependencies>true</includePluginDependencies>
<includeProjectDependencies>true</includeProjectDependencies>
<classpathScope>test</classpathScope>
<longClasspath>true</longClasspath>
<commandlineArgs>
<!-- CDATA is crucial here... -->
<![CDATA[-cp selenese-runner-java-${selenese.runner.java.version}.jar jp.vmi.selenium.selenese.Main --driver chrome --chromedriver path/to/chrome-driver --baseurl http://localhost:8080 --set-speed ${speed} src/test/TestSuite.html --html-result target/selenium-reports]]>
</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>