预期 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;
  });
}