添加@javascript标记时,Cucumber中的HTTP身份验证失败
我的RubyonRails应用程序中有一个功能,可以很好地处理从后台给定步骤响应浏览器\基本\授权的消息 但是,如果我在场景之前添加@javascript标记,那么我的背景将失败,因为我不知道如何登录 出了什么问题,如何在我的应用程序上测试JavaScript交互添加@javascript标记时,Cucumber中的HTTP身份验证失败,javascript,ruby-on-rails,cucumber,capybara,Javascript,Ruby On Rails,Cucumber,Capybara,我的RubyonRails应用程序中有一个功能,可以很好地处理从后台给定步骤响应浏览器\基本\授权的消息 但是,如果我在场景之前添加@javascript标记,那么我的背景将失败,因为我不知道如何登录 出了什么问题,如何在我的应用程序上测试JavaScript交互 Background: Given I perform HTTP authentication as "<id>/<password>" When I go to the homepage
Background:
Given I perform HTTP authentication as "<id>/<password>"
When I go to the homepage
Then I should see "Text-that-you-should-see-on-your-home-page"
Scenario: Displaying injury causative factors
Given I am on the new_incident_report page
When I choose "incident_report_employee_following_procedures_true"
Then I should see "Equipment failure?"
Then I should not see "Lack of training"
When /^I perform HTTP authentication as "([^\"]*)\/([^\"]*)"$/ do |username, password|
puts "id/pswd: #{username}/#{password}"
### Following works ONLY if performed first before even going to a page!!!
if page.driver.respond_to?(:basic_auth)
puts 'Responds to basic_auth'
page.driver.basic_auth(username, password)
elsif page.driver.respond_to?(:basic_authorize)
puts 'Responds to basic_authorize'
page.driver.basic_authorize(username, password)
elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize)
puts 'Responds to browser_basic_authorize'
page.driver.browser.basic_authorize(username, password)
else
raise "I don't know how to log in!"
end
end
我使用的是RubyonRails 3.0.9,当前的gems和其他测试都通过了。我假设您的@javascript驱动程序是Selenium,因为这是默认的。中给出的关于基本身份验证的建议是在URL中提供用户名和密码,例如。http://user:pass@myexample.com/blah
我还没有找到一个明确的答案,但似乎Capybara使用的Selenium Webdriver不支持访问或修改HTTP头,因此在URL中提供此信息可能是唯一的方法