I have 100+ tests automated using playwright, but so far I was running in local and now planning to have them as part of CI/CD pipeline. But there is a concern on the test execution time, in parallel run also it takes around 2 hrs to complete those tests. How to configure it with CI/CD and how to use less and less resources remotely to avoid huge costs to run them. <#1054804523652231198>
This thread is trying to answer question "How to configure automated tests with CI/CD and use less resources remotely to avoid high costs and long execution times?"
Related Ask AI answer for "What are some best practices for setting up a large number of automated tests with CI/CD using Playwright while minimizing resource usage and costs?".
To minimize resource usage and costs, you can follow several best practices.
Ideally, run your tests on each commit and pull request. Playwright comes with a GitHub actions workflow so that tests will run on CI for you with no setup required. You can also set up Playwright on the CI environment of your choice.
Linux is cheaper, so it's advisable to use it on the Continuous Integration (CI) platform.
Linting helps catch errors early. Use the @typescript-eslint/no-floating-promises ESLint rule to ensure there are no missing awaits before the asynchronous calls to the Playwright API.
Playwright runs tests in parallel by default, saving time and resources. If you have many independent tests in a single file, run them in parallel using test.describe.configure({ mode: 'parallel' });
.
Sharding allows a test suite to be executed across multiple machines or processes concurrently, reducing overall execution time significantly.
npx playwright test --shard=1/3
Ensure CI agent can run browsers, install Playwright, and run your tests.
npm ci
npx playwright install --with-deps
npx playwright test
For stability and reproducibility, set workers to "1" in CI environments. This ensures each test gets the full system resources, avoiding potential conflicts.
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
workers: process.env.CI ? 1 : undefined,
});
Distribute tests across multiple CI jobs using the --shard
option in Playwright command line tool.
npx playwright test --project=${{ matrix.project }} --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
These practices will help you configure a large number of automated tests with CI/CD while minimizing resource usage and costs. For more tips on efficient Playwright test scripts, check out this blog post.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].