http authentication fails in cucumber when adding @javascript tag

Posted by JESii on Stack Overflow See other posts from Stack Overflow or by JESii
Published on 2012-08-29T14:51:18Z Indexed on 2012/08/29 21:38 UTC
Read the original article Hit count: 224

I have a feature in my Rials app 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 javascrpt interactions on my app?

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

Rails 3.0.9, current gems, other tests passing.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ruby-on-rails