How to Automate Microsoft Live Login with Playwright
On this page
Playwright allows us to automate logging in to a Microsoft Online account.
Steps
- We start at
https://login.microsoftonline.com/
- We provide the username and password, injected by using environment variables
- We are redirected to the main account page
Run this example as follows. Replace the username and password placeholder with your own credentials.
MS_USER=username MS_PWD=password npx playwright test ms-account-login.spec.ts
SET MS_USER=username
SET MS_PWD=password
npx playwright test ms-account-login.spec.ts
This example does not work when you have 2-factor authentication enabled, and you might trigger a recaptcha check.
Takeaways
- Use environment variables to inject secrets.
- Wait for the navigation as your are redirected to Microsoft.
- Wait for the navigation as you are redirected back to the start site.