0
votes

using rspec with the default driver is working fine and all tests are passed.

changing driver: :webkit will have a bad side-effect.

  1. step: the user is logged in
  2. step: visiting root_path with a session (current_user)
  3. step: visiting root_path without a session (current_user = nil)

so either after the first visit root_path or before the second, the session is killed or whatever - we can't get the user to stay logged in.

test looks like this

scenario 'something', driver: :webkit do
  user = FactoryGirl.create :user
  login_as(user)
  visit root_path
  visit root_path
end

is this a known bug? are there any workarounds or are we missing something ?


as requested:

 def login_as(user)
    visit root_path
    click_on "Login"
    fill_in "user[login]", with: user.username
    fill_in "user[password]", with: user.password
    click_on "Sign in"
  end
2
How are you implementing login_as? - Thomas Walpole
i edited my question - Tim Kretschmer
How do you know the login is actually working? There's no check anywhere in the code you're showing that after the visits they have any specific content on them? It's possible you're actually triggering the visit root_path before the submit for login has even occurred, which would cancel the login. Try adding something like expect(page).to have_content('You are now logged in') (or whatever text would be shown after a successful login) after the login_as step (or as the last step of the login_as method) - Thomas Walpole
well, defenitely logged in. if i call visit root_path the first time and then say save_and_opeÇıim defenitely logged in. also the login-specs (using exactly the same method and then expecting some code on the page to make sure the login is working) is green. as i said before, with the default webdriver all tests are green. if we switch to webkit, they are losing session/or/cookie - Tim Kretschmer
The default driver runs everything synchronously --- drivers that use real browsers and support javascript do not necessarily do things synchronously - so it's possible in drivers other than rack-test for click_on 'Sign in' to return immediately. Therefore if you're not checking for content that would be seen on success the next visit root_path can get executed immediately and cancel the submission of the login form. If that is not happening then the only place (given your sample code) that can be logging the user out is your own app - Thomas Walpole

2 Answers

1
votes

The default driver runs everything synchronously --- drivers that use real browsers and support javascript do not necessarily do things synchronously - so it's possible in drivers other than rack-test for click_on 'Sign in' to return immediately. Therefore if you're not checking for content that would be seen on success the next visit root_path can get executed immediately and cancel the submission of the login form. To fix that add something like

expect(page).to have_content('You are now logged in') # whatever text is shown on a successful login

as the last line of your login_as method. This is not normally an issue for most people, because after logging in the next step is usually to click on something on the page, which will make Capybara wait for that item to appear thereby waiting for the login to complete.

If that is not what is happening here then the only place (given your sample code) that can be logging the user out is your own app

0
votes

if you are deleting the session after the first visit, it is expected that the user logout.

Does visiting without session means that visiting the page as anonymous?