Our documentation site has been updated to AIO Tests Knowledge Base
Playwright
AIO Tests supports importing Playwright test results through it’s support for JUnit reports/Cucumber reports or via the AIO Tests REST APIs, which can be invoked from the hooks available in Playwright.
Playwright is an open-source NodeJS-based framework by Microsoft used for web testing and automation. It supports end to end cross-browser testing through its high-level API, allowing the tester to control a wide variety of browses and also headless browsers.
This document provides an overview on :
Generating the Junit report from Playwright tests and uploading it to AIO Tests.
Generating Cucumber reports with Playwright + Cucumber and uploading it in AIO Tests
Using AIO Tests REST APIs to report results and much more, using the Playwright framework hooks.
Playwright + JUnit
The demo example is based on the Getting Started project of Playwright.
Required Playwright Setup
npm init playwright@latest
. On prompt, select the tests folderFor reporting results
For JUnit report :
PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --reporter=junit
For reporting results via AIO Tests API :
npm install axios
(This can be replaced with any library to make API calls)
Mapping and Running your tests
The sample test generated by Playwright is as follows.
In AIO Tests, a unique key PROJKEY-TC-12 exists for each case. The unique key can be added to the test name to report results against it in AIO Tests.
The example below shows PROJ1-TC-23 added to the test name. On running the test, the reports will contain the case key.
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
});
const TODO_ITEMS = [
'feed the cat',
'book a doctors appointment'
];
test.describe('New Todo', () => {
test('PROJ1-TC-23 : should allow me to add todo items', async ({page}) => {
// create a new todo locator
const newTodo = page.getByPlaceholder('What needs to be done?');
// Create 1st todo.
await newTodo.fill(TODO_ITEMS[0]);
await newTodo.press('Enter');
// Make sure the list only has one todo item.
await expect(page.getByTestId('todo-title')).toHaveText([
TODO_ITEMS[0]
]);
// Create 2nd todo.
await newTodo.fill(TODO_ITEMS[1]);
await newTodo.press('Enter');
// Make sure the list now has two todo items.
await expect(page.getByTestId('todo-title')).toHaveText([
TODO_ITEMS[0],
TODO_ITEMS[1]
]);
});
});
To trigger the Playwright tests, use:
npx playwright test
Reporting results via JUnit file
Using the native JUnit reporter
Playwright Test comes with a few built-in reporters for different needs and ability to provide custom reporters. The easiest way to try out built-in reporters is to pass --reporter
.
Running the tests generates the following Junit xml:
Uploading results to AIO Tests
Post execution of a suite, the TEST-<xxx>.xml file can be uploaded either via
AIO Tests REST API call using multipart form-data to upload file
Please follow the above links to continue to import results using either of the options.
Uploading the above file for the first time will
create new cases in the system. The new case is created with
- title as thename
value from <testcase> tag of the JUnit report
- automation key asclassname.name
from the JUnit report.
- status as Published
- automation status as Automated
- automation owner as user uploading the resultsAdd the newly created case to the cycle being uploaded to
Mark the details of the run
Execution mode is set to Automated
Duration of run is set to Actual Effort
Status of run is set based on status mapping table below
Failures and errors are reported as Run Level comments
If the same file is uploaded again, the cases will be identified using the automation key (
classname.name )
and would be updated, instead of creating new cases.
Status Mapping JUnit → AIO Tests
JUnit XML | Description | AIO Tests Mapping |
---|---|---|
No tag inside <testcase> means Passed | Passed case | Passed |
</skipped> | Skipped case either by @Ignore or others | Not Run |
</failure> |
| Failed |
</error> |
| Failed |
Reporting results via Playwright Hooks and AIO Tests REST APIs
AIO Tests provides a rich set of APIs for Execution Management, using which users can not only report execution status, but also add effort, actual results, comments, defects and attachments to runs as well as steps.
AIO Tests also provides APIs to create cycles and to add cases to cycles for execution planning.
The basic sample below will show how Mocha Hooks in WebdriverIO can leverage the AIO Tests REST APIs to report results. In the wdio.conf.js, the afterTest
method can be used to make AIO API call.
Mocha aftestTest method
The afterTest call is defined as below: [ref Configuration File | WebdriverIO ]
/**
* Function to be executed after a test (in Mocha/Jasmine only)
* @param {Object} test test object
* @param {Object} context scope object the test was executed with
* @param {Error} result.error error object in case the test fails, otherwise `undefined`
* @param {Any} result.result return object of test function
* @param {Number} result.duration duration of test
* @param {Boolean} result.passed true if test has passed, otherwise false
* @param {Object} result.retries informations to spec related retries, e.g. `{ attempts: 0, limit: 0 }`
*/
afterTest: function (test, context, { error, result, duration, passed, retries }) {
},
Establish a convention for AIO Tests Case keys
For the purpose of the example, we have established a convention to map cases - the AIO Tests case key is the prefix to the case title e.g. it('NVPROJ-TC-11: should login with valid credentials'
contains NVPROJ-TC-11, which is the AIO Tests Case key.
Any convention can be established and the code consuming it can cater to the convention. In our case, we are using startsWith to identify the case key.
Reporting result via API
Playwright provides a way to develop custom reporters.
In the example below, a new class AIOReporter (aio-reporter.js) uses the onTestEnd
method to make a call to AIO REST API
Register the reporter in the playwright.config file as below:
reporter: './aio-reporter.js',
In the example above, the postResults
method uses Axios to make an HTTP call.
It uses the test title to identify the case key [ based on the convention established]
Create a POST request
URL : For cloud the url host would be
https://tcms.aiojiraapps.com/aio-tcms/api/v1
. For Jira server, it would be the native Jira server hostname.Authorization : Please refer to Rest API Authentication to understand how to authorize users. The authentication information goes in the
headers: {'Authorization': '<Auth based on Jira Cloud/Jira Server>'},
POST Body : The body consists of data from the test and result object provided by Playwright. If the case has failed, the error is posted as comments.
If required, the basic example can be extended to upload attachments against the case using the upload attachment API.
The above is a basic example of what can be done with the hooks and AIO Tests APIs. It is recommended to add appropriate error handling and enhance it based on your automation requirements.
Playwright + Cucumber Setup
npm init playwright@latest
. On prompt, select the tests foldernpm install @cucumber/cucumber
.
Mapping and Running your tests
Cucumber generates a cucumber.json report which can be directly imported in AIO Tests.
In AIO Tests, a unique key PROJKEY-TC-12 exists for each case. The unique key can be added to the scenario tags to report results against it in AIO Tests. All scenario that are not tagged, will be created as new cases, alongwith the steps from the json report.
Below example maps a scenario to an AIO Case
To trigger the cucumber tests:
./node_modules/.bin/cucumber-js -f json:tmp/cucumber_report1.json --exit
This would generate the Cucumber JSON report as below:
Uploading results to AIO Tests
Post execution of a suite, the cucumber.json file can be uploaded either via
AIO Tests REST API call using multipart form-data to upload file
Please follow the above links to continue to import results using either of the options.
Uploading the above file for the first time will
create new cases in the system. The new case is created with
- title as thescenario description
- automation key asscenario.id
from the JSON report.
- steps
- status as Published
- automation status as Automated
- automation owner as user uploading the resultsAdd the newly created case to the cycle being uploaded to
Mark the details of the run
Execution mode is set to Automated
Duration of run is set to Actual Effort
Status of run is set based on status mapping table below
Failures and errors are reported as Run Level comments
Steps level results and step level actual result in case of failure
If the same file is uploaded again, the cases will be identified using the automation key (
scenario.id)
and would be updated, instead of creating new cases.
Reporting results via Cucumber Hooks and AIO Tests REST APIs
AIO Tests provides a rich set of APIs for Execution Management, using which users can not only report execution status, but also add effort, actual results, comments, defects and attachments to runs as well as steps.
AIO Tests also provides APIs to create cycles and to add cases to cycles for execution planning.
The basic sample below will show how Cucumber Hooks can leverage the AIO Tests REST APIs to report results.
To trigger the playwright tests with the above file, the reporting file needs to be provided to cucumber-js, using the following command:
./node_modules/.bin/cucumber-js -f json:./tmp/cucumber_report1.json --require features/support/handlers.js --require features/support/steps.js