From b7da4531f80c868589dfbfbbfbff2434d8a6b3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 2 Feb 2024 12:18:55 +0300 Subject: [PATCH] Add a dispatch event example --- examples/dispatch.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/dispatch.js diff --git a/examples/dispatch.js b/examples/dispatch.js new file mode 100644 index 000000000..5414eae8c --- /dev/null +++ b/examples/dispatch.js @@ -0,0 +1,36 @@ +import { check } from 'k6'; +import { browser } from 'k6/x/browser'; + +export const options = { + scenarios: { + ui: { + executor: 'shared-iterations', + options: { + browser: { + type: 'chromium', + }, + }, + }, + }, + thresholds: { + checks: ["rate==1.0"] + } +} + +export default async function() { + const context = browser.newContext(); + const page = context.newPage(); + + try { + await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); + + page.locator('a[href="/contacts.php"]') + .dispatchEvent("click"); + + check(page, { + header: (p) => p.locator("h3").textContent() == "Contact us", + }); + } finally { + page.close(); + } +}