简体   繁体   English

TestNG / Webdriver / Java - 通过注释传递参数?

[英]TestNG/Webdriver/Java - passing parameters via annotations?

I am relatively new to Java, TestNG and Selenium Webdriver (3 weeks) and it seems Im not passing parameters correctly, the way TestNG wants me to. 我相对较新的Java,TestNG和Selenium Webdriver(3周),似乎我没有正确传递参数,就像TestNG想要的那样。

The test runs perfectly, but then it says it failed for the following reason: 测试运行完美,但后来因为以下原因导致测试失败:

org.testng.TestNGException: 
The data provider is trying to pass 2 parameters but the method com.pragmaticqa.tests.AppTest2#twoUsersSignUp takes 1

Here is my code: 这是我的代码:

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).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM