How to create maven project in eclipse for selenium
In my earlier post I have discussed about maven tool on automation front. I have also discussed about whats is POM and why we use maven tool for java project . In this post I will create one sample selenium project using maven. Before creating the maven project we need to download and install maven. I am assuming you have JAVA and eclipse IDE installed in your machine.Prerequisite
- Download Maven LINK.
- Install maven .
- Add M2_HOME and MAVEN_HOME in the Windows environment, and point it to your Maven folder.
- Add Path
- Verify
- Install maven plugin in your eclipse.
1. Download Maven
You can download maven from the below link.
- 3.5.0 (2017-04-07): Latest stable release. - Download
2. Install maven .
There is no installation file. You just need to download the archive file and extract in tour hard drive. Assuming you have extract the folder in C:\Program Files\Apache\maven
3. Add M2_HOME and MAVEN_HOME
Add M2_HOME and MAVEN_HOME variable in windows environment.
M2_HOME should be C:\Program Files\Apache\maven
MAVEN_HOME should be C:\Program Files\Apache\maven
4. Add Path
You need to Update PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere.
5. Verify
Run the below command to know that maven installed and configured in your system properly or not. If you see the version and maven home after executing the command it means maven configured properly.
Maven command
mvn –version in the command prompt/cmd
6. Install maven plugin in your eclipse.
You need to download eclipse maven plugin from eclipse marketplace.
Or if you really don't want to do this above mentioned steps to configure maven in your system there is another simple way to solve this problem.You just need to download maven enabled eclipse from the eclipse website. Here is the link below for eclipse luna with eclipse integration .
Till now we have configured the maven environment. Now we will create selenium project with maven
Step 1: Create maven project from eclipse IDE
Go to File -> Project -> Maven -> Maven Project
Next screen will ask for your project location where you want to create the project. You can use Default Workspace location.
Step 2: Select Archetype
In the next screen, It will ask you to select an Archetype. Depending on the type of project that you are working, you need to choose the archetype
Now you need to enter a group id for the artifact, artifact id ,version and package,
We will input as shown in the below image. Version number will be by default 0.0.1-SNAPSHOT
After clicking finish button the maven project will be created with maven structure. It will create one sample POM also.
Sample POM look like this
Step 4: Edit POM file and add selenium dependency
Copy the selenium dependency XML from maven central. or you can also get the XML from selenium org web site
- selenium website - LINK http://docs.seleniumhq.org/download/maven.jsp
2. maven central - LINK
Edit the POM XML file for the project and add the selenium dependency
Once you save the project it maven start building the project. Means maven start pulling all required dependency from the maven central.
You can build the project using build maven command. you can set the goal as compile.
Step 7: Navigate to src/test/java
If you navigate to src/test/java folder , you will see there is class call AppTest . You can use this call for writing test case or you can create different class file per your requirement.
I have created separate class file called "TestCode" under src/test/java folder. I am using junit for writing test. If you look into the POM file , you will see junit is already added in the dependency. If you observe junit is not added in your POM file then you need to add the dependency for junit.
Step 8: Run the Junit test
Run the test in junit you will see chrome will open and navigate to facebook page . In my previous post I have mentioned how to open chrome in selenium.

2 comments
commentsIt is really a great work and the way in which you are sharing the knowledge is excellent.Thanks for your informative article
Replysoftware testing course in chennai
Great Article
ReplyJava Projects for Engineering Students of Computer Science
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai