diff --git a/commands/metamask.js b/commands/metamask.js index b361bac..1f2979b 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -1305,6 +1305,7 @@ const metamask = { password, enableAdvancedSettings, enableExperimentalSettings, + playwrightInstance, }) { const isCustomNetwork = (process.env.NETWORK_NAME && @@ -1312,7 +1313,7 @@ const metamask = { process.env.CHAIN_ID) || typeof network == 'object'; - await playwright.init(); + await playwright.init(playwrightInstance); await playwright.assignWindows(PROVIDER); await playwright.assignActiveTabName(PROVIDER); await module.exports.getExtensionDetails(); diff --git a/commands/phantom.js b/commands/phantom.js index ed3f7bf..03912d0 100644 --- a/commands/phantom.js +++ b/commands/phantom.js @@ -146,6 +146,7 @@ module.exports = { ); // STEP: Input password, confirm and continue + await new Promise(resolve => setTimeout(resolve, 1000)); // the transitioning is too fast await playwright.waitAndType( PROVIDER, firstTimeFlowImportPageElements.passwordInput, @@ -166,13 +167,13 @@ module.exports = { firstTimeFlowImportPageElements.continueAfterPasswordButton, ); // shortcut confirmation - await new Promise(resolve => setTimeout(resolve, 500)); // the transitioning is too fast + await new Promise(resolve => setTimeout(resolve, 1000)); // the transitioning is too fast await playwright.waitAndClick( PROVIDER, firstTimeFlowImportPageElements.continueOnShortcutConfirm, ); // finish - await new Promise(resolve => setTimeout(resolve, 500)); // the transitioning is too fast + await new Promise(resolve => setTimeout(resolve, 1000)); // the transitioning is too fast await playwright.waitAndClick( PROVIDER, firstTimeFlowImportPageElements.continueOnShortcutConfirm, @@ -232,8 +233,12 @@ module.exports = { await switchToCypressIfNotActive(); return walletAddress; }, - initialSetup: async ({ secretWordsOrPrivateKey, password }) => { - await playwright.init(); + initialSetup: async ({ + secretWordsOrPrivateKey, + password, + playwrightInstance, + }) => { + await playwright.init(playwrightInstance); await playwright.assignWindows(PROVIDER); await playwright.assignActiveTabName(PROVIDER); await module.exports.getExtensionDetails(); @@ -378,19 +383,19 @@ module.exports = { }, selectWallet: async (wallet = 'metamask', mode = 'once') => { const notificationPage = await playwright.switchToNotification(PROVIDER); - if (wallet === 'metamask') { + + if (mode === 'always') { await playwright.waitAndClick( PROVIDER, - selectWalletElements.buttons.continueWithMetamask, + selectWalletElements.buttons.alwaysUse, notificationPage, ); - return true; } - if (mode === 'always') { + if (wallet === 'metamask') { await playwright.waitAndClick( PROVIDER, - selectWalletElements.buttons.alwaysUsePhantom, + selectWalletElements.buttons.continueWithMetamask, notificationPage, ); return true; diff --git a/commands/playwright.js b/commands/playwright.js index 966bd4a..ae1f373 100644 --- a/commands/playwright.js +++ b/commands/playwright.js @@ -39,6 +39,7 @@ module.exports = { const chromium = playwrightInstance ? playwrightInstance : require('@playwright/test').chromium; + const debuggerDetails = await fetch('http://127.0.0.1:9222/json/version'); //DevSkim: ignore DS137138 const debuggerDetailsConfig = await debuggerDetails.json(); const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl; @@ -127,13 +128,14 @@ module.exports = { return true; }, switchToWindow: async provider => { - if (pageWindows[provider].isClosed()) { + if (module.exports.windows(provider).isClosed()) { const newPage = await browser.contexts()[0].newPage(); if (provider === 'phantom') { await Promise.all([ newPage.waitForNavigation(), newPage.goto( - pageWindows[provider] + module.exports + .windows(provider) .url() .replace('onboarding.html', 'popup.html'), ), @@ -141,7 +143,7 @@ module.exports = { } else { await Promise.all([ newPage.waitForNavigation(), - newPage.goto(pageWindows[provider].url()), + newPage.goto(module.exports.windows(provider).url()), ]); await newPage.waitUntilStable(provider); } @@ -149,7 +151,7 @@ module.exports = { pageWindows[provider] = newPage; } - await pageWindows[provider].bringToFront(); + await module.exports.windows(provider).bringToFront(); await module.exports.assignActiveTabName(provider); return true; }, @@ -168,7 +170,9 @@ module.exports = { notificationWindows[provider] = page; retries = 0; await page.bringToFront(); - await module.exports.waitUntilStable(provider, page); + if (provider == 'metamask') { + await module.exports.waitUntilStable(provider, page); + } if (provider === 'phantom') { await module.exports.waitFor(provider, app.root, page); } else { @@ -193,8 +197,10 @@ module.exports = { ); } }, - async waitFor(provider, selector, page = pageWindows[provider]) { - await module.exports.waitUntilStable(provider, page); + async waitFor(provider, selector, page = module.exports.windows(provider)) { + if (provider == 'metamask') { + await module.exports.waitUntilStable(provider, page); + } await page.waitForSelector(selector, { strict: false }); const element = page.locator(selector).first(); await element.waitFor(); @@ -211,7 +217,7 @@ module.exports = { async waitAndClick( provider, selector, - page = pageWindows[provider], + page = module.exports.windows(provider), args = {}, ) { const element = await module.exports.waitFor(provider, selector, page); @@ -240,7 +246,7 @@ module.exports = { } else { await element.click({ force: args.force }); } - if (process.env.PROVIDER !== 'phantom') { + if (provider === 'metamask') { await module.exports.waitUntilStable(provider); } return element; @@ -249,19 +255,32 @@ module.exports = { provider, selector, text, - page = pageWindows[provider], + page = module.exports.windows(provider), ) { await module.exports.waitFor(provider, selector, page); const element = page.locator(`text=${text}`); await element.click(); - await module.exports.waitUntilStable(provider); + if (provider === 'metamask') { + await module.exports.waitUntilStable(provider); + } }, - async waitAndType(provider, selector, value, page = pageWindows[provider]) { + async waitAndType( + provider, + selector, + value, + page = module.exports.windows(provider), + ) { const element = await module.exports.waitFor(provider, selector, page); await element.type(value); - await module.exports.waitUntilStable(provider, page); + if (provider === 'metamask') { + await module.exports.waitUntilStable(provider, page); + } }, - async waitAndGetValue(provider, selector, page = pageWindows[provider]) { + async waitAndGetValue( + provider, + selector, + page = module.exports.windows(provider), + ) { const expect = global.expect ? global.expect : require('@playwright/test').expect; @@ -273,7 +292,11 @@ module.exports = { const value = await element.innerText(); return value; }, - async waitAndGetInputValue(provider, selector, page = pageWindows[provider]) { + async waitAndGetInputValue( + provider, + selector, + page = module.exports.windows(provider), + ) { const expect = global.expect ? global.expect : require('@playwright/test').expect; @@ -286,7 +309,7 @@ module.exports = { provider, selector, attribute, - page = pageWindows[provider], + page = module.exports.windows(provider), ) { const expect = global.expect ? global.expect @@ -300,7 +323,7 @@ module.exports = { provider, text, selector, - page = pageWindows[provider], + page = module.exports.windows(provider), ) { const element = await module.exports.waitFor(provider, selector, page); await element.fill(''); @@ -311,7 +334,7 @@ module.exports = { async waitAndClearWithBackspace( provider, selector, - page = pageWindows[provider], + page = module.exports.windows(provider), ) { await module.exports.waitFor(provider, selector, page); const inputValue = await page.evaluate(selector, el => el.value); @@ -324,7 +347,7 @@ module.exports = { provider, text, selector, - page = pageWindows[provider], + page = module.exports.windows(provider), ) { const element = await module.exports.waitAndClick( provider, diff --git a/package.json b/package.json index 61badb5..f767972 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phantom/synpress", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.6", "description": "Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.", "keywords": [ "Synpress", diff --git a/pages/phantom/select-wallet-page.js b/pages/phantom/select-wallet-page.js index 47a8948..8c3c50a 100644 --- a/pages/phantom/select-wallet-page.js +++ b/pages/phantom/select-wallet-page.js @@ -2,6 +2,6 @@ module.exports.selectWalletElements = { buttons: { continueWithPhantom: '[data-testid="select_wallet--phantom"]', continueWithMetamask: '[data-testid="select_wallet--metamask"]', - alwaysUsePhantom: '[data-testid="metamask_override-always_use_phantom"]', + alwaysUse: '[data-testid="select_wallet--always"]', }, };