Expect API

概述

Nightwatch 提供了一个流畅的 BDD 风格接口,用于对元素执行断言,定义在主 Nightwatch 实例上的 expect 命名空间中。它基于 Chai Expect 断言库,并提供了更高的灵活性,还添加了超越传统 assert 接口的新功能。

它使用一个可链式语言来构建断言,给定一个由 css/xpath 选择器指定的元素。一个简单的例子如下所示

javascript
describe('expect example', function() {
  it('sample test', function (browser) {
    // start with identifying the element
    // and then assert the element is present
    browser.expect.element('#main').to.be.present;
    // or assert the element is visible
    browser.expect.element('#main').to.be.visible;
  });
}