

Test("Confirm text on page", async () => Add this code: const puppeteer = require("puppeteer") The tests will confirm that these elements are on the page and contain the expected text within them.Īdd a new test file named at the root of the project. The first elements you will be testing are the header and the paragraph. With these installed, you can now begin adding browser tests to the project. Install these packages as development dependencies using this command: npm install -save-dev puppeteer jest Jest serves as the test runner for the test suites that you will write.Puppeteer is the browser testing framework.You will be testing the demo page to confirm that it contains the elements displayed on the page, and to verify the behavior of the form. When filled and submitted, the form prints the submitted email to the screen.

The demo page consists of a header that reads Welcome to the demo Web Page, a paragraph that contains the text This is a sample text in a paragraph on the page, and a form with an email field and submit button. The application server will boot up at Go to that URL on your browser to review the demo app homepage. With the dependencies fully installed, run the application using this command: node server Then, go to the root of the project ( cd browser-testing) and install dependencies by running: npm install You will need to clone a demo application by running this command: git clone -single-branch -branch base-project The first step is to set up a web application to test. Cloning and running the sample application With all these installed and set up, we can begin the tutorial.

Node.js installed on your system (version >= 12).To follow this tutorial, a few things are required: You will then take this a step further by automating the testing process in a continuous integration flow.

In this tutorial, you will learn and demonstrate how to write tests for the browser using Puppeteer. Unit tests are great, but nothing beats testing an application by interacting with the user-facing frontend. Users search items, fill forms, create shopping carts, log into their profiles, and perform many other tasks. Most interactions with a web application occur at the browser.
