Skip to content

Commit

Permalink
docs: update browser smoke test example
Browse files Browse the repository at this point in the history
- Use loadAll to always load all rows in the CSV file (instead of
  relying on creating the right number of VUs)
- Update CSV file
  • Loading branch information
hassy committed Oct 16, 2024
1 parent 69dd606 commit 8e09e1a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
8 changes: 7 additions & 1 deletion examples/browser-load-testing-playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ That's it! Artillery will create headless Chrome browsers that will run Playwrig

## Example 2: A smoke test

This example shows how we can implement a smoke test (or a synthetic check) using a headless browser. We make use of Artillery's [CSV payload](https://artillery.io/docs/guides/guides/test-script-reference.html#Payload-files) feature to specify the URLs we want to check, and [custom metric API](https://artillery.io/docs/guides/guides/extending.html#Tracking-custom-metrics) to track custom metrics.
This example shows how we can implement a smoke test (or a synthetic check) using a headless browser.

We make use of Artillery's [CSV payload](https://artillery.io/docs/guides/guides/test-script-reference.html#Payload-files) feature to specify the URLs we want to check, and [custom metric API](https://artillery.io/docs/guides/guides/extending.html#Tracking-custom-metrics) to track custom metrics.

For every row in the CSV file, we'll load the URL from the first column, and check that the page contains the text specified in the second column.

The test will load each page specified in the CSV file, and check that it contains the text

```sh
npx artillery run browser-smoke-test.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ config:
fields:
- "url"
- "title"
loadAll: true
name: pageChecks
engines:
playwright: {}
processor: ./flows.js
Expand Down
28 changes: 15 additions & 13 deletions examples/browser-load-testing-playwright/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ async function checkOutArtilleryCoreConceptsFlow(
// A simple smoke test using a headless browser:
//
async function checkPage(page, userContext, events) {
const url = userContext.vars.url;
const title = userContext.vars.title;
const response = await page.goto(url);
if (response.status() !== 200) {
events.emit('counter', `user.status_check_failed.${url}`, 1);
} else {
events.emit('counter', `user.status_check_ok.${url}`, 1);
}
// The pageChecks variable is created via the config.payload
// section in the YML config file
for (const { url, title } of userContext.vars.pageChecks) {
const response = await page.goto(url);
if (response.status() !== 200) {
events.emit('counter', `user.status_check_failed.${url}`, 1);
} else {
events.emit('counter', `user.status_check_ok.${url}`, 1);
}

const isElementVisible = await page.getByText(title).isVisible();
const isElementVisible = await page.getByText(title).isVisible();

if (!isElementVisible) {
events.emit('counter', `user.element_check_failed.${title}`, 1);
}
if (!isElementVisible) {
events.emit('counter', `user.element_check_failed.${title}`, 1);
}

await page.reload();
await page.reload();
}
}

async function multistepWithCustomMetrics(page, userContext, events, test) {
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-load-testing-playwright/pages.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://www.artillery.io/,The Artillery Manifesto
https://www.artillery.io/docs,What's different about Artillery?
https://www.artillery.io/cloud,Test more effectively & fix issues faster
https://www.artillery.io/changelog,Feature updates and improvements to Artillery

0 comments on commit 8e09e1a

Please sign in to comment.