Test cases may fail while executing the test cases. While we are executing the test cases manually we just take a screenshot and place it in the local machine as an image or as a document of images then attach it to the required bug or test in the Test management tool.
The same can be done by using WebDriverIO, Some of the places we might need to capture screenshots with WebDriverIO.
Syntax to capture and save the screenshot using WebdriverIO
browser.saveScreenshot("file name with path")
Donot forget to mention the screenshot name with .png extension
You must provide the file name for the screenshot along with the file path,
it('Navigation Commands with WebdriverIO', () => {
browser.url('https://chercher.tech/practice/popups')
browser.saveScreenshot("full.png")
/*below line won't work, also won't throw error
$("//input[@name='prompt']").saveScreenshot("abc.png")
*/
});
By default, webdriverIO take the given path as a relative path with respect to the conf file.