В Nightwatch, Как вызвать команду в тесте, которая существует в «разделе»? - PullRequest
0 голосов
/ 14 января 2020

Я использую Nightwatch для написания своих тестов. В моей странице объекта у меня есть «раздел». В этом разделе есть команды, но когда я вызываю команды в тесте, он возвращает «раздел не является функцией». пожалуйста, найдите объект моей страницы и проверьте ниже.

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

    }
},

В тесте я вызываю команду, подобную этой

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

Я пытался, как вы упомянули. пожалуйста, найдите детали ниже.

    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

1 Ответ

0 голосов
/ 14 января 2020

Есть несколько ошибок:

  1. Вы использовали неправильное свойство и должны изменить

    myprofile:'#myprofile'
    

    на

    selector: '#myprofile'
    
  2. Вы использовали неправильный селектор

    var profileSection = this.profileTest.section.redeemMenu
    
  3. Для использования команды:

    profileSection.clickRedeem()
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...