To run all test cases by invoking driver once for a suite



  • I want to run all my test cases with one start up and tear down process. I have written code for multiple browser testing and as of now I am repeating those codes in every class file under @BeforeMethod to run my test cases present in that class.

    But I want to write them once and execute all my test cases with it. Is it possible to do so?

    I have tried with different annotations but nothing worked for me. I am probably not writing it in perfect manner. I have also given @Data Providers for inputs.

    Is it I am making it complex? Or we can do all those things in one run.

    Kindly suggest.



  • This should work:

    class Hull {
    
        protected WebDriver driver;
    
        @BeforeMethod     public void initializeDriver() {
            // Initialize the driver here.
        }
    }
    
    class ClassWithTestMethods extends Hull {
        // Test methods with @Test annotation.
        // Use the driver variable of Hull in the test methods.
    }
    

    The initializeDriver method should always be executed before each test method.

    Currently I do not know how you use the data providers. But it should work if you define it in the Hull class too.

    A @BeforeSuite annotation also exists.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2