Road to execute java webdriver test scripts using maven build tool

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.
  • Java should be installed on machine.
  • maven should be installing and setup path in system environment variable. 
Maven Project: 

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 “”.
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;
                      public void setUp() throws Exception {
                        driver = new FirefoxDriver();
                        baseUrl = "";
                        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

                      public void testSearchCountry() throws Exception {
                        driver.get(baseUrl + "/");
                        driver.findElement(By.xpath("//a[contains(@title, \"English — Wikipedia\")]")).click();
                        String searchedResult = driver.findElement(By.xpath("//h1[@id='firstHeading']/span"))

                      public void tearDown() throws Exception {
Below is testng suite “TestNGSuite.xml” file which I have created for above test script.

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution