Selenium 无法连接到 Mac 上的 ChromeDriver 75

我们正在将以前工作的Selenium/Java/Chrome 测试配置升级到更新版本:


ChromeDriver           2.35 -> 75.0.3770.90

Selenium Java          3.14 -> 3.141.59


macOS                  10.14.5       (unchanged)

Java                   11.0.3        (unchanged)

Chrome                 75.0.3770.100 (unchanged)

然而,当尝试运行 Selenium 测试时,我们看到:


java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719

完整的堆栈/日志:


Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}) on port 28719

Only local connections are allowed.

Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

Jun 26, 2019 10:45:03 AM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C



...



org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

System info: host: 'Craigs-iMac.local', ip: '192.168.1.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '11.0.3'

Driver info: driver.version: RemoteWebDriver


    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)

    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)

    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)

    at org.openqa.selenium.remote.RemoteWebDriver.findElementByTagName(RemoteWebDriver.java:396)

    at org.openqa.selenium.By$ByTagName.findElement(By.java:320)

我在这方面找到的所有资源都建议使用--whitelisted-ips='',这没有效果,或者与不兼容的Selenium/Chrome/ChromeDriver 版本有关,我认为这不是这里的问题。


更新:我可以确认驱动程序已启动,并且正在侦听端口28719,但随后会在启动和实际测试执行之间的某个时刻停止。我没有发现与关机相关的错误/日志记录。


更新 2:我已经调试过了,发送到远程驱动程序的初始命令成功了(setWindowSize()),但是这一行导致驱动程序静默死去:


((WebStorage) driver).getLocalStorage().setItem("token", token);


尚方宝剑之说
浏览 198回答 2
2回答

慕哥9229398

似乎较新版本的 ChromeDriver(或 Selenium?我不知道。)启动 Chrome,初始页面位于 URL 处data:。通过在实例化之前添加这些系统属性ChromeDriver:System.setProperty("webdriver.chrome.logfile", "/Users/craig/chromedriver.log");System.setProperty("webdriver.chrome.verboseLogging", "true");在司机退出之前,我能够收集到以下信息:[1561563455.971][INFO]: [01517094c63c0dd609c06a5622afe6b1] RESPONSE ExecuteScript ERROR <unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.&nbsp; (Session info: headless chrome=75.0.3770.100)因此,通过在我的测试实用程序代码中更改此调用:((WebStorage) driver).getLocalStorage().setItem("token", token);对此:if (driver.getCurrentUrl().startsWith("data:")) {&nbsp; &nbsp; // Driver will quit if we try to access localStorage without a page load&nbsp; &nbsp; driver.get("/");}((WebStorage) driver).getLocalStorage().setItem("token", token);现在一切都很好。https://i.imgur.com/edBQBeJ.gif

UYOU

编辑:LocalStorage 仅在启动任何网站后可用。即在 driver.get 之后https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/html5/LocalStorage.html
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java