运行 PhantomJS 和 Chrome 浏览器在同一 Selenium 网格节点上
Run PhantomJS and Chrome browser on the same Selenium grid node
我有一个 Selenium 网格集群,包括 1 个集线器和多个节点。我想 运行 在所有节点上 Chrome 的多个实例和 PhantomJS 的多个实例。
我有以下节点配置文件:
{
"capabilities":
[
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "phantomjs",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
到运行节点,我用:
java -Dphantomjs.binary.path="ghostdriver" -Dwebdriver.chrome.driver=chromedriver -Dwebdriver.gecko.driver=geckodriver -jar selenium-server-standalone-3.8.1.jar -role node -hub http://{myIp}:4444/grid/register/ -nodeConfig "/Users/myUser/Desktop/selenium/nodeConfig.json"
我正在成功连接到 Chrome 远程驱动程序:
String hubURL = "http://localhost:4444/wd/hub";
ChromeOptions chromeOptions = new ChromeOptions();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);
但是,当尝试连接到 PhantomJS 远程驱动程序时,我仍然得到具有 chrome 功能的 Chrome 浏览器:
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
DesiredCapabilities capabilities = new DesiredCapabilities();
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);
从网格控制台我可以看到所有浏览器都可用(包括 PhantomJS)grid console
我做错了什么??
编辑:
问题是在 Selenium 服务器版本 3.7.1 之前支持 PhantomJS
虽然您已经为 PhantomJS
定义了 capabilities
,如下所示;
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
但是当 new RemoteWebDriver(new URL(hubURL), capabilities);
被调用时,我没有看到那些 capabilities
被传递,因为 DesiredCapabilities capabilities
是在稍后阶段定义的。你能试试这个代码块吗:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);
我有一个 Selenium 网格集群,包括 1 个集线器和多个节点。我想 运行 在所有节点上 Chrome 的多个实例和 PhantomJS 的多个实例。
我有以下节点配置文件:
{
"capabilities":
[
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "phantomjs",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
到运行节点,我用:
java -Dphantomjs.binary.path="ghostdriver" -Dwebdriver.chrome.driver=chromedriver -Dwebdriver.gecko.driver=geckodriver -jar selenium-server-standalone-3.8.1.jar -role node -hub http://{myIp}:4444/grid/register/ -nodeConfig "/Users/myUser/Desktop/selenium/nodeConfig.json"
我正在成功连接到 Chrome 远程驱动程序:
String hubURL = "http://localhost:4444/wd/hub";
ChromeOptions chromeOptions = new ChromeOptions();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);
但是,当尝试连接到 PhantomJS 远程驱动程序时,我仍然得到具有 chrome 功能的 Chrome 浏览器:
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
DesiredCapabilities capabilities = new DesiredCapabilities();
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);
从网格控制台我可以看到所有浏览器都可用(包括 PhantomJS)grid console
我做错了什么??
编辑:
问题是在 Selenium 服务器版本 3.7.1 之前支持 PhantomJS
虽然您已经为 PhantomJS
定义了 capabilities
,如下所示;
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
但是当 new RemoteWebDriver(new URL(hubURL), capabilities);
被调用时,我没有看到那些 capabilities
被传递,因为 DesiredCapabilities capabilities
是在稍后阶段定义的。你能试试这个代码块吗:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);