Reputation: 1502
I have a selenium Grid 3 Set up. And right now i have 1 hub + 2 nodes. ( 1 local node, one external node). When i run my test it executes it on local node ( opens 3 browser).
How and where i should set up test execution? If i want to run all tests on 2 browsers, or if i want to run 50/50 tests on 2 browsers? I will Attached my existing code below.
package com.ParallelTest;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
public class Framework {
protected WebDriver driver;
@Parameters({ "platform","browser","version", "url" })
@BeforeClass(alwaysRun=true)
public void setup(String platform, String browser, String
version, String url) throws MalformedURLException
{
driver = getDriverInstance(platform, browser, version, url);
}
public static WebDriver getDriverInstance(String platform, String browser, String version, String url)
throws MalformedURLException {
String nodeURL = null;
*// IS this should be a Node or Hub path? Because right now it`s a node path. But if i want to use 2 different nodes? How i can implement it????*
String nodeURL = "http://10.11.161.249:5555/wd/hub";
WebDriver driver = null;
DesiredCapabilities caps = new DesiredCapabilities();
// Platforms
if (platform.equalsIgnoreCase("Windows")) {
caps.setPlatform(Platform.WINDOWS);
}
if (platform.equalsIgnoreCase("MAC")) {
caps.setPlatform(Platform.MAC);
}
// Browsers
if (browser.equalsIgnoreCase("chrome")) {
caps = DesiredCapabilities.chrome();
System.setProperty("webdriver.chrome.driver", "/Users/antonfiliptsov/Desktop/Grid/ChromeDriver/chromedriver");
}
if (browser.equalsIgnoreCase("firefox")) {
caps = DesiredCapabilities.firefox();
System.setProperty("webdriver.gecko.driver","/Users/antonfiliptsov/Desktop/Grid/Firefox/geckodriver");
}
if (browser.equalsIgnoreCase("safari")){
caps = DesiredCapabilities.safari();
}
// Version
caps.setVersion(version);
driver = new RemoteWebDriver(new URL(nodeURL), caps);
// Maximize the browser's window
// driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Open the Application
driver.get(url);
return driver;
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
Here is my TestNG File
<suite name="TestSuite" parallel="tests">
<test name="FireFox Test">
<parameters>
<parameter name="platform" value="MAC" />
<parameter name="browser" value="firefox" />
<parameter name="version" value="50.1.0" />
<parameter name="url" value="https://google.com" />
</parameters>
<classes>
<class name="com.test">
</class>
</classes>
</test>
<test name="Chrome Test">
<parameters>
<parameter name="platform" value="MAC" />
<parameter name="browser" value="chrome" />
<parameter name="version" value="55.0.2883.87" />
<parameter name="url" value="https://google.com" />
</parameters>
<classes>
<class name="com.test">
</class>
</classes>
</test>
<test name="Chrome Test 1">
<parameters>
<parameter name="platform" value="MAC" />
<parameter name="browser" value="chrome" />
<parameter name="version" value="55.0.2883.87" />
<parameter name="url" value="https://google.com" />
</parameters>
<classes>
<class name="com.test">
</class>
</classes>
</test>
</suite>
In my test i have String nodeURL = "http://10.11.161.249:5555/wd/hub"; Which points my test for specific node, but how i can set up test pointing to to different node, or running parallel on 2 nodes?
Upvotes: 0
Views: 1869
Reputation: 14736
The Grid is designed to perform the below roles :
So you should be pointing your tests to run only against the HUB URL and not against the node URL. The Grid will take care of distributing the tests to the nodes based on the capability matching.
The error
org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{browserName=firefox, version=55.0.2883.87, platform=ANY}]
is basically the Grid's way of telling you that, you requested for a firefox
browser flavour with its version as 55.0.2883.87
running on any platform, but the grid does not have any nodes registered to it that have this capability.
This is rightly so, because your node configuration JSON does not specify version for firefox.
{
"capabilities": [
{
"browserName": "firefox",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "safari",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://192.168.1.115:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets": [
],
"withoutServlets": [
],
"custom": {
}
}
To fix this problem, either
caps.setVersion(version);
from your setup()
method (or)Consolidating my responses as an answer.
Upvotes: 1