我们正在将以前有效的 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);
答案 0 :(得分:0)
似乎新版本的ChromeDriver(我不知道是Sem还是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.
(Session info: headless chrome=75.0.3770.100)
因此,通过在我的测试实用程序代码中更改此调用:
((WebStorage) driver).getLocalStorage().setItem("token", token);
对此:
if (driver.getCurrentUrl().startsWith("data:")) {
// Driver will quit if we try to access localStorage without a page load
driver.get("/");
}
((WebStorage) driver).getLocalStorage().setItem("token", token);
现在一切都很好。 https://i.imgur.com/edBQBeJ.gif
答案 1 :(得分:-1)
编辑:
LocalStorage仅在启动任何网站后可用。即在driver.get之后
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/html5/LocalStorage.html