Skip to content

Commit

Permalink
Add an example script for waitForEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Sep 20, 2023
1 parent ef7f258 commit 13d0aac
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/waitForEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { browser } from 'k6/experimental/browser';

export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}

export default async function() {
const context = browser.newContext()

var counter = 0
const promise = context.waitForEvent("page", { predicate: page => {
if (++counter == 2) {
return true
}
return false
} })

const page = context.newPage()
const page2 = context.newPage()

await promise
console.log('promise evaluated')

page.close()
page2.close()
};

0 comments on commit 13d0aac

Please sign in to comment.