1
votes

I am using watir-webdriver with cucumber and ruby to build up automated regression tests for a website. Cucumber and watir-webdriver are outside of the rails application that is used for the actual site. To get my tests to run on Jenkins, I would like to start to use phantomjs to run the tests headlessly. In order to access the the pre-production environments of the website, I need to get past the site's basic authentication.

The issue I am running in to is: when phantomjs attempts to access an external URL that has basic auth, it is getting hung up and not getting past the basic auth username/password.

Any thoughts on how to get phantomjs to recognize a URL like the following:

https://admin:[email protected]"

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:[email protected]"

Running cucumber:

cucumber -p website BROWSER=phantomjs

The result:

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

1 Answers

2
votes
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'