Hi all,
I have to run my test parallel in different browsers at same time. I have used testng but still it is not running in parallel. It is running sequentially one by one.first it opens Firefox, after completion it open IE.
like my test() need to be run in fireox and test2() in IE parallel at same time
Please have a look & correct me if any thing wrong.
----------------------------------------------------------------------------------------------------
package remotRuneWebdriver;
import java.net.MalformedURLException;
import java.net.URL;
import
org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ParallelRun {
@BeforeTest
public void setUp() throws Exception {
System.out.println("firefox Started");
}
@Test
public void test() {
DesiredCapabilities capability = DesiredCapabilities.firefox();
RemoteWebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL(String.format("
http://127.0.0.1:4444/wd/hub")), capability);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.get("
http://www.google.co.in/");
driver.findElement(By.name("q"));
driver.findElement(By.name("q"));
driver.findElement(By.name("q"));
driver.findElement(By.name("q"));
try {
driver.wait(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.quit();
}
@Test
public void test2() {
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
RemoteWebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL(String.format("
http://127.0.0.1:4444/wd/hub")), capability);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.get("
http://www.google.co.in/");
driver.findElement(By.name("q"));
try {
driver.wait(50000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.quit();
}
}
----------------------------------------------------------------------------------------------------------------------------
testng xml file:
____________________________________________________________________________
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium TestNG Suite" parallel="tests"
thread-count="2">
<test name="Selenium TestNG - 1">
<classes>
<class name="remotRuneWebdriver.ParallelRun" />
</classes>
</test>
</suite>
_-------------------------------------------------------------------------------------------------------------------------------
______________________________________________________________________________
--
Regards
RAJIV KUMAR NANDVANI
http://rajivkumarnandvani.wordpress.comhttp://testeverythingqtp.blogspot.com/