首先在带有testng批注的测试类中调用什么方法:


  
  用@DataProvider注释
  用@BeforeMethod注释
  




在测试期间,我找到了以下顺序:1. @DataProvider 2. @BeforeMethod

但是我的@DataProvider使用仅在@BeforeMethod中初始化的变量。
什么解决方法可能是最好的?

我的情况如下:

class Test
  @BeforeClass
    //here I initialize pages (pageobjects in context of selenium)
  @BeforeMethod
    //here i 'get' the page I want (and the one i'll use in dataprovider)

  @Test(dataProvider = "dp")
    //my test goes here...

  @DataProvider
  dp
    //here I use page. The page may be 'usable' only if it was already 'get'.

最佳答案

删除@BeforeMethod批注,使其成为private,然后从数据提供者中显式调用它。

关于java - @DataProvider和@BeforeMethod顺序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18177359/

10-11 22:33