How to write End to End automation test using puppeteer
How to create End to End web automation using puppeteer and jest. Puppeteer is a web scraping and web automation tool. Puppeteer is a node js library that contains lots of features to automation a web application over the latest version of chromium and chrome that we have cover in the puppeteer tutorial.
To start web automation with the puppeteer and Jest we need Node installed in the machine and an IDE.
- Install NodeJS.
- Download IDE(Visual Studio code/Notepad/SublimeText).
Node Commands to Install puppeteer and Jest.
The below command will install the puppeteer.
npm i puppeteer npm i puppeteer-core
End to End automation test using puppeteer
In this example, we are going to write pure puppeteer code. Will cover other tools like Jest, mocha, and chai with puppeteer in upcoming tutorials.
Automation Steps:
- Launch browser.
- Navigate to URL.
- Click to the login button.
- Enter the email-id and click on the button.
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless:false}); const page = await browser.newPage(); //Enter URL await page.goto('http://automationpractice.com/index.php'); //wait for login button await page.waitForSelector(".login"); //Click to login button const signinbtn = await page.$(".login"); signinbtn.click(); await page.waitForSelector("#email_create"); //Enter email id await page.type("#email_create", "Nununnnn@gmail.com") //Click to signup button const signupbtn = await page.$("#SubmitCreate"); signupbtn.click(); await page.waitFor(10000); //Close browser await browser.close(); })();