Feature request - a way to manage cookies #79

Closed
ahenobarbi opened this Issue Jun 15, 2011 · 12 comments

Projects

None yet

4 participants

@ahenobarbi

I'd like to write a feature to test if "Remember me" feature works properly. So I need to somehow remove cookies that have already expired. I believe it's not possible now. Could you add support for that?

@ahenobarbi

Something like ahenobarbi@52c4a21

@ahenobarbi ahenobarbi closed this Jun 15, 2011
@ahenobarbi ahenobarbi reopened this Jun 15, 2011
@jferris
Member
jferris commented Jun 21, 2011

I think you should be able to just reset the capybara session, right?

@ahenobarbi

I think that removes all cookies.

@ahenobarbi

Let me explain it once more in case first description was not detailed enough.
As I wrote need to test "Remember me" feature of my application. To do this I have scenarios:

  Scenario: Do not remember log in if "Remeber me" field was not checked
    Given example user
    When I am on the login page
    And I uncheck "remember_me"
    And I login as example user
    When I close browser
    And I am on the home page
    Then I should see "Login"

  Scenario: Remember log in if "Remeber me" field was checked
    Given example user
    When I am on the login page
    And I check "remember_me"
    And I login as example user
    When I close browser
    And I am on the home page
    Then I should see "Log out"

Now "When I close browser" is impossible to write with current capybara-webkit. I can reset capybara session but that will remove all cookies. But I need to remove session (and possibly expired) cookies and keep valid cookies. My patch allows that behavior (it keeps outdated cookies, but I can fix this if you want).

@jferris
Member
jferris commented Jul 8, 2011

I think clearing the session cookies could potentially be useful, so if you want to put together a pull request for that, I'd take a look. In order to take a patch, it would need specs as well as some kind of Ruby API to issue the command.

@janx
janx commented Jul 11, 2011

+1, facing the exactly same problem :)

@ahenobarbi

I wrote a commit

https://github.com/ahenobarbi/capybara-webkit/commit/d3793b7abe792e4a51c6a9cff66d9394280cdedc

but apparently it doesn't clear cookies, it crashes webkit_server. Do you know what's wrong?

@ahenobarbi ahenobarbi closed this Jul 16, 2011
@ahenobarbi ahenobarbi reopened this Jul 16, 2011
@jferris
Member
jferris commented Jul 20, 2011

I don't see anything obvious in your commit that would make it crash. Do you have a test that causes it to crash?

@ahenobarbi

Add this to spec

    it "has an empty page after removing session cookies" do
      subject.remove_session_cookies!
      subject.find("//*[contains(., 'hello')]").should be_empty
    end

and watch rake wait forever for line

      subject.remove_session_cookies!

to finish.

@ahenobarbi

Actually wehn I left only

void CleanableCookieJar::clean_session_cookies(){
  allCookies();
}

in method that removes cookies, all tests after test from previous comment fail.

@niklasb
Contributor
niklasb commented Sep 25, 2011

I implemented this and the functionality to set and enumerate cookies: #169

@jferris
Member
jferris commented Apr 4, 2012

I'm closing this, because I think it was resolved by #169. If that's not the case, please reopen.

@jferris jferris closed this Apr 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment