virtualpain's avatar

How to interact with dialog in Laravel Dusk?

I created a browser test with Dusk to test functionality of links on a page. One of the links has onclick event that create confirm dialog. The test simply raised UnexpectedAlertOpenException. How do I interact with the dialog such as cancel or click OK button on it?

I did tried to do switchTo as some discussion on SO suggested:

...
->clickLink("hapus")
                    ->switchTo()
                    ->alert()
                    ->accept()
                    ->aseertNotSee("Hello World")

It doesn't work.

Thanks

0 likes
1 reply
plateena's avatar
plateena
Best Answer
Level 1

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

$browser->acceptDialog() = press OK

$browser->assertDialogOpened('Text in dialog'); = check dialog exist with text specified.

4 likes

Please or to participate in this conversation.