HTTP basic auth for Capybara

后端 未结 6 995
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 00:06

I\'m writing some RSpec tests for my Rails 3 application and trying to switch from Webrat to Capybara. So far so good but the application uses HTTP basic auth to authorize m

6条回答
  •  感动是毒
    2020-12-05 01:01

    I had to do this horrible hack to get it work worth headless and with javascript

    Given /^I am logged in$/ do
     if page.driver.respond_to?(:basic_authorize)
       page.driver.basic_authorize('admin', 'password')
     else
       # FIXME for this to work you need to add pref("network.http.phishy-userpass-length", 255); to /Applications/Firefox.app/Contents/MacOS/defaults/pref/firefox.js
       page.driver.visit('/')
       page.driver.visit("http://admin:password@#{page.driver.current_url.gsub(/^http\:\/\//, '')}")
     end
    end
    

提交回复
热议问题