Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add key literals to driver #10854

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add key literals to driver
  • Loading branch information
brad-decker committed Apr 12, 2021
commit bb06502e7f63d96b803badfdbe2c268454b31f84
3 changes: 1 addition & 2 deletions test/e2e/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const path = require('path');
const { promises: fs, constants: fsConstants } = require('fs');
const ttest = require('ttest');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('./helpers');
const { PAGES } = require('./webdriver/driver');

Expand All @@ -16,7 +15,7 @@ async function measurePage(pageName) {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);
await driver.findElement('.selected-account__name');
await driver.navigate(pageName);
await driver.delay(1000);
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/from-import-ui.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert');
const { Key, until } = require('selenium-webdriver');
const { until } = require('selenium-webdriver');

const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { regularDelayMs, largeDelayMs } = require('./helpers');
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Using MetaMask with an existing account', function () {
it('accepts the account password after lock', async function () {
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.key.ENTER);
await driver.delay(largeDelayMs);
});
});
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/metamask-ui.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('assert');
const { Key } = require('selenium-webdriver');

const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
Expand Down Expand Up @@ -169,7 +168,7 @@ describe('MetaMask', function () {
it('accepts the account password after lock', async function () {
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);
await driver.delay(largeDelayMs * 4);
});
});
Expand Down Expand Up @@ -272,11 +271,11 @@ describe('MetaMask', function () {
'send screen should render an insufficient fund error message',
);

await inputAmount.sendKeys(Key.BACK_SPACE);
await inputAmount.sendKeys(driver.Key.BACK_SPACE);
await driver.delay(50);
await inputAmount.sendKeys(Key.BACK_SPACE);
await inputAmount.sendKeys(driver.Key.BACK_SPACE);
await driver.delay(50);
await inputAmount.sendKeys(Key.BACK_SPACE);
await inputAmount.sendKeys(driver.Key.BACK_SPACE);
await driver.delay(tinyDelayMs);

await driver.assertElementNotPresent('.send-v2__error-amount');
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/metrics.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const waitUntilCalled = require('../lib/wait-until-called');
const { withFixtures } = require('./helpers');

Expand Down Expand Up @@ -35,7 +34,7 @@ describe('Segment metrics', function () {

const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await threeSegmentEventsReceived();

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/tests/address-book.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { Key, until } = require('selenium-webdriver');
const { until } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Address Book', function () {
Expand All @@ -24,7 +24,7 @@ describe('Address Book', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.clickElement('[data-testid="eth-overview-send"]');

Expand Down Expand Up @@ -87,7 +87,7 @@ describe('Address Book', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.clickElement('[data-testid="eth-overview-send"]');
const recipientRowTitle = await driver.findElement(
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/localization.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Localization', function () {
Expand All @@ -19,7 +18,7 @@ describe('Localization', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);
const secondaryBalance = await driver.findElement(
'[data-testid="eth-overview__secondary-currency"]',
);
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/permissions.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Permissions', function () {
Expand All @@ -25,7 +24,7 @@ describe('Permissions', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.openNewPage('http://127.0.0.1:8080/');
await driver.clickElement({
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/personal-sign.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Personal sign', function () {
Expand All @@ -24,7 +23,7 @@ describe('Personal sign', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.openNewPage('http://127.0.0.1:8080/');
await driver.clickElement('#personalSign');
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/provider-events.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const { withFixtures, regularDelayMs } = require('../helpers');

describe('MetaMask', function () {
Expand All @@ -24,7 +23,7 @@ describe('MetaMask', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.openNewPage('http://127.0.0.1:8080/');
const networkDiv = await driver.findElement('#network');
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/tests/send-edit.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { Key, until } = require('selenium-webdriver');
const { until } = require('selenium-webdriver');
const {
withFixtures,
tinyDelayMs,
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('Editing Confirm Transaction', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

const transactionAmounts = await driver.findElements(
'.currency-display-component__text',
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/signature-request.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Signature Request', function () {
Expand All @@ -25,7 +24,7 @@ describe('Signature Request', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);

await driver.openNewPage('http://127.0.0.1:8080/');

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tests/simple-send.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');

describe('Simple send', function () {
Expand All @@ -18,7 +17,7 @@ describe('Simple send', function () {
await driver.navigate();
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await passwordField.sendKeys(driver.Key.ENTER);
await driver.clickElement('[data-testid="eth-overview-send"]');
const recipientAddressField = await driver.findElement(
'[data-testid="ens-input"]',
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Driver {
this.browser = browser;
this.extensionUrl = extensionUrl;
this.timeout = timeout;
// The following values are found in
// /~https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/input.js#L50-L110
// These should be replaced with string constants 'Enter' etc for playwright.
this.Key = {
BACK_SPACE: '\uE003',
ENTER: '\uE007',
};
}

buildLocator(locator) {
Expand Down