3

在带有 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'.
4

1 回答 1

1

移除@BeforeMethod注解,制作它private,然后从数据提供者显式调用它。

于 2014-09-02T11:52:37.813 回答