Kiskot, kurkku, Capybara: istunto ei jatku

original title: "Rails, Cucumber, Capybara: session is not persisted"


I'm trying to write a test for a feature that relies on some session stored data and my scenario looks like this:

Scenario: Create offer
  Given I am on the start offer page
  When I select "Foo" from "bar"
  And I press "Go on"
  Then I should see "You are going to offer foo"

By using the debugger I found out, that the information is stored in the session correctly, but on every new request I get a fresh session.

Should'nt there be a working session for at least every scenario? Any ideas why this isn't the case?

Thanks in advance, Joe

Versions: Running on rails 2.3.10, cucumber 0.10.0, cucumber-rails 0.3.2, capybara

Yritän kirjoittaa testin ominaisuudelle, joka perustuu joihinkin istunnon tallennettuihin tietoihin, ja skenaarioni näyttää tältä: Skenaario: Luo tarjous Koska olen aloitustarjoussivulla ...

Tämä on yhteenveto käännöksen jälkeen. Jos haluat tarkastella koko käännöstä, napsauta käännä-kuvaketta

Kaikki vastaukset
  • Translate

    We had the problem with loosing the session due to capybara switching the host name in mid-test. The scenario was something like the following:

    # Good
    When I visit some page
    # will call 'http://capybarawhatever/some_page
    And I click the the button
    # will call 'http://capybarawhatever/some_new_page'
    Then I still have the session
    # Failing
    When I visit some page
    # will call 'http://capybarawhatever/some_page'
    And I do something that redirects me to ""
    And I visit some page
    # No this may go to '
    Then I have lost my session

    This may be worth investigating. You can get the current_url in your session, and you may set a new host for capybara using host! ''

  • Translate

    Some of the drivers don't have a clear way of setting cookies. This is a hacky workaround until they are sorted out:

      def set_cookie(name, value, domain)
        driver = Capybara.current_session.driver rescue nil
        return unless driver
        case driver
        when Capybara::Driver::RackTest
          driver.set_cookie "#{name}=#{value}"
        when Capybara::Driver::Selenium
          visit '/' # must visit the domain before we can set the cookie
          br = driver.browser.send(:bridge)
            'name'    => name,
            'domain'  => domain,
            'value'   => value,
            'path'    => '/',
            'expires' => ( + 100.years).to_i
          raise "Unsupported driver #{driver}"

  • Translate

    Possibly this bug?