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

Second Metamask account persist between Playwright invocations #766

Open
norswap opened this issue May 23, 2023 · 12 comments
Open

Second Metamask account persist between Playwright invocations #766

norswap opened this issue May 23, 2023 · 12 comments
Labels
bug 🐛 Something isn't working

Comments

@norswap
Copy link

norswap commented May 23, 2023

I set up Metamask in my fixtures with the mnemonic "test test test test test test test test test test test junk", to get the standard Anvil/Hardhat test account.

Later, in my tests, I imported the second Anvil account with await metamask.importAccount("59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d") (I realize now I could just have down await metamask.createAccount().

Anyhow, now whenever I rerun my e2e tests, the initialSetup will input the seed account ... and there will immediately be two accounts populated (first and second metamask account).

This is a little bit annoying, as it causes the metamask.importAccount to fail in the test (because the account already exists).

Note that metamask.createAccount does not seem to have the same problem: when I invoke it, a new account is created (the third one), but it does not persist across playwright runs.

This thus seems like a weird edge case that only occurs when you import an account that is also a valid account for your seed?

I'm kind of wondering what kind of data is being persisted between runs and how I could clear it.

Note that using initialSetup with a different seed, there is only one account, but when switching back to the old Anvil seed, both accounts are right there waiting for me.

@norswap norswap added the bug 🐛 Something isn't working label May 23, 2023
@DavitMkhitaryan
Copy link

DavitMkhitaryan commented Jul 26, 2023

@drptbl Please take a view at this issue. Seems like there is something fundamentally wrong with initialSetup method when using Synpress with Playwright. I am getting an issue when trying to switchNetwork in each test. I am using polygon network in initialSetup method, I have 4 tests running in the same spec file, for 1st test only it is successfully switched to polygon, for the rest of the tests it doesn't work and remains on ethereum mainnet network, calling getNetwork in the failing tests shows the current network is polygon.

Commenting my issue here, because seems like the root cause is the same.

Please note, I have tried using changeNetwork in each test, and several other methods, but everything fails, this makes synpress integration with Playwright useless. Please, at least provide a workaround until the issue is fixed.

@drptbl
Copy link
Collaborator

drptbl commented Jul 26, 2023

@DavitMkhitaryan Thanks for reporting. Do you have any repo where I can reproduce this issue?

@DavitMkhitaryan
Copy link

DavitMkhitaryan commented Jul 26, 2023

@DavitMkhitaryan Thanks for reporting. Do you have any repo where I can reproduce this issue?

Thanks for the quick response, unfortunately I cannot share the repo as it is a corporate one, but I think it will be reproduced in any case, where you have more than one test in the same spec file. If you start any project, in the initial setup set the network to polygon, and run the tests, starting from the second one the network will not change to polygon anymore. Again, the root cause I think is connected to some metamask state not being cleared, as when I check with getNetwork for the failed tests, it says polygon, but starting from the second test the polygon is not even there.

@drptbl Please let me know if you were able to reproduce it, or if you need any more information from my side. It is currently blocking my work and I am more than happy to get this fixed asap. Thanks!

@DavitMkhitaryan
Copy link

DavitMkhitaryan commented Aug 14, 2023

@drptbl Hello, is there any update regarding this issue?

This is impossible to have more than one test in the same spec file because of this if this is the case. Again, suppose I am using "polygon" in my initalSetup in Playwright fixtures, for the first test in spec file it works, and for the second test it doesn't as it thinks that polygon is already there, however it isn't.

Another case, if I choose "ethereum" in initialSetup, and I do addNetwork("polygon") at the start of each test, the first one will work, the second one will fail because it will try to change network to Polygon without importing, because for some reason it thinks Polygon is already imported, but IT IS NO THERE. Please, tell me if I am doing something wrong here, and if this is indeed an issue as I described, this is a blocking issue making Playwright + Synpress useless.

Another useful info, again, this action is working for first, third, fifth... tests, but not working for seond, fourth, sixth, tests. The polygon network is successfully added for the first and third test, but it fails for second and fourth tests... This is very strange but may help you to find the root cause. So maybe if addNetwork fails once, the next one again correctly imports the polygon network and so on...

Thank you.

Screenshot 2023-08-14 at 11 34 56

@DavitMkhitaryan
Copy link

@drptbl As @norswap wrote: "I'm kind of wondering what kind of data is being persisted between runs and how I could clear it." If there is any way to do an additional step or method call to make sure the metamask data is not persisted between tests, this maybe also solve my issue for now.

@r3kt-eth
Copy link
Contributor

hello @DavitMkhitaryan, i think that if there would be a repository where this issue can be reproduced, it would speed up resolution of this issue.

@DavitMkhitaryan
Copy link

@r3kt-eth As I said the issue is being reproduced on a corporate repository which I cannot share, but I will create a separete public repo with tests on a different SUT, and will send you the link here later today. Thanks.

@DavitMkhitaryan
Copy link

DavitMkhitaryan commented Aug 15, 2023

@r3kt-eth @drptbl . Here I created a repo with the reproduction of the issue: https://github.com/DavitMkhitaryan/test-automation-playwright-synpress

You can find more details in readme. Please, check this as soon as possible and let me know if there is any workarounds or fixes to this issue. Thanks.

@DavitMkhitaryan
Copy link

@r3kt-eth Please let me know if you could reproduce the issue and if there is any workaround for this right now

@r3kt-eth r3kt-eth mentioned this issue Aug 17, 2023
2 tasks
@r3kt-eth
Copy link
Contributor

r3kt-eth commented Aug 17, 2023

@DavitMkhitaryan fix has been released with @synthetixio/[email protected]

please test it out and let me know if that helps

take a look at updated fixture for reference:
https://github.com/synpress-io/synpress-examples/blob/master/playwright/isolated-state/fixtures.ts

in particular you need these changes:
use await setExpectInstance(expect); instead of global.expect
and
await resetState(); after await context.close()

@DavitMkhitaryan
Copy link

@r3kt-eth Thanks. Updated package to @synthetixio/[email protected], and added the await setExpectInstance(expect); and await resetState(); accordingly. Issue is now fixed.

@harry-nutsfi
Copy link

Seems the same thing happen for shared-state testing. It went well if there is only one test file (with the exact setup as shared-state example on playwright). If there is another one, the second time of metamask setup (for the 2nd test file) constantly failed for me. Maybe we need to "resetState" after each test file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants
@norswap @drptbl @DavitMkhitaryan @r3kt-eth @harry-nutsfi and others