Maven Build Automation Tool Selenium WebDriver
Ques-What is Maven and Why to use in Selenium?
Ans- Maven is a build automation tool used primarily for Java projects. The word maven means “accumulator of knowledge” .
Maven addresses two aspects of building software:
First, it describes how software is built,
Second, it describes its dependencies.
Setting up the Maven Project in Eclipse
Precondition- Maven should be installed in Eclipse -Install Maven
Step1- Open Eclipse and Click on New >Project
Step 2-Select Maven > Maven Project >Next
Step 3- Check the mention checkbox then Click Next button.
Step 4- Enter Group id (as per your requirement ) and Artifact ID (as per your requirement ) > Next
In the Group Id, enter Selenium.maven. In artifact Id, enter the project name, for example,Selenium.maven.demo. Click on Finish to create the project.
Artifact ID – project name.
GroupID -> com.maven(package name)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.53.1</version> </dependency> <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.6.12</version> </dependency> |
Step 5- Click on pom.xml and you will get the source code of pom.xml
Step 6-To integrate Maven with Selenium then we need to add dependency with Selenium
so navigate to http://docs.seleniumhq.org/download/maven.jsp
Step 8- Selenium already provided maven dependency so simply copy the below dependency
Step 9- Open pom.xml and add <dependencies> tag and paste above copy code inside <dependencies> tag
Note – Each tag should be closed like <dependencies> —-</dependencies>
After paste your pom.xml will look like
Step 10- Lets integrate the TestNG also in Maven project and Repeat the same steps as we did for Selenium
http://testng.org/doc/maven.html
Note- Once you will update pom.xml then inside your project you will get maven dependency
Write testcases in Maven Project
Step 1- Inside project select src>test>java and right click then create a class
Step 2- Specify package and class name and finish
Step 3- Create the below testng program.
Note- Its demo program you can write your test cases
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package MavenDemo; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class Testfacebook { @Test public void TestFireFox(){ WebDriver driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.get(“http://www.facebook.com”); driver.quit(); } } |
3.Right click on project, click on ‘Run As’ and then click on ‘Maven Test’
Executing the testng.xml from pom:Add the below lines to the pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <forkCount>0</forkCount> <suiteXmlFiles> <suiteXmlFile>xxx.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build> |