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