1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00

Add pasteIntoField webdriver method (#14004)

A new method has been added to the e2e webdriver for pasting text into
a field. This will be required to properly test a change to the SRP
input, which will be coming in a separate PR.

A few existing e2e tests have been updated to use this method to input
the SRP, to show that it works properly.
This commit is contained in:
Mark Stacey 2022-03-16 19:13:21 -02:30 committed by GitHub
parent 383a21f735
commit 13bb4662a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 7 deletions

View File

@ -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,
);

View File

@ -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');

View File

@ -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');

View File

@ -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,
);

View File

@ -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) {