Java 如何在Docker for Windows上运行selenium测试
关于使用Docker运行Selenium脚本,我已经开始向测试人员发出我的诅咒。所有这些都很简单,显然很简单,但是应该在预构建容器Selenium standalone和Chrome或Firefox中运行的脚本都失败了…: 剧本:Java 如何在Docker for Windows上运行selenium测试,java,windows,selenium,docker,Java,Windows,Selenium,Docker,关于使用Docker运行Selenium脚本,我已经开始向测试人员发出我的诅咒。所有这些都很简单,显然很简单,但是应该在预构建容器Selenium standalone和Chrome或Firefox中运行的脚本都失败了…: 剧本: package docker; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.chrome.ChromeOptions; import
package docker;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class DockerWithChrome {
public static void main(String args[]) throws MalformedURLException {
ChromeOptions cap = new ChromeOptions();
cap.setHeadless(true);
//cap.setCapability(CapabilityType.BROWSER_NAME,"Chrome" );
RemoteWebDriver driver;
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver.get("https://opensource-demo.orangehrmlive.com/");
System.out.println("Title of the Home page:" + driver.getTitle());
driver.quit();
}
}`
结果是:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
"desiredCapabilities": {
"browserName": "chrome",
"server:CONFIG_UUID": "30eb3a22-af38-4fa4-9698-8cef0b36ea4c",
"goog:chromeOptions": {
"args": [
"--headless",
"--disable-gpu"
],
"extensions": [
]
}
},
"capabilities": {
"firstMatch": [
{
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
"--headless",
"--disable-gpu"
],
"extensions": [
]
},
"server:CONFIG_UUID": "30eb3a22-af38-4fa4-9698-8cef0b36ea4c"
}
]
}
}
在Chrome和Firefox上也是如此。
我是一个使用Docker的初学者,到目前为止,如果我不能运行Selenium测试,对我来说是无用的。。。请指教
操作系统是:Microsoft Windows 10企业版10.0.17763构建17763
Raluca您可能希望共享一份小型回购协议和您的Dockerfile,以便重新创建您的问题。Dockerfile内容: