FR EN
Integrating Automation into CI/CD
Integrating Automation into CI/CD — AutomationDataCamp
April 25, 2026 · Updated September 29, 2026 Oussama Belakhdar 8 min read

Integrating Automation into CI/CD

To integrate test automation into CI/CD, keep your tests in the same repository as the code, run them automatically on every pull request, run the fastest tests first and block the merge when a test fails. GitHub Actions, GitLab CI and Jenkins all do this with a pipeline defined as code in the repository. This guide explains which tests to run at each stage, how the three platforms compare and how to keep the pipeline fast and trustworthy.

Key takeaways
  • Pipeline as code: .github/workflows/*.yml (GitHub Actions), .gitlab-ci.yml (GitLab CI) or a Jenkinsfile (Jenkins), versioned and reviewed like application code
  • Fail fast: unit tests first, then API tests, then end-to-end tests; each stage stops the pipeline when it fails
  • Protect the main branch: make the test job a required check, so a red pipeline blocks the merge
  • Speed comes from caching and parallelisation (matrix jobs, Playwright sharding, pytest-xdist), not from skipping tests
  • Flaky tests are bugs: quarantine and fix them; never rerun the pipeline until it turns green

What does integrating test automation into CI/CD mean?

It means your automated tests run by themselves, on a clean machine, every time someone pushes code or opens a pull request, and their result decides whether the change can be merged or deployed. Continuous integration (CI) is the practice of merging small changes often and verifying each one with an automated build and test run. Continuous delivery or deployment (CD) extends the same pipeline to package and release the application once those checks pass.

A test that only runs on a developer's laptop protects nobody else; the same test in CI protects the whole team.

Why should automated tests run in a CI/CD pipeline?

Because a regression found minutes after the commit that caused it is cheap to fix, while the same regression found in production is expensive and visible to users. CI adds three guarantees that local runs cannot:

  • Consistency: every change is tested in the same clean environment, which removes the "it works on my machine" problem
  • Enforcement: with branch protection, a failing test prevents the merge instead of relying on everyone's discipline
  • Traceability: each run keeps its logs, reports and artifacts, so anyone can see what failed, when, and on which commit

Which tests should run at each stage of the pipeline?

Run the fastest and most reliable tests first and the slowest ones last, so the pipeline fails as early as possible. This follows the test pyramid: many unit tests, fewer API and integration tests, and a small set of end-to-end tests on critical user journeys.

StageTriggerTestsGoal
1. Commit checksEvery pushLinting, unit testsFast feedback on the change itself
2. IntegrationEvery pull requestAPI and integration tests against real services or containersCheck the contracts between components
3. End-to-endPull requests to main, or after mergePlaywright, Cypress or Selenium tests on critical journeysVerify the application as a user sees it
4. Post-deploymentAfter each deploymentSmoke tests on the deployed environmentConfirm the release is up and usable
5. ScheduledNightlyFull regression, cross-browser, performanceCatch what is too slow to run on every commit

API tests are fast and point straight at the faulty endpoint. Our comparison of API testing tools (Postman, REST Assured, Playwright) explains which one to run in your pipeline.

How do you run automated tests in GitHub Actions?

Create a YAML workflow file in .github/workflows/, declare the events that trigger it and list the steps that install dependencies and run the tests. GitHub then runs the workflow on a hosted runner (Ubuntu, Windows or macOS) or on your own self-hosted runner.

  1. Trigger: on: pull_request and on: push to main; add schedule for a nightly run and workflow_dispatch for manual runs.
  2. Set up: actions/checkout, then actions/setup-node or actions/setup-python with dependency caching enabled.
  3. Install: npm ci or pip install -r requirements.txt; for Playwright, npx playwright install --with-deps installs the browsers and their system dependencies.
  4. Run: npx playwright test, or pytest --junitxml=report.xml for a Python suite.
  5. Keep the evidence: actions/upload-artifact with if: always(), so reports, traces and screenshots are kept even when the job fails. Store credentials in encrypted secrets, never in the test code.
  6. Enforce: in the repository settings, add the job as a required status check on the protected main branch.

GitHub Actions is free for public repositories on standard GitHub-hosted runners; private repositories get a monthly quota of included minutes that depends on the GitHub plan (source: GitHub Actions billing documentation).

GitHub Actions vs GitLab CI vs Jenkins: which should you choose?

Choose the platform that already hosts your code: GitHub Actions for GitHub repositories, GitLab CI for GitLab, and Jenkins when you need a self-hosted automation server with full control, typically in on-premise enterprise environments. All three can run any test framework, run jobs in parallel and publish test reports.

CriterionGitHub ActionsGitLab CIJenkins
Pipeline file.github/workflows/*.yml.gitlab-ci.ymlJenkinsfile (Groovy-based)
Where jobs runGitHub-hosted or self-hosted runnersShared runners on GitLab.com or self-managed runnersYour own controller and agents
Parallel testsstrategy: matrixparallel keyword, needs for DAG pipelinesparallel stages
Test resultsArtifacts and report actionsJUnit reports displayed in merge requestsJUnit plugin with result trends
Best forGitHub projects, first CI pipelinesGitLab users, multi-stage pipelinesOn-premise and highly customised setups

How do you keep a CI test pipeline fast?

Cache, parallelise and schedule, but never delete coverage to save time. A pipeline that takes too long gets bypassed.

  1. Cache dependencies (npm, pip, browser binaries) between runs.
  2. Parallelise with matrix jobs, Playwright sharding (npx playwright test --shard=1/4) or pytest-xdist (pytest -n auto).
  3. Order the stages so cheap checks fail before expensive ones start.
  4. Move slow suites such as full cross-browser regression and performance tests to a nightly schedule.
  5. Use containers for databases and dependent services, so every run starts from a known state.
  6. Prepare test data through APIs rather than through the user interface.

How do you handle flaky tests in CI?

Treat a flaky test as a bug: isolate it, find the cause and fix it, instead of rerunning the pipeline until it turns green. Once failures are ignored by default, a real regression slips through unnoticed.

The usual causes are fixed waits (sleep) instead of waiting for a condition, tests that depend on each other's data, shared environments and unstable selectors. Retries help with diagnosis: Playwright reports a test that fails and then passes on retry as "flaky", and its trace viewer (trace: 'on-first-retry') records what happened. Give every quarantined test an owner. Our guide to test automation best practices covers the design rules that prevent flakiness in the first place.

Where should a small team start?

Start with one workflow that runs your existing unit and API tests on every pull request, make it a required check, then add end-to-end tests on two or three critical journeys. Add parallelisation and a nightly regression run once that loop is trusted.

Frequently asked questions

What is the difference between CI and CD?

Continuous integration (CI) automatically builds and tests every change merged into the shared code base. Continuous delivery or deployment (CD) takes the changes that passed CI and packages, deploys or releases them automatically. Automated tests are the gate between the two.

Which tests should run on every pull request?

Linting, unit tests and API or integration tests, plus a small set of end-to-end tests on critical user journeys. Long cross-browser or performance suites usually run on a nightly schedule instead.

Is GitHub Actions free for running automated tests?

It is free for public repositories on standard GitHub-hosted runners. Private repositories get a monthly quota of included minutes that depends on the GitHub plan, and you can also use your own self-hosted runners.

Should failed tests be retried automatically in CI?

One retry is acceptable to detect flakiness, as long as tests that pass only on retry are reported and fixed. Rerunning the pipeline until it turns green hides real regressions.

Can Playwright tests run in Jenkins or GitLab CI?

Yes. Playwright runs from the command line with npx playwright test, so any CI platform that can install Node.js and the browsers can run it. Microsoft also publishes Docker images with the browsers preinstalled.

Learn CI/CD for test automation

At Automation DataCamp (ADC), the CI/CD for Automation course (35 h, online) covers Jenkins, GitLab CI, GitHub Actions and Azure DevOps, with reporting, notifications and pipeline optimisation. Our flagship QA Automation & AI Tester programme (399 h over 12 weeks, taught in French) includes a GitHub Actions CI pipeline for your Playwright tests.

View the CI/CD course View the 3-month programme

Related articles