End to End Testing with Playwright

A presentation at DrupalCon Prague 2022 in September 2022 in Prague, Czechia by Petar Basic

Slide 1

Slide 1

End to end testing with Playwright

Slide 2

Slide 2

About me ● ● ● Petar Basic Bachelor with honours in Electrical and Computer Engineering, Faculty of Technical Sciences, Novi Sad (Serbia) DevOps and Drupal engineer at

Slide 3

Slide 3

drunomics GmbH 1060 Vienna, Austria ● Wide range of creative and flexible Drupal-based publishing solutions ● Drupal & Nuxt.js <3 ● lupus digital - out-of-the-box solution ○ decoupled frontend ○ contentpool function ○ flexible page building for editors via core’s Layout-builder ○ and more… ● lupus decoupled drupal

Slide 4

Slide 4

End To End Testing ● Automated tests are a vital part of the Quality Assurance process ● Integral part of our CI pipelines ● Save time and energy, avoid repetative manual testing

Slide 5

Slide 5

Previously used - Behat Problems, downsides ● Open-source, but maintainance and support are limited ● Flaky tests ● Poor debugging experience ● Writing test experience nice to the naked eye, but sometimes not dev-friendly Upsides ● Extendable ● Existing extensions with pre-defined steps for use with Drupal ● Interacts directly with Drupal API ● PHP framework ● Encourages Behavior Driven Development (BDD)

Slide 6

Slide 6

What prompted us to change Expecting reliable, thrusworthy tests What we got: ● ● Flaky tests ○ ○ Uncertainty Time loss ○ Limited options (code debugging, headed tests, manual checks) In a CI environment Time consuming Poor debugging experience ○ ○

Slide 7

Slide 7

What we use now - Playwright “Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.” Why playwright? Related post

Slide 8

Slide 8

Capabilities - upsides ● ● ● ● ● ● ● ● ● ● ● Auto-wait Auto-retry Cross-browser - Chromium, Firefox, WebKit, Google Chrome & Microsoft Edge Cross-platform (Linux, Windows, macOS) Full isolation Tracing Powerful tooling - Codegen, Inspector, Trace Viewer Cross language (TypeScript, JavaScript, Python, .NET, Java) VRT testing Parallel execution and more…

Slide 9

Slide 9

Challenges ● Communication with Drupal API ○ from dockerized Playwright to dockerized Drupal Other (minor): ● ● ● Environment setup ○ no dotenv integrated with php autoloader ○ no existing analog for drupal specific behat extensions ○ presenting and sharing test results and reports Writing testing steps from the ground up CI setup

Slide 10

Slide 10

Communication with Drupal API ● Drush! require(‘child_process’).execSync(drush <command>); ● From container to container? ○ Docker socket + docker-cli require(‘child_process’).execSync(docker exec <container_name> bash -c 'drush <command>');

Slide 11

Slide 11

Other challenges Environment setup ● dotenv! ○ ○ prepoulate .env with needed variables process.env.<VARIABLE> Writing steps from the ground up ● ● ● Manual labor Transfer knowledge from behat Read the docs! CI setup ● ● Publish tests html report on cloudflare junit reporter available

Slide 12

Slide 12

Slide 13

Slide 13

Demo ● ● ● Typical test (headless, headed) Playwright inspector Trace viewer

Slide 14

Slide 14

Our experience so far ● ● ● ● ● ● ● ● Performance comparable with behat ○ Additional container build time with dockerized playwright ○ Seems pretty reliable and stable Don’t forget await ! Use Playwright Assertions when possible Tag tests - easily filter tests when running Use hook functions to prepare environment and cleanup after testing So far no flaky tests! Developer experience positive Debugging experience excellent

Slide 15

Slide 15

petar_basic petar.basic@drunomics.com https://drunomics.com https://github.com/drunomics/playwright-drupal-starter

Slide 16

Slide 16

Resources ● ● ● ● https://github.com/drunomics/playwright-drupal-starter https://playwright.dev https://docs.behat.org/ https://medium.com/uk-hydrographic-office/why-we-chose-playwright-over-cy press-db4770cf5204

Slide 17

Slide 17

Join us for contribution opportunities 20-23 September, 2022 Room C2 + C3 Mentored Contribution First Time Contributor Workshop General Contribution 23 September: 09:00 - 18:00 Room C2 + C3 20 September: 17:15 - 18:00 Room D9 21 September: 10:30 - 11:15 Room D9 23 September: 09:00 - 12:30 Room C2 20 - 22 September: 9:00 18:00 Room C3 23 September: 9:00 - 18:00 Room C2 + C3 #DrupalContributions

Slide 18

Slide 18

What did you think? Please fill in this session survey directly from the Mobile App.

Slide 19

Slide 19

We appreciate your feedback! Please take a moment to fill out: 1 the general conference survey Flash the QR code OR It will be sent by email 2 the Individual session surveys (located under each session description)