I have a feature in my Ruby on Rails application that works just fine with the message “Responds to browser_basic_authorize” from the background given step.
However, if I add a @javascript tag before the scenario, then my background given fails with “I don’t know how to login”.
What’s going wrong, and how do I go about testing JavaScript interactions on my application?
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
I am using Ruby on Rails 3.0.9, current gems, and other tests are passing.
I presume that your
@javascriptdriver is Selenium as that is the default. The advice given in the Selenium Core FAQ regarding basic authentication is to supply the username and password in the URL e.g.http://user:pass@myexample.com/blah.I haven’t been able to find a definitive answer, but it appears that Selenium Webdriver (as used by Capybara), doesn’t support accessing or modifying HTTP headers, so supplying this information in the URL is probably the only way.