Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question
    
Can you provide a code snippet please? It would be helpful to understand how the current structure is. –  Twaldigas Jul 15 at 13:22

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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. –  razizcool4all Jul 16 at 9:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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