Automated Software Testing with Puppeteer & amp; Jest
WHAT IS PUPPETEER?
Puppeteer is a Node.js library developed by Google that lets you control headless Chrome through the DevTools Protocol. It is a tool for automating testing in your application using headless Chrome or Chromebit devices without requiring browser extensions like Selenium Webdriver or PhantomJS.
WHAT IS JEST?
Illustrates the overall Puppeteer architecture.
- Basic understanding of Node.js
- Basic understanding of Puppeteer
- A suitable IDE such as VS Code
PUPPETEER SETUP AND LIBRARIES INSTALLATION
Once the above setup is done, the jest.config.js file should be created at the root in the project.
Open that file and make a few changes as follows:
set bail: 5,
set preset: "jest-puppeteer",
Create two files at the root
TEST CASES IMPLEMENTATION
Once you finish the above installation and code set up, we are good to go for test case automation!
Now, create a folder in your project at the root with name tests
Then create one file for writing test cases in the tests folder with the name example.test.js
EXECUTION AND EXPLANATION
To run above written test cases, you need to create a script in the package.json file
Go to the package.json file and update the code in the script section as follows:
Once you added Script to test case, open your terminal and type npm run test and press enter
SOURCE CODE LINK
I hope going through this blog gives you an insight into puppeteer and helps you familiarize yourself with the tool and its capabilities.
I think it’s one of the best libraries to automate trivial tasks with an easy-to-use API; if you also feel so, go ahead and automate the tedious tasks in your day-to-day life with Puppeteer.
If you have any queries or feedback, please let me know in the comment section,