Krishna
Krishna

Reputation: 21

How can i run my script multiple time by using TestNG framework

I am using POM framework for automating my site.I need to execute all @Test methods including @BeforeClass and @AfterClass attributes in my script for number of times by using 'for' loop.I tried it in many ways but i didn't get required output.By using jUnit I did it.But I want it by using TestNG.Please help me.

Upvotes: 0

Views: 1195

Answers (2)

Sajal Singh
Sajal Singh

Reputation: 385

You can provide invocationCount=n(number of times you want to run your test method) in the @Test

@Test(invocationCount=2)
public void Test1(){
System.out.println("This is a Test");
}

Upvotes: 0

shank087
shank087

Reputation: 492

You can use the invocation count to execute the script multiple times. Example:

    @Test(invocationCount=3)
    public void m2(){
        System.out.println("execute method 2");
    }

The above method will be invoked 3 times. Are you expecting the same or something different?

Upvotes: 1

Related Questions