javascript - Nightwatch JS 命令链在异步函数中不起作用
问题描述
我试图在我的 Nightwatch 测试中调用异步页面对象命令,但测试失败。正如您在代码示例中看到的那样,我试图将几个 .pause 命令链接在一起,但链接机制不起作用。如果我删除“异步”关键字并注释掉“等待”代码,则链接命令将起作用。因此,似乎使用“异步”会破坏命令链接。有解决方案吗?
夜班测试...
module.exports = {
'Test Commmand Queue': async function (browser) {
browser.page.clients.sandbox.simpleTestPageObject().testCommandQueue() // async function
}
}
页面对象文件...
module.exports = {
elements: {},
commands: [{
testCommandQueue: async function () {
this
.pause(1)
.pause(1)
console.log("0001")
await this.pause(3000, function () {
console.log("0002")
})
console.log("0003")
}
}]
}
输出 ...
Running: Test Commmand Queue
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (4.939s)
TypeError: this.pause(...).pause is not a function
守夜人 v 1.5.0
解决方案
As much as it looks appealing to use chaining commands I suggest use this.api
or browser
.
It sounds like a chore but in the long run you will encounter less issues with methods and custom commands.
For example I can't use chaining commands if I need to use the expect
by Mocha
so I just rather use browser
推荐阅读
- mysql - 从数据块收到的 Sql 服务器连接丢失错误。连接池有用吗?
- android - setTextCursorDrawable (<=29) 缺少 Android 数据绑定 API 级别检查
- angular - 如何显示从代码初始化的角度组件?
- azure - 使用多容器 linux 应用程序限制配置 azure appservice
- list - 飞镖上的新列表(我认为给出错误是因为我使用的是旧列表?)
- sql-server - xp_cmdshell 的 SQL Server 权限?
- windows - 如何将用户配置文件与 Powershell 脚本中相应 C:\User 文件夹中的文件匹配?
- angular - 当用户点击网站上的关注按钮时,有什么方法可以直接关注 Instagram 帐户
- java - Thymeleaf Java:如何将输入字段从 html 页面发送到控制器的请求参数
- linux - chroot 和 pivot_root 有什么区别?