> For the complete documentation index, see [llms.txt](https://coldbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/continuous-integration.md). Agents can also search and read this documentation through its [MCP server](https://coldbox.ortusbooks.com/~gitbook/mcp).

# Continuous Integration

Run ColdBox browser tests on GitHub Actions: start the application, install Chromium with its system libraries, run the specs and upload the artifacts.

A browser test job does four things: install BoxLang, bx-playwright and a browser, start your application in the `testing` environment, run the specs with the `ci` profile, and upload the screenshots, traces and videos of failed specs.

## GitHub Actions

This workflow runs a ColdBox application on a CommandBox BoxLang server and runs its tests through the HTML runner with `box testbox run`.

```yaml
name: Browser Tests

on: [ push, pull_request ]

jobs:
  browser-tests:
    runs-on: ubuntu-latest
    env:
      # The application detects its environment from this variable
      ENVIRONMENT: testing
      # Headless, keep screenshots, traces and videos of failures
      BX_PLAYWRIGHT_PROFILE: ci
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: "21"

      # BoxLang OS runtime + bx-playwright, for the bxplaywright CLI
      - uses: ortus-boxlang/setup-boxlang@main
        with:
          version: latest
          modules: bx-playwright

      - uses: Ortus-Solutions/setup-commandbox@v2.0.1
        with:
          install: commandbox-boxlang

      - name: Install dependencies
        run: box install

      # Driver, Node.js and browsers: one download per bx-playwright version
      - name: Read the bx-playwright version
        id: pw
        run: echo "version=$( jq -r .version ~/.boxlang/modules/bx-playwright/box.json )" >> "$GITHUB_OUTPUT"

      - uses: actions/cache@v4
        with:
          path: ~/.boxlang/playwright
          key: playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}

      # --with-deps installs the system libraries, which are not cached
      - name: Install Chromium
        run: |
          export PATH="$HOME/.boxlang/bin:$PATH"
          bxplaywright install chromium --with-deps
          bxplaywright doctor

      - name: Start the application
        run: |
          box server start --noSaveSettings
          curl --silent --show-error --fail --retry 10 --retry-delay 3 --retry-all-errors http://127.0.0.1:8080 > /dev/null

      - name: Run the tests
        run: box testbox run

      - name: Upload failure artifacts
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: browser-test-artifacts
          path: |
            ~/.boxlang/playwright/artifacts
            tests/results
          if-no-files-found: ignore

      - name: Server log on failure
        if: failure()
        run: box server log
```

Adapt it to your project:

* The `server.json` of the application must install bx-playwright in the server (`"onServerInitialInstall": "install bx-playwright --noSave"`) and listen on the port your specs use as `baseURL`, here `8080`. See [Setup](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/setup.md).
* `box testbox run` needs the runner URL in your `box.json` (`testbox.runner`), see the [Testing quick start](https://coldbox.ortusbooks.com/the-basics/testing-quick-start.md#commandbox-runner).
* The server inherits `ENVIRONMENT` and `BX_PLAYWRIGHT_PROFILE` from the job, and so do the specs running inside it.
* Store the passwords of your test users as CI secrets, and read them in your saved session setup. See [Authentication](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/authentication.md#test-users-and-passwords).
* Open a downloaded trace locally with `bxplaywright show-trace trace.zip`.

## With the BoxLang MiniServer

Without CommandBox, serve the application with the BoxLang MiniServer and call the HTML runner. The runner answers with `x-testbox-totalFail` and `x-testbox-totalError` headers, so the job can fail on them. Replace the last steps with:

```yaml
      - name: Run the browser tests
        run: |
          install-bx-module bx-playwright
          install-bx-module bx-esapi
          boxlang-miniserver --port 8080 --rewrites &
          until curl -s -o /dev/null http://127.0.0.1:8080/; do sleep 2; done
          curl -s -D headers.txt "http://127.0.0.1:8080/tests/runner.bxm?directory=tests.specs.browser&reporter=text"
          ! grep -qiE "^x-testbox-total(Fail|Error): [1-9]" headers.txt
```

TestBox's BoxLang CLI runner (`./testbox/run`) and its `--web-server` options cannot run `BaseTestCase` specs yet, because ColdBox needs the `cgi` scope of a web request (see [Setup](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/setup.md#run-your-application)).

## Tips

* **Cache `~/.boxlang/playwright`** between runs, as above, to skip the driver and browser downloads.
* **Run browser specs in their own job** so a slow or flaky browser run does not hold back your fast unit and integration tests.
* **Publish JUnit reports** with an action such as `mikepenz/action-junit-report`: TestBox writes each attachment as an `[[ATTACHMENT|path]]` line in the `<system-out>` of the spec.
* **Retry sparingly**: `--retries=1` hides a timing glitch, but a spec that needs retries usually needs a better wait or selector.

## See Also

* [Artifacts & Debugging](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/artifacts-and-debugging.md)
* [Troubleshooting](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/troubleshooting.md)
* [bx-playwright Testing: CI](https://bxplaywright.boxlang.io/testing/)
* [setup-boxlang action](https://github.com/ortus-boxlang/setup-boxlang)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox.ortusbooks.com/the-basics/testing-quick-start/browser-testing/continuous-integration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
