简体   繁体   中英

In Nightwatch , How to call a command in test that exists in the "section"?

I am using nightwatch to write my tests. In my page object i have "section". That section have commands but when I call the commands in the test, it returns "section is not a function". please find my page object and test below.

Page Object
sections:{
    Profile:{
        myprofile:'#myprofile',
        elements:{
            firstName:{
                selector:'//a [contains(text(),\'firstName\')]',
                locateStrategy:'xpath'
            }
        },
        commands:[{
            clickRedeem(){
                return this
                    .click('@myprofile')
            },
            clickMerchandise(){
                return this
                    .click('@firstName')
            }
        }]

    }
},

In test I am calling the command like this

 this.profileTest.section('@myprofile').clickProfile(); but its returning  
 this.profileTest.section is not a function  

I tried as you mentioned. please find the details below.

    redeemMenu:{
    selector:'#myprofile',
    elements:{
       merchandiseMenu:{
            selector:'//a [contains(text(),\'Merchandise\')]',
            locateStrategy:'xpath'
        },
    },
    commands:[{
        clickRedeem(){
            return this
                .waitForElementVisible('@redeemMenu')
                .click('@redeemMenu')
        },
        clickMerchandise(){
            return this
                .waitForElementVisible('@merchandiseMenu')
                .click('@merchandiseMenu')
        },


    }]

},



test

var profileSection = await this.profileTest.section.redeemMenu 
profileSection.clickRedeem()


Error: Element "redeemMenu" was not found in "redeemMenu". Available 
elements: merchandiseMenu

There are few errors:

  1. You used wrong property and should change

    myprofile:'#myprofile'

    to

    selector: '#myprofile'
  2. You used the wrong selector

    var profileSection = this.profileTest.section.redeemMenu
  3. To use command :

     profileSection.clickRedeem()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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