Take a Screenshot with WebdriverIO

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.

  • Application issues
  • Assertion Failure
  • Visibility issues like Difficulty finding Web elements on the web page
  • Loading issues like Timeout to find Web elements on the web page

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, by the way, you cannot take element level screenshot in WebdriverIO.

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.

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions