robotframework-browser
robotframework-browser copied to clipboard
Intercepting and modifying responses (playwright page.route)
Modifying responses As a tester I need to intercept and modify response to a request, so that I can mock various error states handling on UI.
(eg.: How will application frontend handle error state 500? - it should show specific message to user, but in fully working application it is not easy to cause backend to fail)
Solution: New Page Route
keyword
Based on playwright documentation it should be possible to intercept and modify HTTP and HTTPS requests/responses.
Playwright-python: page.route : Documentation
Playwright page.route for this.
This would be of great value for testing.
Thanks a lot for considering this, regards, Jan.
Thank you for the issue! I believe currently you can achieve this only by extending our library with a JS module. https://marketsquare.github.io/robotframework-browser/Browser.html#Extending%20Browser%20library%20with%20a%20JavaScript%20module
async function error500route(page, args) {
await page.route(args[0], route => {
route.fulfill({
status: 500,
contentType: 'text/plain',
body: 'Internal Server Error'
});
});
}
exports.__esModule = true;
exports.error500route = error500route;
And using it in RF when you have an open page
*** Test Cases ***
Failing server
New Page someurl
error500route yoururlpattern
Do actions to make a call to route
Thanks for the response and suggestion, I will try this next sprint :).
@mkorpela Is there any plan to integrate this to built in feature? I would like to intercept request and response with recorded HAR file on staging serve.
Just to raise up a discussion regarding this feature - https://www.scrapingbee.com/webscraping-questions/playwright/how-to-block-resources-in-playwright/ has python example of this. Dunno if this approach would work with browserlibrary thought "for reasons" ..