Integrating Playwright with TestRail
Playwright (opens in a new tab) is a one of the most popular browser automation tools similar to Selenium WebDriver (opens in a new tab). Railflow CLI consumes the Playwright JSON Reports (opens in a new tab) to provide a seamless integration with TestRail (opens in a new tab)
Railflow for Playwright provides the following capabilities
Test Mapping
: Map Playwright tests to existing tests in TestRailAuto Extraction
: Automatically process Playwright JSON reportsCustom Fields
: Support for TestRail custom fields.Smart Failure Assignment
: Auto assign test failures to TestRail userTestRail Entities
: Update / Create Test Plans, Runs, Milestone, Tests, ResultsTest Steps
: Ability to capture Playwright steps as TestRail StepsScreenshot Attachment
: Automatically take and attach screenshotsCI Application
: Support for Jenkins, TeamCity, Gitlab, Github, etc.
Getting Started
To demonstrate this integration, we have created a sample project: Playwright Demo Project (opens in a new tab). This project contains some tests that pass and fail and produce screenshots.
Basic Flow
In this example, we will simply export all the playwright tests to TestRail. Railflow CLI will automatically create tests, milestones, runs, plans.
The sample project contains json report config in playwright.config.ts
. Make sure to do so in your own Playwright project
//playwright.config.ts
const config: PlaywrightTestConfig = {
reporter: [['json', { outputFile: 'playwright-report/test-results.json' }]],
};
Run tests and produce json report
git clone https://github.com/railflow/playwright-railflow-demo/tree/main
npx playwright test
After test run ends, feed the playwright-report/test-results.json
report to Railflow CLI
npx railflow -k ABCDE-12345-FGHIJ-67890 -url https://testrail.your-server.com/ -u testrail-username -p testrail-password -pr "Railflow Demo" -path section1/section2 -f playwright -r ./playwright-report/test-results.json -sm path
CLI Reference
Railflow CLI will automatically create tests, runs, plans, milestones, etc. if they do not exist.
Environment Variables:
To avoid exposing sensitive information like TestRail URL, License, username, and password in CLI arguments, users can set the following environment variables: RAILFLOW_LICENSE
, RAILFLOW_TR_URL
, RAILFLOW_TR_USER
, RAILFLOW_TR_PASSWORD
. Railflow CLI will always check these environment variables at run time.
Use double quotes for argument values with spaces. Example: --project "demo project"
Key | Required | Description | Example |
---|---|---|---|
-v, --version | No | Outputs Railflow version number | -v |
-k, --key | -k or -l | (online activation) License key. Can be set with RAILFLOW_LICENSE environment variable | -k XXXXX-XXXXX-XXXXX-XXXXX |
-l, --license-file | -k or -l | (offline activation) File path or remote url license file | -l /files/ActivationFile.skm |
-url, --url | Yes | TestRail instance URL. Can be set with RAILFLOW_TR_URL environment variable | -url https://example.testrail.io (opens in a new tab) |
-u, --username | Yes | TestRail username. Can be set with RAILFLOW_TR_USER environment variable | -u test-username |
-p, --password | Yes | TestRail password or API Key. Can be set with RAILFLOW_TR_PASSWORD environment variable | -p XtpHXiPLEODyhF |
-pr, --project | Yes | TestRail project name | -pr "example project" |
-path, --test-path | Yes | TestRail test cases path | -path "Section1/subsection2/ShoppingCart |
-f, --format | Yes | Report format: JUnit, JUnit-Steps, TestNg, TestNg-Steps, Cucumber, NUnit, NUnit-SpecFlow, Allure, Robot, TRX, xUnit, PyTest-Railflow, Playwright (case insensitive) | -f junit |
-r, --report-files | Yes | The file path(s) to the test report file(s) generated during the build. User can pass multiple values separated with spaces. Ant-style patterns such as **/surefire-reports/*.xml can be used. E.g. use target/surefire-reports/*.xml to capture all XML files in target/surefire-reports directory. | -r target/surefire-reports/*.xml target/failsafe-reports/*.xml |
-sm, --search-mode | Yes | Specifies the test case lookup algorithm. name: search for test case matching the name within the entire test suite. If test case found, update the test case. If test case not found, create a new test case within specified -path path: search for test case matching the name within the specified -path . If test case found, update the test case. If test case not found, create a new test case within specified -path | -sm path |
-px, --proxy | No | HTTP or SOCKS proxy configuration E.g. socks://username:[email protected]:1080 | -px socks://username:[email protected]:1080 |
-t, --timeout | No | Upload timeout (seconds) | -t 10 |
-tr, --test-run | No | TestRail test run name | -tr "Chrome Regression Run" |
-tp, --test-plan | No | TestRail test plan Name | -tp "Shopping Cart Test Plan" |
-mp, --milestone-path | No | TestRail milestone path | -mp Milestone1/Milestone2 |
-cf, --case-fields | No | TestRail test case custom fields. The format is [Field label]=[value] pairs, separated with space. E.g. "Case Field 1=value 1" "Case Field 2=value 2" ... | -cf "Case Field 1=value 1" "Case Field 2=value 2" |
-rf, --result-fields | No | TestRail test result custom fields. The format is [Field label]=[value] pairs, separated with space. E.g. "Result Field 1=value 1" "Result Field 2=value 2" ... | -rf "Result Field 1=value 1" "Result Field 2=value 2" |
-a, --assign | No | Smart Test Failure Assignment. Comma-separated list of TestRail users (email addresses). Railflow will assign failures based on a round robin algorithm. | -a [email protected],[email protected] |
-af, --assign-file | No | Smart Test Failure Assignment. File path containing list of TestRail users (email addresses). Note: One user per line | -af /assignees.txt |
-cn, --config-names | No | TestRail test plan configuration options. Configuration format is: [config_group_name]/[config_name]. E.g. "Operating Systems/Linux" "Browsers/Chrome" ... | -cn "Operating Systems/Linux" "Browsers/Chrome" |
-cr, --close-run | No | If Railflow should close the corresponding run after uploading test results | -cr |
-cp, --close-plan | No | If Railflow should close the corresponding plan after uploading test results | -cp |
-dg, --disable-grouping | No | If Railflow should ignore report structure and just upload all tests into a folder which is set by test-path parameter | -dg |
-tn, --template-name | No | The name of a template to use in TestRail. If it is not set, 'Test Case (Steps)' or the default one will be used | -tn "Test Case (Steps)" |
-cst, --case-type | No | The name of a type for cases | -cst other |
-csp, --case-priority | No | The name of a priority for cases | -csp medium |
-th, --thread-number | No | The number of concurrent threads for exporting data. Default is 4 | -th 8 |
-um, --upload-mode | No | Upload mode. Available values are: 0 (default) - create new test cases and do not overwrite existing ones; 1 - create new cases and overwrite existing ones; 2 - do not create new cases and overwrite existing ones; 3 - do not create new cases and do not overwrite existing ones | -um 1 |
-csf, --case-search-field | No | The name of the case field in TestRail which will be using for searching for existing test cases instead of test case title | -csf "Custom field" |
-ds, --disable-stats | No | If Railflow should disable collecting usage and error logs | -ds |
-fqtn, --fully-qualified-test-name | No | If checked, Railflow will use fully qualified test names from the report files for test names in TestRail | -fqtn |
-us, --untested-status | No | The name of the status to use in TestRail for untested/skipped tests | -us Skipped |
-ams, --attachment-max-size | No | Maximum size of an attachment. Can be set in Gb, Mb, Kb or b. If the unit is not provided considered as Mb. E.g. 1Gb, 2, 20Kb, 3Mb | -ams 1Gb |
-atw, --attachment-type-whitelist | No | The comma-separated list of file extensions which are allowed to upload. E.g. json, .html, .xml | -atw "json, .html, .xml" |
-atb, --attachment-type-blacklist | No | The comma-separated list of file extensions which are not allowed to upload. E.g. json, .html, .xml | -atb "json, .html, .xml" |
-nr, --no-run | No | Do not create or update Test Run in TestRail | -nr |
-tfn, --tags-field-name | No | The name of a test case field which will be holding tags from the report file if any. E.g. Cucumber Tags | -tfn "Cucumber Tags" |
-h, --help | No | Show the help information | -h |
Test Mapping
In many organizations tests are first developed in TestRail and then eventually automated and mapped back to TestRail. Railflow uses a convienient annoation testrail.id
to help user spcify the TestRail ID for any Playwright tests. This information is automatically added to JSON report and processed accordingly by the Railflow CLI.
import {expect, test} from '@playwright/test';
test.describe("Login tests", () => {
test('some sample tests', async ({page}) => {
//this means that this tests is mapped to two tests in TestRail
//type contains the name of annotation - `testrail.id` and `description` is TestRail Test ID
test.info().annotations.push(
{type: 'testrail.id', description: 'C1825'},
{type: 'testrail.id', description: 'C1826'}
)
//your test logic
});
});
Test Steps
Playwright provides the ability to add test steps (opens in a new tab) to your tests. These are reported in the json report and can therefore be processed by Railflow CLI and mapped to Steps in TestRail. This is incredibly useful and powerful.
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await test.step('Log in', async () => {
// ...
});
await test.step('Outer step', async () => {
// ...
// You can nest steps inside each other.
await test.step('Inner step', async () => {
// ...
});
});
});
Metadata / Custom Fields
Railflow CLI looks out for a variety of annotations in the JSON report. The following can be specifed using Playwright annotations. There are a few reasons why you may find this helpful
- The Playwight title may not be super friend and you want to have a different test title in TestRail
- Sometimes using Railflow CLI for all tests may not be suitable and you want more granular control
- Specify TestRail Custom Fields
Annotation type | Description |
---|---|
testrail.title | Test Case title. If provided, it overrides the default test name |
testrail.case_type | Defines the case type for this test case in TestRail |
testrail.case_priority | Defines the priority for this test case in TestRail |
testrail.case_field | Defines the value for a particular field of the corresponding test case in TestRail. The format is [TR field label]=[value], e.g. Required field = Some value If you need to provide values for several fields, use multiple testrail.case_field annotations - one per field |
testrail.result_field | Defines the value for a particular field of the corresponding test result in TestRail. The format is [TR field label]=[value], e.g. Custom result field = Some value If you need to provide values for several fields, use multiple testrail.result_field annotations - one per field |
import {expect, test} from '@playwright/test';
test.describe("Login tests", () => {
test('User logs into home cabinet using incorrect user name and password', async ({page}) => {
test.info().annotations.push({type: 'testrail.title', description: 'This title was modified by Railflow!'},
{type: 'testrail.case_type', description: 'Railflow'},
{type: 'testrail.case_priority', description: 'Critical'},
{type: 'testrail.case_field', description: "Required Text Field = Hello from Playwright annotations"},
{type: 'testrail.case_field', description: "Estimate = 10s"},
{type: 'testrail.result_field', description: "Custom field = Results from Playwright"},
{type: 'testrail.result_field', description: "Version = 1.0"});
// test logic
});
});
Test Results