Since Nightwatch has access to the browser console, it's possible to inspect client side objects using the .execute()
API. In the following example, we're checking the Session object for a particular session variable. First, we begin by creating the file ./tests/nightwatch/api/meteor/checkSession
, where we will keep the following command:
// syncrhonous version; only works for checking javascript objects on client
exports.command = function(sessionVarName, expectedValue) {
var client = this;
this
.execute(function(data){
return Session.get(data);
}, [sessionVarName], function(result){
client.assert.ok(result.value);
if(expectedValue){
client.assert.equal(result.value, expectedValue);
}
})
return this;
};
We can then chain it like so:
module.exports = {
"Check Client Session" : function (client) {
client
.url("http://localhost:3000")
.checkSession("currentUser", "Jane Doe")
.end();
}
};