avirup
avirup

Reputation: 1701

How to change the @Test method dynamically in TestNG

This is more of a question on test automation framework design. Very hard indeed to summarize whole question in one line :) I am creating a test automation framework using Selenium. Mostly I am accessing the data (methods name) from an excel file.

In my main Runner class I am getting a list of test cases. Each test case has a set of methods (can be same or different) which I have defined in a java class and executing each method using java reflection api. Everything is fine till this point.

Now I want to incorporate TestNG and reporting/logging in my automation suite. Problem is I cant use @Test for each method as TestNG considers @Test = 1 Test Case - but my 1 Test case might have more than 1 methods. My methods are more like a test steps for a test case, reason is I dont want repeat the code. I want to create a @Test dynamically calling different sets of methods and executing them in Java Or defining each teststeps for a @Test. I was going through the TestNG documentation, but could not able to locate any feature to handle this situation.

Any help is really appreciated and if you have any other thoughts to handle this situaton I am here to listen.

Upvotes: 1

Views: 562

Answers (1)

javaprogrammer
javaprogrammer

Reputation: 25

Did you try the following?

@Test(priority = 1)
    public void step1() {
    //code
}
@Test(priority = 2)
    public void step2() {
    //code
}

You need to use "priority" for each method, otherwise it won't work.

Upvotes: 0

Related Questions