Reporting your Playwright tests to Microsoft Teams

When you work in a team that uses Microsoft Teams as its primary communication tool, it can be useful to report your test results directly to a Teams channel. This way, everyone on your team can quickly see the test results and act on them if needed.

Show image Playwright test results in Microsoft Teams
Playwright test results in Microsoft Teams

In this article, I will show you how you can report your Playwright test results to a Microsoft Teams channel.

Prerequisites

Before you can start reporting your Playwright test results to Microsoft Teams, you need to have the following:

Create an incoming webhook for Microsoft Teams channel (will stop working after October 1, 2024)

important

As Microsoft announce the retirement of Office 365 connectors within Microsoft Teams. It is best to make use of the Power Automate webhook functionality.

The playwright-msteams-reporter dependency uses the incoming webhook feature in Microsoft Teams. You can find more information on how to do this in the Microsoft documentation.

Once you have configured the incoming webhook, you will receive a URL that you can use to send messages to a specific channel. Copy this URL, as you will need it in the reporter’s configuration.

Show image Incoming webhook URL
Incoming webhook URL

Create a Microsoft Teams webhook with Power Automate

To create a webhook with Power Automate, you can follow these steps:

  • Start with the following post to a channel when a webhook request is received template
  • Click continue to use the template
  • Click on the Post your own adaptive card as the Flow bot to a channel action
  • Configure the action with the following settings:
    • Team: Select the team where you want to post the message
    • Channel: Select the channel where you want to post the message
Show image Update the channel setting for the Adaptive Card action
Update the channel setting for the Adaptive Card action
  • Click on the Save button
  • Click on When a Teams webhook request is received and copy the HTTP URL

Installing the reporter

To install the playwright-msteams-reporter dependency, run the following command in your Playwright project:

Install the reporter
1
npm install playwright-msteams-reporter

Configuring the reporter

Once you installed the reporter, it is time to configure it. In your playwright.config.js configuration file, you can add the following configuration to enable the reporter:

Configure the reporter
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['html'],
    [
      'playwright-msteams-reporter',
      {
        webhookUrl: "<webhookUrl>",
        webhookType: "powerautomate", // or "msteams"
      }
    ]
  ],
});

Add your webhook URL to the <webhookUrl> property. You can also specify the webhook type as powerautomate or msteams. The default value is powerautomate.

Mentioning users on failed tests

The playwright-msteams-reporter also supports mentioning users in the message when a test fails. To enable this feature, you can add the mentionOnFailure property to the configuration:

Configure the reporter with user mentions
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['html'],
    [
      'playwright-msteams-reporter',
      {
        webhookUrl: "<webhookUrl>",
        mentionOnFailure: "[email protected], [email protected]",
      }
    ]
  ],
});
important

When a test fails, the reporter will mention the user(s).

Show image Failed tests with mentions
Failed tests with mentions

Linking to the GitHub workflow run

If you are running your Playwright tests in a GitHub Actions workflow, you can add a link to the workflow run. To enable this feature, you can add the linkToResultsUrl property to the configuration:

Configure the reporter with workflow URL
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['html'],
    [
      'playwright-msteams-reporter',
      {
        webhookUrl: "<webhookUrl>",
        mentionOnFailure: "Name <[email protected]>, [email protected]",
        linkToResultsUrl: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
      }
    ]
  ],
});

Running your tests

Once you have configured the reporter, you can run your Playwright tests. The reporter will send a message with the test results to the configured Microsoft Teams channel.

Show image Playwright test results in Microsoft Teams
Playwright test results in Microsoft Teams

More configuration options are available for the playwright-msteams-reporter. For more information, check out the playwright-msteams-reporter documentation.

Give it a try, and let me know your experiences. Feedback and suggestions are always appreciated!

Update

2024-07-09

Updated the article with the information of the retirement of Office 365 connectors within Microsoft Teams. Therefore, it is better to make use of the Power Automate webhook functionality to send messages to Microsoft Teams.

Comments

Back to top