banner



How To Create Maven Project In Eclipse For Selenium

Before creating maven project In eclipse IDE for selenium webdriver, You must be aware about maven and It should be Installed properly In your eclipse IDE. Earlier we learnt about what Is maven In THIS POST and how to download and Install maven In THIS POST. So If maven Is Installed In eclipse then you are ready to create new maven project as described In bellow given steps.

Steps to create new maven project

Step 1 : First of all, Open eclipse IDE and go for creating new project from New -> Other as shown In bellow Image.

It will open new project creation window.

Step 2 : Expand Maven folder In new project creation wizard window and select Maven Project and then click on Next button as shown In bellow Image.

It will take you to project name and location selection screen.

Step 3 : On  project name and location selection screen, You can choose work space location for maven project by clicking on browse button. If wants to use default work space location then select that check box and click on Next button as bellow.

It will take you to Archetype selection screen.

Steps 4 : On Archetype selection screen, Select Maven-archetype-quickstart option as bellow and click on Next button.

Step 5 : On next screen, Enter Group Id = STTA, Artifact Id = MavenProject and Package =STTA. MavenProject as shown In bellow Image. Then click on Finish button.

It will create new maven project In eclipse as bellow.

Now your maven project Is created. You can see there Is pom.cml file under your project as shown above.

Step 6 : Now you need to add selenium webdriver and TestNG dependencies with latest version In pom.xml file. Open pom.xml file and copy-paste bellow given code In It and then save It.


          <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">   <modelVersion>4.0.0</modelVersion>    <groupId>STTA</groupId>   <artifactId>MavenProject</artifactId>   <version>0.0.1-SNAPSHOT</version>   <packaging>jar</packaging>    <name>MavenProject</name>   <url>http://maven.apache.org</url>    <properties>     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>   </properties>   <dependencies>     <dependency>      <groupId>org.seleniumhq.selenium</groupId>      <artifactId>selenium-java</artifactId>      <version>2.44.0</version>    </dependency>       <dependency>     <groupId>org.testng</groupId>     <artifactId>testng</artifactId>     <version>6.8.8</version>     <scope>test</scope>  </dependency>   </dependencies> </project>        

Current latest version of selenium webdriver Is 2.44.0. TestNG latest version Is 6.8.8. You can change It If version updated version release In future.

Step 7: Delete existing AppTest.java file from src/testjava folder package and create new class file under same package with name =WebDriverTest.java as bellow.

Now copy-paste bellow given code In that WebDriverTest.java file and save It.

          package STTA.MavenProject;  import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test;  public class WebDriverTest {  WebDriver driver;    @Test   public void verifySearch() {    driver = new FirefoxDriver();    driver.get("http://only-testing-blog.blogspot.com/");    driver.quit();   } }        

Above file will show you errors as we do not have Included selenium and testng jar files In project's build path. Here maven will do It automatically for us.

When you save It, It will start building work space by downloading required jar files from maven central repository and store In local repository based on your selenium webdriver and TestNG versions as bellow. It can take 5 to 20 minutes based on your Internet speed.

Running webdriver project from pom.xml file

When above process get completed, You can run your project from pom.xml file. To run It, Right click on pom.xml file and select Run As -> Maven test as shown In bellow Image.

It will start executing webdriver testWebDriverTest.java file. This Is the way to create and run webdriver test In eclipse using maven and testng.


How To Create Maven Project In Eclipse For Selenium

Source: https://www.software-testing-tutorials-automation.com/2015/03/create-new-maven-project-in-eclipse-for.html

Posted by: carterthreatin1945.blogspot.com

0 Response to "How To Create Maven Project In Eclipse For Selenium"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel