我们终于准备好宣布 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 以及示例的信息,请查看捆绑的 示例文件夹 中的化身。
您也可以在新的项目中立即试用这些示例,自动生成的 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 上提交错误,或在我们的 Discussions 页面 上提交一般反馈。感谢您的帮助!