I'm trying to run selenium in parallel but I'm having some major issues. One major issue I have is that WebDriver sends all values to one browser then another time it'll work first OK for test then second test it'll not send any values and then another test it may hang on opening. I've seen people get it to work flawless on YouTube and even thought I've tried everything I can think of its never worked like this for me. I know the port can be passed in as a parameter and I had this before but I don't think its mandatory.
Here's how I've got everything setup starting with my hub/node setup...
java -jar selenium-server-standalone-2.47.1.jar -role hub -maxInstances=10 -maxSession=10 -port 7777 -timeout 29000
java -jar selenium-server-standalone-2.47.1.jar -role webdriver -hub http://localhost:7777/grid/register -maxSession=5 -maxInstance=5 -port 4441 -timeout 30000 -browser browserName="safari",platform=WINDOWS
java -jar selenium-server-standalone-2.45.0.jar -role webdriver -hub http://localhost:7777/grid/register -port 4448 -timeout 30000 -browser browserName="firefox",platform=WINDOWS,maxSession=5,maxInstances=5
My xml file
<?xml version="1.0" encoding="UTF-8"?>
<suite name = "Cross Browser Testing" verbose = "3" parallel = "tests" thread-count="5">
<test name = "Firefox Test">
<parameter name = "browser" value ="firefox">
</parameter>
<classes>
<class name = "TestClass.Dashboard"/>
<class name = "TestClass.Login"/>
</classes>
</test>
<test name = "Safari Test">
<parameter name = "browser" value ="safari">
</parameter>
<classes>
<class name = "TestClass.Dashboard"/>
<class name = "TestClass.Login"/>
</classes>
</test>
</suite>
Here's how I'm calling my xml
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.*;
public class Launch extends AbstractPage {
public Launch() {
super();
}
@BeforeMethod
@Parameters({"browser"})
public void launchBrowsers(String browser) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(browser);
capabilities.setJavascriptEnabled(true);
// To remove message "You are using an unsupported command-line
// flag: --ignore-certificate-errors.
// Stability and security will suffer."
// Add an argument 'test-type'
ChromeOptions chrome = new ChromeOptions();
chrome.addArguments("test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, chrome);
capabilities.setCapability("chrome.binary",
"C:\\location\\chromedriver.exe");
//setup internet explorer
capabilities.setCapability("InternetExplorerDriverServer.IE_ENSURE_CLEAN_SESSION",true);
System.setProperty("webdriver.ie.driver",
"C:\\location\\IEDriverServer.exe");
selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities);
getSelenium().manage().window().maximize();
getSelenium().manage().deleteAllCookies();
}
@AfterMethod
public void tearDown() {
//close down browser window
if (selenium == null) {
try {
selenium.quit();
selenium.close();
} catch (Exception e) {
}
}
}
}
I've also tried the switch statement
switch(browser) {
case "iexplorer":
System.setProperty("webdriver.ie.driver",
"C:\\location\\IEDriverServer.exe");
DesiredCapabilities capabilities1 = DesiredCapabilities.internetExplorer();
selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities1);
break;
case "firefox":
DesiredCapabilities capabilities2 = DesiredCapabilities.firefox();
selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities2);
break;
case "safari":
DesiredCapabilities capabilities3 = DesiredCapabilities.safari();
selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities3);
break;
case "chrome":
System.setProperty("chrome.binary",
"C:\\location\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities);
break;
default:
break;
}
Any help to get this working is greatly appreciated.