Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset cookies after browse closure completes #268

Closed
wants to merge 2 commits into from

Conversation

inxilpro
Copy link
Contributor

Right now, each call to browse() shares the same Browser instance, which means that tests that open sessions or set other cookies can influence each other. This adds a clearCookies() method the Browser class, and automatically calls it after the browse() closure completes. That way each test starts fresh. This should resolve issue #100.

@taylorotwell
Copy link
Member

That's the whole point of it staying open I believe. If you don't want that behavior you can start a fresh browser for each test.

@inxilpro
Copy link
Contributor Author

I don't think it's an obvious behavior or one that's consistent with typical testing where the expectation is that tests run in isolation. How would you feel about exposing it as an option on the Dusk test case? Looking at the issue I referenced, it doesn't look like I'm alone.

@ryancwalsh
Copy link

I have spent hours working on this. I'd love to know how to have just one test class that has 3 test cases... where Test 2 has a new browser started (separate from Test 1, so all cookies are cleared, etc), but then Test 3 continues using the same browser as Test 2. Is that possible? How?

Thanks @inxilpro and @taylorotwell . I have found your various Github conversations helpful (not to mention all of Laravel, which is mind-blowingly awesome).

@ryancwalsh
Copy link

I think this is working for me (a new utility method within my test class):

protected function clearCookies() {
    foreach (static::$browsers as $b) {
        Log::debug('browser=' . json_encode($b));
        Log::debug('cookies=' . json_encode($b->driver->manage()->getCookies()));
        $b->driver->manage()->deleteAllCookies(); //https://github.com/laravel/dusk/pull/285/files
        Log::debug('cookies=' . json_encode($b->driver->manage()->getCookies()));
    }
}

I still don't understand Webdriver and how there are multiple "browsers", but I think I'm making progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants