I am trying to build a custom logger and what I am trying to do as after I take a screenshot I want to call my logger function to log the image name. When I am in the then of the promise it cannot see all the functions in the class
module.exports = {
takeScreenshot: function(driver, filename) {
driver.takeScreenshot().then(function(data) {
name = filename || 'ss.png';
var screenshotPath = 'results/screenshots/';
fs.writeFileSync(screenshotPath + name, data, 'base64');
return screenshotPath + name;
}).then(function(e) {
this.logger(e, "true");
});
},
logger: function(log, screenshot) {
isScreenshot = screenshot || "false";
var obj = {};
if (isScreenshot == "true") {
obj[testName.replace(/ /g,'')] = {
logs: "",
screenshot: "<img src=\"" +log+ "\" class=\"test-img\" />"
};
logger.push(obj);
} else {
obj[testName.replace(/ /g,'')] = {
logs: "<span class=\"test-log\">" +log + "</span>",
screenshot: ''
};
logger.push(obj);
}
}
}
Basically its not seeing the logger method. What am I missing? Thanks