Skip to content

Commit

Permalink
chore: updated examples
Browse files Browse the repository at this point in the history
we will now be using the k6 example website to reduce test flakiness
  • Loading branch information
nicholasvuono committed Mar 30, 2024
1 parent 6ca8ff0 commit b362c65
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
15 changes: 10 additions & 5 deletions examples/connect-over-cdp-example.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import pw from 'k6/x/playwright';

export default function () {
pw.connect("http://localhost:9222")
pw.goto("https://www.github.com/", {waitUntil: 'networkidle'})
pw.waitForSelector(".search-input", {state: 'visible'})
pw.kill()
}
pw.connect('http://localhost:9222');
try {
pw.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
pw.waitForSelector("input[name='login']", { state: 'visible' });
} catch (err) {
console.log(err);
} finally {
pw.kill();
}
}
17 changes: 11 additions & 6 deletions examples/headless-false-example.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import pw from 'k6/x/playwright';

export default function () {
pw.launch({headless: false})
pw.newPage()
pw.goto("https://www.github.com/", { waitUntil: 'networkidle'})
pw.waitForSelector(".search-input", {state: 'visible'})
pw.kill()
}
try {
pw.launch({ headless: false });
pw.newPage();
pw.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
pw.waitForSelector("input[name='login']", { state: 'visible' });
} catch (err) {
console.log(err);
} finally {
pw.kill();
}
}
28 changes: 16 additions & 12 deletions examples/monitor-real-user-metrics.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import pw from 'k6/x/playwright';

export default function () {
pw.launch()
pw.newPage()
pw.goto("https://www.github.com/")
pw.waitForSelector(".search-input", {state: 'visible'})
pw.type(".search-input", "how to measure real user metrics with the xk6-playwright extension for k6?")
try {
pw.launch()
pw.newPage()
pw.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
pw.waitForSelector("input[name='login']", { state: 'visible' });
pw.type("input[name='login']", "admin")

//print out real user metrics of the google search page
console.log(`First Paint: ${pw.firstPaint()}ms`)
console.log(`First Contentful Paint: ${pw.firstContentfulPaint()}ms`)
console.log(`Time to Minimally Interactive: ${pw.timeToMinimallyInteractive()}ms`)
console.log(`First Input Delay: ${pw.firstInputDelay()}ms`)

pw.kill()
//print out real user metrics of the google search page
console.log(`First Paint: ${pw.firstPaint()}ms`)
console.log(`First Contentful Paint: ${pw.firstContentfulPaint()}ms`)
console.log(`Time to Minimally Interactive: ${pw.timeToMinimallyInteractive()}ms`)
console.log(`First Input Delay: ${pw.firstInputDelay()}ms`)
} catch (err) {
console.log(err);
} finally {
pw.kill();
}
}
21 changes: 11 additions & 10 deletions examples/simplest-working-example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import pw from 'k6/x/playwright';

export const options = {
vus: 1,
};

export default function () {
pw.launch()
pw.newPage()
pw.goto("https://www.github.com/", {waitUntil: 'networkidle'})
pw.waitForSelector(".search-input", {state: 'visible'})
pw.kill()
}
try {
pw.launch();
pw.newPage();
pw.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
pw.waitForSelector("input[name='login']", { state: 'visible' });
} catch (err) {
console.log(err);
} finally {
pw.kill();
}
}

0 comments on commit b362c65

Please sign in to comment.