Recently, I encountered an issue with a small nightwatch test that checks for a positive number value in a price field. Everything runs smoothly when the code is directly within the test itself. However, when I tried moving it to my page object file as a function, I ran into errors.
checkPrice: function (){
this.expect.element('@price').text.to.be.visible.before(1000);
this.getText ('@price', function(result) {
var myPrice = Number(result.value.replace('-.','').trim());
this.assert.ok(isPositive(myPrice), 'price is a positive number');
});
},
The error message reads: "Cannot read property 'ok' of undefined." Despite attempting to use assert.equal
, I faced the same problem where the property was inaccessible. After some research, I found that the issue might be related to the scope of assert
as a member of client
.
Many discussions mention the tricky nature of using this
, especially for someone like me with limited programming skills in JavaScript. Even switching from this
to client
resulted in "Cannot read property 'assert' of undefined".
Considering these challenges, I seek suggestions on why this setup isn't working and how I can resolve the issue. Any insights or recommendations would be greatly appreciated.