繁体   English   中英

Nightwatch JS 命令链在异步函数中不起作用

[英]Nightwatch JS command chaining doesn't work in async functions

我试图在我的 Nightwatch 测试中调用异步页面 object 命令,但测试失败。 正如您在代码示例中看到的那样,我试图将几个 .pause 命令链接在一起,但链接机制不起作用。 如果我删除“异步”关键字并注释掉“等待”代码,则链接命令将起作用。 因此,似乎使用“异步”会破坏命令链接。 有解决方案吗?

夜班测试...

module.exports = {
    'Test Commmand Queue': async function (browser) {
        browser.page.clients.sandbox.simpleTestPageObject().testCommandQueue() // async function
    }
}

页 object 文件...

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")
        }
    }]
}

output...

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

尽管使用链接命令看起来很有吸引力,但我建议使用this.apibrowser

这听起来像是一件苦差事,但从长远来看,您会遇到更少的方法和自定义命令问题。

例如,如果我需要使用Mochaexpect ,我不能使用链接命令,所以我宁愿使用browser

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM