Skip to content

Commit

Permalink
Add page.on test example
Browse files Browse the repository at this point in the history
  • Loading branch information
ka3de committed Aug 25, 2023
1 parent 97d5577 commit de28297
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/pageon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { browser } from 'k6/x/browser';
import { check } from 'k6';

export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
thresholds: {
checks: ["rate==1.0"]
}
}

export default async function() {
const page = browser.newPage();

try {
await page.goto('https://test.k6.io/');

page.on('console', msg => {
check(msg, {
'assertConsoleMessageType': msg => msg.type() == 'log',
'assertConsoleMessageText': msg => msg.text() == 'this is a console.log message 42',
'assertConsoleMessageArgs0': msg => msg.args()[0].jsonValue() == 'this is a console.log message',
'assertConsoleMessageArgs1': msg => msg.args()[1].jsonValue() == 42,
});
});

page.evaluate(() => console.log('this is a console.log message', 42));
} finally {
page.close();
}
}

0 comments on commit de28297

Please sign in to comment.