Skip to content

Instantly share code, notes, and snippets.

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

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

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

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

Copy link


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