Anurag Shukla
Anurag Shukla

Reputation: 379

Defining order of execution of @BeforeGroups methods for a test belonging to same group in Java

I have a test method belonging to multiple groups, I want to ensure that one @BeforeGroups method (setupHomePage) runs before another (setupUniversalSearchPage). The order must be defined within java only as I am supposed to use any testng xml. Although in similar case in another test class the order of execution is as desired.

public abstract class HomePageTest extends TestBase
{
   @BeforeGroups("homePageTests")
   public void setupHomePage()
   {
       loadHomePage();
   }
}

public abstract class UniversalSearchPageTest extends HomePageTest
{
   @BeforeGroups("universalPageTests")
   public void setupUniversalSearchPage()
   {
       navigateToSearchPage();
   }
}

public class UniversalSearchPageBasicTest extends UniversalPageTest
{
   @Test(groups = {"homePageTests","universalPageTests")
   public void searchVerificationTest()
   {
       //test code here
   }
}

So far I have tried following : 1. reversing the order of groups in @Test annotation of searchVerificationTest 2. adding @Test(groups = "homePageTests") above declaration of UniversalSearchPageBasicTest class.

I would like to know how the order @BeforeGroups method is determined as it is different in one class than other. If it is of any relation I am using maven in eclipse and Appium I am new to testng , let me know if I am missing anything basic here

Upvotes: 0

Views: 731

Answers (1)

anshul Gupta
anshul Gupta

Reputation: 1270

@BeforeMethod methods will run in inheritance order - the highest superclass first, then going down the inheritance chain. @AfterMethod methods run in reverse order (up the inheritance chain).

Note, however, that the ordering of multiple annotated methods within one class is not guaranteed (so it's best to avoid that).

Also there is a online documentation available, checkout http://testng.org/doc/documentation-main.html#annotations

Upvotes: 1

Related Questions