jeudi 4 octobre 2018

How to avoid giving name of DataProvider front of every method that uses data provider?

Given below is small code snippet that illustrates how data provider works.How to avoid giving name of DataProvider front of every method that uses data provider? Is there any way of optimizing this functionality rather re-writing the Data providers name front of every method that use it?

package TestNG;

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

public class DemoTestNG {
     static WebDriver driver ;


     @BeforeTest
        public void browserLauncher() {

            System.getProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
            driver = new  FirefoxDriver();
            driver.get("https://www.facebook.com");
        }

     @DataProvider(name = "TestData")
     public Object[][] getData() {

         Object[][] data = new Object[3][2];

         data[0][0]= "username1";
         data[0][1]= "password1";

         data[1][0]= "username2";
         data[1][1]= "password2";

         data[2][0]= "username3";
         data[2][1]= "password3";

         return data;

     }


  @Test(dataProvider="TestData")
  public void Dp_Test(String username, String pass) {

      driver.findElement(By.id("email")).clear();
        driver.findElement(By.id("email")).sendKeys(username);
        driver.findElement(By.id("pass")).clear();
        driver.findElement(By.id("pass")).sendKeys(pass);
        driver.findElement(By.id("u_0_2")).click();
    }
}

Aucun commentaire:

Enregistrer un commentaire