使用PhantomJS的Watir-Webdriver可以访问具有基本身份验证的外部URL吗?

时间:2013-07-24 21:03:22

标签: ruby phantomjs watir-webdriver

我正在使用带黄瓜和红宝石的watir-webdriver为网站建立自动回归测试。 Cucumber和watir-webdriver不在用于实际站点的rails应用程序之外。为了让我的测试在Jenkins上运行,我想开始使用phantomjs无头地运行测试。为了访问网站的预生产环境,我需要通过网站的基本身份验证。

我遇到的问题是:当phantomjs尝试访问具有基本身份验证的外部URL时,它会挂起并且没有超过基本身份验证用户名/密码。

有关如何让phantomjs识别以下URL的任何想法:

https://admin:password@test.website.com"

env.rb:

BASE_URL = Configuration["base_url"]
require "watir-webdriver"

case ENV['BROWSER']
  when 'chrome'
    profile = Selenium::WebDriver::Chrome::Profile.new
    browser = Watir::Browser.new :chrome, :profile => profile
  when 'firefox'
    profile = Selenium::WebDriver::Firefox::Profile.new
    browser = Watir::Browser.new :firefox, :profile => profile
  when 'phantomjs'
    browser = Watir::Browser.new :phantomjs
  end
end

config.yml

website:
    base_url: "https://admin:password@test.website.com"

运行黄瓜:

cucumber -p website BROWSER=phantomjs

结果:

Scenario: User Logs In
    Given a logged out user
    timed out after 30 seconds, waiting for {foobar...}

1 个答案:

答案 0 :(得分:2)

caps = { 'phantomjs.page.settings.userName' => 'admin', 'phantomjs.page.settings.password' => 'password' }
driver = Selenium::WebDriver.for(:phantomjs, :desired_capabilites => caps)
browser = Watir::Browser.new(driver)
browser.goto 'https://test.website.com'