【佳乐Selenium】DAY-5 参数化DataProviders
转自:http://www.51testing.com/html/87/300987-832116.html两处的DataProvider的名字必须相同,这样子程序发现@Test(dataProvider ="denglu")时会主动去搜索DataProvider name="denglu"的注解,然后查找到DataProvider()这个方法,将此方法的两个返回值作为实参传递给login(String, String)方法。
package com.test.com.test.java;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataProvidersTestLogin {
@DataProvider(name ="denglu")
public Object[][] DataProvider(){
return new Object[][]{{"justForYourTestingDP","135135"}};
}
@Test(dataProvider ="denglu")
public void login(String username, String password)
{
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
login m=PageFactory.initElements(driver, login.class);
m.login(driver,username,password);
}
}
页:
[1]