Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

browser.switchTo().alert() no longer works as expected on dialogs #1486

@facultymatt

Description

@facultymatt

Overview

I have a set of tests which rely on browser.switchTo().alert() to accept and dismiss both alerts and dialogs. The tests no longer work on the dialogs. The dialogs remain open, the test is not able to accept or dismiss the dialog, and the test control flow hangs.

// PASSES
it('should handle alerts', function() {
  // trigger $location.url('/page2');
  element(by.id('navigateAway')).click();
  var alertDialog = browser.switchTo().alert();
  expect(alertDialog.accept).toBeDefined();
  alertDialog.accept();
});

// FAILS
it('should handle dialogs', function() {
  // trigger window.onbeforeunload = function() { return 'are you sure?'; }
  browser.navigate().refresh();
  var alertDialog = browser.switchTo().alert();
  expect(alertDialog.accept).toBeDefined(); // fails
  alertDialog.accept(); // alertDialog and accept are not defined 
});

The full test suite is here

Investigation

There is discussion on the interwebs about similar problems where dialogs are not accessible by using browser.switchTo(). There is an open bug on selenium chromedriver here

There are a few related issues on protractor, specifically #308 and #55

I've tried using getAllWindowHandles and this fails too:

browser.getAllWindowHandles().then(function (handles) {
  browser.switchTo().window(handles[0]);
});

I've also tried rolling back to previous versions of protractor.

  • In protractor 1.0.0 the tests still fail, however the open dialog box is somehow ignored and doesn't block the control flow - all tests run and fail.
  • In 0.9.0 the tests fail AND block the control flow - the first failing test stops the remaining tests from running.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions