1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

use locator abstraction in tests folder (#10833)

This commit is contained in:
Brad Decker 2021-04-07 09:57:40 -05:00 committed by GitHub
parent d1d7622c93
commit cd97340bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 631 additions and 985 deletions

View File

@ -3,7 +3,7 @@
const path = require('path');
const { promises: fs, constants: fsConstants } = require('fs');
const ttest = require('ttest');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('./helpers');
const { PAGES } = require('./webdriver/driver');
@ -14,10 +14,10 @@ async function measurePage(pageName) {
let metrics;
await withFixtures({ fixtures: 'imported-account' }, async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.findElement(By.css('.selected-account__name'));
await driver.findElement('.selected-account__name');
await driver.navigate(pageName);
await driver.delay(1000);
metrics = await driver.collectMetrics();

View File

@ -1,7 +1,6 @@
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const { Key, until } = require('selenium-webdriver');
const { By, Key, until } = webdriver;
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
@ -61,94 +60,78 @@ describe('Using MetaMask with an existing account', function () {
describe('First time flow starting from an existing seed phrase', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header'));
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
await driver.delay(largeDelayMs);
});
it('clicks the "Import Wallet" option', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import wallet')]`),
);
await driver.clickElement({ text: 'Import wallet', tag: 'button' });
await driver.delay(largeDelayMs);
});
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () {
await driver.clickElement(By.css('.btn-default'));
await driver.clickElement('.btn-default');
await driver.delay(largeDelayMs);
});
it('imports a seed phrase', async function () {
const [seedTextArea] = await driver.findElements(
By.css('input[placeholder="Paste seed phrase from clipboard"]'),
'input[placeholder="Paste seed phrase from clipboard"]',
);
await seedTextArea.sendKeys(testSeedPhrase);
await driver.delay(regularDelayMs);
const [password] = await driver.findElements(By.id('password'));
const [password] = await driver.findElements('#password');
await password.sendKeys('correct horse battery staple');
const [confirmPassword] = await driver.findElements(
By.id('confirm-password'),
);
const [confirmPassword] = await driver.findElements('#confirm-password');
confirmPassword.sendKeys('correct horse battery staple');
await driver.clickElement(By.css('.first-time-flow__terms'));
await driver.clickElement('.first-time-flow__terms');
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver.clickElement({ text: 'Import', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('clicks through the success screen', async function () {
await driver.findElement(
By.xpath(`//div[contains(text(), 'Congratulations')]`),
);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver.findElement({ text: 'Congratulations', tag: 'div' });
await driver.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
});
describe('Show account information', function () {
it('shows the correct account address', async function () {
await driver.clickElement('[data-testid="account-options-menu-button"]');
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
'[data-testid="account-options-menu__account-details"]',
);
await driver.clickElement(
By.css('[data-testid="account-options-menu__account-details"]'),
);
await driver.findVisibleElement(By.css('.qr-code__wrapper'));
await driver.findVisibleElement('.qr-code__wrapper');
await driver.delay(regularDelayMs);
const [address] = await driver.findElements(
By.css('.readonly-input__input'),
);
const [address] = await driver.findElements('.readonly-input__input');
assert.equal(await address.getAttribute('value'), testAddress);
await driver.clickElement(By.css('.account-modal__close'));
await driver.clickElement('.account-modal__close');
await driver.delay(largeDelayMs);
});
it('shows a QR code for the account', async function () {
await driver.clickElement('[data-testid="account-options-menu-button"]');
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
'[data-testid="account-options-menu__account-details"]',
);
await driver.clickElement(
By.css('[data-testid="account-options-menu__account-details"]'),
);
await driver.findVisibleElement(By.css('.qr-code__wrapper'));
const detailModal = await driver.findElement(By.css('span .modal'));
await driver.findVisibleElement('.qr-code__wrapper');
const detailModal = await driver.findElement('span .modal');
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('.account-modal__close'));
await driver.clickElement('.account-modal__close');
await driver.wait(until.stalenessOf(detailModal));
await driver.delay(regularDelayMs);
});
@ -156,11 +139,11 @@ describe('Using MetaMask with an existing account', function () {
describe('Lock and unlock', function () {
it('logs out of the account', async function () {
await driver.clickElement(By.css('.account-menu__icon .identicon'));
await driver.clickElement('.account-menu__icon .identicon');
await driver.delay(regularDelayMs);
const lockButton = await driver.findClickableElement(
By.css('.account-menu__lock-button'),
'.account-menu__lock-button',
);
assert.equal(await lockButton.getText(), 'Lock');
await lockButton.click();
@ -168,7 +151,7 @@ describe('Using MetaMask with an existing account', function () {
});
it('accepts the account password after lock', async function () {
const passwordField = await driver.findElement(By.id('password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.delay(largeDelayMs);
@ -177,42 +160,34 @@ describe('Using MetaMask with an existing account', function () {
describe('Add an account', function () {
it('switches to localhost', async function () {
await driver.clickElement(By.css('.network-display'));
await driver.clickElement('.network-display');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//span[contains(text(), 'Localhost')]`),
);
await driver.clickElement({ text: 'Localhost', tag: 'span' });
await driver.delay(largeDelayMs);
});
it('choose Create Account from the account menu', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Create Account')]`),
);
await driver.clickElement({ text: 'Create Account', tag: 'div' });
await driver.delay(regularDelayMs);
});
it('set account name', async function () {
const [accountName] = await driver.findElements(
By.css('.new-account-create-form input'),
'.new-account-create-form input',
);
await accountName.sendKeys('2nd account');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Create')]`),
);
await driver.clickElement({ text: 'Create', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('should show the correct account name', async function () {
const accountName = await driver.findElement(
By.css('.selected-account__name'),
);
const accountName = await driver.findElement('.selected-account__name');
assert.equal(await accountName.getText(), '2nd account');
await driver.delay(regularDelayMs);
});
@ -220,63 +195,57 @@ describe('Using MetaMask with an existing account', function () {
describe('Switch back to original account', function () {
it('chooses the original account from the account menu', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('.account-menu__name'));
await driver.clickElement('.account-menu__name');
await driver.delay(regularDelayMs);
});
});
describe('Send ETH from inside MetaMask', function () {
it('starts a send transaction', async function () {
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.clickElement('[data-testid="eth-overview-send"]');
await driver.delay(regularDelayMs);
const inputAddress = await driver.findElement(
By.css('input[placeholder="Search, public address (0x), or ENS"]'),
'input[placeholder="Search, public address (0x), or ENS"]',
);
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970');
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
const inputAmount = await driver.findElement('.unit-input__input');
await inputAmount.sendKeys('1');
// Set the gas limit
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`));
const gasModal = await driver.findElement('span .modal');
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.wait(until.stalenessOf(gasModal));
await driver.delay(regularDelayMs);
// Continue to next screen
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`));
await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('confirms the transaction', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('finds the transaction in the transactions list', async function () {
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElements(
By.css('.transaction-list-item__primary-currency'),
'.transaction-list-item__primary-currency',
);
assert.equal(txValues.length, 1);
assert.ok(/-1\s*ETH/u.test(await txValues[0].getText()));
@ -285,47 +254,39 @@ describe('Using MetaMask with an existing account', function () {
describe('Imports an account with private key', function () {
it('choose Create Account from the account menu', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Import Account')]`),
);
await driver.clickElement({ text: 'Import Account', tag: 'div' });
await driver.delay(regularDelayMs);
});
it('enter private key', async function () {
const privateKeyInput = await driver.findElement(
By.css('#private-key-box'),
);
const privateKeyInput = await driver.findElement('#private-key-box');
await privateKeyInput.sendKeys(testPrivateKey2);
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver.clickElement({ text: 'Import', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('should show the correct account name', async function () {
const accountName = await driver.findElement(
By.css('.selected-account__name'),
);
const accountName = await driver.findElement('.selected-account__name');
assert.equal(await accountName.getText(), 'Account 4');
await driver.delay(regularDelayMs);
});
it('should show the imported label', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
// confirm 4th account is account 4, as expected
const accountMenuItemSelector = '.account-menu__account:nth-child(4)';
const accountName = await driver.findElement(
By.css(`${accountMenuItemSelector} .account-menu__name`),
`${accountMenuItemSelector} .account-menu__name`,
);
assert.equal(await accountName.getText(), 'Account 4');
// confirm label is present on the same menu item
const importedLabel = await driver.findElement(
By.css(`${accountMenuItemSelector} .keyring-label`),
`${accountMenuItemSelector} .keyring-label`,
);
assert.equal(await importedLabel.getText(), 'IMPORTED');
});
@ -333,71 +294,57 @@ describe('Using MetaMask with an existing account', function () {
describe('Imports and removes an account', function () {
it('choose Create Account from the account menu', async function () {
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Import Account')]`),
);
await driver.clickElement({ text: 'Import Account', tag: 'div' });
await driver.delay(regularDelayMs);
});
it('enter private key', async function () {
const privateKeyInput = await driver.findElement(
By.css('#private-key-box'),
);
const privateKeyInput = await driver.findElement('#private-key-box');
await privateKeyInput.sendKeys(testPrivateKey3);
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver.clickElement({ text: 'Import', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('should see new account in account menu', async function () {
const accountName = await driver.findElement(
By.css('.selected-account__name'),
);
const accountName = await driver.findElement('.selected-account__name');
assert.equal(await accountName.getText(), 'Account 5');
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
const accountListItems = await driver.findElements(
By.css('.account-menu__account'),
'.account-menu__account',
);
assert.equal(accountListItems.length, 5);
await driver.clickPoint(By.css('.account-menu__icon'), 0, 0);
await driver.clickPoint('.account-menu__icon', 0, 0);
});
it('should open the remove account modal', async function () {
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
);
await driver.clickElement('[data-testid="account-options-menu-button"]');
await driver.clickElement(
By.css('[data-testid="account-options-menu__remove-account"]'),
'[data-testid="account-options-menu__remove-account"]',
);
await driver.findElement(By.css('.confirm-remove-account__account'));
await driver.findElement('.confirm-remove-account__account');
});
it('should remove the account', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Remove')]`),
);
await driver.clickElement({ text: 'Remove', tag: 'button' });
await driver.delay(regularDelayMs);
const accountName = await driver.findElement(
By.css('.selected-account__name'),
);
const accountName = await driver.findElement('.selected-account__name');
assert.equal(await accountName.getText(), 'Account 1');
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
const accountListItems = await driver.findElements(
By.css('.account-menu__account'),
'.account-menu__account',
);
assert.equal(accountListItems.length, 4);
});
@ -405,18 +352,17 @@ describe('Using MetaMask with an existing account', function () {
describe('Connects to a Hardware wallet', function () {
it('choose Connect Hardware Wallet from the account menu', async function () {
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Connect Hardware Wallet')]`),
);
await driver.clickElement({
text: 'Connect Hardware Wallet',
tag: 'div',
});
await driver.delay(regularDelayMs);
});
it('should open the TREZOR Connect popup', async function () {
await driver.clickElement(By.css('.hw-connect__btn:nth-of-type(2)'));
await driver.clickElement('.hw-connect__btn:nth-of-type(2)');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Connect')]`),
);
await driver.clickElement({ text: 'Connect', tag: 'button' });
await driver.delay(regularDelayMs);
const allWindows = await driver.getAllWindowHandles();
assert.equal(allWindows.length, 2);

View File

@ -1,7 +1,6 @@
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const { until } = require('selenium-webdriver');
const { By, until } = webdriver;
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
@ -59,69 +58,61 @@ describe('MetaMask', function () {
describe('Going through the first time flow, but skipping the seed phrase challenge', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header'));
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
await driver.delay(largeDelayMs);
});
it('clicks the "Create New Wallet" option', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Create a Wallet')]`),
);
await driver.clickElement({ text: 'Create a Wallet', tag: 'button' });
await driver.delay(largeDelayMs);
});
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () {
await driver.clickElement(By.css('.btn-default'));
await driver.clickElement('.btn-default');
await driver.delay(largeDelayMs);
});
it('accepts a secure password', async function () {
const passwordBox = await driver.findElement(
By.css('.first-time-flow__form #create-password'),
'.first-time-flow__form #create-password',
);
const passwordBoxConfirm = await driver.findElement(
By.css('.first-time-flow__form #confirm-password'),
'.first-time-flow__form #confirm-password',
);
await passwordBox.sendKeys('correct horse battery staple');
await passwordBoxConfirm.sendKeys('correct horse battery staple');
await driver.clickElement(By.css('.first-time-flow__checkbox'));
await driver.clickElement('.first-time-flow__checkbox');
await driver.clickElement(By.css('.first-time-flow__form button'));
await driver.clickElement('.first-time-flow__form button');
await driver.delay(regularDelayMs);
});
it('skips the seed phrase challenge', async function () {
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.remindMeLater.message}')]`,
),
);
await driver.clickElement({
text: enLocaleMessages.remindMeLater.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="account-options-menu-button"]');
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
);
await driver.clickElement(
By.css('[data-testid="account-options-menu__account-details"]'),
'[data-testid="account-options-menu__account-details"]',
);
});
it('gets the current accounts address', async function () {
const addressInput = await driver.findElement(
By.css('.readonly-input__input'),
);
const addressInput = await driver.findElement('.readonly-input__input');
publicAddress = await addressInput.getAttribute('value');
const accountModal = await driver.findElement(By.css('span .modal'));
const accountModal = await driver.findElement('span .modal');
await driver.clickElement(By.css('.account-modal__close'));
await driver.clickElement('.account-modal__close');
await driver.wait(until.stalenessOf(accountModal));
await driver.delay(regularDelayMs);
@ -140,13 +131,13 @@ describe('MetaMask', function () {
});
it('sends eth to the current account', async function () {
const addressInput = await driver.findElement(By.css('#address'));
const addressInput = await driver.findElement('#address');
await addressInput.sendKeys(publicAddress);
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('#send'));
await driver.clickElement('#send');
const txStatus = await driver.findElement(By.css('#success'));
const txStatus = await driver.findElement('#success');
await driver.wait(until.elementTextMatches(txStatus, /Success/u), 15000);
});
@ -156,7 +147,7 @@ describe('MetaMask', function () {
it('should have the correct amount of eth', async function () {
const balances = await driver.findElements(
By.css('.currency-display-component__text'),
'.currency-display-component__text',
);
await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText();
@ -167,48 +158,43 @@ describe('MetaMask', function () {
describe('backs up the seed phrase', function () {
it('should show a backup reminder', async function () {
const backupReminder = await driver.findElements(
By.xpath(
const backupReminder = await driver.findElements({
xpath:
"//div[contains(@class, 'home-notification__text') and contains(text(), 'Backup your Secret Recovery code to keep your wallet and funds secure')]",
),
);
});
assert.equal(backupReminder.length, 1);
});
it('should take the user to the seedphrase backup screen', async function () {
await driver.clickElement(By.css('.home-notification__accept-button'));
await driver.clickElement('.home-notification__accept-button');
await driver.delay(regularDelayMs);
});
let seedPhrase;
it('reveals the seed phrase', async function () {
const byRevealButton = By.css(
await driver.clickElement(
'.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button',
);
await driver.clickElement(byRevealButton);
await driver.delay(regularDelayMs);
const revealedSeedPhrase = await driver.findElement(
By.css('.reveal-seed-phrase__secret-words'),
'.reveal-seed-phrase__secret-words',
);
seedPhrase = await revealedSeedPhrase.getText();
assert.equal(seedPhrase.split(' ').length, 12);
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.next.message}')]`,
),
);
await driver.clickElement({
text: enLocaleMessages.next.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
async function clickWordAndWait(word) {
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`,
),
`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`,
);
await driver.delay(tinyDelayMs);
}
@ -220,22 +206,18 @@ describe('MetaMask', function () {
await clickWordAndWait(word);
}
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('can click through the success screen', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'All Done')]`),
);
await driver.clickElement({ text: 'All Done', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('should have the correct amount of eth', async function () {
const balances = await driver.findElements(
By.css('.currency-display-component__text'),
'.currency-display-component__text',
);
await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText();
@ -244,7 +226,7 @@ describe('MetaMask', function () {
});
it('should not show a backup reminder', async function () {
await driver.assertElementNotPresent(By.css('.backup-notification'));
await driver.assertElementNotPresent('.backup-notification');
});
});
});

View File

@ -1,7 +1,6 @@
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const { until } = require('selenium-webdriver');
const { By, until } = webdriver;
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
@ -48,73 +47,66 @@ describe('MetaMask', function () {
describe('Going through the first time flow', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header'));
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
await driver.delay(largeDelayMs);
});
it('clicks the "Create New Wallet" option', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Create a Wallet')]`),
);
await driver.clickElement({ text: 'Create a Wallet', tag: 'button' });
await driver.delay(largeDelayMs);
});
it('clicks the "I Agree" option on the metametrics opt-in screen', async function () {
await driver.clickElement(By.css('.btn-primary'));
await driver.clickElement('.btn-primary');
await driver.delay(largeDelayMs);
});
it('accepts a secure password', async function () {
const passwordBox = await driver.findElement(
By.css('.first-time-flow__form #create-password'),
'.first-time-flow__form #create-password',
);
const passwordBoxConfirm = await driver.findElement(
By.css('.first-time-flow__form #confirm-password'),
'.first-time-flow__form #confirm-password',
);
await passwordBox.sendKeys('correct horse battery staple');
await passwordBoxConfirm.sendKeys('correct horse battery staple');
await driver.clickElement(By.css('.first-time-flow__checkbox'));
await driver.clickElement('.first-time-flow__checkbox');
await driver.clickElement(By.css('.first-time-flow__form button'));
await driver.clickElement('.first-time-flow__form button');
await driver.delay(regularDelayMs);
});
let seedPhrase;
it('reveals the seed phrase', async function () {
const byRevealButton = By.css(
await driver.clickElement(
'.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button',
);
await driver.clickElement(byRevealButton);
await driver.delay(regularDelayMs);
const revealedSeedPhrase = await driver.findElement(
By.css('.reveal-seed-phrase__secret-words'),
'.reveal-seed-phrase__secret-words',
);
seedPhrase = await revealedSeedPhrase.getText();
assert.equal(seedPhrase.split(' ').length, 12);
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.next.message}')]`,
),
);
await driver.clickElement({
text: enLocaleMessages.next.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
async function clickWordAndWait(word) {
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`,
),
`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`,
);
await driver.delay(tinyDelayMs);
}
@ -126,48 +118,41 @@ describe('MetaMask', function () {
await clickWordAndWait(word);
}
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('clicks through the success screen', async function () {
await driver.findElement(
By.xpath(`//div[contains(text(), 'Congratulations')]`),
);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver.findElement({ text: 'Congratulations', tag: 'div' });
await driver.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
});
describe('Show account information', function () {
it('show account details dropdown menu', async function () {
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
);
await driver.clickElement('[data-testid="account-options-menu-button"]');
const options = await driver.findElements(
By.css('.account-options-menu .menu-item'),
'.account-options-menu .menu-item',
);
assert.equal(options.length, 3); // HD Wallet type does not have to show the Remove Account option
// click outside of menu to dismiss
// account menu button chosen because the menu never covers it.
await driver.clickPoint(By.css('.account-menu__icon'), 0, 0);
await driver.clickPoint('.account-menu__icon', 0, 0);
await driver.delay(regularDelayMs);
});
});
describe('Import seed phrase', function () {
it('logs out of the vault', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
const lockButton = await driver.findClickableElement(
By.css('.account-menu__lock-button'),
'.account-menu__lock-button',
);
assert.equal(await lockButton.getText(), 'Lock');
await lockButton.click();
@ -176,7 +161,7 @@ describe('MetaMask', function () {
it('imports seed phrase', async function () {
const restoreSeedLink = await driver.findClickableElement(
By.css('.unlock-page__link--import'),
'.unlock-page__link--import',
);
assert.equal(
await restoreSeedLink.getText(),
@ -185,40 +170,37 @@ describe('MetaMask', function () {
await restoreSeedLink.click();
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('.import-account__checkbox-container'));
await driver.clickElement('.import-account__checkbox-container');
const seedTextArea = await driver.findElement(By.css('textarea'));
const seedTextArea = await driver.findElement('textarea');
await seedTextArea.sendKeys(testSeedPhrase);
await driver.delay(regularDelayMs);
const passwordInputs = await driver.findElements(By.css('input'));
const passwordInputs = await driver.findElements('input');
await driver.delay(regularDelayMs);
await passwordInputs[0].sendKeys('correct horse battery staple');
await passwordInputs[1].sendKeys('correct horse battery staple');
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.restore.message}')]`,
),
);
await driver.clickElement({
text: enLocaleMessages.restore.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
it('switches to localhost', async function () {
await driver.clickElement(By.css('.network-display'));
await driver.clickElement('.network-display');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(
`//span[contains(@class, 'network-name-item') and contains(text(), 'Localhost 8545')]`,
),
);
await driver.clickElement({
xpath: `//span[contains(@class, 'network-name-item') and contains(text(), 'Localhost 8545')]`,
});
await driver.delay(largeDelayMs * 2);
});
it('balance renders', async function () {
const balance = await driver.findElement(
By.css('[data-testid="eth-overview__primary-currency"]'),
'[data-testid="eth-overview__primary-currency"]',
);
await driver.wait(until.elementTextMatches(balance, /100\s*ETH/u));
await driver.delay(regularDelayMs);
@ -227,17 +209,15 @@ describe('MetaMask', function () {
describe('Send ETH from inside MetaMask', function () {
it('starts to send a transaction', async function () {
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.clickElement('[data-testid="eth-overview-send"]');
await driver.delay(regularDelayMs);
const inputAddress = await driver.findElement(
By.css('input[placeholder="Search, public address (0x), or ENS"]'),
'input[placeholder="Search, public address (0x), or ENS"]',
);
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970');
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
const inputAmount = await driver.findElement('.unit-input__input');
await inputAmount.sendKeys('1');
const inputValue = await inputAmount.getAttribute('value');
@ -247,41 +227,37 @@ describe('MetaMask', function () {
it('opens and closes the gas modal', async function () {
// Set the gas limit
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
const gasModal = await driver.findElement('span .modal');
await driver.clickElement(By.css('.page-container__header-close-text'));
await driver.clickElement('.page-container__header-close-text');
await driver.wait(until.stalenessOf(gasModal), 10000);
await driver.delay(regularDelayMs);
});
it('clicks through to the confirm screen', async function () {
// Continue to next screen
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`));
await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('confirms the transaction', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
});
it('finds the transaction in the transactions list', async function () {
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElement(
By.css('.transaction-list-item__primary-currency'),
'.transaction-list-item__primary-currency',
);
await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/u), 10000);
});

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const waitUntilCalled = require('../lib/wait-until-called');
const { withFixtures } = require('./helpers');
@ -33,7 +33,7 @@ describe('Segment metrics', function () {
});
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key, until } = require('selenium-webdriver');
const { Key, until } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Address Book', function () {
@ -22,64 +22,52 @@ describe('Address Book', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.clickElement('[data-testid="eth-overview-send"]');
const inputAddress = await driver.findElement(
By.css('input[placeholder="Search, public address (0x), or ENS"]'),
'input[placeholder="Search, public address (0x), or ENS"]',
);
await inputAddress.sendKeys(
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
);
await driver.clickElement(
By.css('.dialog.send__dialog.dialog--message'),
);
await driver.clickElement('.dialog.send__dialog.dialog--message');
const addressBookAddModal = await driver.findElement(
By.css('span .modal'),
);
await driver.findElement(By.css('.add-to-address-book-modal'));
const addressBookAddModal = await driver.findElement('span .modal');
await driver.findElement('.add-to-address-book-modal');
const addressBookInput = await driver.findElement(
By.css('.add-to-address-book-modal__input'),
'.add-to-address-book-modal__input',
);
await addressBookInput.sendKeys('Test Name 1');
await driver.clickElement(
By.css('.add-to-address-book-modal__footer .btn-primary'),
'.add-to-address-book-modal__footer .btn-primary',
);
await driver.wait(until.stalenessOf(addressBookAddModal));
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
const inputAmount = await driver.findElement('.unit-input__input');
await inputAmount.sendKeys('1');
const inputValue = await inputAmount.getAttribute('value');
assert.equal(inputValue, '1');
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Next')]`),
);
await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElement(
By.css('.transaction-list-item__primary-currency'),
'.transaction-list-item__primary-currency',
);
await driver.wait(
until.elementTextMatches(txValues, /-1\s*ETH/u),
@ -97,45 +85,37 @@ describe('Address Book', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.clickElement('[data-testid="eth-overview-send"]');
const recipientRowTitle = await driver.findElement(
By.css('.send__select-recipient-wrapper__group-item__title'),
'.send__select-recipient-wrapper__group-item__title',
);
const recipientRowTitleString = await recipientRowTitle.getText();
assert.equal(recipientRowTitleString, 'Test Name 1');
await driver.clickElement(
By.css('.send__select-recipient-wrapper__group-item'),
'.send__select-recipient-wrapper__group-item',
);
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
const inputAmount = await driver.findElement('.unit-input__input');
await inputAmount.sendKeys('2');
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Next')]`),
);
await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElement(
By.css('.transaction-list-item__primary-currency'),
'.transaction-list-item__primary-currency',
);
await driver.wait(
until.elementTextMatches(txValues, /-2\s*ETH/u),

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Localization', function () {
@ -17,11 +17,11 @@ describe('Localization', function () {
{ fixtures: 'localization', ganacheOptions, title: this.test.title },
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
const secondaryBalance = await driver.findElement(
By.css('[data-testid="eth-overview__secondary-currency"]'),
'[data-testid="eth-overview__secondary-currency"]',
);
const secondaryBalanceText = await secondaryBalance.getText();
const [fiatAmount, fiatUnit] = secondaryBalanceText

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Permissions', function () {
@ -23,14 +23,15 @@ describe('Permissions', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.openNewPage('http://127.0.0.1:8080/');
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Connect')]`),
);
await driver.clickElement({
text: 'Connect',
tag: 'button',
});
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
@ -39,42 +40,45 @@ describe('Permissions', function () {
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Next')]`),
);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Connect')]`),
);
await driver.clickElement({
text: 'Next',
tag: 'button',
});
await driver.clickElement({
text: 'Connect',
tag: 'button',
});
await driver.switchToWindow(extension);
// shows connected sites
await driver.clickElement(
By.css('[data-testid="account-options-menu-button"]'),
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement(
By.css('[data-testid="account-options-menu__connected-sites"]'),
'[data-testid="account-options-menu__connected-sites"]',
);
await driver.findElement(
By.xpath(`//h2[contains(text(), 'Connected sites')]`),
);
await driver.findElement({
text: 'Connected sites',
tag: 'h2',
});
const domains = await driver.findClickableElements(
By.css('.connected-sites-list__domain-name'),
'.connected-sites-list__domain-name',
);
assert.equal(domains.length, 1);
// can get accounts within the dapp
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'eth_accounts')]`),
);
await driver.clickElement({
text: 'eth_accounts',
tag: 'button',
});
const getAccountsResult = await driver.findElement(
By.css('#getAccountsResult'),
'#getAccountsResult',
);
assert.equal(
(await getAccountsResult.getText()).toLowerCase(),

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Personal sign', function () {
@ -22,12 +22,12 @@ describe('Personal sign', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.openNewPage('http://127.0.0.1:8080/');
await driver.clickElement(By.id('personalSign'));
await driver.clickElement('#personalSign');
await driver.waitUntilXWindowHandles(3);
@ -38,14 +38,12 @@ describe('Personal sign', function () {
);
const personalMessageRow = await driver.findElement(
By.css('.request-signature__row-value'),
'.request-signature__row-value',
);
const personalMessage = await personalMessageRow.getText();
assert.equal(personalMessage, 'Example `personal_sign` message');
await driver.clickElement(
By.css('[data-testid="request-signature__sign"]'),
);
await driver.clickElement('[data-testid="request-signature__sign"]');
await driver.waitUntilXWindowHandles(2);
},

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures, regularDelayMs } = require('../helpers');
describe('MetaMask', function () {
@ -22,13 +22,13 @@ describe('MetaMask', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.openNewPage('http://127.0.0.1:8080/');
const networkDiv = await driver.findElement(By.css('#network'));
const chainIdDiv = await driver.findElement(By.css('#chainId'));
const networkDiv = await driver.findElement('#network');
const chainIdDiv = await driver.findElement('#chainId');
await driver.delay(regularDelayMs);
assert.equal(await networkDiv.getText(), '1337');
assert.equal(await chainIdDiv.getText(), '0x539');
@ -36,16 +36,14 @@ describe('MetaMask', function () {
const windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindow(windowHandles[0]);
await driver.clickElement(By.css('.network-display'));
await driver.clickElement(
By.xpath(`//span[contains(text(), 'Ropsten')]`),
);
await driver.clickElement('.network-display');
await driver.clickElement({ text: 'Ropsten', tag: 'span' });
await driver.delay(regularDelayMs);
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
const switchedNetworkDiv = await driver.findElement(By.css('#network'));
const switchedChainIdDiv = await driver.findElement(By.css('#chainId'));
const accountsDiv = await driver.findElement(By.css('#accounts'));
const switchedNetworkDiv = await driver.findElement('#network');
const switchedChainIdDiv = await driver.findElement('#chainId');
const accountsDiv = await driver.findElement('#accounts');
assert.equal(await switchedNetworkDiv.getText(), '3');
assert.equal(await switchedChainIdDiv.getText(), '0x3');

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key, until } = require('selenium-webdriver');
const { Key, until } = require('selenium-webdriver');
const {
withFixtures,
tinyDelayMs,
@ -26,12 +26,12 @@ describe('Editing Confirm Transaction', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
const transactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
'.currency-display-component__text',
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '1');
@ -40,21 +40,19 @@ describe('Editing Confirm Transaction', function () {
assert.equal(await transactionFee.getText(), '0.00025');
await driver.clickElement(
By.css('.confirm-page-container-header__back-button'),
);
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
'.confirm-page-container-header__back-button',
);
const inputAmount = await driver.findElement('.unit-input__input');
await inputAmount.clear();
await inputAmount.sendKeys('2.2');
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
const gasModal = await driver.findElement('span .modal');
const [gasPriceInput, gasLimitInput] = await driver.findElements(
By.css('.advanced-gas-inputs__gas-edit-row__input'),
'.advanced-gas-inputs__gas-edit-row__input',
);
await gasPriceInput.clear();
@ -65,17 +63,13 @@ describe('Editing Confirm Transaction', function () {
await gasLimitInput.sendKeys('100000');
await driver.delay(largeDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Save')]`),
);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.wait(until.stalenessOf(gasModal));
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Next')]`),
);
await driver.clickElement({ text: 'Next', tag: 'button' });
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
'.currency-display-component__text',
);
const editedTransactionAmount = editedTransactionAmounts[0];
assert.equal(await editedTransactionAmount.getText(), '2.2');
@ -84,23 +78,19 @@ describe('Editing Confirm Transaction', function () {
assert.equal(await editedTransactionFee.getText(), '0.0008');
// confirms the transaction
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElements(
By.css('.transaction-list-item__primary-currency'),
'.transaction-list-item__primary-currency',
);
assert.equal(txValues.length, 1);
assert.ok(/-2.2\s*ETH/u.test(await txValues[0].getText()));

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Signature Request', function () {
@ -23,14 +23,14 @@ describe('Signature Request', function () {
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.openNewPage('http://127.0.0.1:8080/');
// creates a sign typed data signature request
await driver.clickElement(By.id('signTypedDataV4'), 10000);
await driver.clickElement('#signTypedDataV4', 10000);
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
@ -40,13 +40,13 @@ describe('Signature Request', function () {
);
const title = await driver.findElement(
By.css('.signature-request-content__title'),
'.signature-request-content__title',
);
const name = await driver.findElement(
By.css('.signature-request-content__info--bolded'),
'.signature-request-content__info--bolded',
);
const content = await driver.findElements(
By.css('.signature-request-content__info'),
'.signature-request-content__info',
);
const origin = content[0];
const address = content[1];
@ -61,16 +61,13 @@ describe('Signature Request', function () {
);
// Approve signing typed data
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Sign')]`),
10000,
);
await driver.clickElement({ text: 'Sign', tag: 'button' }, 10000);
// switch to the Dapp and verify the signed addressed
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
await driver.clickElement(By.id('signTypedDataV4Verify'), 10000);
await driver.clickElement('#signTypedDataV4Verify', 10000);
const recoveredAddress = await driver.findElement(
By.id('signTypedDataV4VerifyResult'),
'#signTypedDataV4VerifyResult',
);
assert.equal(await recoveredAddress.getText(), publicAddress);
},

View File

@ -1,4 +1,4 @@
const { By, Key } = require('selenium-webdriver');
const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers');
describe('Simple send', function () {
@ -16,28 +16,22 @@ describe('Simple send', function () {
{ fixtures: 'imported-account', ganacheOptions, title: this.test.title },
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
const passwordField = await driver.findElement('#password');
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.clickElement('[data-testid="eth-overview-send"]');
const recipientAddressField = await driver.findElement(
By.css('[data-testid="ens-input"]'),
'[data-testid="ens-input"]',
);
await recipientAddressField.sendKeys(
'0x985c30949c92df7a0bd42e0f3e3d539ece98db24',
);
const amountField = await driver.findElement(
By.css('.unit-input__input'),
);
const amountField = await driver.findElement('.unit-input__input');
await amountField.sendKeys('1');
await driver.clickElement(
By.css('[data-testid="page-container-footer-next"]'),
);
await driver.clickElement(
By.css('[data-testid="page-container-footer-next"]'),
);
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.findElement(By.css('.transaction-list-item'));
await driver.clickElement('[data-testid="page-container-footer-next"]');
await driver.clickElement('[data-testid="page-container-footer-next"]');
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.findElement('.transaction-list-item');
},
);
});

View File

@ -1,8 +1,7 @@
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const { until } = require('selenium-webdriver');
const getPort = require('get-port');
const { By, until } = webdriver;
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
@ -58,64 +57,56 @@ describe('MetaMask', function () {
describe('set up data to be restored by 3box', function () {
describe('First time flow starting from an existing seed phrase', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header'));
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
await driver.delay(largeDelayMs);
});
it('clicks the "Import Wallet" option', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import wallet')]`),
);
await driver.clickElement({ text: 'Import wallet', tag: 'button' });
await driver.delay(largeDelayMs);
});
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () {
await driver.clickElement(By.css('.btn-default'));
await driver.clickElement('.btn-default');
await driver.delay(largeDelayMs);
});
it('imports a seed phrase', async function () {
const [seedTextArea] = await driver.findElements(
By.css('input[placeholder="Paste seed phrase from clipboard"]'),
'input[placeholder="Paste seed phrase from clipboard"]',
);
await seedTextArea.sendKeys(testSeedPhrase);
await driver.delay(regularDelayMs);
const [password] = await driver.findElements(By.id('password'));
const [password] = await driver.findElements('#password');
await password.sendKeys('correct horse battery staple');
const [confirmPassword] = await driver.findElements(
By.id('confirm-password'),
'#confirm-password',
);
confirmPassword.sendKeys('correct horse battery staple');
await driver.clickElement(By.css('.first-time-flow__terms'));
await driver.clickElement('.first-time-flow__terms');
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver.clickElement({ text: 'Import', tag: 'button' });
await driver.delay(regularDelayMs);
});
it('clicks through the success screen', async function () {
await driver.findElement(
By.xpath(`//div[contains(text(), 'Congratulations')]`),
);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver.findElement({ text: 'Congratulations', tag: 'div' });
await driver.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
});
it('balance renders', async function () {
const balance = await driver.findElement(
By.css('[data-testid="wallet-balance"] .list-item__heading'),
'[data-testid="wallet-balance"] .list-item__heading',
);
await driver.wait(until.elementTextMatches(balance, /25\s*ETH/u));
await driver.delay(regularDelayMs);
@ -124,44 +115,36 @@ describe('MetaMask', function () {
describe('turns on threebox syncing', function () {
it('goes to the settings screen', async function () {
await driver.clickElement(By.css('.account-menu__icon'));
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Settings')]`),
);
await driver.clickElement({ text: 'Settings', tag: 'div' });
});
it('turns on threebox syncing', async function () {
await driver.clickElement({ text: 'Advanced', tag: 'div' });
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Advanced')]`),
);
await driver.clickElement(
By.css('[data-testid="advanced-setting-3box"] .toggle-button div'),
'[data-testid="advanced-setting-3box"] .toggle-button div',
);
});
});
describe('updates settings and address book', function () {
it('navigates to General settings', async function () {
await driver.clickElement(
By.xpath(`//div[contains(text(), 'General')]`),
);
await driver.clickElement({ text: 'General', tag: 'div' });
});
it('turns on use of blockies', async function () {
await driver.clickElement(By.css('.toggle-button > div'));
await driver.clickElement('.toggle-button > div');
});
it('adds an address to the contact list', async function () {
await driver.clickElement(
By.xpath(`//div[contains(text(), 'Contacts')]`),
);
await driver.clickElement({ text: 'Contacts', tag: 'div' });
await driver.clickElement(By.css('.address-book-add-button__button'));
await driver.clickElement('.address-book-add-button__button');
await driver.delay(tinyDelayMs);
const addAddressInputs = await driver.findElements(By.css('input'));
const addAddressInputs = await driver.findElements('input');
await addAddressInputs[0].sendKeys('Test User Name 11');
await driver.delay(tinyDelayMs);
@ -172,13 +155,9 @@ describe('MetaMask', function () {
await driver.delay(largeDelayMs * 2);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Save')]`),
);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.findElement(
By.xpath(`//div[contains(text(), 'Test User Name 11')]`),
);
await driver.findElement({ text: 'Test User Name 11', tag: 'div' });
await driver.delay(regularDelayMs);
});
});
@ -199,64 +178,56 @@ describe('MetaMask', function () {
describe('First time flow starting from an existing seed phrase', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver2.findElement(By.css('.welcome-page__header'));
await driver2.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver2.findElement('.welcome-page__header');
await driver2.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
await driver2.delay(largeDelayMs);
});
it('clicks the "Import Wallet" option', async function () {
await driver2.clickElement(
By.xpath(`//button[contains(text(), 'Import wallet')]`),
);
await driver2.clickElement({ text: 'Import wallet', tag: 'button' });
await driver2.delay(largeDelayMs);
});
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () {
await driver2.clickElement(By.css('.btn-default'));
await driver2.clickElement('.btn-default');
await driver2.delay(largeDelayMs);
});
it('imports a seed phrase', async function () {
const [seedTextArea] = await driver2.findElements(
By.css('input[placeholder="Paste seed phrase from clipboard"]'),
'input[placeholder="Paste seed phrase from clipboard"]',
);
await seedTextArea.sendKeys(testSeedPhrase);
await driver2.delay(regularDelayMs);
const [password] = await driver2.findElements(By.id('password'));
const [password] = await driver2.findElements('#password');
await password.sendKeys('correct horse battery staple');
const [confirmPassword] = await driver2.findElements(
By.id('confirm-password'),
'#confirm-password',
);
confirmPassword.sendKeys('correct horse battery staple');
await driver2.clickElement(By.css('.first-time-flow__terms'));
await driver2.clickElement('.first-time-flow__terms');
await driver2.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver2.clickElement({ text: 'Import', tag: 'button' });
await driver2.delay(regularDelayMs);
});
it('clicks through the success screen', async function () {
await driver2.findElement(
By.xpath(`//div[contains(text(), 'Congratulations')]`),
);
await driver2.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver2.findElement({ text: 'Congratulations', tag: 'div' });
await driver2.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
await driver2.delay(regularDelayMs);
});
it('balance renders', async function () {
const balance = await driver2.findElement(
By.css('[data-testid="wallet-balance"] .list-item__heading'),
'[data-testid="wallet-balance"] .list-item__heading',
);
await driver2.wait(until.elementTextMatches(balance, /25\s*ETH/u));
await driver2.delay(regularDelayMs);
@ -265,36 +236,28 @@ describe('MetaMask', function () {
describe('restores 3box data', function () {
it('confirms the 3box restore notification', async function () {
await driver2.clickElement(By.css('.home-notification__accept-button'));
await driver2.clickElement('.home-notification__accept-button');
});
it('goes to the settings screen', async function () {
await driver2.clickElement(By.css('.account-menu__icon'));
await driver2.clickElement('.account-menu__icon');
await driver2.delay(regularDelayMs);
await driver2.clickElement(
By.xpath(`//div[contains(text(), 'Settings')]`),
);
await driver2.clickElement({ text: 'Settings', tag: 'div' });
});
it('finds the blockies toggle turned on', async function () {
await driver2.delay(regularDelayMs);
const toggleLabel = await driver2.findElement(
By.css('.toggle-button__status'),
);
const toggleLabel = await driver2.findElement('.toggle-button__status');
const toggleLabelText = await toggleLabel.getText();
assert.equal(toggleLabelText, 'ON');
});
it('finds the restored address in the contact list', async function () {
await driver2.clickElement(
By.xpath(`//div[contains(text(), 'Contacts')]`),
);
await driver2.clickElement({ text: 'Contacts', tag: 'div' });
await driver2.delay(regularDelayMs);
await driver2.findElement(
By.xpath(`//div[contains(text(), 'Test User Name 11')]`),
);
await driver2.findElement({ text: 'Test User Name 11', tag: 'div' });
await driver2.delay(regularDelayMs);
});
});