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

后端 未结 4 1785
再見小時候
再見小時候 2020-12-15 11:02

I currently use Eclipse as my Java IDE and I use Maven. I click the run button and it is able to run a Selenium Java test I wrote.

I then proceeded to install Maven

4条回答
  •  -上瘾入骨i
    2020-12-15 11:17

    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:

        
         
          
           org.codehaus.mojo
           exec-maven-plugin
           1.1.1
           
            
             test
             
              java
             
             
              Selenium2Example
              
               arg0
               arg1
              
             
            
           
          
         
        
    

    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.

提交回复
热议问题