Playwright
To use Captain with Playwright, you need to configure your test suite to output test results to a file and then tell Captain where to find those test results.
Getting Started
Playwright can output test results to a file using the --reporter flag. Configure Captain by creating a .captain/config.yml file in the root directory of your repository:
For additional configuration options, see the reference for the configuration file.
test-suites:
your-project-playwright:
command: bash -c 'PLAYWRIGHT_JSON_OUTPUT_NAME=tmp/playwright.json npx playwright test --reporter=json'
results:
path: tmp/playwright.json
You can change your-project-playwright to any name you like, but we typically recommend using the name of your project followed by a dash followed by playwright.
The command is the command you already use to run your test suite. Captain will invoke this command to run your tests. The example above shows what you might use if you use npx playwright test and want to store test results in tmp/playwright.json.
Make sure to include the --reporter flag!
Once Captain is configured, you can run captain run your-project-playwright --print-summary. If you see your typical test output followed by a captain block like this:
--------------------------------------------------------------------------------
----------------------------------- Captain ------------------------------------
--------------------------------------------------------------------------------
then you've configured everything correctly! You can now supercharge your test framework's capabilities. See below for configuring each of Captain's features.
Identifying Tests
Captain uses framework specific "identity recipes" to identify the tests in your suite. These recipes are order dependent components extracted from native test framework output.
We use this identity to track the executions of a test over the course of their lifetime in your suite. This enables us to do things like flake detection, quarantining, and retries.
For Playwright, Captain constructs the identity by parsing out the project, file and description attributes.
Quarantining Tests
Captain makes managing flaky tests easier than ever. When a test is identified as flaky, you can quarantine the test without modifying it, so that if only those tests fail, Captain reports a success with a 0 exit code. Unlike skipped tests, quarantined tests will continue to run, so you can still view their failure messages and see how frequently they are failing.
If you're using Captain Cloud or RWX, you can quarantine tests directly from the web interface instead of managing quarantined tests in your repository, so no code commit is required. Metrics are built-in to help you monitor how frequently your quarantines are being applied.
You can quarantine tests in OSS mode with captain add quarantine like so:
captain add quarantine your-project-playwright \
--project chromium \
--file example.spec.js \
--description "homepage has title and links to intro page"
See the OSS quarantining guide for more information on managing quarantined tests in OSS mode.
Retrying Tests
You can configure Captain to automatically retry failed tests to help you determine if failing tests are flaky or are genuinely failing. To configure retries, update your .captain/config.yml file like so:
test-suites:
your-project-playwright:
command: bash -c 'PLAYWRIGHT_JSON_OUTPUT_NAME=tmp/playwright.json npx playwright test --reporter=json'
results:
path: tmp/playwright.json
output:
print-summary: true
retries:
attempts: 2
command: bash -c "PLAYWRIGHT_JSON_OUTPUT_NAME=tmp/playwright.json npx playwright test {{ tests }} --project '{{ project }}' --reporter=json"
Once configured, Captain will invoke your original test command, check for any failures, and retry your tests however many times you've specified (in this example, two additional times) by templating the failures into the command specified by retries.command. The output.print-summary option is not required, but we've added it for convenience in understanding the overall results after the retries have been factored in.
Retries work with quarantining enabled, so feel free to use them together. Tests will be retried according to the configuration; if they fail after exhausting all attempts, quarantines will be applied to the remaining failures.
Partitioning
Captain can optimally partition your test suite's files into multiple groups for execution on multiple CI nodes. Captain tracks your test file runtime so that it can balance each partition.
Configure partitioning in .captain/config.yml:
test-suites:
your-project-playwright:
command: bash -c 'PLAYWRIGHT_JSON_OUTPUT_NAME=tmp/playwright.json npx playwright test --reporter=json'
results:
path: tmp/playwright.json
output:
print-summary: true
partition:
command: bash -c 'PLAYWRIGHT_JSON_OUTPUT_NAME=tmp/playwright.json npx playwright test {{ testFiles }} --reporter=json'
globs:
- tests/**/*.spec.js
Captain will fill in the testFiles placeholder of your partition.command with the files resulting from expanding your configured partition.globs.
Playwright can be configured with a testDir option, causing it to report
test results relative to this directory. When configured, this will prevent
test file paths from matching the recorded timings Captain uses to partition,
resulting in the application of a round-robin partition strategy. To work
around this, configure a
partition.trim-prefix.
Then partition across your CI provider's parallel jobs:
# .rwx/ci.yml
tasks:
- key: code
call: git/clone 2.0.7
- key: node
call: nodejs/install 1.1.14
with:
node-version: 20
- key: deps
use: [code, node]
run: npm ci
- key: browsers
use: deps
run: npx playwright install --with-deps
- key: captain
call: rwx/install-captain 1.1.6
- key: playwright
use: [browsers, captain]
parallel: 8
run: captain run your-project-playwright
To verify your config before wiring it into CI, run
captain run your-project-playwright --partition-index 0 --partition-total 8 locally and compare the test count to an unpartitioned run.
Usage with ABQ
Captain works with ABQ to support parallel test distribution while respecting the quarantine status of any tests. To use Captain with ABQ, the Captain CLI will wrap ABQ and ABQ will wrap your test suite. For example:
Note that in this example, ABQ's --reporter and Captain's test results path
use the same path.
test-suites:
your-project-playwright:
command: bash -c "abq test --worker $ABQ_WORKER --reporter rwx-v1-json=tmp/abq.json -- npx playwright test"
results:
path: tmp/abq.json
ABQ_WORKER=0 captain run your-project-playwright