This repository serves as an example of how to integrate Report Portal and MS Teams webhook notifications in a Playwright testing environment.
The project is structured as follows:
.github/workflows/playwright.yml
: This file contains the GitHub Actions workflow for running Playwright tests.playwright.config.ts
: This file contains the configuration for Playwright tests.tests/
: This directory contains the test files.utils/report/
: This directory contains the files for sending notifications to MS Teams.
- Report Portal Integration: This project is configured to send test results to Report Portal.
- MS Teams Notifications: The
NotificationSender
class inutils/report/notificationSender.ts
is used to send notifications to MS Teams.
- Clone the repository.
- Run
npm install
to install the dependencies. - Set up your Report Portal and MS Teams webhook configurations.
- Run the tests with
npx playwright test
.
The project is configured to send test results to Report Portal. The configuration is located in the playwright.config.ts
file:
export const RPconfig = {
apiKey: 'Your_Report_Portal_API_Key',
endpoint: 'Your_Report_Portal_Endpoint',
project: 'Your_Report_Portal_Project_Name',
launch: process.env.RPlaunchName,
attributes: [
{
key: 'attributeKey',
value: 'attrbiuteValue',
},
{
value: 'anotherAttrbiuteValue',
},
],
includeTestSteps: true,
uploadTrace: true,
description: process.env.URL,
};
Replace the placeholders with your actual Report Portal details:
apiKey
: Your Report Portal API key.endpoint
: The URL of your Report Portal server.project
: The name of your Report Portal project.launch
: The name of your test launch. This is read from theRPlaunchName
environment variable.attributes
: An array of attributes to be attached to the launch.includeTestSteps
: If set to true, test steps will be included in the report.uploadTrace
: If set to true, trace files will be uploaded to Report Portal.description
: The description of the launch. This is read from theURL
environment variable.
To set up MS Teams notifications, you need to create an Incoming Webhook in MS Teams and use it in your project:
- Go to the channel where you want to receive the notifications.
- Click on the three dots (...) next to the channel name and select "Connectors".
- Search for "Incoming Webhook" and click "Configure".
- Provide a name and upload an image for your webhook, then click "Create".
- Copy the webhook URL provided by Microsoft Teams.
- Replace
'YOUR_WEBHOOK_URL'
in thesendNotification
function inutils/report/notificationSender.ts
with the webhook URL you got from Microsoft Teams.
const axios = require('axios');
async function sendSummaryNotification(summary) {
const webhookUrl = process.env.TEAMS_WEBHOOK_URL;
const message = {
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"summary": "Test Summary",
"sections": [{
"activityTitle": "Playwright Tests",
"activitySubtitle": "Automated tests",
"facts": [{
"name": "Total tests",
"value": summary.total
}, {
"name": "Passed tests",
"value": summary.passed
}, {
"name": "Failed tests",
"value": summary.failed
}]
}]
};
try {
const response = await axios.post(webhookUrl, message);
console.log(`Sent summary message to Teams with response status: ${response.status}`);
} catch (error) {
console.error(`Failed to send summary message to Teams: ${error}`);
}
}
const summary = {
total: 100,
passed: 90,
failed: 10
};
sendSummaryNotification(summary);
Notifications are sent to MS Teams at the end of each test. The notifications include a summary of the test results. This is handled by the SummaryReport
class in utils/report/summaryReport.ts
.
Contributions are welcome. Please open an issue or submit a pull request.
This project is licensed under the ISC license.