This project sets up an Azure Timer Trigger Function to execute a Playwright test that performs a login operation on a sample website (https://www.saucedemo.com). The test results are sent to Azure Application Insights for synthetic monitoring and availability tracking.
By implementing this solution, organizations can:
- Automatically test website login functionality at regular intervals.
- Detect login failures proactively and resolve them before impacting users.
- Monitor site availability using Azure Application Insights Availability Tests.
- Automate synthetic monitoring to track system health in real time.
- ✅ Runs every 5 minutes using an Azure Timer Trigger
- ✅ Launches a browser and performs a login test using Playwright
- ✅ Logs success and failure events to Application Insights
- ✅ Enables synthetic monitoring to track login availability
- ✅ Can be deployed to Azure Functions for cloud execution
Ensure you have the following installed:
- Azure Functions Core Tools
npm install -g azure-functions-core-tools@4
- Node.js (LTS version recommended)
- Azure CLI
az login
- An active Azure Subscription with Application Insights set up
-
Clone the repository
git clone <repository-url> cd AppInsights-Playwright
-
Install dependencies
npm install
- Install Playwright browsers:
This downloads browser binaries for Windows, which will later be pushed to the Azure Function App.
$env:PLAYWRIGHT_BROWSERS_PATH=0; npx playwright install --with-deps
- Install Playwright browsers:
-
Run the Function Locally
-
Add the following settings in
local.settings.json
:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true" } }
-
Run Azurite in a new terminal:
azurite
If Azurite is not recognized install it using this command:
npm install -g azurite
-
Start the function app in a separate terminal:
func start
-
-
Login to Azure
az login
-
Create an Azure Function App (Premium EP1 Plan)
Use the Azure Portal to create the app. -
Set App Settings in Azure Portal
PLAYWRIGHT_BROWSERS_PATH=0
-
Linux Function App Only
Add Playwright browser binaries for Chromium Linux insidenode_modules/playwright-core/.local-browsers
. Download and extract the following:- https://cdn.playwright.dev/dbazure/download/playwright/builds/chromium/1161/chromium-linux.zip
- https://cdn.playwright.dev/dbazure/download/playwright/builds/chromium/1161/chromium-headless-shell-linux.zip
-
Deploy the Function App
func azure functionapp publish <function-app-name>
-
Go to Azure Portal → Application Insights
-
Navigate to Investigate → Availability
-
Click Custom Availability Tests
-
View the results of Playwright test runs
-
Create Alerts in Application Insights
- Navigate to Alerts → New Alert Rule
- Set condition:
availabilityResults/availabilityPercentage < 100
- Choose notification method: Email, Teams, etc.
- Ensures Login Reliability: Automates login testing to identify failures proactively
- Synthetic Monitoring: Provides real-time monitoring of website availability
- Early Detection: Detects authentication issues before they impact users
- Scalable: Runs in Azure Functions, eliminating the need for a dedicated server
- Integrated with Application Insights: Allows tracking of availability trends over time
To learn more about writing Playwright tests, visit the Playwright Documentation.