How to Run Playwright Tests for Microsoft 365 in GitHub Actions Workflows
You can run Playwright tests for Microsoft 365 in GitHub Actions workflows by linking your test scripts with automatic pipelines. This way, you can check your Microsoft 365 solutions each time you push code. Using these tools together gives you fast feedback and strong Test Automation. You set up safe authentication, control your workflow, and keep your apps working well with less manual work.
Key Takeaways
Set up a Microsoft 365 test environment. This helps your Playwright tests work well. Use cloud browsers for testing. Change test settings for better results.
Use GitHub Actions to run Playwright tests automatically. Tests run each time you push code. This helps you find problems early. It also makes your app more reliable.
Keep important information safe with environment variables and GitHub Secrets. This keeps your credentials private. They will not show up in your code.
Make good test scripts by using fixtures. Do not use hard-coded values. Mock API requests when needed. This makes your tests stronger and easier to fix.
Watch your test results carefully. Use GitHub Actions to see summaries. Set up alerts for test failures. This helps your team know if something is wrong with your app.
Prerequisites
Tools and Accounts
You need some things before you begin. First, make a GitHub account. You also need a Microsoft 365 tenant for testing. Put Node.js on your computer. Use Visual Studio Code or another editor to write Playwright tests. Make sure you can create and manage things in Microsoft 365. You should know a little about JavaScript or TypeScript.
💡 Tip: Use a different Microsoft 365 test account. This keeps your real data safe and stops mistakes in your main account.
Microsoft 365 Test Environment
A good test setup helps you run Playwright tests well. Here are steps to set up your Microsoft 365 test environment:
Make sure your tests work on your computer.
Use cloud browsers with Microsoft Playwright Testing.
Check the Azure region for remote browsers.
Try using more or fewer parallel workers.
Give your computer more power if you need it.
Change your Playwright test settings.
You can use these steps for SharePoint, Teams, or other Microsoft 365 apps. This setup helps you find problems early and supports strong Test Automation.
Install Playwright
You need to install Playwright to run tests. Sometimes, you might have trouble installing it. Here are some common problems and what they mean:
🛠️ Note: Always check your permissions before you install Playwright and browsers. This helps you avoid problems and saves time.
Playwright Test Setup
Create Test Scripts
Start by making Playwright test scripts for your Microsoft 365 workflows. Your tests should be easy to use and fix. Here are some good tips:
Use fixtures to set up and clean up. This keeps your tests neat and makes sure each test starts the same way.
Do not use hard-coded values. Put your test data in other files or use environment variables. This helps you use the same tests in different places.
Pick selectors that do not change a lot. Use data attributes or ARIA labels instead of class names that might change. This keeps your tests working even if the UI changes.
Use Playwright’s locators to find elements. This makes your tests more accurate.
Mock API requests when you can. This means your tests do not need to wait for outside services and will run faster.
Run tests at the same time. This saves time and gives you results quicker.
Use Playwright’s tools like tracing, screenshots, and video to help you find problems.
Make your tests use different inputs without copying code.
Clean up your test data after each run. This stops old data from messing up new tests.
📝 Tip: Test the most important workflows first. You do not have to test every feature to get good results from Test Automation.
Microsoft 365 Authentication
Microsoft 365 uses safe login steps, sometimes with multi-factor authentication. It can be hard to handle login in automated tests, but you have some choices:
Keep usernames and passwords in environment variables in your CI/CD pipeline. This keeps them safe and out of your code.
Use time-based one-time passwords with plugins like
otplib
to make MFA codes during tests.Use APIs like GetMyMFA to get verification codes for SMS-based MFA.
Log in by hand once, save the session, and use it again in your tests. This stops you from logging in over and over and makes tests faster.
Keep session states safe and load them at the start of each test run.
🔒 Note: Always keep your access tokens and credentials safe. Never put them in your code or leave them in plain text. Use Microsoft Entra ID for login if you can, and cancel tokens if you think they are not safe.
Test Data and Permissions
Having good test data and the right permissions is important for Test Automation in Microsoft 365. Here is how you can handle them:
Use a special test account with the right permissions for SharePoint, Teams, or other Microsoft 365 apps.
Get your test data ready before you run tests. Clean up the data after tests to keep things tidy.
Make your tests check different cases without copying code.
Mock or stub things outside your app to keep tests fast and steady.
Save logs and screenshots from your tests so you can look at them later.
You can change Playwright tests for different Microsoft 365 apps. For SharePoint, test document libraries, lists, and permissions. For Teams, test chat, meetings, and app add-ons. Playwright helps you automate these steps and find bugs before you release your app.
💡 Tip: To send Playwright test results to Microsoft Teams, install the
playwright-msteams-reporter
and set it up in your Playwright settings. This helps your team see test results right away.
GitHub Actions Setup
When you set up GitHub Actions, you can run Playwright tests for Microsoft 365 each time you push code. This helps you test your app automatically. It also helps your app stay healthy. Follow these steps to make a good workflow.
Workflow YAML
You need a workflow YAML file in your repository. This file tells GitHub Actions what to do. Here are the main parts you should put in:
Copy this structure into your .github/workflows/playwright.yml
file. This lets you run tests in different browsers. It also makes your Test Automation faster.
Dependencies
You need to install the right tools for your tests. Here is what you should do:
Use
npm ci
to install all your project’s dependencies.Run
npx playwright install --with-deps
to set up browsers for testing.If your tests need a Dev Proxy, add a bash command in your setup script to install it.
These steps make sure your GitHub Actions runner has everything ready for Playwright tests.
Environment Variables
Keep your secrets and settings safe. Use environment variables for things like passwords and URLs. Here is a table to help you organize them:
Never put passwords or tokens in your test scripts.
Use GitHub Secrets to store these values safely.
💡 Tip: Use special test accounts and reset your test data after each run. This keeps your Test Automation safe and steady.
You can save logs and test files to look at later. Set up alerts to tell your team if a test fails. Running tests at the same time and using the newest GitHub runner will help your tests finish quickly and keep your workflow smooth.
Test Automation Best Practices
Running Tests
It is smart to run your Playwright tests a lot. This helps you find problems early. Set up GitHub Actions to run tests when you push code. This way, you catch issues before users see them. You can test in many browsers at once. Playwright works with Chromium, Firefox, and WebKit. This makes sure your Microsoft 365 app works for everyone.
Try these tips when running tests:
Keep a test database separate from your main one.
Refresh your data automatically so tests start clean.
Use browser contexts to keep tests apart.
Turn on auto-waits in Playwright to stop errors from slow pages.
For visual regression, Playwright can check screenshots for changes. Use .toHaveScreenshot()
or .toMatchSnapshot()
in your tests. Here is an example:
const { test, expect } = require('@playwright/test');
test('Visual check', async ({ page }) => {
await page.goto('https://your-m365-app.com');
expect(await page.screenshot()).toMatchSnapshot();
});
Viewing Results
After tests finish, you need to see what happened. GitHub Actions shows a summary of your test results. You can set up alerts for your team if something fails. Playwright gives detailed reports with notes, tags, and more details.
You can also send results to Microsoft Teams for fast updates.
Troubleshooting
Sometimes, tests fail because of login or CI/CD problems. If you see certificate errors, check your script for the right settings. Make sure your environment variables are set in GitHub Actions. Keep all your tools and browsers updated. If you get timeout or WebSocket errors, try making timeouts longer or check your network.
Common errors are:
Different results on your computer and in the cloud.
Timeout errors in GitHub Actions.
WebSocket connection problems.
🛠️ Tip: Look at your logs and screenshots to see why a test failed. Change your test cases when your app changes to keep Test Automation working well.
You can use GitHub Actions to run Playwright tests for Microsoft 365. Here are the steps you need to follow:
Test Automation lets you release updates faster. It helps your team find mistakes and fix them quickly. You spend less time writing scripts and your team can do more work.
Check out these advanced tips:
Handle changing content by setting custom timeouts.
Use fixtures to set up test data.
Connect Playwright with CI/CD pipelines.
FAQ
How do you store Microsoft 365 credentials safely in GitHub Actions?
You should use GitHub Secrets to store your credentials. Go to your repository settings, add your secrets, and reference them in your workflow file. This keeps your login details safe and out of your code.
What should you do if Playwright tests fail only in GitHub Actions?
Check your environment variables and browser settings in the workflow file. Make sure you install all dependencies. Review logs and screenshots from the failed runs to find the problem.
Can you run Playwright tests on multiple browsers at once?
Yes, you can use the matrix strategy in your workflow YAML file. This lets you test your Microsoft 365 app in Chromium, Firefox, and WebKit at the same time.
How do you handle multi-factor authentication (MFA) in automated tests?
You can use session storage to save a logged-in state. Log in once by hand, save the session, and reuse it in your tests. This helps you avoid repeated MFA prompts.
How can you send Playwright test results to Microsoft Teams?
Install the playwright-msteams-reporter
package. Set it up in your Playwright configuration. Your test results will post directly to your chosen Teams channel for quick updates.