How To Create in addition to Run Selenium Test In Maven Project From Command Prompt

Earlier nosotros learnt how to DOWNLOAD AND CONFIGURE MAVEN In Windows, CREATE MAVEN PROJECT in addition to IMPORT MAVEN PROJECT IN ECLIPSE. All 3 previous steps should hold out executed past times you lot earlier writing selenium examination In maven project. Once you lot consummate all 3 previous steps, You are laid upwards to practise in addition to run selenium examination In maven project.

As you lot know, Maven manages local jolt files repository It self in addition to download required jolt files from cardinal repository based on your projection dependency configuration In POM.xml file. You tin read to a greater extent than most maven on THIS PAGE.

Step 1 : Set Selenium WebDriver in addition to TestNG dependencies
We volition practise in addition to run our selenium examination using testng thus nosotros necessitate to laid required jolt files of selenium in addition to testng In our project's construct path. As you lot know, We get got non laid required jolt files In our project's construct path till now. And too nosotros practise non necessitate to worry most It every bit this draw volition hold out done past times maven Itself. Only nosotros necessitate to laid testng in addition to selenium webdriver dependencies In POM.xml file amongst their latest versions.

Update MavenProject's POM.xml file amongst bellow given xml code. Selenium adn TestNG version may alter In futurity thus you lot necessitate to updated them accordingly In bellow given file.
<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>com.demopack</groupId>   <artifactId>MavenProject</artifactId>   <version>1.0-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.testng</groupId>   <artifactId>testng</artifactId>   <version>6.8.8</version>  </dependency>     <dependency>   <groupId>org.seleniumhq.selenium</groupId>   <artifactId>selenium-java</artifactId>   <version>2.44.0</version>  </dependency>   </dependencies> </project>

Step 2 : Compile projection to download required jolt files In local repository
Now nosotros necessitate to compile projection to download required dependency jolt files. Follow steps given bellow.
  1. Open dominance prompt.
  2. Set MavenProject folder every bit working directory In dominance prompt.
  3. Run mvn compile dominance In dominance prompt every bit bellow. It volition compile projection in addition to download required jolt files of selenium in addition to testng from maven cardinal repository to local repository folder called M2. It tin get got 10 to twenty minutes If you lot are downloading It outset time. For me, All files are already available In local repository thus maven non downloaded whatsoever jolt file.


Step 3 : Adding required jolt files nether project's construct path from dominance prompt
You non necessitate to add together required jolt files manually nether project's construct path. Run mvn eclipse:eclipse dominance In dominance prompt every bit bellow. Selenium WebDriver in addition to TestNG Jar files volition hold out added automatically nether project's construct path in addition to It volition present message BUILD SUCCESS.


Now If you lot depository fiscal establishment gibe your project's construct path, all selenium in addition to TestNG jolt files volition hold out there.

Step iv : Create selenium webdriver examination cases
First of all delete existing AppTest.java file from src/test/java packet in addition to practise 2 coffee files every bit bellow nether same package.

GoogleTest.java
package com.demopack;  import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace aeroplane GoogleTest {  WebDriver driver;   @BeforeTest  populace void StartBrowser_NavURL() {   driver = novel FirefoxDriver();   driver.manage().window().maximize();  }   @AfterTest  populace void CloseBrowser() {   driver.quit();  }   @Test  populace void testToCompareDoubles() {   driver.get("http://www.google.com");  } }

BingTest.java
package com.demopack;  import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace aeroplane BingTest {  WebDriver driver;   @BeforeTest  populace void StartBrowser_NavURL() {   driver = novel FirefoxDriver();   driver.manage().window().maximize();  }   @AfterTest  populace void CloseBrowser() {   driver.quit();  }   @Test  populace void testToCompareDoubles() {   driver.get("http://www.bing.com");  } }


Step v : Run Maven-Selenium WebDriver tests from dominance prompt
For running selenium examination cases, run mvn package dominance In dominance prompt. It volition validate in addition to compile maven projection in addition to thus run selenium webdriver examination cases.

At the cease of examination execution, Refresh "MavenProject" projection folder in addition to expand target folder. Go to surefire-reports -> Open index.html file. It volition opened upwards testng execution study every bit shown bellow.


This agency nosotros tin practise in addition to run selenium examination cases In maven projection using testng in addition to generate testng reports.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post