Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Update sync examples with check to async check #1448

Merged
merged 22 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ee46a5f
Update examples/colorscheme to async check
inancgumus Sep 27, 2024
3167545
Update examples/cookies to async check
inancgumus Sep 27, 2024
4ef8c0a
Update examples/device_emulation to async check
inancgumus Sep 27, 2024
9c49e6f
Update examples/dispatch to async check
inancgumus Sep 27, 2024
89999c9
Update examples/elementstate to async check
inancgumus Sep 27, 2024
bf09afb
Update examples/evaluate to async check
inancgumus Sep 27, 2024
686b21e
Update examples/fillform to async check
inancgumus Sep 27, 2024
f1277a5
Update examples/getattribute to async check
inancgumus Sep 27, 2024
d100d0b
Update examples/hosts to async check
inancgumus Sep 27, 2024
df8a7b8
Update examples/pageon to async check
inancgumus Sep 27, 2024
67163da
Update examples/querying to async check
inancgumus Sep 27, 2024
adcb65f
Update examples/shadowdom to async check
inancgumus Sep 27, 2024
18eb2dd
Update waitforfunction.js to async check
inancgumus Sep 27, 2024
d64fce2
Update example dispatch to await
inancgumus Sep 30, 2024
0cc556b
Update example elementstate to await
inancgumus Sep 30, 2024
ce0ffce
Update example evaluate to await
inancgumus Sep 30, 2024
565c4a0
Update example fillform to await
inancgumus Sep 30, 2024
1bb4f1e
Update example getattribute to await
inancgumus Sep 30, 2024
4048025
Update example pageon to await
inancgumus Sep 30, 2024
a2149b7
Update example querying to await
inancgumus Sep 30, 2024
d76cfcd
Update example shadowdom to await
inancgumus Sep 30, 2024
470b26f
Update example waitforfunction to await
inancgumus Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions examples/evaluate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { check } from 'k6';
import { browser } from 'k6/x/browser/async';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';

export const options = {
scenarios: {
Expand All @@ -25,20 +25,21 @@ export default async function() {
await page.goto("https://test.k6.io/", { waitUntil: "load" });

// calling evaluate without arguments
let result = await page.evaluate(() => {
return Promise.resolve(5 * 42);
});
check(result, {
"result should be 210": (result) => result == 210,
});
await check(page, {
'result should be 210':
async p => p.evaluate(
inancgumus marked this conversation as resolved.
Show resolved Hide resolved
() => 5 * 42
)
.then(r => r == 210)
});

// calling evaluate with arguments
result = await page.evaluate(([x, y]) => {
return Promise.resolve(x * y);
}, [5, 5]
);
check(result, {
"result should be 25": (result) => result == 25,
await check(page, {
'result should be 25':
async p => p.evaluate(
([x, y]) => x * y, [5, 5],
)
.then(r => r == 25),
});
} finally {
await page.close();
Expand Down