将守夜人从 1.3.2 升级到 1.3.4 会破坏页面对象中的现有测试

Upgrading the night-watch from 1.3.2 to 1.3.4 breaks the existing test specially in page object

我使用的是守夜版 1.3.2。在我将守夜人更新到最新版本 1.3.4 之前,所有测试都运行良好。测试特别在页面对象中中断。我已经检查了 night-watch 1.3.4 的发行说明,它具有支持 async/await - https://github.com/nightwatchjs/nightwatch/releases.

页面对象的新功能

我相信我收到的错误消息指出要使用异步等待包装页面对象。我想知道如何使用 async/await 更新我现有的页面对象。带有 async await 的例如页面对象将非常有助于参考。我在下面列出了带有页面对象和错误消息的示例测试,在将守夜人更新到最新版本之前它工作正常。任何想法或帮助将不胜感激。

Test
 it('Verify Login', async (browser)=> {
     await this.loginTest.loginSuccess(browser.globals.Username,browser.globals.Password);
     this.homepage.expect.element('@profile').to.be.visible;
  });
Page-Object

module.exports = {

    url:function () {
        return this.api.launchUrl;
    },
    elements:{
        btnSignInRegister:'#SignInRegister',
        btnSelectBusiness:'#business',
        body:'body',
        txtUsernameInput:'#login-username',
        txtPasswordInput:'#login-password',
        signInBtn:'#SignIn',
        pageBody:'body',
        myAccountBtn:'#myAccount',
     },
    commands:[{
        clickSignInRegister(){
            return this
                .click('@btnSignInRegister')
        },
        waitForBody(){
            return this
                .waitForElementVisible('@pageBody')
        },
        loginSuccess(username,pwd){
            return this
                .navigate()
                 .waitForBody()
                .click('@btnSignInRegister')
                .waitForElementVisible('@btnSelectBusiness',5000)
                .click('@btnSelectBusiness')
                .setValue('@txtUsernameInput',username)
                .setValue('@txtPasswordInput',pwd)
                .click('@signInBtn')
                .waitForBody()
        },
        logoutSuccess(){
            return this
                .waitForElementVisible('@btnProfile',5000)
                .click('@btnProfile')
                .waitForElementVisible('@btnLogout',5000)
                .click('@btnLogout')
        }
    }]
}

问题解决了我用 async await 包装函数

 async loginSuccess(username,pwd){
            await this.navigate()
            await this.waitForBody()
            await this.click('@btnSignInRegister')
            //await this.pause(7000);
            await this.waitForElementVisible('@btnSelectBusiness',5000)
            await this.click('@btnSelectBusiness')
            await this.waitForElementVisible('@txtUsernameInput',5000)
            await this.setValue('@txtUsernameInput',username)
            await this.setValue('@txtPasswordInput',pwd)
            await this.click('@signInBtn')
            await this.waitForBody()
        },
        async logoutSuccess(){
           await this.waitForElementVisible('@btnProfile',5000)
           await this.click('@btnProfile')
           await this.waitForElementVisible('@btnLogout',5000)
           await this.click('@btnLogout')
        },

我能够弄清楚这个问题。我已经通过将页面对象命令函数升级为带有等待的异步函数来解决了这个问题。请在主要 post 中找到示例。

来自这个相关的 GitHub 问题:https://github.com/nightwatchjs/nightwatch/issues/2370

If async/await is being used, chaining is not possible anymore, 
because the commands will return a Promise. 
But in your testcase, there's no need to use await, 
since you're not using the result of the command.