问题描述
我在 ubuntu 服务器中运行 selenium 测试用例,该服务器基本上在 firefox 和 chrome 中运行测试用例.Firefox 启动和测试用例运行成功但 chrome 抛出异常:
I am running selenium test cases in a ubuntu server which basically runs testcases in both firefox and chrome. Firefox launches and test cases run successfully but chrome throws exception:
*****下面是堆栈跟踪的片段:*****
*****below is the snippet of the stacktrace:*****
在端口 21549 上启动 ChromeDriver (v2.8.240825)
Starting ChromeDriver (v2.8.240825) on port 21549
PAC 支持被禁用,因为没有系统实现
PAC support disabled because there is no system implementation
测试 IntegrationTest.AdminUserelementscheck 失败:
Test IntegrationTest.AdminUserelementscheck failed:
org.openqa.selenium.WebDriverException: chrome 无法访问(驱动信息:chromedriver=2.8.240825,platform=Linux 2.6.32-431.el6.x86_64 x86_64)(警告:服务器未提供任何堆栈跟踪信息)[错误] 命令持续时间或超时:20.83 秒
org.openqa.selenium.WebDriverException: chrome not reachable (Driver info: chromedriver=2.8.240825,platform=Linux 2.6.32-431.el6.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) [error] Command duration or timeout: 20.83 seconds
下面是我的代码的一小段:
Hi Below is the small snippet of my code :
public class IntegrationTest {
private static final String configFile="test.properties";
private final String FIREFOX="firefox";
private final String CHROME="chrome";
private final String PHANTOMJS="phantomjs";
private final String BROWSERNAME="browser";
private static Properties props = new Properties();
public WebDriver webDriver;
private static Configuration additionalConfigurations;
@BeforeClass
public static void setUp() throws IOException, SQLException{
props.load(IntegrationTest.class.getResourceAsStream("/" + configFile));
}
@test
public void AdminUserelementscheck() throws SQLException, IOException {
String[] browsers = props.getProperty(BROWSERNAME).split(",");
System.out.println("Number of browsers specified in conf:"+props.getProperty(BROWSERNAME));
for(String browser:browsers){
System.out.println("Browser currently processing:"+browser);
if(browser.equalsIgnoreCase(FIREFOX))
webDriver = new FirefoxDriver();
else if(browser.equalsIgnoreCase(CHROME))
webDriver = new ChromeDriver();
else
webDriver = new PhantomJSDriver();
running(testServer(3333,fakeApplication()),webDriver, new Callback<TestBrowser>() {
********* LOGIN AND ASSERTION STATMENTS*******************
browser.quit()
}
});
}
推荐答案
这是因为 Chrome 也在使用 unix 容器来运行.如果您希望它在 docker 中运行,请传递 docker run 命令
This would be because Chrome is also making use of unix containers in order to run. If you want this to run within docker, pass the docker run command
--特权
否则您可以使用
--无沙盒
这篇关于Webdriver 异常:“chrome 无法访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2