The countdown is on: Register today + save your seatLearn how to leverage new AI features and observability tools, attend technical deep dives. & leave with tips for growing your observability strategy. Seats are limited and in high demand, register now!
📢 Registration + agenda now live
Explore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).
Route represents a network request intercepted by the
page.route() function and allows to modify its behavior. Once routing is enabled, every request intercepted by a route will stall unless it’s continued, fulfilled or aborted.
When several routes match the given pattern, only the last registered route handler will run, and all others will be skipped.
import{ browser }from'k6/browser';exportconst options ={scenarios:{browser:{executor:'shared-iterations',options:{browser:{type:'chromium',},},},},};exportdefaultasyncfunction(){const page =await browser.newPage();// Abort all images requestsawait page.route(/(\.png$)|(\.jpg$)/,asyncfunction(route){await route.abort();});// Fulfill request with the following response which// changes the quotes displayed on the pageawait page.route(/.*\/quotes$/,asyncfunction(route){await route.fulfill({body:JSON.stringify({quotes:['"We ❤️ pizza" - k6 team'],}),});});// Change the pizza request when the button is clickedawait page.route(/.*\/pizza$/,asyncfunction(route){await route.continue({headers:{...route.request().headers(),foo:'bar',},method:'POST',postData:JSON.stringify({maxCaloriesPerSlice:500,mustBeVegetarian:true,excludedIngredients:['Pineapple'],excludedTools:['Knife','Scissors'],maxNumberOfToppings:1,minNumberOfToppings:1,customName:'Classic Pizza',}),});});await page.goto('https://quickpizza.grafana.com/');await page.getByRole('button',{name:'Pizza, Please!'}).click();await page.close();}