Setting up Selenium WebDriver using Maven

For this post I will go through how to set up your Selenium WebDriver automation framework using Maven.

I have only been using Maven for a few months now (so quite new to it) but so far I like it. All you have to do is update the pom.xml with the dependencies you require in your project and it will fetch all the jar files it needs. So there is no need to save the jar files locally as they are saved on Mavens own repository.

For the purpose of this post I will be using IntelliJ IDEA but you can use Eclipse or any other IDE of your choice. I will also try and show as many screenshots as possible so you can compare your screen with the screenshots.

Now lets get started.

Open your IDE and start a new project. You should be able to select the type of project you want to set up. In this case select Maven from the list of options.
While using Maven you can use different set up types. I usually use the maven-archetype-quickstart option. The image below shows you the options I have selected.

MavenProject
Setting up a Maven project

Next you will be asked to enter a GroupId, ArtifacetId and Version.

  • GroupId will identify your project uniquely across all projects.  This corresponds to the domain name of the project.  Although you could use any arbitrary value, it’s recommended to use your company domain name here.
  • ArtifactId is a unique id for the project (within the group).  This name will be used when creating jar/war/ear files.
  • Version represents the current version of the project.

groupId

Continue clicking Next until you are asked to name your project and select the project location. Enter this in then click on the Finish button.

Once the setup has completed expand your project and click to open up the pom.xml file. The pom.xml contains information about the project and configuration details used by Maven to build the project. By default you should notice you will already have junit as the list of dependencies. Lets first update the version for the junit used in the project to 4.11.

Now lets add in the Selenium dependencies as well. You can usually find the maven dependency you need by googleing it. In our case if you search for “Selenium webDriver Maven“, your top result will be a link from Selenium’s own website (http://www.seleniumhq.org/download/maven.jsp). If you go to that link you will find the dependency, which looks like this.

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.45.0</version>
</dependency>

Copy the dependency and paste it into the pom.xml within the <dependencies> section. If you get a popup saying “Maven projects need to be imported” click on the “Import Changes” link so your project builds out the new changes. Your pom.xml file should look like the image below.

pom.xml file showing all the dependencies

Now you have your project set up correctly. In the next post I will go through how to write a selenium test using this setup.

One comment:

Leave a Reply