Skip to content
Go back

Test Automation - Flexible Test Execution with Playwright Python and GitHub Actions

Published:

Introduction

In the world of test automation, flexibility is key. Scaling specific tests or test suites on demand can significantly enhance your testing workflow. This article explores how to leverage GitHub Actions to create a flexible testing pipeline for Playwright Python tests, allowing for both scheduled runs and on-demand execution with custom pytest commands.

The solution presented in this article is exemplified in my Playwright Python example project, developed in collaboration with Elias Shourosh.

Implementing the Solution

The solution code can be found here. Here’s the key part of the workflow:

Let’s break down the key parts:

  1. Trigger Configuration: The workflow is set to run on a nightly schedule using a cron expression. It also supports manual triggering via ”, allowing for on-demand execution.
  2. Input Parameters: When manually triggered, users can provide a custom pytest command through the input. A default command is provided to run tests not marked as “devRun”.
  3. Conditional Execution: The workflow uses conditional steps to determine whether to run the custom command or the default command. For manual triggers, it uses the provided custom command. For scheduled runs, it uses the default command.

Benefits of This Approach:

  1. Flexibility: This setup allows for both automated nightly runs and on-demand testing with custom parameters.
  2. Ease of Use: Team members can easily trigger specific test runs without modifying the workflow file.
  3. Consistency: The default command ensures that regular scheduled runs always execute a predefined set of tests.

Usage Example

To manually trigger the workflow with a custom pytest command:

  1. Navigate to the “Actions” tab in your GitHub repository.
  2. Select the “Nightly regression tests” workflow.
  3. Click “Run workflow”.
  4. Enter your custom pytest command, e.g., .
  5. Click “Run workflow” to start the execution.

This will run only the tests that match the provided expression, giving you precise control over which tests are executed.

In Conclusion

By leveraging GitHub Actions with customizable pytest commands, we’ve created a flexible and powerful testing pipeline for Playwright Python tests. This approach allows teams to maintain a balance between consistent nightly regression runs and the ability to execute specific tests on demand. It enhances the testing workflow, allowing quicker iterations and more targeted testing when needed.

Remember to adapt the workflow to your specific project structure and requirements.

Happy testing!


Suggest Changes

Have a challenge? Let's Talk


Previous Post
Test Automation - Efficient Element Selection with Playwright Python using Test IDs
Next Post
Test Automation - Accelerating Playwright Python Tests with Parallel Execution in GitHub Actions