我的2个不同节点上的selenium网格中有2个测试。运行MAC的节点之一,另一个WIN。
当我在TestNG中指定时,运行两个测试 (例如,我想启动仅限Win Chrome测试和仅测试MAC FF。)
随机启动它们,有时mac会再次获得FF镀铬,或者如果win取消,它将在mac上启动两个测试。
当我在测试中指定时
<parameter name="platform" value="WINDOWS" />
它可以在mac上启动此测试,反之亦然。
这是我的TestNG文件:
<suite name="TestSuite" parallel="tests">
<test name="win chrome test">
<parameters>
<parameter name="platform" value="WINDOWS" />
<parameter name="browser" value="chrome" />
<parameter name="version" value="55.0" />
<parameter name="url" value="https://google.com" />
</parameters>
<classes>
<class name="com.ParallelTest.CreateRandomProfileTest"/>
<class name="com.ParallelTest.LogInTest">
</class>
</classes>
</test>
<test name="mac 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.ParallelTest.CreateRandomProfileTest"/>
<class name="com.ParallelTest.LogInTest">
</class>
</classes>
</test>
</suite>
这是我的网格设置文件:
package com.parallelSetUp;
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;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class Framework{
String browser;
protected WebDriver driver;
@Parameters({ "platform","browser","version", "url" })
@BeforeClass(alwaysRun=true)
public void setup(String platform, String browser, String
version, String url) throws MalformedURLException
{
this.browser = browser;
driver = getDriverInstance(platform, browser, version, url);
}
public static WebDriver getDriverInstance(String platform, String browser, String version, String url)
throws MalformedURLException {
String nodeURL = "http://192.168.1.115:4444/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);
}
if (platform.equalsIgnoreCase("ANDROID")) {
caps.setPlatform(Platform.ANDROID);
}
// Browsers
if (browser.equalsIgnoreCase("chrome")) {
caps = DesiredCapabilities.chrome();
//System.setProperty("webdriver.chrome.driver", "/Users/antonfiliptsov/Desktop/Grid/Chrome/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();
}
}
这是我的Node.json
{
"capabilities":
[
{
"browserName": "firefox",
"maxInstances": 5,
"version": "50.1.0",
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"version": "55.0",
"seleniumProtocol": "WebDriver"
},
{
"browserName": "safari",
"maxInstances": 1,
"version": "10.0.2",
"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": {}
}
答案 0 :(得分:0)
首先,您应该确保节点在启动它们之后具有哪些功能并与集线器连接,请在集线器上的http://localhost:{port}/grid/console
处查看。节点匹配中考虑的功能是 PLATFORM , BROWSER_NAME , VERSION , BROWSER_VERSION 和 APPLICATION_NAME
之后,您可以确定您的网格节点是如何匹配的,如果它不足以满足您的需求,您可以扩展DefaultCapabilityMatcher类并添加自己的匹配器(我几周前做过,添加了我的自定义参数,以确保它的行为符合我的要求)。 如果您决定扩展默认匹配器,This link将是一个良好的开端。