Selenium with Maven

To execute Selenium with local maven Repository we need to follow the steps –

1. First create a Maven Project. Goto File -> New->Others -> Select Maven Project

2. Click on Next and make a check on “Create a simple project”

3. Click on Next and you need to provide the following information and after that click Finish

4. Now in Project Explorer you can see the following structure

5. Click on “pom.xml” and we will find the repository location as –

<repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>

6. Now if we have changed our maven default repository location (.m2 folder) , we need to set it in eclipse
A. Click on Windows and Navigate to Preferences

B. Select User Settings under Maven option

C. Browse the settings.xml from Maven’s conf folder and it will change the local repository path.

7. Click Ok and again open “pom.xml” and change the repository node as –

<repository>
          <id>local-maven-repository</id>
          <name>Local project libraries</name>
          <url>E:/apache/maven_local_repo</url>
         <layout>default</layout>
</repository>

8. Now add dependencies in “pom.xml”

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

9. Now Create a sample test class

10. And the sample code should look like –

package com.testwebsite;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class FirstTest {
	
	public WebDriver driver;
	private String baseUrl;
	
	@Test
	public void test1()
	{
		baseUrl = "http://google.co.in";		
		driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.get(baseUrl);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e)             
                {
			e.printStackTrace();
		}
		driver.quit();
	}

}

11. After executing this code (as testng code) we will get the testng report.

That’s it 🙂

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *