I've been utilizing nightwatch for my test automation. Within my page object, I have a "section" containing various commands. However, when attempting to call these commands in the test script, I encountered an error stating "section is not a function". Please see my page object and test script 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 the test script, the command is called as follows:
this.profileTest.section('@myprofile').clickProfile(); but it results
in an error message: this.profileTest.section is not a function
I attempted the suggested solution provided. Details are outlined 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