Executing tests in parallel with TestNG Framework
Step 1: Create a testing.xml with parallel keyword as
Step 2: create PE1 and PE2 classes (which needs to be executed in parallel)
package TestNG;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class PE1 {
WebDriver driver;
@Parameters({“myBrowser”})
@BeforeClass
public void launchBrowser(String myBrowser) {
if (myBrowser.equalsIgnoreCase(“chrome”)) {
System.setProperty(“webdriver.chrome.driver”, “C:\\softwares\\Selenium jars\\chromedriver.exe”);
driver = new ChromeDriver();
} else if (myBrowser.equalsIgnoreCase(“firefox”)) {
driver = new FirefoxDriver();
}
}
@Test
public void T1() {
driver.get(“http://www.google.co.in”);
driver.findElement(By.name(“q”)).sendKeys(“Hello Sheetal”);
driver.findElement(By.id(“gsr”)).click();
}
}
package TestNG;
import org.testng.annotations.Test;
public class PE2 {
@Test
public void T1() {
System.out.println(“Test 1 in C2”);
}
@Test
public void T2() {
System.out.println(“Test 2 in C2”);
}
@Test
public void T3() {
System.out.println(“Test 3 in C2”);
}
}
0 comments