1

Ruby on Railsアプリケーションには、バックグラウンドで指定された手順から「Respondstobrowser_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

私はRubyonRails 3.0.9を使用していますが、現在のgem、およびその他のテストに合格しています。

4

1 に答える 1

0

I presume that your @javascript driver 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.

于 2012-08-29T21:37:15.803 に答える