Can someone let me know why it stops execute after the first @test(priority=1)? It ran the @beforeclass, then @test(priority 1) then @aftermethod. So it skipped @test(prority=2) and @test(priority=3)

public class SDSearchTest {

    private WebDriver driver;
    private String baseUrl= "website";
    ExtentReports report;
    ExtentTest test;

    public void beforeClass() {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    public void sdLogin() {
        //enter username and password 


    public void testDocument() throws Exception {
        //find the element 1, enter data and drag and drop 

    public void pheWastesting() {

       //find the element 2, enter data and drag and drop 

    public void tearDown(ITestResult testResult) throws IOException {


  • Can you Share the error shown on the stacktrace Jun 30, 2018 at 2:07
  • Were there any exceptions thrown? You shouldn't use driver.quit(); in @AfterMethod, if you're planning to use the driver in other test methods as well. Jul 1, 2018 at 6:08
  • Are you using testng.xml to run the test cases? if yes. paste the text of the testng.xml file in the description.
    – Alok
    Jul 1, 2018 at 7:34

3 Answers 3


You are mixing TestNG annotations with different behavior to set up and tear down the WebDriver:

  • @BeforeClass: Runs once before the first test method of the class.
  • @AfterClass: Runs once after the last test method of the class.
  • @BeforeMethod: Runs before each test method.
  • @AfterMethod: Runs after each test method.

Change @AfterMethod to @AfterClass—just like you did with @BeforeClass for your setup method—on your teardown method to only quit the WebDriver when all test methods have been executed.


This is expected behavior, because there is a driver.quit() in the @AfterMethod.

The purpose of @AfterMethod is it runs after each @Test method in a class.

So the execution flow will be @BeforeClass then the @Test with highest priority followed by @AfterMethod. Here the execution will stop.

Hope this explains.


You shouldn't use driver.quit(); in your @AfterMethod. Instead you can use it in @AfterClass. So your execution will be as follows:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.