acceptDialog with laravel dusk

Published 3 months ago by fconstans


I am trying to test a functionality to disable/enable a resource. It detects correctly the dialog but acceptDialog() seems to not work correctly.

The test is like:

                ->resize(1440, 3000)
                ->visitRoute('route', ['id' => $id])
                ->assertDialogOpened('Are you sure you wish to activate/deactivate this resource?')

If I don't use the acceptDialog, an exception is raised -> Facebook\WebDriver\Exception\UnexpectedAlertOpenException

But using the acceptDialog seems like the dialog is dismissed instead of being accepted, because It stays on the same page ( notice the pause function to ensure enough time to change the page).

I get a screenshot of the page like the button was never clicked and the dialog accepted. Can't take an screenshoot when the dialog is displayed because I get an UnexpetedAlertOpenException.

The html code of the element with the state-resource id is:

<button style="display:inline" class="submit small text_only has_text" id="state-resource"  onclick="return confirm('Are you sure you wish to activate/deactivate this resource?')">

Somebody knows why this test doesn't work?


Your code looks correct! Do you use the latest version of Laravel Dusk?


I'm using the version 3.0.8 of laravel/dusk, looked at it and seems the last one.

Just upgraded chromium from 65.0.3325.181-0ubuntu1 to 66.0.3359.181-0ubuntu0.18.04.1 on the homestead machine, with the same result.

I don't know what else check or how I can debug this behaviour.


I can't find anything that might cause this... Maybe you can try to find out what's happening in the acceptDialog method and see what the alert object holds at that time!


I think the problem is with the form being submitted.

The button itself is inside a form with serveral data.

've changed it to use SweetAlert instead of native javascript confirm and the result is the same. Now I can make a screenshot and see the dialog displayed and 'accepted' (is no longer there when the test fails) but seems like the form is not submitted.

Works in both cases when there is 'human' interaction.

The log generated on console folder should show me any javascript errors no? Or I'm wrong?

I say this because this platform has a really old jQuery version and I have read that some instructions make dusk inject jQuery library so maybe is there some version conflict?


Finally... now the test works fine. Was an error on my side after disabling the resource and redirecting...

Now validating with pure javascript and with sweetalert.

Thank you @bobbybouwmann


Aah great! Glad you fixed it :D

Please sign in or create an account to participate in this conversation.