我們終於準備好宣布 Nightwatch v2.0 的第一個 beta 版本。接下來的 beta 版本將會逐步在 NPM 上以 next 標籤提供,因此為了安裝它,您必須執行以下命令:
npm i nightwatch@next
在接下來的幾週內,我們也將完成文件更新,在「指南」部分增加更多頁面,並記錄新的 API。
新功能
以下是發布說明,其中包含自上次 alpha 版本以來的重要變更詳細資訊。
您也可以回顧宣布第一個 alpha 版本的部落格文章,以更好地了解新功能和增強功能的列表,但讓我們也在此簡要回顧最重要的部分。
新的使用者動作 API、支援 Chrome DevTools Protocol 和 WebDriver BiDi
v2 的主要變更之一是底層架構已完全重構,改為使用官方的 selenium-webdriver 函式庫與瀏覽器驅動程式通訊。
這表示更好的跨瀏覽器整合和更可靠的 DOM 元素處理。有關此相關變更的更多詳細資訊,請參閱之前關於alpha 版本的部落格文章。
新的整合測試執行器,用於在 Nightwatch 中使用 CucumberJS
在之前的v2.0.0-alpha.3中,我們宣布了用於 CucumberJS 的新整合測試執行器,以及基於 Mocha v9 的升級版 Mocha 測試執行器。此版本中另一個值得注意的更新是新的程式化 API。
為了在 Nightwatch 2 中使用 CucumberJs,除了 Cucumber 函式庫 本身(7.3 或更高版本)之外,不需要其他外掛程式。有關如何在 Nightwatch 2 中使用 CucumberJs 以及範例的更多詳細資訊,請參閱捆綁的 examples 資料夾。
您也可以立即在新專案上嘗試這些範例,自動產生的 Nightwatch 設定檔包含必要的設定
npx nightwatch --env cucumber-js
請查看 v2.0.0-alpha.3 取得更多詳細資訊。
範例
我們也更新了捆綁的範例,因此請務必查看這些範例,以更好地了解新的 Nightwatch 2 功能。
這是一個使用 AngularJS 首頁上提供的範例待辦事項應用程式的範例。
describe('angularjs homepage todo list', function() {
// using the new element() global utility in Nightwatch 2 to init elements
// before tests and use them later
const todoElement = element('[ng-model="todoList.todoText"]');
const addButtonEl = element('[value="add"]');
it('should add a todo using global element()', function() {
// adding a new task to the list
browser
.navigateTo('https://angularjs.org')
.sendKeys(todoElement, 'what is nightwatch?')
.click(addButtonEl);
// verifying if there are 3 tasks in the list
expect.elements('[ng-repeat="todo in todoList.todos"]').count.to.equal(3);
// verifying if the third task if the one we have just added
const lastElementTask = element({
selector: '[ng-repeat="todo in todoList.todos"]',
index: 2
});
expect(lastElementTask).text.to.equal('what is nightwatch?');
// find our task in the list and mark it as done
lastElementTask.findElement('input', function(inputResult) {
if (inputResult.error) {
throw inputResult.error;
}
const inputElement = element(inputResult.value);
browser.click(inputElement);
});
// verify if there are 2 tasks which are marked as done in the list
expect.elements('*[module=todoApp] li .done-true').count.to.equal(2);
});
});
請將您的回饋意見發送給我們
有關 Beta 版本的更多詳細資訊,請參閱v2.0.0-beta.1發布說明。請隨時在我們的Github Issues上提交錯誤,或在我們的討論頁面上提交一般回饋意見。感謝您的幫助!