使用 Watir/Selenium 自动测试时绕过 NTLM 身份验证

Bypass NTLM auth when using Watir/Selenium to automate testing

我了解到 Watir 和 Selenium 在尝试登录网页进行测试时遇到 NTLM 身份验证问题。我的研究表明有两种正常的解决方法。 1. 将凭据添加到 URL 2. 使用自动身份验证 plugin/extension。我目前没有在我的环境中使用扩展的选项,尽管我正在努力。所以,我只剩下通过凭证了。

我遇到的问题如下。

Chrome: 在 Chrome 中,我手动传递凭据(就像我直接将其输入浏览器一样)作为 http://password:user@example.com/ and it opens the page, but does not populate the popup. If I try to manually pass it as http://example.com?username=usr&password=password,它会填充身份验证弹出窗口但不会继续。

如果我尝试使用以下代码通过 ruby 实现自动化,我得到的只是未知的用户名和密码。我确认usr和pwd是正确的。

browser.goto("http://example.com?login=usr&password=password") browser.goto("http://password:usr@example.com/")

浏览器 IE 的行为有点不同。 在 IE 中,我手动将凭据作为 http://password:user@example.com/ and it returns an error that it can't find the page. If I try to manually pass it as http://example.com?username=usr&password=password 传递,它可以正确登录。

如果我尝试使用以下代码通过 ruby 实现自动化,第一个示例会抛出页面无法找到错误。第二个示例打开页面,但不填充弹出窗口。我确认usr和pwd是正确的

browser.goto("http://example.com?login=usr&password=password") browser.goto("http://password:usr@example.com/")

我做错了什么?

我的环境是 Windows 7 Pro,IE 11 和 Chrome 60。

发现一篇文章表明 MS 在 URL 中删除了身份验证。所以 pwd:usr@ 不起作用是有道理的。文章编号:834489

好的,我找到了答案。与我公司的高级架构师讨论后,无法通过设计访问 NTLM Windows 身份验证表单。它的字面设计使其无法以这种方式作为安全措施进行自动化。

他建议的一种解决身份验证问题的解决方法是使用 C#(我们的标准)之类的东西,并在假设用户已经登录的情况下打开浏览器。这将完全绕过授权弹出窗口使问题无效。我不清楚具体如何执行此操作,但我希望这为其他人提供了一个有用的方向。