【发布时间】:2021-12-27 10:50:32
【问题描述】:
我正在 selenium 独立 chrome 调试 docker 容器上使用 TestNG 执行 Selenium 测试。
以下是用于实例化远程 Web 驱动程序的 Selenium 代码:
ChromeOptions co = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4445"), co);
下面是启动容器的 docker 代码:
docker run --name chromecontainer -d -p 4445:4444 -p 5901:5900 --shm-size="2g" selenium/standalone-chrome-debug:latest
它正在跳过测试并抛出以下错误:
FAILED CONFIGURATION: @BeforeMethod bmeth(org.testng.TestRunner@fcdb78, org.testng.xml.XmlTest@769036db, public void testing.TC_005.vabc() throws java.lang.Exception, [], [TestResult name={null} status=CREATED method=TC_005.vabc()[pri:0, instance:testing.TC_005@1e3708] output={null}])
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>
<link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />
<script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="/assets/displayhelpservlet.js" type="text/javascript"></script>
<script type="text/javascript">
var json = Object.freeze('{"consoleLink": "\u002fwd\u002fhub","type": "Standalone","class": "org.openqa.grid.web.servlet.DisplayHelpHandler$DisplayHelpServletConfig","version": "3.141.59"}');
</script>
</head>
<body>
Caused by: org.openqa.selenium.json.JsonException: Unable to parse: <!DOCTYPE html>
Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: <. Last 1 characters read: <
但是如果我在远程 url 中添加/wd/hub,那么测试运行正常。
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4445/wd/hub"), co);
我试图搜索它的原因,但找不到。
如果我们不添加 /wd/hub,任何人都可以解释为什么它会抛出错误,因为根据 Selenium doc https://github.com/SeleniumHQ/docker-selenium#quick-start,它提到它不再需要?
【问题讨论】:
标签: docker selenium-webdriver selenium-grid