如何使用 ruby、page-object 和 watir-webdriver 输入需要弹出的身份验证数据

How to enter data for authentication required pop up using ruby, page-object and watir-webdriver

我觉得我的问题有一个简单的解决方案(虽然我无法通过研究找到相关的答案)。我正在使用 RubyMine ruby 2.0.0 进行自动化测试,主要使用 watir-webdriver 0.6.4 和页面对象 0.9.4 gems。

当 Ruby 打开我正在测试的站点时。在页面加载之前,会显示一个需要身份验证的弹出框。它说,"The server http://example.com:80 requires a username and password. The server says: Authentication Required." 我无法将它作为一个元素进行检查,因此我不知道如何与它交互。我一直通过手动输入用户名和密码来绕过这个问题。

我认为只需填写字段并单击“登录”而不是存储 cookie 会更容易,但你们最清楚。

您可以通过 URL 传递身份验证凭据,这将绕过该对话框。 http://watirwebdriver.com/basic-browser-authentication/:

上有一个例子
require 'watir-webdriver'
b = Watir::Browser.start 'http://admin:password@yourwebsite.com'
b.goto 'https://admin:password@yourwebsite.com/cart'  # replace 'cart' as appropriate