diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index fc4b1d8db..89e5491aa 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -226,7 +226,7 @@ const completeImportSRPOnboardingFlow = async ( await driver.clickElement('.btn-secondary'); // Import Secret Recovery Phrase - await driver.fill( + await driver.pasteIntoField( 'input[placeholder="Enter your Secret Recovery Phrase"]', seedPhrase, ); diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index 30ca8d43b..01a3a9cac 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -202,11 +202,10 @@ describe('MetaMask', function () { await restoreSeedLink.click(); await driver.delay(regularDelayMs); - await driver.fill( + await driver.pasteIntoField( 'input[placeholder="Enter your Secret Recovery Phrase"]', testSeedPhrase, ); - await driver.delay(regularDelayMs); await driver.fill('#password', 'correct horse battery staple'); await driver.fill('#confirm-password', 'correct horse battery staple'); diff --git a/test/e2e/tests/add-account.spec.js b/test/e2e/tests/add-account.spec.js index 5c0d3fcb9..f9318cc7f 100644 --- a/test/e2e/tests/add-account.spec.js +++ b/test/e2e/tests/add-account.spec.js @@ -129,11 +129,10 @@ describe('Add account', function () { await restoreSeedLink.click(); await driver.delay(regularDelayMs); - await driver.fill( + await driver.pasteIntoField( 'input[placeholder="Enter your Secret Recovery Phrase"]', testSeedPhrase, ); - await driver.delay(regularDelayMs); await driver.fill('#password', 'correct horse battery staple'); await driver.fill('#confirm-password', 'correct horse battery staple'); diff --git a/test/e2e/tests/metamask-responsive-ui.spec.js b/test/e2e/tests/metamask-responsive-ui.spec.js index e01e5b307..38f1f350f 100644 --- a/test/e2e/tests/metamask-responsive-ui.spec.js +++ b/test/e2e/tests/metamask-responsive-ui.spec.js @@ -169,7 +169,7 @@ describe('Metamask Responsive UI', function () { assert.equal(await restoreSeedLink.getText(), 'Forgot password?'); await restoreSeedLink.click(); - await driver.fill( + await driver.pasteIntoField( 'input[placeholder="Enter your Secret Recovery Phrase"]', testSeedPhrase, ); diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 84342ae69..8f23f3cdc 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1,6 +1,6 @@ const { promises: fs } = require('fs'); const { strict: assert } = require('assert'); -const { until, error: webdriverError, By } = require('selenium-webdriver'); +const { until, error: webdriverError, By, Key } = require('selenium-webdriver'); const cssToXPath = require('css-to-xpath'); /** @@ -257,6 +257,26 @@ class Driver { } } + /** + * Paste a string into a field. + * + * @param {string} element - The element locator. + * @param {string} contentToPaste - The content to paste. + */ + async pasteIntoField(element, contentToPaste) { + // Throw if double-quote is present in content to paste + // so that we don't have to worry about escaping double-quotes + if (contentToPaste.includes('"')) { + throw new Error('Cannot paste content with double-quote'); + } + // Click to focus the field + await this.clickElement(element); + await this.executeScript( + `navigator.clipboard.writeText("${contentToPaste}")`, + ); + await this.fill(element, Key.chord(Key.CONTROL, 'v')); + } + // Navigation async navigate(page = Driver.PAGES.HOME) {