Chrome 59和Selenium / Fluentlenium的基本身份validation

Chrome 59已取消对https:// user:password@example.comurl的支持 。

我有一个使用此function的测试,现在已经坏了,所以我试图用等待认证弹出窗口的版本替换它并填写详细信息。 但以下内容在Chrome上不起作用(它没有将auth弹出窗口视为警报):

alert().authenticateUsing(new UserAndPassword("test", "test")); 

仅限selenium的版本具有相同的问题:

 WebDriverWait wait = new WebDriverWait(getDriver(), 10); Alert alert = wait.until(ExpectedConditions.alertIsPresent()); alert.authenticateUsing(new UserAndPassword("test", "test")); 

(基于此处给出的答案: 如何使用Java处理Selenium WebDriver的身份validation弹出窗口 )

我可以看到在FireFox中处理此问题的几种解决方法,但Chrome没有。 有没有替代方法?

我确信Florent B的解决方案是可行的,但是为了改进旧的测试,我发现zoonabar的解决方案发布到这个重复的问题更容易实现,代码少得多,并且不需要对测试盒进行特殊准备。 对于查看代码的新开发人员来说,似乎也更容易理解。

简而言之:在访问受测试的URL(没有凭据)之前访问具有凭据的任何URL将导致浏览器记住凭据。

 goTo("http://user:password@localhost"); // Caches auth, but page itself is blocked goTo("http://localhost"); // Uses cached auth, page renders fine // Continue test as normal 

这可能感觉浏览器中的漏洞会被修补,但我认为这不太可能; 已经施加限制以避免网络钓鱼风险(选择的用户名看起来像域名,例如“ http://google.com:long-token-here-which-makes-the-real-domain-disappear@example.com / “),这种设置凭据的解决方法不会带来相同的风险。

见zoonabar的答案

一种解决方案是运行透明代理以使用所需凭据注入标头。

但另一个更简单的解决方案是创建一个小扩展来自动设置凭据:

https://gist.github.com/florentbr/25246cd9337cebc07e2bbb0b9bf0de46

在https://bugs.chromium.org/p/chromium/issues/detail?id=435547#c33中,您可以看到mkwst说有关于基本身份validation凭据的错误,并且相同的原始网站使其变得稳定。

如果您使用“–disable-blink-features = BlockCredentialedSubresources”或转到Chrome Canary版本,您可能会发现您看到的原始问题不再发生……

Florent B.在铬延伸的帮助下找到了一种解决方案,在selenium测试中即时添加。 如果需要,扩展将处理基本身份validation凭据:

 ChromeOptions options = new ChromeOptions(); options.addExtensions(new File("C:/path_to/credentials_extension.zip")); driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), options); 

Chrome扩展程序代码: https : //gist.github.com/florentbr/25246cd9337cebc07e2bbb0b9bf0de46
(只需修改background.js中的用户名和密码,然后将文件background.js和manifest.json压缩到credentials_extension.zip)

在此处找到: Selenium – 通过URL进行基本身份validation