Closed badgooooor closed 4 months ago
solution is simple but this is not the only issue, then it failing due to metamask popup if use privateKey :)
I didn't understand why this version is not beta... is not working from the box if you are using it as a plugin with playwright
solution for this error:
fixtures.ts
import { BrowserContext, test as base, chromium } from "@playwright/test";
import { prepareMetamask } from "@synthetixio/synpress/helpers";
import playwright from "@synthetixio/synpress/commands/playwright";
const contextOptions = {
context: async ({}, use: any) => {
const metamaskVersion = "11.15.1";
const metamaskPath = await prepareMetamask(metamaskVersion);
const browserArgs = [
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`,
"--remote-debugging-port=9222",
"--reset-browser-instance-between-tests",
];
const context = await chromium.launchPersistentContext("", {
headless: false,
args: browserArgs,
});
await playwright.init(context.browser()); // this line make "metamaskWindow" to be set, in other cases it's undefined in initialSetup function
await context.pages()[0].waitForTimeout(5000);
await use(context);
await context.close();
},
};
export const test = base.extend<BrowserContext>(contextOptions);
export const expect = test.expect;
And make sure in test you don't use standard fixture page
instead of it you need to use const page = context.pages()[0]
Then use "initialSetup" inside test, but as I mentioned before wait for popup that is not handled by synpress after wallet creation if you pass a private key, with mnemonic phrase it works for me
For devs pay attention to "importAccount" function to fix that issue
...
if (secretWordsOrPrivateKey.includes(' ')) {
// secret words
await module.exports.importWallet(secretWordsOrPrivateKey, password);
} else {
// private key
await module.exports.createWallet(password);
await module.exports.importAccount(secretWordsOrPrivateKey); //here
}
// Enhanced Transaction Protection
await playwright.waitAndClick(
mainPageElements.accountModal.primaryButton,
);
await setupSettings(enableAdvancedSettings, enableExperimentalSettings);
await module.exports.changeNetwork(network);
...
If we use initialSetup
with private key in function importAccount
it's not handle the Enhanced Transaction Protection popup
@badgooooor @itev4n7 fixed in @synthetixio/synpress@3.7.3
- it was external contribution btw
@itev4n7 Just tested out the edited fixture you suggested earlier, it's working. Thanks. @drptbl From this issue, should the examples in synpress-example needed to update? At least for those who come in new would not for to this kind of pitfall.
๐ Have you searched existing issues to avoid duplicates?
๐งช Have you tested your code using latest version of Synpress?
๐ก Are you able to provide enough information to be able to reproduce your issue locally?
Synpress version
3.7.2
Node.js version
v18.19.1
Operating system
14.5
Run mode
Playwright + Synpress (as plugin)
CI platform (if applicable)
No response
Are you running your tests inside docker? (if applicable)
What happened?
I tried to setup synpress test on playwright on my private working directory which currently using
npm
as package manager. Upon running, the error was prompted in console like this.What is your expected behavior?
It should work correctly same as setup using
pnpm
How to reproduce the bug.
I decided to retest this setup using
synpress-example
which originally usingpnpm
setup but install usingnpm
instead and it has the same result as above.This is step that I did to reproduce this issue
cd playwright/isolated-state
npm install
npm run test
Relevant log output