# How to Automate Microsoft Live Login with Playwright - Checkly Docs

> Automate signing in to a Microsoft Live account with Playwright, injecting credentials through environment variables to reach the account page.

Source: https://www.checklyhq.com/docs/learn/playwright/microsoft-login-automation/

---

Back to top
- Steps
- Takeaways

E2E Examples

# How to Automate Microsoft Live Login with Playwright

Automate signing in to a Microsoft Live account with Playwright, injecting credentials through environment variables to reach the account page.

If you’re using Playwright for end-to-end testing, you should check out [Playwright Check Suites](https://www.checklyhq.com/docs/detect/synthetic-monitoring/playwright-checks/overview) and start testing in production.

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

ms-account-login.spec.ts

```
import { test } from '@playwright/test'

test('test', async ({ page }) => {
await page.goto('https://login.microsoftonline.com/')

await page.getByRole('heading', { name: 'Sign in' }).click()
await page.getByPlaceholder('Email address, phone number').fill(process.env.MS_USERNAME)
await page.getByRole('button', { name: 'Next' }).click()

await page.getByTestId('i0118').fill(process.env.MS_PASSWORD)
await page.getByTestId('textButtonContainer').getByRole('button', { name: 'Sign in' }).click()
await page.getByTestId('checkboxField').check()
await page.getByLabel('Stay signed in?').click()
})
```

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 you are redirected to Microsoft.

- Wait for the navigation as you are redirected back to the start site.

Bugs don’t stop at CI/CD. Why would Playwright?

[Sign up](https://app.checklyhq.com/signup) and start using Playwright for end-to-end monitoring with Checkly.

Was this page helpful?

[Suggest edits](https://github.com/checkly/docs/edit/main/learn/playwright/microsoft-login-automation.mdx)[Raise issue](https://github.com/checkly/docs/issues/new?title=Issue%20on%20docs&body=Path:%20/learn/playwright/microsoft-login-automation)

[How to Automate Login with Playwright Previous](https://www.checklyhq.com/docs/learn/playwright/login-automation)[How to Test Coupons and Discounts with Playwright Next](https://www.checklyhq.com/docs/learn/playwright/testing-coupons)

[x](https://x.com/checklyhq)[github](https://github.com/checkly)[linkedin](https://linkedin.com/company/checkly)

[Powered by This documentation is built and hosted on Mintlify, a developer documentation platform](https://www.mintlify.com/?utm_campaign=poweredBy&utm_medium=referral&utm_source=checkly-422f444a)
