1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +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 path = require('path');
const { promises: fs, constants: fsConstants } = require('fs'); const { promises: fs, constants: fsConstants } = require('fs');
const ttest = require('ttest'); const ttest = require('ttest');
const { By, Key } = require('selenium-webdriver'); const { Key } = require('selenium-webdriver');
const { withFixtures } = require('./helpers'); const { withFixtures } = require('./helpers');
const { PAGES } = require('./webdriver/driver'); const { PAGES } = require('./webdriver/driver');
@ -14,10 +14,10 @@ async function measurePage(pageName) {
let metrics; let metrics;
await withFixtures({ fixtures: 'imported-account' }, async ({ driver }) => { await withFixtures({ fixtures: 'imported-account' }, async ({ driver }) => {
await driver.navigate(); 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('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER); 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.navigate(pageName);
await driver.delay(1000); await driver.delay(1000);
metrics = await driver.collectMetrics(); metrics = await driver.collectMetrics();

View File

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

View File

@ -1,7 +1,6 @@
const assert = require('assert'); 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 enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers'); const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver'); 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 () { 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 () { it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header')); await driver.findElement('.welcome-page__header');
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.getStarted.message,
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`, tag: 'button',
), });
);
await driver.delay(largeDelayMs); await driver.delay(largeDelayMs);
}); });
it('clicks the "Create New Wallet" option', async function () { it('clicks the "Create New Wallet" option', async function () {
await driver.clickElement( await driver.clickElement({ text: 'Create a Wallet', tag: 'button' });
By.xpath(`//button[contains(text(), 'Create a Wallet')]`),
);
await driver.delay(largeDelayMs); await driver.delay(largeDelayMs);
}); });
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () { 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); await driver.delay(largeDelayMs);
}); });
it('accepts a secure password', async function () { it('accepts a secure password', async function () {
const passwordBox = await driver.findElement( const passwordBox = await driver.findElement(
By.css('.first-time-flow__form #create-password'), '.first-time-flow__form #create-password',
); );
const passwordBoxConfirm = await driver.findElement( 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 passwordBox.sendKeys('correct horse battery staple');
await passwordBoxConfirm.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); await driver.delay(regularDelayMs);
}); });
it('skips the seed phrase challenge', async function () { it('skips the seed phrase challenge', async function () {
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.remindMeLater.message,
`//button[contains(text(), '${enLocaleMessages.remindMeLater.message}')]`, tag: 'button',
), });
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="account-options-menu-button"]');
await driver.clickElement( 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"]'),
); );
}); });
it('gets the current accounts address', async function () { it('gets the current accounts address', async function () {
const addressInput = await driver.findElement( const addressInput = await driver.findElement('.readonly-input__input');
By.css('.readonly-input__input'),
);
publicAddress = await addressInput.getAttribute('value'); 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.wait(until.stalenessOf(accountModal));
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
@ -140,13 +131,13 @@ describe('MetaMask', function () {
}); });
it('sends eth to the current account', async 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 addressInput.sendKeys(publicAddress);
await driver.delay(regularDelayMs); 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); 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 () { it('should have the correct amount of eth', async function () {
const balances = await driver.findElements( 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); await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText(); const balance = await balances[0].getText();
@ -167,48 +158,43 @@ describe('MetaMask', function () {
describe('backs up the seed phrase', function () { describe('backs up the seed phrase', function () {
it('should show a backup reminder', async function () { it('should show a backup reminder', async function () {
const backupReminder = await driver.findElements( const backupReminder = await driver.findElements({
By.xpath( xpath:
"//div[contains(@class, 'home-notification__text') and contains(text(), 'Backup your Secret Recovery code to keep your wallet and funds secure')]", "//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); assert.equal(backupReminder.length, 1);
}); });
it('should take the user to the seedphrase backup screen', async function () { 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); await driver.delay(regularDelayMs);
}); });
let seedPhrase; let seedPhrase;
it('reveals the seed phrase', async function () { it('reveals the seed phrase', async function () {
const byRevealButton = By.css( await driver.clickElement(
'.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button', '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button',
); );
await driver.clickElement(byRevealButton);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
const revealedSeedPhrase = await driver.findElement( const revealedSeedPhrase = await driver.findElement(
By.css('.reveal-seed-phrase__secret-words'), '.reveal-seed-phrase__secret-words',
); );
seedPhrase = await revealedSeedPhrase.getText(); seedPhrase = await revealedSeedPhrase.getText();
assert.equal(seedPhrase.split(' ').length, 12); assert.equal(seedPhrase.split(' ').length, 12);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.next.message,
`//button[contains(text(), '${enLocaleMessages.next.message}')]`, tag: 'button',
), });
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
async function clickWordAndWait(word) { async function clickWordAndWait(word) {
await driver.clickElement( 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); await driver.delay(tinyDelayMs);
} }
@ -220,22 +206,18 @@ describe('MetaMask', function () {
await clickWordAndWait(word); await clickWordAndWait(word);
} }
await driver.clickElement( await driver.clickElement({ text: 'Confirm', tag: 'button' });
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('can click through the success screen', async function () { it('can click through the success screen', async function () {
await driver.clickElement( await driver.clickElement({ text: 'All Done', tag: 'button' });
By.xpath(`//button[contains(text(), 'All Done')]`),
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('should have the correct amount of eth', async function () { it('should have the correct amount of eth', async function () {
const balances = await driver.findElements( 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); await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText(); const balance = await balances[0].getText();
@ -244,7 +226,7 @@ describe('MetaMask', function () {
}); });
it('should not show a backup reminder', async 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 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 enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers'); const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver'); const { buildWebDriver } = require('./webdriver');
@ -48,73 +47,66 @@ describe('MetaMask', function () {
describe('Going through the first time flow', function () { describe('Going through the first time flow', function () {
it('clicks the continue button on the welcome screen', async function () { it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header')); await driver.findElement('.welcome-page__header');
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.getStarted.message,
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`, tag: 'button',
), });
);
await driver.delay(largeDelayMs); await driver.delay(largeDelayMs);
}); });
it('clicks the "Create New Wallet" option', async function () { it('clicks the "Create New Wallet" option', async function () {
await driver.clickElement( await driver.clickElement({ text: 'Create a Wallet', tag: 'button' });
By.xpath(`//button[contains(text(), 'Create a Wallet')]`),
);
await driver.delay(largeDelayMs); await driver.delay(largeDelayMs);
}); });
it('clicks the "I Agree" option on the metametrics opt-in screen', async function () { 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); await driver.delay(largeDelayMs);
}); });
it('accepts a secure password', async function () { it('accepts a secure password', async function () {
const passwordBox = await driver.findElement( const passwordBox = await driver.findElement(
By.css('.first-time-flow__form #create-password'), '.first-time-flow__form #create-password',
); );
const passwordBoxConfirm = await driver.findElement( 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 passwordBox.sendKeys('correct horse battery staple');
await passwordBoxConfirm.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); await driver.delay(regularDelayMs);
}); });
let seedPhrase; let seedPhrase;
it('reveals the seed phrase', async function () { it('reveals the seed phrase', async function () {
const byRevealButton = By.css( await driver.clickElement(
'.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button', '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button',
); );
await driver.clickElement(byRevealButton);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
const revealedSeedPhrase = await driver.findElement( const revealedSeedPhrase = await driver.findElement(
By.css('.reveal-seed-phrase__secret-words'), '.reveal-seed-phrase__secret-words',
); );
seedPhrase = await revealedSeedPhrase.getText(); seedPhrase = await revealedSeedPhrase.getText();
assert.equal(seedPhrase.split(' ').length, 12); assert.equal(seedPhrase.split(' ').length, 12);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.next.message,
`//button[contains(text(), '${enLocaleMessages.next.message}')]`, tag: 'button',
), });
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
async function clickWordAndWait(word) { async function clickWordAndWait(word) {
await driver.clickElement( 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); await driver.delay(tinyDelayMs);
} }
@ -126,48 +118,41 @@ describe('MetaMask', function () {
await clickWordAndWait(word); await clickWordAndWait(word);
} }
await driver.clickElement( await driver.clickElement({ text: 'Confirm', tag: 'button' });
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('clicks through the success screen', async function () { it('clicks through the success screen', async function () {
await driver.findElement( await driver.findElement({ text: 'Congratulations', tag: 'div' });
By.xpath(`//div[contains(text(), 'Congratulations')]`), await driver.clickElement({
); text: enLocaleMessages.endOfFlowMessage10.message,
await driver.clickElement( tag: 'button',
By.xpath( });
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
}); });
describe('Show account information', function () { describe('Show account information', function () {
it('show account details dropdown menu', async function () { it('show account details dropdown menu', async function () {
await driver.clickElement( await driver.clickElement('[data-testid="account-options-menu-button"]');
By.css('[data-testid="account-options-menu-button"]'),
);
const options = await driver.findElements( 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 assert.equal(options.length, 3); // HD Wallet type does not have to show the Remove Account option
// click outside of menu to dismiss // click outside of menu to dismiss
// account menu button chosen because the menu never covers it. // 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); await driver.delay(regularDelayMs);
}); });
}); });
describe('Import seed phrase', function () { describe('Import seed phrase', function () {
it('logs out of the vault', async 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); await driver.delay(regularDelayMs);
const lockButton = await driver.findClickableElement( const lockButton = await driver.findClickableElement(
By.css('.account-menu__lock-button'), '.account-menu__lock-button',
); );
assert.equal(await lockButton.getText(), 'Lock'); assert.equal(await lockButton.getText(), 'Lock');
await lockButton.click(); await lockButton.click();
@ -176,7 +161,7 @@ describe('MetaMask', function () {
it('imports seed phrase', async function () { it('imports seed phrase', async function () {
const restoreSeedLink = await driver.findClickableElement( const restoreSeedLink = await driver.findClickableElement(
By.css('.unlock-page__link--import'), '.unlock-page__link--import',
); );
assert.equal( assert.equal(
await restoreSeedLink.getText(), await restoreSeedLink.getText(),
@ -185,40 +170,37 @@ describe('MetaMask', function () {
await restoreSeedLink.click(); await restoreSeedLink.click();
await driver.delay(regularDelayMs); 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 seedTextArea.sendKeys(testSeedPhrase);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
const passwordInputs = await driver.findElements(By.css('input')); const passwordInputs = await driver.findElements('input');
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
await passwordInputs[0].sendKeys('correct horse battery staple'); await passwordInputs[0].sendKeys('correct horse battery staple');
await passwordInputs[1].sendKeys('correct horse battery staple'); await passwordInputs[1].sendKeys('correct horse battery staple');
await driver.clickElement( await driver.clickElement({
By.xpath( text: enLocaleMessages.restore.message,
`//button[contains(text(), '${enLocaleMessages.restore.message}')]`, tag: 'button',
), });
);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('switches to localhost', async 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.delay(regularDelayMs);
await driver.clickElement( await driver.clickElement({
By.xpath( xpath: `//span[contains(@class, 'network-name-item') and contains(text(), 'Localhost 8545')]`,
`//span[contains(@class, 'network-name-item') and contains(text(), 'Localhost 8545')]`, });
),
);
await driver.delay(largeDelayMs * 2); await driver.delay(largeDelayMs * 2);
}); });
it('balance renders', async function () { it('balance renders', async function () {
const balance = await driver.findElement( 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.wait(until.elementTextMatches(balance, /100\s*ETH/u));
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
@ -227,17 +209,15 @@ describe('MetaMask', function () {
describe('Send ETH from inside MetaMask', function () { describe('Send ETH from inside MetaMask', function () {
it('starts to send a transaction', async 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); await driver.delay(regularDelayMs);
const inputAddress = await driver.findElement( 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 inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970');
const inputAmount = await driver.findElement( const inputAmount = await driver.findElement('.unit-input__input');
By.css('.unit-input__input'),
);
await inputAmount.sendKeys('1'); await inputAmount.sendKeys('1');
const inputValue = await inputAmount.getAttribute('value'); const inputValue = await inputAmount.getAttribute('value');
@ -247,41 +227,37 @@ describe('MetaMask', function () {
it('opens and closes the gas modal', async function () { it('opens and closes the gas modal', async function () {
// Set the gas limit // Set the gas limit
await driver.clickElement(By.css('.advanced-gas-options-btn')); await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs); 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.wait(until.stalenessOf(gasModal), 10000);
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('clicks through to the confirm screen', async function () { it('clicks through to the confirm screen', async function () {
// Continue to next screen // Continue to next screen
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`)); await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}); });
it('confirms the transaction', async function () { it('confirms the transaction', async function () {
await driver.clickElement( await driver.clickElement({ text: 'Confirm', tag: 'button' });
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
}); });
it('finds the transaction in the transactions list', async function () { 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 () => { await driver.wait(async () => {
const confirmedTxes = await driver.findElements( 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; return confirmedTxes.length === 1;
}, 10000); }, 10000);
const txValues = await driver.findElement( 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); 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 { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver'); const { Key } = require('selenium-webdriver');
const waitUntilCalled = require('../lib/wait-until-called'); const waitUntilCalled = require('../lib/wait-until-called');
const { withFixtures } = require('./helpers'); const { withFixtures } = require('./helpers');
@ -33,7 +33,7 @@ describe('Segment metrics', function () {
}); });
await driver.navigate(); 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('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER); await passwordField.sendKeys(Key.ENTER);

View File

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

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver'); const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers'); const { withFixtures } = require('../helpers');
describe('Localization', function () { describe('Localization', function () {
@ -17,11 +17,11 @@ describe('Localization', function () {
{ fixtures: 'localization', ganacheOptions, title: this.test.title }, { fixtures: 'localization', ganacheOptions, title: this.test.title },
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); 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('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER); await passwordField.sendKeys(Key.ENTER);
const secondaryBalance = await driver.findElement( 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 secondaryBalanceText = await secondaryBalance.getText();
const [fiatAmount, fiatUnit] = secondaryBalanceText const [fiatAmount, fiatUnit] = secondaryBalanceText

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { By, Key } = require('selenium-webdriver'); const { Key } = require('selenium-webdriver');
const { withFixtures } = require('../helpers'); const { withFixtures } = require('../helpers');
describe('Signature Request', function () { describe('Signature Request', function () {
@ -23,14 +23,14 @@ describe('Signature Request', function () {
}, },
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); 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('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER); await passwordField.sendKeys(Key.ENTER);
await driver.openNewPage('http://127.0.0.1:8080/'); await driver.openNewPage('http://127.0.0.1:8080/');
// creates a sign typed data signature request // creates a sign typed data signature request
await driver.clickElement(By.id('signTypedDataV4'), 10000); await driver.clickElement('#signTypedDataV4', 10000);
await driver.waitUntilXWindowHandles(3); await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles(); const windowHandles = await driver.getAllWindowHandles();
@ -40,13 +40,13 @@ describe('Signature Request', function () {
); );
const title = await driver.findElement( const title = await driver.findElement(
By.css('.signature-request-content__title'), '.signature-request-content__title',
); );
const name = await driver.findElement( const name = await driver.findElement(
By.css('.signature-request-content__info--bolded'), '.signature-request-content__info--bolded',
); );
const content = await driver.findElements( const content = await driver.findElements(
By.css('.signature-request-content__info'), '.signature-request-content__info',
); );
const origin = content[0]; const origin = content[0];
const address = content[1]; const address = content[1];
@ -61,16 +61,13 @@ describe('Signature Request', function () {
); );
// Approve signing typed data // Approve signing typed data
await driver.clickElement( await driver.clickElement({ text: 'Sign', tag: 'button' }, 10000);
By.xpath(`//button[contains(text(), 'Sign')]`),
10000,
);
// switch to the Dapp and verify the signed addressed // switch to the Dapp and verify the signed addressed
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
await driver.clickElement(By.id('signTypedDataV4Verify'), 10000); await driver.clickElement('#signTypedDataV4Verify', 10000);
const recoveredAddress = await driver.findElement( const recoveredAddress = await driver.findElement(
By.id('signTypedDataV4VerifyResult'), '#signTypedDataV4VerifyResult',
); );
assert.equal(await recoveredAddress.getText(), publicAddress); 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'); const { withFixtures } = require('../helpers');
describe('Simple send', function () { describe('Simple send', function () {
@ -16,28 +16,22 @@ describe('Simple send', function () {
{ fixtures: 'imported-account', ganacheOptions, title: this.test.title }, { fixtures: 'imported-account', ganacheOptions, title: this.test.title },
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); 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('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER); 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( const recipientAddressField = await driver.findElement(
By.css('[data-testid="ens-input"]'), '[data-testid="ens-input"]',
); );
await recipientAddressField.sendKeys( await recipientAddressField.sendKeys(
'0x985c30949c92df7a0bd42e0f3e3d539ece98db24', '0x985c30949c92df7a0bd42e0f3e3d539ece98db24',
); );
const amountField = await driver.findElement( const amountField = await driver.findElement('.unit-input__input');
By.css('.unit-input__input'),
);
await amountField.sendKeys('1'); await amountField.sendKeys('1');
await driver.clickElement( await driver.clickElement('[data-testid="page-container-footer-next"]');
By.css('[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.clickElement( await driver.findElement('.transaction-list-item');
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'));
}, },
); );
}); });

View File

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