Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Laravel Dusk macro that waits for a page change
<?php
// Define in some ServiceProvider
Browser::macro('waitForReload', function () {
$this->script("window.duskPageIsStale = {}");
return $this->waitUntil("return typeof window.duskPageIsStale === 'undefined';");
});
// Usage:
->click('button')
->waitForReload()
->assertSee('Something on new page')
@joelharkes
Copy link

joelharkes commented Sep 25, 2019

little improve, execute a script or click inside the callback which expects to reload page:

    public function waitForNavigation($callable)
    {
        $this->driver->executeScript('window.oldPageStillIn = {}');
        $callable();

        return $this->waitUntil("return typeof window.oldPageStillIn === 'undefined';");
    }

@calebporzio
Copy link
Author

calebporzio commented Oct 3, 2019

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment