1
我的Ruby on Rails應用程序中有一項功能,該功能適用於從給定步驟中的消息「響應browser_basic_authorize」的消息。在添加@javascript標記時,黃瓜HTTP身份驗證失敗
但是,如果我在場景之前添加了@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,目前的寶石,和其他測試都通過。