Take a screenshot

Another way of debugging is to take a screenshot of the current browser window when an error/failure occurs. Selenium supports this in a very easy way:

var fs = require('fs');    
driver.takeScreenshot().then(function(data) {
  // Base64 encoded png
  fs.writeFileSync(__dirname + "/tmp/screenshot1.png", data, 'base64');      
});

However, there is one problem with the above script. When the above script runs for the second time, it will return an error The file already exists. So, a simple workaround is to write a file with the timestamped file name as:

Get hands-on with 1200+ tech skills courses.