


So in our example, we shall run the following command −Īfter the command has been successfully executed, a new file called the tutorialspoint.png gets created within the page directory. Step 4 − Execute the code with the command given below − Step 3 − Add the below code within the testcase1.js file created.Īwait p.setViewport() Step 2 − Enter a filename, say testcase1.js. Right-click on the folder where the node_modules folder is created, then click on the New file button. The details on Puppeteer installation is discussed in the Chapter of Puppeteer Installation. Step 1 − Create a new file within the directory where the node_modules folder is created (location where the Puppeteer and Puppeteer core have been installed). To begin, follow Steps 1 to 2 from the Chapter of Basic Test on Puppeteer which are as follows − Let us capture the screenshot of the below page − In this example we'll use CSS selectors to target the element. We can use CSS selectors or XPath expressions to find the element.
Puppetteer screenshot path how to#
Path: 'tutorialspoint.png', fullPage: true In order for puppeteer to capture an element screenshot, it needs to know how to find the specific element in the DOM. To capture the full page screenshot, we have to pass another parameter called the fullPage and set its value to true.

With this, only the viewable part of the web page shall be captured. Here, the path where the screenshot is to be saved is passed as a parameter to the method. The syntax to capture screenshot in Puppeteer is as follows − A screenshot is generally captured if we encounter an application error, a failure in a test case, and so on. We can capture screenshots while working on automation tests developed in Puppeteer using the screenshot method. Comparison Between Puppeteer & Protractor.Comparison Between Puppeteer & Selenium.
