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.

  • Can you provide a code snippet please? It would be helpful to understand how the current structure is.
    – Twaldigas
    Jul 15, 2014 at 13:22

1 Answer 1


This should work:

class Hull {

    protected WebDriver driver;

    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.

  • I was doing the same thing but was getting some exception. I finally resolved them. With your answer I became sure that whatever I was trying is correct.Thanks. Jul 16, 2014 at 9:15

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.