Page Object Modeling with Python and Playwright

Page Object Modeling with Python and Playwright

How to construct effective models for Playwright frameworks.

Microsoft’s Playwright quietly released in May of 2020. Written by a group of engineers who originally wrote the Puppeteer library, Playwright is intentionally similar to Puppeteer. While Microsoft has provided an example of a page object within Playwright’s documentation, the example is fairly simple and does not delve into the use of page properties or helper methods.

What is a Page Object?

A page object is an abstraction of a web page using a programming language. The intention is to represent all of the page within code so as to take action against specific elements. Page objects are routinely used in the field of test automation where a Quality Engineer creates objects and tests for the purpose of testing application user journeys.

This tutorial will focus on building a page object for the DemoQA Bookstore application login page. The login page features a username input, a password input, a login button, and a new user button.

Getting Started

In order to begin, we need to install our dependencies. The following packages should be installed:

  • pytest
  • pytest-playwright
  • playwright

Simply install the above using pip (or the dependency manager of your choosing).

The pytest library is included as it is the most popular test runner for Python. The pytest-playwright package provides simple fixtures for use within tests, such as the page fixture which automates browser setup. It can also be configured to take screenshots upon failure which is helpful in debugging flakey or failing tests.

automation-testing python quality-assurance pytest

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top 10 Automation Testing Tools: 2020 Edition

The demand for delivering quality software faster — or “Quality at Speed” — requires organizations to search for solutions in Agile, continuous integration (CI), and DevOps methodologies. Test automation is an essential part of these aspects.

Measure Your Test Automation Maturity

Feel free to grade your team's maturity through my research. By the end of the article, you'll have your Test Automation Maturity Level.

Review — Automated Visual Testing With WebdriverIO

If you use WebdriverIO regularly, and you are unfamiliar with the basics of using Applitools for automated visual testing, you will appreciate this course.

Where To Learn Test Programming — July 2020 Edition

What do you do when you have lots of free time on your hands? Why not learn test programming strategies and approaches?

Why Python Is My Favourite For Test Automation?

When it comes to Selenium test automation, Python automation testing is our go-to choice. We explain why automation testing using Python is simply the best.