Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercepting and modifying responses (playwright page.route) #524

Open
JanDubcak opened this issue Nov 27, 2020 · 4 comments
Open

Intercepting and modifying responses (playwright page.route) #524

JanDubcak opened this issue Nov 27, 2020 · 4 comments
Labels
enhancement New feature or request priority: medium

Comments

@JanDubcak
Copy link

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.

@mkorpela mkorpela added the enhancement New feature or request label Nov 27, 2020
@mkorpela
Copy link
Member

mkorpela commented Nov 27, 2020

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

@JanDubcak
Copy link
Author

Thanks for the response and suggestion, I will try this next sprint :).

@aquadrehz
Copy link

aquadrehz commented Aug 22, 2022

@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.

@Snooz82 Snooz82 added this to the Some Next Issues milestone Jul 28, 2023
@rasjani
Copy link
Contributor

rasjani commented May 20, 2024

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" ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority: medium
Projects
None yet
Development

No branches or pull requests

6 participants