Creating a Maven Selenium Project

Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. The website of Maven is –  https://maven.apache.org/. We need to integrate Selenium with Maven when are in a phase to create test automation framework. Selenium inherently doesn’t come with any feature other than providing us with methods to automate the browser to maintain, create, manage, share a test automation framework. So to support the full life cycle of the project we require maven to be integrated with Selenium

 

Install Maven

To install maven in the eclipse environment we have to perform the following steps-

  1. Open the eclipse environment, the one we used in here is the eclipse kepler version.
  2. Go to help
  3. Install new software, and provide the url in here – http://download.eclipse.org/technology/m2e/releases/
  4. Accept the license agreement

Maven Project

After installing maven, we can now create a maven project in the eclipse environment. We create a project by selecting an archetype. And the artifact type which we select is – quickstart.

 

POM – Project Object Model

POM is an xml file, which is associated with a Maven project. A Project Object Model or POM is the fundamental unit of work in Maven. It is anXML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects More details about pom can be read from here-  https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

In the POM we need to add dependency for the jars we like to use. For that we search maven repository and fetch the xml to be added in the pom. E.g. for Selenium it is available in here – http://www.mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/3.3.1

A sample POM is available here –

Creating TestNg Test in Maven

After we have created a maven project, by default in the src/java and in the src/test we have some files available. Delete those files from there. And in the src/test folder we create our testng test files. Ensure that the file name contains test. An example project looks like as follows –

Executing Maven Project

To execute the maven project we right click and select ‘Run as maven test’. This launches the tests and executes them.

Conclusion

So in the above article we saw how easy it is to set up maven for a selenium project which uses testng. We need to ensure the dependencies required for the project are added in the pom.xml .