By Rohit Shinde | LinkedIn
Using Cypress, we will create a test automation framework with example tests Test Reports being sent to your Microsoft Teams Channel.
npm init -y
npm install
npx cypress open
In cypress.config.js we used two environment variables as shown below
env: {
SEND_MS_TEAMS_NOTIFICATIONS: true,
MS_TEAMS_WEBHOOK_URL: ""
}
We need to set SEND_MS_TEAMS_NOTIFICATIONS
to true or false based on if you want to send teams notifications or not.
Second environment varaible we used MS_TEAMS_WEBHOOK_URL
should have webhook url to your microsoft teams channel
You can follow the guide here to create the webhook to you teams channel.
Using below command you can run the tests and can get the test results in your teams channel.
npx cypress run --spec cypress/e2e/1-getting-started/todo.cy.js
You can add or use scripts already saved in package.json or can also run the tests through CI jobs and get the results in teams channel as long you have SEND_MS_TEAMS_NOTIFICATIONS
set to true.
Result with passed and failed tests.
Result with all passed tests.
- This functionality of sending teams notfications with test results is built using cypress-plugin method.
- With new version of cypress we can write the plugins directly in
cypress.config.js
file, however to keep the file clean following old way I wrote the plugin functions in*cypress\plugins\index.js
file. - To add custom image to you webhook messages as you can see in screenshot, you can add it while creating the webhook or later once created also. You can download cypress logos from google.