HTTP basic auth for Capybara

后端 未结 6 993
伪装坚强ぢ
伪装坚强ぢ 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:08

    I got it to work using page.driver.basic_authorize(name, password) instead

    Update:

    At the moment, after a Capybara upgrade, I'm using this pile of workarounds:

    if page.driver.respond_to?(:basic_auth)
      page.driver.basic_auth(name, password)
    elsif page.driver.respond_to?(:basic_authorize)
      page.driver.basic_authorize(name, password)
    elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize)
      page.driver.browser.basic_authorize(name, password)
    else
      raise "I don't know how to log in!"
    end
    

提交回复
热议问题