Reporters, Screenshots on Failure and CI
On this page
The spec reporter is made for a person watching a terminal. A CI server wants machine-readable results it can display per test, and the person who opens a failed build the next morning wants a screenshot of what the browser showed. This chapter adds both, then runs the suite on TestingBot from GitHub Actions.
JUnit XML for the CI server#
Almost every CI system (GitHub Actions through a test-report action, GitLab, Jenkins, Azure DevOps, CircleCI) can read JUnit XML. Install the reporter:
npm install --save-dev @wdio/junit-reporter
and add it next to spec in wdio.testingbot.conf.ts:
reporters: [
'spec',
['junit', {
outputDir: './reports/junit',
outputFileFormat: ({ cid }) => `results-${cid}.xml`
}]
],
Reporters run side by side, so you keep the readable terminal output and get one XML file per worker. outputFileFormat receives the worker id (cid, such as 2-1) so the files from parallel workers do not overwrite each other. A failing test looks like this in the XML:
<testcase classname="chrome.157_0_8103_78.mac.Deliberate_failure" name="expects the wrong heading" time="3.885">
<failure message="Expect $(`h2`) to have text

Expected: "Welcome back"
Received: "Login Page""/>
The classname includes the browser, so a CI report that shows the same test failing only in Safari makes that obvious. Other reporters exist for Allure, JSON and more; the Appium course's reporters chapter sets up JUnit and Allure in detail, and the setup is the same for web tests.
The CI report only ever shows the results of one spec file, although twelve workers ran. What is the likely cause?
Each worker has its own reporter instance and writes its own file. Without a unique name per worker, only the last file survives. Several reporters can run together.
A screenshot when a test fails#
The afterTest hook runs after every test with its result. Add it to wdio.testingbot.conf.ts, together with an onPrepare hook that creates the folder:
import { mkdirSync } from 'node:fs'
import { browser } from '@wdio/globals'
// inside the config object:
onPrepare: function () {
mkdirSync('./reports/screenshots', { recursive: true })
},
afterTest: async function (test, _context, { passed }) {
if (!passed) {
const browserName = browser.capabilities.browserName ?? 'browser'
const name = `${browserName} ${test.parent} ${test.title}`.replace(/[^a-z0-9]+/gi, '-')
await browser.saveScreenshot(`./reports/screenshots/${name}-${browser.sessionId}.png`)
}
},
The onPrepare hook is not optional decoration. The first cloud run of this course had the screenshot hook but not the folder, and every failed test printed an extra error:
ERROR @wdio/utils:shim: Error: directory (.../reports/screenshots) doesn't exist
The file name includes the browser and the session id, because the same test fails in several browsers in parallel workers, and with only the test title in the name each screenshot would overwrite the previous one. saveScreenshot does not create directories. onPrepare runs once in the main process before any worker starts, which makes it the right place for setup like this.
On TestingBot you also get a screenshot of every step and a video of the whole session in the dashboard, so the local screenshot is mostly for the CI artefact: something you can look at from the failed job without opening another tool.
Where should a test suite create the output folder that every worker writes screenshots to?
onPrepare runs once, before the workers, so every worker can rely on the folder. Doing it per test or per file works but repeats the same work in every process.
Run on TestingBot from GitHub Actions#
In CI the runner needs Node.js and your dependencies, but no browsers: they are on TestingBot. Create .github/workflows/e2e.yml:
name: E2E on TestingBot
on:
push:
pull_request:
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- name: Run WebdriverIO on TestingBot
run: npx wdio run wdio.testingbot.conf.ts
env:
TESTINGBOT_KEY: ${{ secrets.TESTINGBOT_KEY }}
TESTINGBOT_SECRET: ${{ secrets.TESTINGBOT_SECRET }}
TB_BUILD: gha-${{ github.run_id }}
TB_PARALLEL: 2
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: wdio-reports
path: reports/
- Add
TESTINGBOT_KEYandTESTINGBOT_SECRETas repository secrets (Settings, then Secrets and variables, then Actions). The config reads them from the environment, so they never appear in the repository or the log. -
TB_BUILDgives each workflow run its own build in the TestingBot dashboard.github.run_idis unique per run, so you can go from a red check on a pull request to exactly the sessions it ran. -
TB_PARALLELshould match your plan's parallel limit (chapter 7). -
wdio runexits with code 1 when any spec file failed, which fails the job; you need nothing extra for that. -
if: always()uploads the JUnit files and failure screenshots even when the test step failed, which is exactly when you need them. - Node.js 24 meets WebdriverIO 10's minimum. Node.js 22 works too, as long as it is 22.23.4 or newer;
setup-nodeinstalls the newest release of the line you name.
For a pull request you might run only the smoke suite and keep the full cross-browser run for the main branch: npx wdio run wdio.testingbot.conf.ts --suite smoke. The GitHub Actions integration guide covers TestingBot-specific extras, and the guides for other CI systems use the same three ingredients: the secrets as environment variables, a build name from the CI run id, and the wdio run command.
The workflow's test step fails, and the "Upload reports" step after it is skipped, so there are no screenshots to look at. What is the fix?
Steps are skipped after a failure unless their condition says otherwise. if: always() runs the upload regardless and keeps the job red. continue-on-error would turn a failing suite into a green job.