03
Sep

Running a TestNG case multiple time in a batch of two

In order to execute a script via two threads and three times total, we can use following code snippet

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class TestNGExample {

@Test(invocationCount = 5, threadPoolSize = 3) // total 3 threads & Script needs to be executed 5 times
public void generateLoadForThisSite() {

WebDriver driver = new FirefoxDriver();
driver.get(“http://www.google.com”);
System.out.println(“Page Title is ” + driver.getTitle());
Assert.assertEquals(“Google”, driver.getTitle());
driver.quit();

}

}

output:
Page Title is Google
Page Title is Google
Page Title is Google
Page Title is Google
Page Title is Google