In this post, I will explain how to execute webdriver java testNG test script using ant maven tool for this first we need to setup following in our machine.
Create maven project for eclipse by using post “” as mentioned in if you have not experience how to create maven eclipse project.
Create webdriver testNG test script and put into “src/test/java” source folder. Also create testNg suite file for same test script and put into desire directory as I put into “src/test/resources” folder.
Your maven eclipse project looks like as below:
- Java should be installed on machine.
- maven should be installing and setup path in system environment variable.
Create maven project for eclipse by using post “” as mentioned in if you have not experience how to create maven eclipse project.
Create webdriver testNG test script and put into “src/test/java” source folder. Also create testNg suite file for same test script and put into desire directory as I put into “src/test/resources” folder.
Your maven eclipse project looks like as below:
I have created a webdriver test scripts and put into “com.test.example” package under “src/test/java” source folder below is my webdriver test script “SearchCountry.java”.
package com.test.example;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class SearchCountry {
private WebDriver driver;
private String baseUrl;
@BeforeSuite
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.wikipedia.org/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testSearchCountry() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.xpath("//a[contains(@title, \"English — Wikipedia\")]")).click();
driver.findElement(By.id("searchInput")).clear();
driver.findElement(By.id("searchInput")).sendKeys("India");
driver.findElement(By.id("searchButton")).click();
String searchedResult = driver.findElement(By.xpath("//h1[@id='firstHeading']/span"))
.getText();
Assert.assertTrue(searchedResult.equals("India"));
}
@AfterSuite
public void tearDown() throws Exception {
driver.quit();
}
}
Below is testng suite “TestNGSuite.xml” file which I have created for above test script.