laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.88k stars 324 forks source link

UnexpectedAlertOpenException: unexpected alert open: {Alert text : Are you sure?} #66

Closed beliolfa closed 6 years ago

beliolfa commented 7 years ago

I am getting this exception when I click the delete button

How could I expect a confirm alert in screen and then press OK?

andremellow commented 7 years ago

You can use $browser->acceptDialog();

deleugpn commented 7 years ago

Can this be closed?

purefun commented 7 years ago

$browser->dismissDialog() = press Cancel (if confirmation) $browser->acceptDialog() = press OK

greatwitenorth commented 7 years ago

I have something like this:

$this->browse(function (Browser $browser) {
            $browser->visit('/')
                ->type('name', 'Jonh')
                ->type('email', '')
                ->type('phone', '555-555-5555')
                ->click('.btn-next')
                ->assertDialogOpened("Email is required");
        });

When I run the tests I see this error:

1) Tests\Browser\PickupFormTest::testMustFillRequiredToProceed
Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected alert open: {Alert text : Email is required
Please provide a valid email}

Shouldn't assertDialogOpened() expect the alert to open and verify the correct text? Why is it throwing an UnexpectedAlertOpenException?

taufek commented 7 years ago

I think if you do below it will pass (added acceptDialog at the end)

$browser->visit('/')
    ->type('name', 'Jonh')
    ->type('email', '')
    ->type('phone', '555-555-5555')
    ->click('.btn-next')
    ->assertDialogOpened("Email is required")
    ->acceptDialog();
amree commented 7 years ago

I think this is related to Chrome's bug itself. The bug has been fixed, but it hasn't been released yet.

Basically you can't verify the message in the dialog as the dialog has been closed automatically.

For now, you can either use js library for the popup or just test what happens after the dialog was closed.

Bug ticket: https://bugs.chromium.org/p/chromium/issues/detail?id=718235

eduardocruz commented 6 years ago

Having the same issue and using ->acceptDialog(); didn't work.

staudenmeir commented 6 years ago

Please post the relevant parts of your code.

splatEric commented 5 years ago

although this is closed, I came across this because I was having some issues with this. It turned out that the message I had in my assertDialogOpened didn't exactly match the message that was being displayed, which was then triggering the exception regardless of any other actions I had in place.

Long and short of it, make sure you are accepting a dialog with the correct text.

johnliu-tw commented 3 years ago

Hi All, maybe you need $browser->waitForDialog(5); to wait until alert dialog appears.

35grain commented 1 year ago

Hi All, maybe you need $browser->waitForDialog(5); to wait until alert dialog appears.

Adding a slight delay did the trick, even though to my eyes the alert comes up instantly after the previous action. My solution:

$browser->waitForDialog(1)
        ->assertDialogOpened('Alert text here')
        ->acceptDialog();