By Oleksii Ostapov
- Playwright website
- QA Mania Telegram Channel <-- SUBSCRIBE š„³
- QA Mania blog
- Playwright coding hints collection
- My Playwright + Python course
In order to run these tests locally you need
- Install Sample project which will be tested by tests. It is easy-to-run Test Case Management system created with Django with main purpose to be tested by autotests. There is installation guide
- Install test dependencies using command
pip install -r requirements.txt
- Install Playwright web browser drivers using command
playwright install
. Check guide
In order to simplify code pytest is used. It is possible to run same code without, as it provided in official documentation.
conftest.py contains main fixture with Playwright itself and page fixture, with already authenticated user
Documentation: https://playwright.dev/python/docs/locators
Test: test_context.py
Description: .locator() does not raise Exception if element not found, but object, and object can be evaluated.
multiple objects can be found and handled.
locator provides more ways to find element with has-text and has arguments
Documentation: https://playwright.dev/python/docs/test-assertions
Test: test_expect.py
Description: as an alternative to python assert method expect can be used. It gets locator object and allows
to check it has or has not attributes, values, css, Checks it is visible or not. Optional stuff, but qute nice
Documentation: https://playwright.dev/python/docs/api-testing
Test: test_http.py
Description: Cool way to test call web API directly from Playwright. No need to run separate http client in your code
Documentation: Test: Description:
Documentation: Test: Description:
Documentation: https://playwright.dev/python/docs/multi-pages
Test: test_context.py
Description: In this test 2 separate contexts created for different users. They act in the same test at the same time!
Documentation: https://playwright.dev/python/docs/api/class-page#page-evaluate
Test: test_evaluate.py
Description: In this test JS directly in browser executed and value received back into test. Any king of complicated JS logic can be triggered directly
Documentation: https://playwright.dev/python/docs/events
Test: test_events.py
Description: In these tests different scenarios of events handling are shown. My favorite way - create context manager, because in this case you can control upcoming events better
Documentation: https://playwright.dev/python/docs/network
Test: test_route.py
Description: In these tests different scenarios of handling browser HTTP requests are shown. You can abort, modify, mock or just log any browser request
Documentation: https://playwright.dev/python/docs/selectors
Test: test_selectors.py
Description: In this test the most awesome Playwright feature is displayed - Selectors. You have a lot of ways to locate you elements
Documentation: https://playwright.dev/python/docs/api/class-page#page-wait-for-selector
Test: test_waiting.py
Description: In these tests different scenarios shown on how you can wait for element, page load or any kind of event emitted by web browser