1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +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
parent c154145e85
commit 35f51275ad
4 changed files with 24 additions and 5 deletions

View File

@ -200,11 +200,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

@ -76,7 +76,7 @@ describe('Metamask Import UI', function () {
await driver.clickElement('.btn-secondary');
// Import Secret Recovery Phrase
await driver.fill(
await driver.pasteIntoField(
'input[placeholder="Enter your Secret Recovery Phrase"]',
testSeedPhrase,
);

View File

@ -172,7 +172,7 @@ describe('Metamask Responsive UI', function () {
);
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');
/**
@ -248,6 +248,26 @@ class Driver {
assert.ok(!dataTab, 'Found element that should not be present');
}
/**
* 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) {