3. Test automation
Last modified by Tiina Silvonen on 2026/11/11 09:03
Test automation is used especially for repetitive testing and regression testing. The purpose of automation is to reduce the amount of repetitive manual testing, improve test coverage, and provide faster feedback on software changes.
The extent of test automation should be based on the needs, risks, and available resources of the application or project.
3.1 Planning automation
When planning test automation, consider the following:
- What to automate: Prioritize tests that are repetitive, critical, or time-consuming. Tests that are rarely executed or cover functionality that changes frequently may be more suitable for manual testing.
- Goals and benefits: Define what the automation is expected to achieve, such as faster feedback, improved coverage, or more consistent test results.
- Testability: Ensure that the application supports effective testing through suitable interfaces, test data, logging, and other mechanisms.
- Tools and technologies: Select tools that are suitable for the technologies used, the team's skills, and the required integrations.
- Test structure and maintainability: Keep automated tests clear, maintainable, modular, and reusable where appropriate.
- Test data management: Define how test data is created, managed, and cleaned up during testing.
- Test execution: Automated tests should be easy to run and, where appropriate, integrated into the CI/CD pipeline.
- Reliability: Avoid flaky tests. Automated tests should produce consistent results and should not depend unnecessarily on other tests, external systems, or changing data.
- Reporting and visibility: Test results and failures should be clearly reported and easily available to the development team.
- Cost and maintenance: Consider the implementation and maintenance effort of automated tests in relation to the benefits they provide.
3.2 Automation with Playwright
Playwright can be used for automated end-to-end and browser testing of web applications. When using Playwright:
- Focus on important user workflows and user-visible behaviour rather than implementation details. This makes tests more resistant to internal application changes.
- Use Playwright locators such as getByRole(), getByLabel() and getByText() instead of relying on fragile CSS or XPath selectors.
- Use Playwright's web-first assertions and built-in automatic waiting instead of adding fixed delays to tests. For example, await expect(locator).toBeVisible() waits for the expected condition.
- Keep tests independent and isolated so that one test does not depend on another test having been executed first. Playwright provides each test with an isolated browser context.
- Use controlled test data and avoid dependencies on production or third-party services where possible. Playwright recommends mocking third-party dependencies that are outside your control.
- Run relevant Playwright tests automatically as part of the CI/CD pipeline. Broader end-to-end tests that take longer to execute can be run at suitable stages rather than requiring every test on every change.
- Use Playwright's debugging capabilities, such as traces, screenshots, and logs, to investigate failed tests.
For more detailed instructions and examples, see the official Playwright Best Practices.