Warm tip: This article is reproduced from serverfault.com, please click

Dismiss leave page dialogs automatically using Chromedriver (Codeception)

发布于 2020-12-31 01:43:31

I have written a series of acceptance tests that work when executed independently. I am using ChromeDriver to carry out this tests with Codeception.

However, when I run all the procedures from a test class I get a dialog about

This page is asking you to confirm that you want to leave - data you have entered may not be saved.

This is a browser modal alert, hence all the tests that follow fail as the browser cannot navigate away from this page.

Is there an way in Codeception or Chromedriver to accept the dialog with default keys so that other tests can be performed sequentially? Or to tell Codeception to force close the current window and try a new window?

Thanks!

Questioner
csaborio
Viewed
0
csaborio 2021-01-03 07:46:31

After playing with settings for a while, the only way to get passed is to set the restart property to true (false by default):

        WebDriver:
            url: 'http://localhost:8080/'
            wait: 2
            window_size: false # disabled in ChromeDriver
            port: 9515
            browser: chrome
            restart: true

This will close the browser window and the dialog will not be displayed. A new browser will be opened for the next test.

This solution will make the acceptance run tests even slow, so I'm keen to see if anyone else has a better solution!

Worth noting that I tried playing with the unexpectedAlertBehaviour capability and no matter what value I have it, the alert would not be dismissed.