I'm trying to run a simple Nightwatch.js
test to login, tell the form to remember the login, and then test the cookie to see if a boolean value exists. Every time I try to run the test, I get an Error:
"Cannot read propery 'equal' of undefined"
which is tied to the callback function for client.getCookie()
.
Can anyone help me to understand how to fix this error?
Here is my code:
module.exports = {
'Test "Keep me logged in." ' : function (client) {
client
.windowMaximize()
.url('www.mysite.com')
.setValue('#login > form > table > tbody > tr:nth-child(1) > td:nth-child(2) > input[type="text"]', 'testuser')
.setValue('#login > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input[type="password"]', 'testpass')
.click('#login > form > table > tbody > tr:nth-child(4) > td > label > input[type="checkbox"]')
.click('#login > form > table > tbody > tr:nth-child(5) > td > input[type="submit"]')
.waitForElementVisible('body', 2000);
client.getCookie('RememberMe', function(result){
this.assert.equal(result.value, 'True');
});
}
};
A function is a lexical scope in javascript, so it sets a new reference to the keyword
this
.Try something like:
Edit:
Seems like
assert
is a member ofclient
, so the call, if supported by the framework should be something like