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

Optionally clear cookies during tearDown() #285

Closed
wants to merge 5 commits into from

Conversation

inxilpro
Copy link
Contributor

This is an alternate version of #268

Right now, an entire test class shares the same primary Browser instance (secondary instances are destroyed after a test, but the primary instance is only cleared after the entire test class has finished running). This means that separate tests that open sessions or set other cookies can influence each other.

This PR adds a clearCookies() method the Browser class, and adds a $clearCookiesBetweenTests property (defaulted to false) to Laravel\Dusk\TestCase that lets you configure dusk to clear cookies between tests.

This means that if you want your tests to run in a more isolated way, you can just set:

class ExampleTest extends DuskTestCase
{
    protected $clearCookiesBetweenTests = true;

    // ...
}

This should resolve issue #100.

@taylorotwell
Copy link
Member

I think I will just let people add this to their own tear down for now.

@HSPDev
Copy link

HSPDev commented Feb 7, 2018

We just hit this today. It was actually expected behaviour for us to have each test completely seperate. Otherwise you are relying on the order of the tests being run.

We have an account switching feature in our SaaS platform, and it proved to be a little buggy with its remains in the session. We had it higher up in our testcase, but a function being run after 5-6 other tests "blew up" because of that. It took ~2 hours to track the bug down because we thought the cookies got cleared and researched everything else; At least we got to know Laravel core even better. 😁

Please consider reopening this.

For the curious coming in from Google, we added this to our DuskTestCase.

public function tearDown()
{
    foreach (static::$browsers as $b) {
        $b->driver->manage()->deleteAllCookies();
    }
    parent::tearDown();
}

@dsandber
Copy link

dsandber commented Feb 28, 2018

I think most users assume regression tests will be independent of each other (since that is usually recommended). Not clearing the cookies violates this.

Please re-consider making the cookies get cleared by default, or if not, at least add an option to do it.

Thanks!

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.

4 participants