Skip to content
Advertisement

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

I was using night-watch version 1.3.2. All the tests were working fine till I update the night-watch to its latest version 1.3.4. The test breaks specially in the page object. I’ve checked the release notes for night-watch 1.3.4 and it has the new feature to support page object with async/await - https://github.com/nightwatchjs/nightwatch/releases.

I believe the error message i am getting is pointing out to wrap the page object with async await. I would like to know how can i update my existing page object with async/await. an e.g- page object with async await will be really helpful to refer. I have listed my sample test with page object and error message below, which was working fine before updating the night-watch to its latest version. any ideas or help will be grateful.

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

Problem solved my wrapping the function with 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')
        },

Advertisement

Answer

I was able to figure out this issue. I have solved this problem by upgrading the page object command function into async function with await. please find the example in the main post.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement