Upgrade to Pro — share decks privately, control downloads, hide ads and more …

API Testing with Playwright

API Testing with Playwright

This is a presentation held during TYPO3 developer days: https://t3dd25.typo3.com/schedule/sessions/api-testing-with-playwright-966

Avatar for Sven Liebert

Sven Liebert

August 09, 2025
Tweet

Other Decks in Programming

Transcript

  1. 2 About me Sven Liebert IT-Architect @ Deutsche Telekom MMS

    Offen | API testing with Playwright | TYPO3 Developer Days 2025 Sven Liebert Dresden Developing applications with TYPO3 since 2019
  2. 3 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Presentation scope • Short introduction into TYPO3 headless • Introduction into Playwright • Setting up Playwright • Write simple and advanced tests • Quick look into CI integration • ”Best practices” • Challenges/Problems
  3. 4 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Introduction Since beginning 2025 we develop a large headless project, which had the need to be tested. We had to gain knowledge and onboard our colleagues.
  4. 5 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert TYPO3 Headless API – Very quick overview Goal: Render TYPO3 content pages as JSON for RESTful communication
  5. 6 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert TYPO3 Headless API – Very quick overview
  6. 7 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert We provide an API? We need to test it!
  7. 8 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Let’s write unit tests!
  8. 9 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Additionally click the frontend!
  9. 10 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert What’s with API testing?
  10. 11 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Goal: An easy, reliable tool stack for API (and acceptance) testing
  11. 13 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert But why not only Functional Tests?! Problem: No real HTTP requests • mocking errors • not checking network access ways • no possibility to run E2E-tests
  12. 14 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert What‘s playwright? Playwright enables reliable end-to- end testing for modern web apps.
  13. 15 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Okay, but why not Cypress? • written in jQuery
  14. 16 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Okay, but why not Selenium stuff? Use Codeception or something like this? • Possible, but a bit edgy (let’s wait)
  15. 17 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Tooling is second. Testing in all is first.
  16. 18 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Why playwright? Supports UI and API testing Powerful features Tracing Mocking Authentication Parallelization Developer experience Multiple languages Simple setup Good debug tools Native Cross-Browser Testing Use native Browser APIs iFrame & Shadow-DOM-Support Is that the solution of all our problems? Unfortunately, no
  17. 19 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Some cool playwright acceptance test features Trace your test (see screenshots for every step)
  18. 20 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Some cool playwright acceptance test features Record your test direct in browser
  19. 21 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Some cool playwright acceptance test features Run your tests in playwright UI or directly with browser visible
  20. 22 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Typical testing challenges Authentication Multiple user roles Correct and stable test results Testing multiple environments
  21. 23 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Setting up Playwright local machine • Needs NodeJS and NPM locally • Just follow the Playwright docs Docker • use official image from Microsoft • use same image in local and CI ddev extension • ddev extension from Julien Loizelet • provides an easy ddev wrapper for playwright cli commands
  22. 24 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Setting up Playwright ddev extension 1. Install ddev extension 2. Initialize test suite 3. Write your tests 4. Run your tests
  23. 25 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Write a simple test case Goal: Get a page, check for content element on this page
  24. 26 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Write a simple test case What we need: • the page slug (obvious) • data which is critical when changed
  25. 27 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Write a very simple test case import dependencies get page check if status code is 200 check for CType check for header
  26. 28 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Struggling with authentication false Reason? Page is only visible with login
  27. 29 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Demo: Struggling with authentication Let’s check inside code and try to fix it Demo Repo from this talk
  28. 30 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert More advanced scenarios • test features with multiple roles/user groups/states with fixtures • usage of setup/teardown logic (e.g. delete all mailpit mails before starting the tests run)
  29. 31 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Quick look into CI integration Short answer: Do it like locally. Grab the docker image, install the npm packages and run your tests
  30. 32 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Quick look into CI integration Long answer: get your secrets safely! Install dependencies Run the tests
  31. 33 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Quick look into CI integration Some stumbling blocks • reachability of your API • environment variables • performance
  32. 34 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Isolate your tests „Best practices“ Avoid things like • use result of other tests before • rely on data changed it in tests before • rely on data you not imported before in general
  33. 35 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Use the power of parallel execution „Best practices“ Run tests parallel whenever possible (default behaviour)
  34. 36 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Reuse authentication states „Best practices“ Don’t login multiple times • use the authentication state feature
  35. 37 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Write tests with AI, but check the value „Best practices“ You can let AI write your tests, but … • is it worth to have a test for this? • what is the AI leaves missing? • what is maybe a wrong developed test?
  36. 38 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Run the tests. Not manually. Automatically „Best practices“ Nothing is more useless than tests, that are not executed automatically. Run and review your tests
  37. 39 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Isolate your tests „Best practices“ Use the power of parallel execution Reuse authentication states Write tests with AI, but check the value Run the tests. Not manually. Automatically
  38. 40 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Challenges with Playwright Concurrency of session related stuff e.g. log in into external application with OAuth concurrent Prepare your data for API tests No easy way to configure database fixtures Steep learning curve Can be complex to handle multiple user roles and states → Use different users or use authentication session per worker → Adjust the tests or export/import the database → Just try it! ☺
  39. 41 Offen | API testing with Playwright | TYPO3 Developer

    Days 2025 Sven Liebert Further resources • TYPO3 Headless Extension: https://github.com/TYPO3-Initiatives/headless • Playwright Documentation: https://playwright.dev/ • Playwright API Testing Documentation: https://playwright.dev/docs/api-testing • Just write your first test and try it out: https://playwright.dev/docs/writing- tests#first-test Demo Repo from this talk