我在我的 Ruby on Rails 应用程序中有一个功能,可以很好地处理来自后台给定步骤的消息“响应 browser_basic_authorize”。
但是,如果我在场景之前添加一个@javascript 标记,那么我给出的背景会因“我不知道如何登录”而失败。
出了什么问题,如何在我的应用程序上测试 JavaScript 交互?
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
我正在使用 Ruby on Rails 3.0.9,当前的 gems 和其他测试正在通过。