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

playwright bot not working with custom "test" fixture #22

Closed
wahreChrist opened this issue Jul 11, 2024 · 4 comments
Closed

playwright bot not working with custom "test" fixture #22

wahreChrist opened this issue Jul 11, 2024 · 4 comments

Comments

@wahreChrist
Copy link

Hey Noam,

I saw your issue in playwright forums when I was looking for a solution for our use case.
In short: I have been trying to sanitize our har files, so they wouldn't save sensitive information with routeFromHar method. It seemed to me that you already did all the heavy lifting with your package, and I was trying to implement it in our project. Unfortunately, I haven't been able to make it work yet: your package requires import of modified "test" fixture, to have access to advancedRouteFromHAR method, but when Im trying to run tests with your fixture, playwright bot just dont execute any actions, apart from navigating to a certain url.
Have you encountered this issue before? Perhaps you know how to fix it?
It looks like your package already has all the necessary functionality for us, and I wouldnt want to mess too much with playwrights source code just to make something similar in the end.

Best regards,

Artem L

@NoamGaash
Copy link
Owner

Hi Artem, thanks for the feedback! Could you please help me reproduce this error?
Also, if you need to import test from somewhere else, you can use Playwright's mergeTests method

@wahreChrist
Copy link
Author

wahreChrist commented Jul 17, 2024

Sorry for the late response, have been busy with other things.
I have managed to make the package work, we have quite complicated setup ourselves, so it was not really straightforward to make it work right away. Now I can run our tests with your fixture and record har files, like with the default routeFromHar method, but there are still a few issues that I faced since then and would like to ask regarding how to implement my use case with your package, if it's fine by you?
As I initially described in the original post, I need to either skip recording of some requests, to avoid storing sensitive information in hars, or edit those specific request bodies afterward, to replace that information with placeholders.
The first option has a downside though: I will need to provide extra logic to handle those requests in the future when I play them back while running tests offline and locally.
So firstly, I just wanted to ask if any of those approaches can be handled by your package and already included methods there, and if yes could you point me in the right direction, so to say, which one should I use in each case.
Secondly, I have been trying to implement the second approach, by just intercepting inside postProcess method an entry.request.postData.text and then modifying it to have placeholders instead of passwords, we do similar approach with regular playwright route method on some tests, but the goal here to do it not with real request bodies on the fly, but just with har recordings. I have faced a couple of issues here along the way though:

  • first, I didn't manage to alter har files this way, even though test is successfully completing;
  • second, when I try to play it back locally, with update: false, I get "SyntaxError: Unexpected token 'P', ""... is not valid JSON" if the hars are in zip file, and failed network requests when its just saved as a *.har. I tried it with and without matcher\postProcess, results are the same. This issue though appears only with "updateContent: "attach", "embed" seems to work fine.
    In general, I think I might be moving in a wrong direction with this approach, that's why I wanted to ask your opinion on this first.

Thanks in advance for the help.

@NoamGaash
Copy link
Owner

Hi, sorry for the late response.
I made a little experiment (#47) about using postProcess (see tests/setup.ts) to hide secrets.
Seems like right now it's not working because playwright record api requests to the har file.
Also I believe there's a bug with Playwright's minimal mode.
I think adding an auto-fixture to this repo that will fix the minimal mode could b a cool idea.
The minimal mode, in my opinion, should not only omit timestamps and metadata, it should also omit api requests and that will solve your security concerns.
Would you like to implement it? If not I'll probably do it but I can't guarantee it will be soon

@NoamGaash
Copy link
Owner

I'll close this issue for now - I believe that after releasing #48 and solving #13 this issue will be resolved. Please feel free to reopen if you have any thoughts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants