我对 Java、TestNG 和 Selenium Webdriver 比较陌生(3 周),我似乎没有按照 TestNG 希望我的方式正确传递参数。
测试运行完美,但随后提示失败,原因如下:
org.testng.TestNGException:
The data provider is trying to pass 2 parameters but the method com.pragmaticqa.tests.AppTest2#twoUsersSignUp takes 1
这是我的代码:
public class AppTest2 {
public WebDriver driver;
public WebDriverWait wait;
@DataProvider(name = "dataProvider")
public Object[][] setUp() throws Exception {
File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"));
FirefoxBinary ffox = new FirefoxBinary(firefoxPath);
ffox.setEnvironmentProperty("DISPLAY", ":20");
driver = new FirefoxDriver(ffox, null);
wait = new WebDriverWait(driver, timeoutInSeconds );
Object[][] data = new Object[1][2];
data[0][0] = driver;
data[0][1] = wait;
twoUsersSignUp(data);
return data;
}
@Parameters({ "data" })
@Test(dataProvider = "dataProvider")
public void twoUsersSignUp(@Optional Object[][] data) throws InterruptedException{
//test here
}
}
最佳答案
您需要使用您在数据提供者中填写的数据来声明您的测试方法,因此在您的情况下,它应该是
public void twoUsersSignUp(WebDriver d, WebDriverWait w).
关于java - TestNG/Webdriver/Java - 通过注释传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17973393/