In today's post I would like to explain how we can quick start a selenium Java project using Maven. The term Maven may not be very familiar to many of the testers but widely used by Java developers. We can create a Selenium project without using Maven. Then why there is so much buzz about this magic word "Maven"? Let me explain how Maven can help testers to a great extend.

1) Dependency management - If you are not using maven you need to manage all the dependencies in your project manually. For example you are referring to selenium web driver version 2.31.0 in your project. So you may need to download the corresponding jar file before using it. Maven will do the same task for us. We just need to add the dependency in pom.xml file and rest maven will take care. Tomorrow if you want to use latest version of selenium just make the entry in pom.xml file, that's it.

2) Folder management - Maven creates a specific folder structure in the project one for keeping everything related to development and one for test. Since your base level folder structure is already created, we can easily customized this as per our need.

3) Plugin support - Maven provides lots of useful plugins which testers can use like for generating reports, creating documentations, configuring emails etc.

4) Integration with CI system - If you have requirements like integrating your tests in a CI system, maven can make your life easy.

Creating a simple java maven project for writing selenium test:
Installation:
Install maven eclipse plugin following the below steps:
Go to Help>Install New Software in eclipse IDE
Add "http://download.eclipse.org/technology/m2e/releases/1.0" in Work with
Follow the installation wizard.

Create a maven project:
1. File > New > Project
2. Select Maven project under Maven folder
3. Check the checkbox "Create simple project" and click on Next
4. Add the necessary details and click on Finish

After step 4 above, your sample maven project will be created.

Configure pom.xml file:
Open the pom.xml file. Default pom.xml file may look like this:

<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>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>
Now we need to add the dependencies we need for selenium.

For example:
<!-- Add all your test dependency here-->
  <dependencies>
  <!-- selenium dependency -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.39.0</version>
    </dependency>

    <!-- testNG dependency -->
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.1.1</version>
    </dependency>
       <dependencies>

And you are all set to try your first test using selenium webdriver and testNG.

Adding test classes:
You can add your test classes under src -> test -> java folder.
Do not forget to add "Test" word in your test class name. Maven picks only those test classes which has test word in name for running.

Running your test classes:
Once you add your test case, now you should be able to run the same as below:
1. Right click on the project folder.
2. Select "Run as" menu
3. Select "Maven test" menu

If everything goes well, you should be able to see your selenium tests running successfully.