概述

The .pause() command allows users to pause their test execution, either for a fixed amount of time (by passing the duration in milliseconds as an argument) or for an unrestricted amount of time with an option to resume anytime.

To suspend the text execution for a limited amount of time (e.g. 300ms), write

it('demos pause command', function(browser) {
  // pause for 300 ms
  browser.pause(300);
});

To suspend the text execution indefinitely, until resumed, write

it('demos pause command', function(browser) {
  // pause indefinitely, until resumed
  browser.pause();
});

用法

虽然 .pause(ms) 命令主要用于以编程方式暂停测试,在执行下一个命令之前等待一小段时间,但 pause() 命令(不带任何参数)可以在调试时使用。

在不带任何参数的情况下使用 pause() 命令时,可以使用以下操作

  • 从停止的位置正常恢复测试
  • 单步执行到下一个命令/断言并再次暂停
  • 退出测试运行
tests/duckDuckGo.js
describe('duckduckgo pause example', function() {
  it('Search Nightwatch.js and check results', function(browser) {
    browser
      .url('https://duckduckgo.com')
      .pause()
      .waitForElementVisible('#search_form_input_homepage')
      .sendKeys('#search_form_input_homepage', ['Nightwatch.js'])
      .click('#search_button_homepage')
      .assert.visible('.results--main')
      .assert.textContains('.results--main', 'Nightwatch.js');
  });
});

.pause() command