Add Maven Dependencies
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium</artifactId> <version>2.0a4</version> <scope>test</scope> </dependency>
Run Configuration
I used the maven-failsafe-plugin to run the SeleniumHQ regression tests in the integration-test phase. The Selenium RC is started with the plugin on port 1234. If you run the tests on a Linux build server without x-server you can find information on the plugin page.
The maven-failsafe-plugin runs any tests with the pattern *IT.java (Surefire uses *Test.java).
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
<port>1234</port>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<buildDir>${project.build.directory}</buildDir>
<selenium.server>${selenium.server}</selenium.server>
<selenium.port>${selenium.port}</selenium.port>
<selenium.browser>${selenium.browser}</selenium.browser>
<selenium.url>${selenium.url}</selenium.url>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
Remark
To run the regression tests against several browsers and Selenium RC servers I added some system properties:
<selenium.server>${selenium.server}</selenium.server>
<selenium.port>${selenium.port}</selenium.port>
<selenium.browser>${selenium.browser}</selenium.browser>
<selenium.url>${selenium.url}</selenium.url>
They can be used in the JUnit Selenium tests like that:
@BeforeClass
public static void startUp() {
String server = System.getProperty("selenium.server", "localhost");
int port = Integer.parseInt(System.getProperty("selenium.port", "1234"));
String browser = System.getProperty("selenium.browser", "*iexploreproxy");
String url = System.getProperty("selenium.url", "http://www.xyz.com:8080/");
selenium = new DefaultSelenium(server, port, browser, url);
selenium.start();
}
These properties will be set in be default as you can see above or via profiles in the POM:
<profiles> <profile> <id>localhost</id> <properties> <selenium.server>localhost</selenium.server> <selenium.port>1234</selenium.port> <selenium.browser>*chrome</selenium.browser> <selenium.url>http://localhost:8080/</selenium.url> </properties> </profile> </profiles>
Simply run the build i.e. mvn install -P localhost to activate the profile.
Skipping Integration Tests
If you need to skip the integration tests you can do this by adding -DskipITs=true. I.e
mvn -DskipITs=true <goal>
0 Kommentare:
Kommentar veröffentlichen