При использовании функции url () платформы Nightwatch оповещение для события onbeforeunload не отображается. - PullRequest
0 голосов
/ 07 апреля 2020

Я следую примеру со страницы nighwatch: https://github.com/nightwatchjs/nightwatch/blob/master/examples/tests/onbeforeunload.js с пользовательской командой для события onbeforeunload.


module.exports = {
  disabled: true,

  'go to page with unload handler': function(client) {
    client
      .url('http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm')
      .waitForElementVisible('body', 1000);
  },

  'navigate away from page WITH unload handler': function(client) {
    var hasDialog = false;

    client
      .hasOnBeforeUnload(function(result) {
        this.verify.equal(result, true, 'The page should have an onbeforeunload handler');
        hasDialog = result;
      })
      .url('http://google.com', function() {
        if (hasDialog) {
          this.acceptAlert();
        }
      })
      .waitForElementVisible('body', 1000);

  },
///....
/// other parts

}

Ожидается: есть предупреждение об изменении URL

Фактически: ничего. Этот тест пройден! Даже если при попытке переключиться на новый URL-адрес http://google.com с текущего URL-адреса не отображается предупреждение http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm

Журналы:


i Connected to localhost on port 4444 (3241ms).
  Using: firefox (74.0.1) on windows 10.0 platform.

Running:  go to page with unload handler

√ Element  was visible after 24 milliseconds.

OK. 1 assertions passed. (661ms)
Running:  navigate away from page WITH unload handler

√ Passed [equal]: The page should have an onbeforeunload handler
 Error while running .acceptAlert() protocol action: An attempt was made to operate on a modal dialog when one was not open.

√ Element  was visible after 14 milliseconds.

.....

P / s: все в порядке, если я выполняю описанные выше шаги вручную вместо теста ночных часов

Тест все еще проходит после удаления this.acceptAlert(); функции

Знаете ли вы root причины этой проблемы ? Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...