因此,我有一台装有Windows 10 Pro的PC,并且通过VMWare工作站将虚拟Windows 10 Pro安装在同一台PC上,虚拟OS中的网络适配器模式设置为“ NAT”。
我在真实操作系统(hub)上运行此命令:
java -jar selenium-server-standalone-3.141.59.jar -role hub
在虚拟OS(节点)上的此命令:
java -jar selenium-server-standalone-3.141.59.jar -role node -nodeConfig nodeconfig.json
nodeconfig.json包含以下内容:
{
"capabilities":
[
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": -1,
"register": true,
"registerCycle": 5000,
"hub": "http://192.168.116.1:4444/grid/register/",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
该节点已成功连接到集线器,但是现在如何开始实际测试? 我在集线器上有带有网页和测试逻辑的项目,但是从那里启动Selenium Server之后,我无法在控制台中键入任何内容,还是应该使用新的cmd窗口?还是应该在节点的cmd中运行“ MVN测试”?并且我应该以某种方式更改我的代码,例如使用RemoteWebDriver而不是ChromeDriver或诸如此类的smth吗?我只是停留在那部分...
更新: 已解决的有效代码:
public class AmazonSearchTest {
public static WebDriver driver;
public static AmazonMainPage amazonMainPage;
public static AmazonSearchResultsPage amazonSearchResultsPage;
@BeforeClass
@Parameters("browser")
public void setup(String browser) throws Exception {
URL server = new URL("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("chrome");
System.out.println("Connecting to " + server);
//Check if parameter passed from TestNG is 'Firefox'
if (browser.equalsIgnoreCase("firefox")) {
//create firefox instance
System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\geckodriver-v0.23.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
//Check if parameter passed as 'Chrome'
else if (browser.equalsIgnoreCase("chrome")) {
//create chrome instance
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver_win32\\chromedriver.exe");
driver = new RemoteWebDriver(server, capabilities);
}
//Check if parameter passed as 'Edge'
else if (browser.equalsIgnoreCase("edge")) {
//create edge instance
System.setProperty("webdriver.edge.driver", "C:\\Program Files\\MicrosoftWebDriver\\MicrosoftWebDriver.exe");
driver = new EdgeDriver();
} else {
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
amazonMainPage = new AmazonMainPage(driver);
amazonSearchResultsPage = new AmazonSearchResultsPage(driver);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.amazon.com");
}
@Test
@Parameters({"searchQuery", "bookToSearch"})
public void searchTest(String searchQuery, String bookToSearch) {
amazonMainPage.inputQuery(searchQuery);
amazonMainPage.clickSearchButton();
amazonSearchResultsPage.getBooksInfo();
amazonSearchResultsPage.checkBookAvailable(bookToSearch);
}
@AfterClass
public static void tearDown() {
driver.quit();
}
}
这是节点的连接线的样子:
D:\Install>java -Dwebdriver.chrome.driver="C:\Program Files\chromedriver_win32\chromedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role node -nodeConfig nodeconfig.json