Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ceruleoscope
Advanced tools
Use Playwright to create availability tests with AppInsights, running on Azure Functions
Ceruleoscope is an open source JavaScript library that facilitates custom web app availability testing by combining Playwright and Application Insights, and allowing tests to run as a scheduled Azure Function, with minimal effort.
This article will cover:
For feedback, feature requests and access to code please use Ceruleoscope github repository
The Short Version below is intended for a quick overview and requires some familiarity with Azure and VSCode. Below that is a Detailed Version of the same steps for those new to these environments.
Create Azure Function App:
It must be Serverless Linux/Node.js app and Application Insights must be enabled.
Add this config setting to the function app:
PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot/node_modules/playwright-chromium/.local-browsers/
Add Managed Identity and Key Vault, configure the function to access they Key Valut for storing test secrets
Add config settings to store variable data, access it via process.env["config_name"]
in test
Using VSCode, create a new Functions project with javascript and Timer trigger
Add this line in .vscode/settings.json:
scmDoBuildDuringDeployment=true
Remove "test" and add "node_modules" in .funcignore
Add these packages to the project (npm install):
playwright
, playwright-chromium
, @playwright/test
and ceruleoscope
Generate a test script by running this command in VSCode's terminal:
npx playwright codegen yourwebsite.com
Save the test script in a new folder in the VSCode project with *.spec.js filename
Replace the require statement in the test with
const { test, expect } = require("ceruleoscope");
If necessary, modify the test code to retrieve secrets and config values
Replace the function's index.js with this snippet:
module.exports = async function (context, myTimer) {
try{
const { PlaywrightTestLauncher } = require("ceruleoscope");
let responseMessage = await PlaywrightTestLauncher.Run();
context.log("Playwright tests console output: " + responseMessage); // optional
} catch(ex){
context.log("Failed to run Playwright tests: " + ex);
}
};
Deploy the function app to Azure
In Azure Portal (after the function has been deployed and triggered):
Navigate to the Function's Application Insights:
Navigate to the Function's Storage account, playwright-insights
container
Open portal.azure.com in a browser, sign in.
Your subscription must allow you to create and modify the resources mentioned in this guide.
Additional information about creating an Azure Function app can be found here.
Navigate to the Function App created above in Azure Portal
PLAYWRIGHT_BROWSERS_PATH
home/site/wwwroot/node_modules/playwright-chromium/.local-browsers/
LOCATION
can be used to override the default location reported in the availability test (it region)TESTNAME
can be used to override the default availability test name (the function app name)VSCode offers the easiest to use environment, although it is possible to use other tools to create the function code. Make sure Azure Functions extension is installed in VSCode as well (CTRL-Shift-X, search, install)
PLAYWRIGHT_BROWSERS_PATH
setting is there and correct(0 */5* \* \* \*)
is for every 5 minutes..vscode/settings.json
with{
"azureFunctions.deploySubpath": ".",
"azureFunctions.projectLanguage": "JavaScript",
"azureFunctions.projectRuntime": "~3",
"azureFunctions.scmDoBuildDuringDeployment": true,
"debug.internalConsoleOptions": "neverOpen"
}
scmDoBuildDuringDeployment=true
is important, as it instructs VSCode/Azure Functions extension to package the function app locally
such that npm install
will run remotely and Playwright install script will download its browser engine binaries.
Without this setting Playwright won't find its browser binaries.
Edit .funcignore
file in the project
test
- if it's present, tests may not be deployed and runnode_modules
- it it's not present, the local copy of node_modules may get deployed and not have the correct browser binaries that Playwright otherwise downloads.Open a new Terminal in VSCode (CTRL-`) and run these commands:\
npm install playwright
npm install playwright-chromium
npm install @playwright/test
npm install ceruleoscope
index.js
for the function with:\ module.exports = async function (context, myTimer) {
try{
const { PlaywrightTestLauncher } = require("ceruleoscope");
let responseMessage = await PlaywrightTestLauncher.Run();
context.log("Playwright tests console output: " + responseMessage);
} catch(ex){
context.log("Failed to run Playwright tests: " + ex);
}
};
Create a new folder in the function's folder (not the project root folder) - GenTest
Create a new file with ".spec.js" extension (ex: gentest.spec.js)
The ".spec.js" part of the file name is important as it is used by @playwright/test as a filename filter to find tests
In the Terminal type this command:
npx playwright codegen yourwebsite.com
A browser opens and shows a "Playwright Inspector" panel on the side
Exercise the feature that needs availability testing by navigating your web site
AVOID USING REAL PASSWORDS, DO NOT LEAVE THEM IN THE TEST CODE
Copy the generated test code from Playwright Inspector (must be JavaScript) into gentest.spec.js, as described above.
The first line of gentest.spec.js will be
const { test, expect } = require('@playwright/test');
Replace the require statement with:
const { test, expect } = require("ceruleoscope");
The test can be further customized as needed, for example to obtain secrets or add various assertions.
Save the file
Run the test locally with this command in VSCode's Terminal:
npx playwright test --headed
where the --headed
option instructs Playwright to show the browser.
Test parameters that are provided in Azure Function's configuration can be emulated locally by adding them to local.settings.json.
Playwright build of chromium v920619 downloaded to /home/site/wwwroot/node_modules/playwright-chromium/.local-browsers/chromium-920619
PLAYWRIGHT_BROWSERS_PATH
config value.vscode/settings.json
and .funcignore
have been modified as described above, and all the npm packages are installed.Navigate to the Function App in Azure Portal
Click on the Log stream blade
Playwright tests console output: done
Click the Application Insights blade, navigate to the configured Application Insights resource
The "Overview" blade of that Application Insights resource should show no Failed requests, and some Server requests (depending on the frequency configured for the time trigger)
Check if there are failing or successful executions.
If there only failing executions, make sure all packages are included and the code runs locally in VSCode
Click the Availability blade.
If the Availability telemetry is not found, but there are no failed executions, then make sure the require
statement in the generated test is replaced.
Click the Availability blade to see the results of the availability test(s)
Click a point on the chart in Scatter Plot mode to see the test's End-to-End transaction.
traceFileLink
, which has a link to a Playwright trace file in Storagenpx playwright show-trace traceFileName.zip
"View all telemetry" will show all logs associated with this availability test and can be useful for troubleshooting
Availability alerts can be configured in the Alerts blade
This step is optional and may depend on the security considerations of your organization.
Ceruleoscope uses a Storage account container playwright-insights
.
The container is private and only accessible via Storage Explorer, Azure Portal etc.
The link in the availability test won't download via browser by default.
If the security constraints allow it, the container access level can be set to "Blob" to allow downloading directly from a browser. "Public" access if generally not a good practice.
It is recommended to create a lifecycle policy for the Storage container, so that old Trace files are automatically deleted.
If Base blobs were last modified more than 90 days ago, then Delete the blob
playwright-insights/
to manage all blobs in the containerThis policy will ensure the Storage account doesn't continuously grow.
FAQs
Use Playwright to create availability tests with AppInsights, running on Azure Functions
The npm package ceruleoscope receives a total of 1 weekly downloads. As such, ceruleoscope popularity was classified as not popular.
We found that ceruleoscope demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.