小编典典

Chrome 59和带有selenium/ F的基本身份验证

selenium

Chrome 59 删除了对https:// user:password@example.com
URL的支持。

我有一个正在使用此功能的测试,该功能现已损坏,因此我尝试将其替换为等待身份验证弹出窗口并填写详细信息的版本。但是以下操作在Chrome上不起作用(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"));

我可以在FireFox中看到几种解决方法,但对于Chrome则看不到。是否有其他替代方法?


阅读 354

收藏
2020-06-26

共1个答案

小编典典

我确信FlorentB的解决方案是可行的,但是为了翻新旧测试,我发现发布到此重复问题的
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 / “),此设置凭据的解决方法不会带来相同的风险。

2020-06-26