-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Brief summary
NOTE: The continue
and fulfill
methods work as expected and do override the request/response, they just aren't updated internally in the request/response data that the browser modules holds in memory. So it's functionally correct.
When working with page.route
to continue a request with overriden request values or when fulfilling a request without it being sent, it seems that the overriden values aren't updated in the request/response instances that are stored in the browser module internally.
It could be that all we need to do is update the request/response instances with the updated values when they're overriden by continue
or fulfill
:
req, ok := m.requestFromID(requestID)
if !ok {
// Is this ok?
return nil
}
for _, header := range opts.Headers {
req.headers[header.Name] = append(req.headers[header.Name], header.Value)
}
req.method = opts.Method
req.postDataEntries = []string{string(opts.PostData)}
req.url = opts.URL
OR maybe we need to wait for a CDP request from chromium with those updated values.
k6 version
v1.2.0
OS
NA
Docker version and image (if applicable)
No response
Steps to reproduce the problem
import { browser } from 'k6/browser'
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default async function () {
const page = await browser.newPage();
// Change the pizza request when the button is clicked
await page.route(/.*\/api\/pizza$/, async function (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"
}),
});
})
page.on('response', async (response) => {
const headers = response.headers();
var json = null;
if (headers["content-type"] === "application/json") {
json = await response.json();
}
console.log(JSON.stringify({
requestUrl: response.request().url(),
requestMethod: await response.request().method(),
requestHeaders: await response.request().allHeaders(), // doesn't contain "foo":"bar"
requestBody: await response.request().postData(), // doesn't contain the updated request post body
}, null, 2));
})
await page.goto('https://quickpizza.grafana.com/');
await page.getByRole('button', { name: 'Pizza, Please!' }).click();
await page.close();
}
Expected behaviour
It to log the updated values for the request that are sent by chromium to the website under test.
Actual behaviour
Logs the old values which aren't sent to the website under test by chromium.