我正在尝试并行运行 selenium,但我遇到了一些重大问题。我遇到的一个主要问题是,WebDriver 将所有值发送到一个浏览器,然后另一次它将首先运行正常进行测试,然后第二次测试它不会发送任何值,然后另一个测试可能会在打开时挂起。 我已经看到人们让它在 YouTube 上完美运行,甚至认为我已经尝试了我能想到的一切,它从来没有像我这样工作过。 我知道端口可以作为参数传入,我以前有过这个,但我认为它不是强制性的。
以下是我如何从集线器/节点设置开始进行所有设置...
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
我的xml文件
<?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>
这是我调用 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) {
}
}
}
}
我也试过 switch 语句
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;
}
非常感谢任何帮助实现此工作的帮助。
最佳答案
这是链接 Selenium Grid使用 Grid 设置和执行 selenium 测试套件。
我之前照着做了,成功执行了。
关于java - Selenium Grid 将值并行发送到一个浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32139022/