简体   繁体   English

在 Nightwatch 中,如何在测试中调用“部分”中存在的命令?

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

I am using nightwatch to write my tests.我正在使用 nightwatch 来编写我的测试。 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()

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

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