<!-- Canonical HTML: https://docs.didro.ai/sap-ui-automation/guides/ci -->

# Running in CI

Recorded tests (`*.saptest.json`) and TypeScript tests (`*.sap.ts`) both
run with no model, so a CI job can run them on each change. This page says
what the machine needs, which settings to pin, and what the job keeps.

| You have | Run | Report |
| --- | --- | --- |
| recordings | `sap-ui-automation replay sap-tests/*.saptest.json --junit report.xml` | JUnit XML, one suite per test and one case per step |
| `*.sap.ts` tests | `sap-ui-automation test --reporter list,junit,html` | `sap-results/junit.xml`, `sap-results/index.html` with each test's trace |

Both exit with 0 when every test passed and 1 otherwise, so the job fails
when a test does. The test runner's flags and reporters:
[Test runner](https://docs.didro.ai/sap-ui-automation/reference/test-runner); replay's:
[CLI commands](https://docs.didro.ai/sap-ui-automation/reference/cli#replay).

## What the machine needs

The server never logs on, and neither do replay and the test runner: they
attach to an SAP session that is open and logged on. A CI runner needs
one:

- **Web GUI or Fiori:** a Chrome with an SAP tab, logged on, that the
  server can reach: the SAP window it starts (`SAP_BROWSER=launch`, kept
  open or on a runner whose SSO logs on automatically), or
  a Chrome started with a debugging port (`SAP_CHROME_CDP`, see
  [Chrome](https://docs.didro.ai/sap-ui-automation/guides/chrome#a-chrome-started-with-a-debugging-port)). On a runner
  with no screen, the SAP window runs headless (`SAP_CHROME_HEADLESS=on`)
  and you log on in it once through `chrome://inspect`, as with the Docker
  image ([Docker](https://docs.didro.ai/sap-ui-automation/guides/docker#log-on); mind its
  [security notes](https://docs.didro.ai/sap-ui-automation/guides/docker#security) on the DevTools port). In practice
  this is a self-hosted runner kept logged on.
- **SAP GUI for Windows:** a Windows runner with SAP GUI running and
  logged on, scripting allowed ([SAP GUI for Windows](https://docs.didro.ai/sap-ui-automation/guides/sap-gui-windows)),
  in the desktop session of the user the job runs as.
- **A runner that must log on by itself:** export the recording to a
  Playwright spec (`export --to playwright`). The spec logs on from
  `SAP_WEBGUI_URL`, `SAP_USER` and `SAP_PASSWORD`, which you keep in the
  CI's secrets; the server never reads them
  ([Export targets](https://docs.didro.ai/sap-ui-automation/guides/record-replay#playwright)).

Neither replay nor the runner creates the data a test needs or restores
the system afterwards. Run them on a test system, with test data the tests
create in earlier steps or find with captures.

## Pin the settings

Set these in the job's environment, not in the tests:

| Setting | Why |
| --- | --- |
| `SAP_WRITE=off` | unless the test system is meant to change: a step that may write then fails with that reason instead of saving |
| `SAP_ALLOW_SYSTEMS=QAS/100` | only the test system's sessions are seen, even if the runner has others open |
| `SAP_ALLOW_TCODES=VA03,MM03` | the transactions the tests may use, and no others |
| `SAP_SURFACES=webgui` | look only where the tests run; no SAP GUI search on a Windows runner that has none |

The test runner's `use: { write: "off" }` in `sap.config.ts` does the same
for one project. Every setting: [Configuration](https://docs.didro.ai/sap-ui-automation/reference/configuration).

## Keep the results

- **Reports.** Upload `report.xml` or `sap-results/junit.xml` to the CI's
  test report view, and `sap-results/` as an artifact.
- **Traces.** Each test's trace is in `sap-results/<test>/`; `show-trace`
  turns one into an HTML page ([Trace viewer](https://docs.didro.ai/sap-ui-automation/guides/trace-viewer)). Traces
  hold the screens, and so business data: keep the artifacts where that
  data may be kept, with a short retention, and never on a public job.
- **A clean folder.** `sap-results/` is not emptied before a run: delete
  it first (`rm -rf sap-results`) so the artifact holds this run only.

## Lock files in CI

A test's lock file (`<name>.sap.lock.json`) records what each screen
looked like on runs that passed; in CI it makes the test fail with
`Drift` where SAP answers otherwise. Commit the lock files with the tests.
Write or refresh them on a test system, not in CI:

```sh
npx sap-ui-automation test --update-locks
```

A run on another system or surface than the lock's skips the comparison.
[Lock files](https://docs.didro.ai/sap-ui-automation/guides/sdk-tests#lock-files) has the rules.
