How do I run a selenium test using maven from the command line? How do I run a selenium test using maven from the command line? selenium selenium

How do I run a selenium test using maven from the command line?


This is a older thread, but still want to provide input for those who are stuck up at this. You have to make sure that the class file names you are creating are ending with "Test" string.e.g. AppTest, TempTest are all valid class file names, but AppCheck, TempTest1 are invalid name; maven will not detect these files for execution.


I would recommend using Maven Failsafe (for integration tests), or Surefire (for unit tests).

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-failsafe-plugin</artifactId>    <version>2.12</version>    <executions>        <execution>            <id>default</id>            <goals>                <goal>integration-test</goal>                <goal>verify</goal>            </goals>        </execution>    </executions></plugin>


I didn't see this until after I had posted my own question...and subsequently found an answer to it! I've included my answer below:

Maven can be made to run the code it compiles by using the exec-maven-plugin and adding the following to the pom.xml:

    <build>     <plugins>      <plugin>       <groupId>org.codehaus.mojo</groupId>       <artifactId>exec-maven-plugin</artifactId>       <version>1.1.1</version>       <executions>        <execution>         <phase>test</phase>         <goals>          <goal>java</goal>         </goals>         <configuration>          <mainClass>Selenium2Example</mainClass>          <arguments>           <argument>arg0</argument>           <argument>arg1</argument>          </arguments>         </configuration>        </execution>       </executions>      </plugin>     </plugins>    </build>

As you can probably gather from the snippet, arguments can be passed in by listing them in the pom.xml. Also, be sure to use the proper package name in the mainClass element.

You can then run mvn compile followed by mvn test to compile and run your code.

Credit has to go to http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ for listing several ways to do this.