Skip to main content
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

GitLab CI with BrowserStack Load Testing

Integrate BrowserStack Load Testing into GitLab CI pipelines to run load tests in your CI/CD workflows.

You can add BrowserStack Load Testing to your GitLab CI pipelines so that every push or merge request triggers a load test.

Prerequisites

Make sure you have the following before you start:

  • A BrowserStack account with access to Load Testing.
  • A GitLab project where you can define pipelines (works on gitlab.com free tier as well as self-hosted GitLab).
  • GitLab CI/CD variables for your BrowserStack credentials. You can find the credentials on your account’s profile page:
    • BROWSERSTACK_USERNAME: Your BrowserStack username.
    • BROWSERSTACK_ACCESS_KEY: Your BrowserStack access key.

To add the variables:

  1. Go to your project on GitLab.
  2. In the left sidebar, navigate to Settings → CI/CD.
  3. Expand the Variables section.
  4. Click Add variable for each of the two credentials.
  5. Set the Type to Variable, mark the variable as Masked, and leave Protect variable unchecked unless you only run pipelines on protected branches.
  6. Save.

GitLab automatically injects these as environment variables into every job.

GitLab CI configuration

Use the following GitLab CI configuration to download the BrowserStack CLI, run a sample Playwright-based load test, and upload JUnit XML reports as a pipeline artifact. Save it at the repository root as .gitlab-ci.yml.

stages:
  - test

load-test:
  stage: test
  image: ubuntu:22.04
  before_script:
    - apt-get update -qq && apt-get install -y -qq curl unzip ca-certificates
  script:
    - echo "Running unit tests"
    - |
      : "${BROWSERSTACK_USERNAME:?set as a CI/CD variable in Project Settings}"
      : "${BROWSERSTACK_ACCESS_KEY:?set as a CI/CD variable in Project Settings}"
    - |
      OS=$(uname -s); ARCH=$(uname -m)
      [ "$OS" = "Darwin" ] && OS=macos || OS=linux
      [[ "$ARCH" == *arm* ]] && ARCH=arm64 || ARCH=x64
      curl -fL "https://load-api.browserstack.com/api/v1/binary?os=${OS}&arch=${ARCH}" -o browserstack-cli.zip
      unzip -oq browserstack-cli.zip
      chmod +x browserstack-cli
    - |
      curl -L https://github.com/browserstack/browserstack-playwright-load-testing-sample/archive/refs/heads/CI/CD-Sample-Playwright.tar.gz \
        | tar -xz --strip-components=1
    - ./browserstack-cli load run
  artifacts:
    when: always
    paths:
      - reports-*/browserstack-load-test-report-*.xml
    reports:
      junit: reports-*/browserstack-load-test-report-*.xml

Result

When this pipeline runs, it:

  • Downloads the BrowserStack CLI for the current runner OS and architecture.
  • Fetches the BrowserStack Playwright load-testing sample project.
  • Starts a BrowserStack Load Testing run using your BrowserStack credentials.
  • Uploads the generated JUnit XML reports as pipeline artifacts and exposes them in GitLab’s Tests tab via JUnit parsing.

Notes

  • gitlab.com new accounts may need to verify a payment method before shared runners pick up the job (no charge; verification only).
  • Default branch is main on new GitLab projects; the pipeline runs on every push and merge request by default.
  • If you need to scope the run to a specific branch, use GitLab’s rules: or only: syntax inside the load-test job.
  • The pipeline works on Linux runners by default (the recommended ubuntu:22.04 image). For macOS or Windows runners, you’d need a self-hosted runner with the corresponding OS.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle