I have written the following test using the testNG annotations:
public class Create {
WebDriver driver;
@BeforeClass
public void testsetup() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@BeforeMethod
public void Login() {
driver.get("www.xyz.com");//just an example
}
@Test(priority=3)
public void AccountCreate() {
System.out.println("Test3");
}
}
@Test(priority=1)
public void CompanyCreate() {
System.out.println("Test1");
}
@Test(priority=2)
public void VerifyResult() {
System.out.println("Test2");
}
}
@AfterMethod
public void Logout() {
System.out.println("print after method");
}
@AfterClass
public void CloseBrowser() {
driver.close();
}
}
The o/p is like this:
print after method
test1
print after method
test2
print after method
test3
Observations; @BeforeClass
executes first, then @Beforemethod
executes, then @Aftermethod
and then @Test(priority=1)
, @Aftermethod
then @Beforemethod
and then @Test(priority=2)
and so on.
But after all the @Test
run, then only the @Aftermethod
executes. Anyone, please help me on this. I really couldn't find what exactly is the problem.