I don't get how the grouping works in TestNG, I have this code :
@AfterMethod(groups = { "refreshPage" })
public void refresh() throws IOException {
driver.navigate().refresh();
}
@Test
public void test1() {
}
@Test(groups = { "refreshPage" })
public void test2() {
}
And the @AfterMethod is run after both of them, even if only the second one is part of that group. I guess it doesn't relate to the Template testng.xml configuration file that is generated by eclipse for the execution. It's just a barebone setting for either the entire test class or individual test method. So it shouldn't influence groupings
EDITED:
So that in order to have @AfterMethod run after some methods only and run the entire test class, I have to run it twice, having two groups of methods (with/without refreshing).
<test name="Test1">
<groups>
<run>
<include name="refreshPage*"/>
</run>
<开发者_StackOverflow社区;/groups>
<classes>
<class name="example.Test"/>
</classes>
</test>
<test name="Test2">
<groups>
<run>
<include name="dontRefreshPage*"/>
</run>
</groups>
<classes>
<class name="example.Test"/>
</classes>
</test>
I have no idea how to make it work when started via Eclipse, cause the <test>
are replaced in the Template.
I'm sorry but I don't understand your description of the problem. Your two test methods belong to the group "refresh", so if you run that group, you will see both of them run, and each of them will be followed by a call to prepareTest() (by the way, it seems odd that an after method would be called "prepareTest()", are you sure you don't mean for this to be a @BeforeMethod?).
There is something odd about your code, though: your two test methods declare a data provider but they don't take any argument. Either they need arguments, so you should update their signature to match what the data providers return, or they don't, and you should remove the dataProvider attribute.
精彩评论