Alternate antrun plugin configuration if you are using a finalName that differs from the artifactId:
|
Selenium is a test tool for web applications. Unlike HtmlUnit? or HttpUnit? tests which simulate a browser, Selenium tests run directly in a real browser such as Firefox or Internet Explorer. The Selenium JavaScript code is deployed alongside your running application, and interacts with it just as the users do.
Selenium Core is available in OpenQA?'s Maven repository, so no installation is necessary.
You may want to download the distribution (which includes the documentation) from: http://www.openqa.org/selenium-core/download.action
While you're there, also install the Firefox plugin Selenium IDE from http://www.openqa.org/selenium-ide/
Write or record some Selenium tests, and place them in src/test/selenium
The Selenium IDE Firefox plugin is the easiest way to edit tests.
Selenium tests are written in plain HTML tables, so you may edit them with any text editor.
Configure Maven to include both the Selenium 'core' directory and your tests in the packaged webapp.
See [this pom] for an example.
The following profile will:
<profile> <id>selenium</id> <activation> <property> <name>selenium</name> </property> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>dependency-maven-plugin</artifactId> <executions> <execution> <id>unzip-selenium</id> <phase>generate-resources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.openqa.selenium.core</groupId> <artifactId>selenium-core</artifactId> <version>0.7.0</version> </artifactItem> </artifactItems> <outputDirectory>${project.build.directory}/selenium</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>copy-selenium</id> <phase>process-resources</phase> <configuration> <tasks> <copy todir="${project.build.directory}/${artifactId}/selenium/core"> <fileset dir="${project.build.directory}/selenium/core"/> </copy> <copy todir="${project.build.directory}/${artifactId}/selenium/tests"> <fileset dir="${basedir}/src/test/selenium"/> </copy> </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> </profile>
Alternate antrun plugin configuration if you are using a finalName that differs from the artifactId:
<configuration> <tasks> <copy todir="${project.build.directory}/${project.build.finalName}/selenium/core"> <fileset dir="${project.build.directory}/selenium/core"/> </copy> <copy todir="${project.build.directory}/${project.build.finalName}/selenium/tests" failonerror="false"> <fileset dir="${basedir}/src/test/selenium"/> </copy> </tasks> </configuration>
Package the webapp with the 'selenium' profile activated.
mvn package -P selenium
The webapp will contain the following additional directories: 'selenium/core' and 'selenium/tests'.
Deploy the webapp to your favorite container. The Cargo or Jetty plugin can be used for this. See [this pom] for an example using Cargo.
Run the tests with the Selenium TestRunner?.
http://localhost:8080/<appname>/selenium/core/TestRunner.html
Run the tests automatically.
?test=../tests/TestSuite.html&auto=true
to the TestRunner?.html URL
After it runs the tests automatically, Selenium will POST
the results to the default URL of ../postResults
.
If there is nothing there to process the request, you will see a 404 Not Found error page in the bottom frame.