Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

Dismiss leave page dialogs automatically using Chromedriver (Codeception)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found similar question for different test framework: Prevent onbeforeunload dialog from interfering with tests

Proposed solution is to execute window.onbeforeunload = undefined; after each page load.

With Codeception you have to use executeJS method:

$I->amOnPage('/');
$I->executeJS('window.onbeforeunload = undefined;');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...