Setting up a selenium web driver project with maven


Setting up a selenium web driver project with maven

The three simple steps will help in configuring a selenium web driver project with maven

step1:  Issue the below command

The below command will generate an archtype
mvn archetype:generate -DgroupId=TestProj -DartifactId=TestProj -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

The above command will generate an output similar to below

[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: TestProj
[INFO] Parameter: packageName, Value: TestProj
[INFO] Parameter: package, Value: TestProj
[INFO] Parameter: artifactId, Value: TestProj
[INFO] Parameter: basedir, Value: /home/shavantha/Desktop/workspace
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/shavantha/Desktop/workspace/TestProj
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.124s
[INFO] Finished at: Sun Apr 26 13:48:42 IST 2015
[INFO] Final Memory: 10M/490M
[INFO] ------------------------------------------------------------------------




On the path from which this command was run the following project stricture will be created

TestProj
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── TestProj
    │           └── App.java
    └── test
        └── java
            └── TestProj
                └── AppTest.java

Step2: However, we cannot still open this project on an IDE such as eclipse and the IDE will show an error such as "No projects are found to import". To overcome this, we can issue the below command for the Eclipse IDE

mvn eclipse:eclipse

Step3: To enable the relevant selenium web driver related artifacts to be added to the project update the pom.xml as below. Highlighted in bold are the dependencies that were added to the pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>new</groupId>
  <artifactId>project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   <dependencies>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.13.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>htmlunit-driver</artifactId>
    <version>2.31.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>3.13.0</version>
</dependency>
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>19.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.13.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.13.0</version>
</dependency>

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>22.0</version>
</dependency>
 <dependency>
     <groupId>com.google.api-client</groupId>
     <artifactId>google-api-client-appengine</artifactId>
     <version>1.23.0</version>
     <exclusions>
        <exclusion>
          <groupId>com.google.guava</groupId>
          <artifactId>guava-jdk5</artifactId>
       </exclusion>
    </exclusions>
 </dependency>

    </dependencies>

</project>







Comments