From cd97340bb817f43b792da9aeac6bfd8b7647f775 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Wed, 7 Apr 2021 09:57:40 -0500 Subject: [PATCH] use locator abstraction in tests folder (#10833) --- test/e2e/benchmark.js | 6 +- test/e2e/from-import-ui.spec.js | 212 +++--- test/e2e/incremental-security.spec.js | 98 ++- test/e2e/metamask-responsive-ui.spec.js | 132 ++-- test/e2e/metamask-ui.spec.js | 778 +++++++++-------------- test/e2e/metrics.spec.js | 4 +- test/e2e/tests/address-book.spec.js | 70 +- test/e2e/tests/localization.spec.js | 6 +- test/e2e/tests/permissions.spec.js | 48 +- test/e2e/tests/personal-sign.spec.js | 12 +- test/e2e/tests/provider-events.spec.js | 20 +- test/e2e/tests/send-edit.spec.js | 40 +- test/e2e/tests/signature-request.spec.js | 21 +- test/e2e/tests/simple-send.spec.js | 24 +- test/e2e/threebox.spec.js | 145 ++--- 15 files changed, 631 insertions(+), 985 deletions(-) diff --git a/test/e2e/benchmark.js b/test/e2e/benchmark.js index 2f02d93cc..3eca88474 100644 --- a/test/e2e/benchmark.js +++ b/test/e2e/benchmark.js @@ -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(); diff --git a/test/e2e/from-import-ui.spec.js b/test/e2e/from-import-ui.spec.js index fdea86cf8..581236291 100644 --- a/test/e2e/from-import-ui.spec.js +++ b/test/e2e/from-import-ui.spec.js @@ -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); diff --git a/test/e2e/incremental-security.spec.js b/test/e2e/incremental-security.spec.js index 7f9b99665..cfa5f78c3 100644 --- a/test/e2e/incremental-security.spec.js +++ b/test/e2e/incremental-security.spec.js @@ -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'); }); }); }); diff --git a/test/e2e/metamask-responsive-ui.spec.js b/test/e2e/metamask-responsive-ui.spec.js index eab3f498e..3683426b7 100644 --- a/test/e2e/metamask-responsive-ui.spec.js +++ b/test/e2e/metamask-responsive-ui.spec.js @@ -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); }); diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index 4ac2ee14d..6aa7cc268 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -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 { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers'); const { buildWebDriver } = require('./webdriver'); @@ -49,74 +48,67 @@ 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 "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); }); let seedPhrase; it('reveals the seed phrase', async function () { - const byRevealButton = By.css( - '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button', - ); + const byRevealButton = + '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button'; await driver.findElement(byRevealButton); 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); } @@ -128,38 +120,31 @@ 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('shows the 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')); + await driver.findVisibleElement('.qr-code__wrapper'); await driver.delay(regularDelayMs); - const accountModal = await driver.findElement(By.css('span .modal')); - await driver.clickElement(By.css('.account-modal__close')); + const accountModal = await driver.findElement('span .modal'); + await driver.clickElement('.account-modal__close'); await driver.wait(until.stalenessOf(accountModal)); await driver.delay(regularDelayMs); @@ -168,11 +153,11 @@ describe('MetaMask', function () { describe('Lock an unlock', function () { it('logs out of the account', 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(); @@ -180,7 +165,7 @@ describe('MetaMask', 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 * 4); @@ -189,32 +174,26 @@ describe('MetaMask', function () { describe('Add account', 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(), 'Create Account')]`), - ); + await driver.clickElement({ text: 'Create Account', tag: 'div' }); await driver.delay(regularDelayMs); }); it('set account name', async function () { const accountName = await driver.findElement( - 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(largeDelayMs); }); it('should display 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); }); @@ -222,11 +201,11 @@ describe('MetaMask', function () { 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(); @@ -235,7 +214,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(), @@ -244,28 +223,27 @@ 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('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, /100\s*ETH/u)); await driver.delay(regularDelayMs); @@ -274,22 +252,18 @@ describe('MetaMask', function () { describe('Send ETH from inside MetaMask using default gas', 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('1000'); - const errorAmount = await driver.findElement( - By.css('.send-v2__error-amount'), - ); + const errorAmount = await driver.findElement('.send-v2__error-amount'); assert.equal( await errorAmount.getText(), 'Insufficient funds.', @@ -303,10 +277,10 @@ describe('MetaMask', function () { await inputAmount.sendKeys(Key.BACK_SPACE); await driver.delay(tinyDelayMs); - await driver.assertElementNotPresent(By.css('.send-v2__error-amount')); + await driver.assertElementNotPresent('.send-v2__error-amount'); const amountMax = await driver.findClickableElement( - By.css('.send-v2__amount-max'), + '.send-v2__amount-max', ); await amountMax.click(); @@ -325,30 +299,26 @@ describe('MetaMask', function () { 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(largeDelayMs * 2); }); 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); }); @@ -356,52 +326,44 @@ describe('MetaMask', function () { describe('Send ETH from inside MetaMask using fast gas option', 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'); const inputValue = await inputAmount.getAttribute('value'); assert.equal(inputValue, '1'); // Set the gas price - await driver.clickElement( - By.xpath(`//button/div/div[contains(text(), "Fast")]`), - ); + await driver.clickElement({ text: 'Fast', tag: 'button/div/div' }); 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(largeDelayMs); }); it('finds the transaction in the transactions list', async function () { 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 === 2; }, 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); }); @@ -409,61 +371,55 @@ describe('MetaMask', function () { describe('Send ETH from inside MetaMask using advanced gas modal', 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'); const inputValue = await inputAmount.getAttribute('value'); assert.equal(inputValue, '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 () { 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'); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(largeDelayMs); }); it('finds the transaction in the transactions list', async function () { 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 === 3; }, 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); }); @@ -476,41 +432,34 @@ describe('MetaMask', function () { let dapp; 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({ text: 'Settings', tag: 'div' }); + + // await driver.findElement('.tab-bar') + + await driver.clickElement({ text: 'Advanced', tag: 'div' }); await driver.delay(regularDelayMs); await driver.clickElement( - By.xpath(`//div[contains(text(), 'Settings')]`), + '[data-testid="advanced-setting-show-testnet-conversion"] .settings-page__content-item-col > div > div', ); - // await driver.findElement(By.css('.tab-bar')) - - await driver.clickElement( - By.xpath(`//div[contains(text(), 'Advanced')]`), - ); - await driver.delay(regularDelayMs); - - await driver.clickElement( - By.css( - '[data-testid="advanced-setting-show-testnet-conversion"] .settings-page__content-item-col > div > div', - ), - ); - - const advancedGasTitle = await driver.findElement( - By.xpath(`//span[contains(text(), 'Advanced gas controls')]`), - ); + const advancedGasTitle = await driver.findElement({ + text: 'Advanced gas controls', + tag: 'span', + }); await driver.scrollToElement(advancedGasTitle); await driver.clickElement( - By.css( - '[data-testid="advanced-setting-advanced-gas-inline"] .settings-page__content-item-col > div > div', - ), + '[data-testid="advanced-setting-advanced-gas-inline"] .settings-page__content-item-col > div > div', ); windowHandles = await driver.getAllWindowHandles(); extension = windowHandles[0]; await driver.closeAllWindowHandlesExcept([extension]); - await driver.clickElement(By.css('.app-header__logo-container')); + await driver.clickElement('.app-header__logo-container'); await driver.delay(largeDelayMs); }); @@ -519,9 +468,7 @@ describe('MetaMask', function () { await driver.openNewPage('http://127.0.0.1:8080/'); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Connect')]`), - ); + await driver.clickElement({ text: 'Connect', tag: 'button' }); await driver.delay(regularDelayMs); @@ -541,10 +488,8 @@ describe('MetaMask', function () { await driver.delay(regularDelayMs); - 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.waitUntilXWindowHandles(2); await driver.switchToWindow(dapp); @@ -552,10 +497,7 @@ describe('MetaMask', function () { }); it('initiates a send from the dapp', async function () { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Send')]`), - 10000, - ); + await driver.clickElement({ text: 'Send', tag: 'button' }, 10000); await driver.delay(2000); windowHandles = await driver.getAllWindowHandles(); @@ -565,12 +507,10 @@ describe('MetaMask', function () { ); await driver.delay(regularDelayMs); - await driver.assertElementNotPresent( - By.xpath(`//li[contains(text(), 'Data')]`), - ); + await driver.assertElementNotPresent({ text: 'Data', tag: 'li' }); 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(); @@ -586,10 +526,7 @@ describe('MetaMask', function () { await driver.delay(1000); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - 10000, - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }, 10000); await driver.delay(regularDelayMs); await driver.waitUntilXWindowHandles(2); @@ -600,29 +537,27 @@ describe('MetaMask', function () { it('finds the transaction in the transactions list', async function () { 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 === 4; }, 10000); const txValue = await driver.findClickableElement( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait(until.elementTextMatches(txValue, /-3\s*ETH/u), 10000); }); it('the transaction has the expected gas price', async function () { const txValue = await driver.findClickableElement( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await txValue.click(); const popoverCloseButton = await driver.findClickableElement( - By.css('.popover-header__button'), + '.popover-header__button', ); const txGasPrice = await driver.findElement( - By.css('[data-testid="transaction-breakdown__gas-price"]'), + '[data-testid="transaction-breakdown__gas-price"]', ); await driver.wait(until.elementTextMatches(txGasPrice, /^10$/u), 10000); await popoverCloseButton.click(); @@ -641,15 +576,17 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(largeDelayMs); - const send3eth = await driver.findClickableElement( - By.xpath(`//button[contains(text(), 'Send')]`), - ); + const send3eth = await driver.findClickableElement({ + text: 'Send', + tag: 'button', + }); await send3eth.click(); await driver.delay(largeDelayMs); - const contractDeployment = await driver.findClickableElement( - By.xpath(`//button[contains(text(), 'Deploy Contract')]`), - ); + const contractDeployment = await driver.findClickableElement({ + text: 'Deploy Contract', + tag: 'button', + }); await contractDeployment.click(); await driver.delay(largeDelayMs); @@ -661,14 +598,14 @@ describe('MetaMask', function () { await driver.switchToWindow(extension); await driver.delay(regularDelayMs); - await driver.clickElement(By.css('.transaction-list-item')); + await driver.clickElement('.transaction-list-item'); await driver.delay(largeDelayMs); }); it('navigates the transactions', async function () { - await driver.clickElement(By.css('[data-testid="next-page"]')); + await driver.clickElement('[data-testid="next-page"]'); let navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); let navigationText = await navigationElement.getText(); assert.equal( @@ -677,9 +614,9 @@ describe('MetaMask', function () { 'changed transaction right', ); - await driver.clickElement(By.css('[data-testid="next-page"]')); + await driver.clickElement('[data-testid="next-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -688,9 +625,9 @@ describe('MetaMask', function () { 'changed transaction right', ); - await driver.clickElement(By.css('[data-testid="next-page"]')); + await driver.clickElement('[data-testid="next-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -699,9 +636,9 @@ describe('MetaMask', function () { 'changed transaction right', ); - await driver.clickElement(By.css('[data-testid="first-page"]')); + await driver.clickElement('[data-testid="first-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -710,9 +647,9 @@ describe('MetaMask', function () { 'navigate to first transaction', ); - await driver.clickElement(By.css('[data-testid="last-page"]')); + await driver.clickElement('[data-testid="last-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -721,9 +658,9 @@ describe('MetaMask', function () { 'navigate to last transaction', ); - await driver.clickElement(By.css('[data-testid="previous-page"]')); + await driver.clickElement('[data-testid="previous-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -732,9 +669,9 @@ describe('MetaMask', function () { 'changed transaction left', ); - await driver.clickElement(By.css('[data-testid="previous-page"]')); + await driver.clickElement('[data-testid="previous-page"]'); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -746,7 +683,7 @@ describe('MetaMask', function () { it('adds a transaction while confirm screen is in focus', async function () { let navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); let navigationText = await navigationElement.getText(); assert.equal( @@ -762,14 +699,14 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(regularDelayMs); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Send')]`)); + await driver.clickElement({ text: 'Send', tag: 'button' }); await driver.delay(regularDelayMs); await driver.switchToWindow(extension); await driver.delay(regularDelayMs); navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); navigationText = await navigationElement.getText(); assert.equal( @@ -781,13 +718,11 @@ describe('MetaMask', function () { it('rejects a transaction', async function () { await driver.delay(tinyDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Reject')]`), - ); + await driver.clickElement({ text: 'Reject', tag: 'button' }); await driver.delay(largeDelayMs * 2); const navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); await driver.delay(tinyDelayMs); const navigationText = await navigationElement.getText(); @@ -796,13 +731,11 @@ describe('MetaMask', function () { it('confirms a transaction', async function () { await driver.delay(tinyDelayMs / 2); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(regularDelayMs); const navigationElement = await driver.findElement( - By.css('.confirm-page-container-navigation'), + '.confirm-page-container-navigation', ); await driver.delay(tinyDelayMs / 2); const navigationText = await navigationElement.getText(); @@ -811,19 +744,15 @@ describe('MetaMask', function () { }); it('rejects the rest of the transactions', async function () { - await driver.clickElement(By.xpath(`//a[contains(text(), 'Reject 3')]`)); + await driver.clickElement({ text: 'Reject 3', tag: 'a' }); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Reject All')]`), - ); + await driver.clickElement({ text: 'Reject All', tag: 'button' }); await driver.delay(largeDelayMs * 2); 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 === 5; }, 10000); @@ -842,28 +771,24 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(regularDelayMs); - await driver.clickElement(By.css('#deployButton')); + await driver.clickElement('#deployButton'); await driver.delay(regularDelayMs); await driver.switchToWindow(extension); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//h2[contains(text(), 'Contract Deployment')]`), - ); + await driver.clickElement({ text: 'Contract Deployment', tag: 'h2' }); await driver.delay(largeDelayMs); }); it('displays the contract creation data', async function () { - await driver.clickElement(By.xpath(`//button[contains(text(), 'Data')]`)); + await driver.clickElement({ text: 'Data', tag: 'button' }); await driver.delay(regularDelayMs); - await driver.findElement( - By.xpath(`//div[contains(text(), '127.0.0.1')]`), - ); + await driver.findElement({ text: '127.0.0.1', tag: 'div' }); const confirmDataDiv = await driver.findElement( - By.css('.confirm-page-container-content__data-box'), + '.confirm-page-container-content__data-box', ); const confirmDataText = await confirmDataDiv.getText(); assert.ok(confirmDataText.includes('Origin:')); @@ -871,28 +796,22 @@ describe('MetaMask', function () { assert.ok(confirmDataText.includes('Bytes:')); assert.ok(confirmDataText.includes('675')); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Details')]`), - ); + await driver.clickElement({ text: 'Details', tag: 'button' }); await driver.delay(regularDelayMs); }); it('confirms a deploy contract transaction', async function () { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(largeDelayMs); 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 === 6; }, 10000); - const txAction = await driver.findElements(By.css('.list-item__heading')); + const txAction = await driver.findElements('.list-item__heading'); await driver.wait( until.elementTextMatches(txAction[0], /Contract\sDeployment/u), 10000, @@ -904,16 +823,16 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(regularDelayMs); - let contractStatus = await driver.findElement(By.css('#contractStatus')); + let contractStatus = await driver.findElement('#contractStatus'); await driver.wait( until.elementTextMatches(contractStatus, /Deployed/u), 15000, ); - await driver.clickElement(By.css('#depositButton')); + await driver.clickElement('#depositButton'); await driver.delay(largeDelayMs); - contractStatus = await driver.findElement(By.css('#contractStatus')); + contractStatus = await driver.findElement('#contractStatus'); await driver.wait( until.elementTextMatches(contractStatus, /Deposit\sinitiated/u), 10000, @@ -922,9 +841,9 @@ describe('MetaMask', function () { await driver.switchToWindow(extension); await driver.delay(largeDelayMs * 2); - await driver.findElements(By.css('.transaction-list-item--unconfirmed')); + await driver.findElements('.transaction-list-item--unconfirmed'); const txListValue = await driver.findClickableElement( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait( until.elementTextMatches(txListValue, /-4\s*ETH/u), @@ -934,18 +853,16 @@ describe('MetaMask', function () { await driver.delay(regularDelayMs); // Set the gas limit - await driver.clickElement( - By.css('.confirm-detail-row__header-text--edit'), - ); + await driver.clickElement('.confirm-detail-row__header-text--edit'); await driver.delay(regularDelayMs); - const gasModal = await driver.findElement(By.css('span .modal')); + const gasModal = await driver.findElement('span .modal'); await driver.delay(regularDelayMs); - await driver.clickElement(By.css('.page-container__tab:nth-of-type(2)')); + await driver.clickElement('.page-container__tab:nth-of-type(2)'); await driver.delay(regularDelayMs); const [gasPriceInput, gasLimitInput] = await driver.findElements( - By.css('.advanced-gas-inputs__gas-edit-row__input'), + '.advanced-gas-inputs__gas-edit-row__input', ); const gasLimitValue = await gasLimitInput.getAttribute('value'); assert(Number(gasLimitValue) < 100000, 'Gas Limit too high'); @@ -961,27 +878,23 @@ describe('MetaMask', function () { await driver.delay(1000); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`)); + await driver.clickElement({ text: 'Save', tag: 'button' }); await driver.delay(regularDelayMs); await driver.wait(until.stalenessOf(gasModal)); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(regularDelayMs); 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 === 7; }, 10000); const txValues = await driver.findElements( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait( until.elementTextMatches(txValues[0], /-4\s*ETH/u), @@ -993,35 +906,29 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(regularDelayMs); - await driver.clickElement(By.css('#withdrawButton')); + await driver.clickElement('#withdrawButton'); await driver.delay(regularDelayMs); await driver.switchToWindow(extension); await driver.delay(largeDelayMs * 2); await driver.clickElement( - By.css( - '.transaction-list__pending-transactions .transaction-list-item', - ), + '.transaction-list__pending-transactions .transaction-list-item', ); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(regularDelayMs); 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 === 8; }, 10000); const txValues = await driver.findElement( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait(until.elementTextMatches(txValues, /-0\s*ETH/u), 10000); @@ -1031,7 +938,7 @@ describe('MetaMask', function () { it('renders the correct ETH balance', async function () { const balance = await driver.findElement( - By.css('[data-testid="eth-overview__primary-currency"]'), + '[data-testid="eth-overview__primary-currency"]', ); await driver.delay(regularDelayMs); await driver.wait( @@ -1054,45 +961,35 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(regularDelayMs * 2); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Create Token')]`), - ); + await driver.clickElement({ text: 'Create Token', tag: 'button' }); windowHandles = await driver.waitUntilXWindowHandles(3); const popup = windowHandles[2]; await driver.switchToWindow(popup); await driver.delay(regularDelayMs); - await driver.clickElement( - By.css('.confirm-detail-row__header-text--edit'), - ); + await driver.clickElement('.confirm-detail-row__header-text--edit'); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Advanced')]`), - ); + await driver.clickElement({ text: 'Advanced', tag: 'button' }); await driver.delay(tinyDelayMs); const [gasPriceInput, gasLimitInput] = await driver.findElements( - By.css('.advanced-gas-inputs__gas-edit-row__input'), + '.advanced-gas-inputs__gas-edit-row__input', ); assert(gasPriceInput.getAttribute('value'), 20); assert(gasLimitInput.getAttribute('value'), 4700000); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`)); + await driver.clickElement({ text: 'Save', tag: 'button' }); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(regularDelayMs); await driver.switchToWindow(dapp); await driver.delay(tinyDelayMs); - const tokenContractAddress = await driver.findElement( - By.css('#tokenAddress'), - ); + const tokenContractAddress = await driver.findElement('#tokenAddress'); await driver.wait(until.elementTextMatches(tokenContractAddress, /0x/u)); tokenAddress = await tokenContractAddress.getText(); @@ -1104,37 +1001,32 @@ describe('MetaMask', function () { }); it('clicks on the Add Token button', async function () { - await driver.clickElement(By.css(`[data-testid="home__asset-tab"]`)); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Add Token')]`), - ); + await driver.clickElement(`[data-testid="home__asset-tab"]`); + await driver.clickElement({ text: 'Add Token', tag: 'button' }); await driver.delay(regularDelayMs); }); it('picks the newly created Test token', async function () { - await driver.clickElement( - By.xpath("//button[contains(text(), 'Custom Token')]"), - ); + await driver.clickElement({ + text: 'Custom Token', + tag: 'button', + }); await driver.delay(regularDelayMs); - const newTokenAddress = await driver.findElement( - By.css('#custom-address'), - ); + const newTokenAddress = await driver.findElement('#custom-address'); await newTokenAddress.sendKeys(tokenAddress); await driver.delay(regularDelayMs); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`)); + await driver.clickElement({ text: 'Next', tag: 'button' }); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Add Tokens')]`), - ); + await driver.clickElement({ text: 'Add Tokens', tag: 'button' }); await driver.delay(regularDelayMs); }); it('renders the balance for the new token', async function () { const balance = await driver.findElement( - By.css('.wallet-overview .token-overview__primary-balance'), + '.wallet-overview .token-overview__primary-balance', ); await driver.wait(until.elementTextMatches(balance, /^10\s*TST\s*$/u)); const tokenAmount = await balance.getText(); @@ -1146,30 +1038,28 @@ describe('MetaMask', function () { describe('Send token from inside MetaMask', function () { let gasModal; 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'); // Set the gas limit - await driver.clickElement(By.css('.advanced-gas-options-btn')); + await driver.clickElement('.advanced-gas-options-btn'); await driver.delay(regularDelayMs); - gasModal = await driver.findElement(By.css('span .modal')); + gasModal = await driver.findElement('span .modal'); await driver.delay(regularDelayMs); }); it('opens customize gas modal', async function () { - await driver.findElement(By.css('.page-container__title')); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`)); + await driver.findElement('.page-container__title'); + await driver.clickElement({ text: 'Save', tag: 'button' }); await driver.delay(regularDelayMs); }); @@ -1177,28 +1067,28 @@ describe('MetaMask', function () { await driver.wait(until.stalenessOf(gasModal)); // 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('displays the token transfer data', async function () { - await driver.clickElement(By.xpath(`//button[contains(text(), 'Data')]`)); + await driver.clickElement({ text: 'Data', tag: 'button' }); await driver.delay(regularDelayMs); const functionType = await driver.findElement( - By.css('.confirm-page-container-content__function-type'), + '.confirm-page-container-content__function-type', ); const functionTypeText = await functionType.getText(); assert.equal(functionTypeText, 'Transfer'); const tokenAmount = await driver.findElement( - By.css('.confirm-page-container-summary__title-text'), + '.confirm-page-container-summary__title-text', ); const tokenAmountText = await tokenAmount.getText(); assert.equal(tokenAmountText, '1 TST'); const confirmDataDiv = await driver.findElement( - By.css('.confirm-page-container-content__data-box'), + '.confirm-page-container-content__data-box', ); const confirmDataText = await confirmDataDiv.getText(); @@ -1209,31 +1099,25 @@ describe('MetaMask', function () { ), ); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Details')]`), - ); + await driver.clickElement({ text: 'Details', tag: 'button' }); await driver.delay(regularDelayMs); }); it('submits 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.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); await driver.wait( @@ -1241,9 +1125,7 @@ describe('MetaMask', function () { 10000, ); - const txStatuses = await driver.findElements( - By.css('.list-item__heading'), - ); + const txStatuses = await driver.findElements('.list-item__heading'); await driver.wait( until.elementTextMatches(txStatuses[0], /Send\sTST/u), 10000, @@ -1265,18 +1147,14 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(tinyDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Transfer Tokens')]`), - ); + await driver.clickElement({ text: 'Transfer Tokens', tag: 'button' }); await driver.switchToWindow(extension); await driver.delay(largeDelayMs); - await driver.findElements( - By.css('.transaction-list__pending-transactions'), - ); + await driver.findElements('.transaction-list__pending-transactions'); const txListValue = await driver.findClickableElement( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait( until.elementTextMatches(txListValue, /-1.5\s*TST/u), @@ -1286,26 +1164,24 @@ describe('MetaMask', function () { await driver.delay(regularDelayMs); const transactionAmounts = await driver.findElements( - By.css('.currency-display-component__text'), + '.currency-display-component__text', ); const transactionAmount = transactionAmounts[0]; assert(await transactionAmount.getText(), '1.5 TST'); // Set the gas limit - await driver.clickElement( - By.css('.confirm-detail-row__header-text--edit'), - ); + await driver.clickElement('.confirm-detail-row__header-text--edit'); await driver.delay(regularDelayMs); - gasModal = await driver.findElement(By.css('span .modal')); + gasModal = await driver.findElement('span .modal'); }); it('customizes gas', async function () { - await driver.clickElement(By.css('.page-container__tab:nth-of-type(2)')); + await driver.clickElement('.page-container__tab:nth-of-type(2)'); await driver.delay(regularDelayMs); 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(); @@ -1319,11 +1195,11 @@ describe('MetaMask', function () { await driver.delay(1000); - await driver.clickElement(By.css('.page-container__footer-button')); + await driver.clickElement('.page-container__footer-button'); await driver.wait(until.stalenessOf(gasModal)); const gasFeeInputs = await driver.findElements( - By.css('.confirm-detail-row__primary'), + '.confirm-detail-row__primary', ); const renderedGasFee = await gasFeeInputs[0].getText(); assert.equal(renderedGasFee, '0.0006'); @@ -1331,41 +1207,35 @@ describe('MetaMask', function () { it('submits the transaction', async function () { const tokenAmount = await driver.findElement( - By.css('.confirm-page-container-summary__title-text'), + '.confirm-page-container-summary__title-text', ); const tokenAmountText = await tokenAmount.getText(); assert.equal(tokenAmountText, '1.5 TST'); - 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.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 === 2; }, 10000); const txValues = await driver.findElements( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait(until.elementTextMatches(txValues[0], /-1.5\s*TST/u)); - const txStatuses = await driver.findElements( - By.css('.list-item__heading'), - ); + const txStatuses = await driver.findElements('.list-item__heading'); await driver.wait( until.elementTextMatches(txStatuses[0], /Send\sTST/u), 10000, ); const tokenBalanceAmount = await driver.findElements( - By.css('.token-overview__primary-balance'), + '.token-overview__primary-balance', ); await driver.wait( until.elementTextMatches(tokenBalanceAmount[0], /7.5\s*TST/u), @@ -1389,48 +1259,42 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(tinyDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Approve Tokens')]`), - ); + await driver.clickElement({ text: 'Approve Tokens', tag: 'button' }); await driver.switchToWindow(extension); await driver.delay(regularDelayMs); await driver.wait(async () => { const pendingTxes = await driver.findElements( - By.css( - '.transaction-list__pending-transactions .transaction-list-item', - ), + '.transaction-list__pending-transactions .transaction-list-item', ); return pendingTxes.length === 1; }, 10000); const [txtListHeading] = await driver.findElements( - By.css('.transaction-list-item .list-item__heading'), + '.transaction-list-item .list-item__heading', ); await driver.wait( until.elementTextMatches(txtListHeading, /Approve TST spend limit/u), ); - await driver.clickElement(By.css('.transaction-list-item')); + await driver.clickElement('.transaction-list-item'); await driver.delay(regularDelayMs); }); it('displays the token approval data', async function () { await driver.clickElement( - By.css('.confirm-approve-content__view-full-tx-button'), + '.confirm-approve-content__view-full-tx-button', ); await driver.delay(regularDelayMs); const functionType = await driver.findElement( - By.css( - '.confirm-approve-content__data .confirm-approve-content__small-text', - ), + '.confirm-approve-content__data .confirm-approve-content__small-text', ); const functionTypeText = await functionType.getText(); assert.equal(functionTypeText, 'Function: Approve'); const confirmDataDiv = await driver.findElement( - By.css('.confirm-approve-content__data__data-block'), + '.confirm-approve-content__data__data-block', ); const confirmDataText = await confirmDataDiv.getText(); assert( @@ -1442,19 +1306,19 @@ describe('MetaMask', function () { it('opens the gas edit modal', async function () { await driver.clickElement( - By.css('.confirm-approve-content__small-blue-text.cursor-pointer'), + '.confirm-approve-content__small-blue-text.cursor-pointer', ); await driver.delay(regularDelayMs); - gasModal = await driver.findElement(By.css('span .modal')); + gasModal = await driver.findElement('span .modal'); }); it('customizes gas', async function () { - await driver.clickElement(By.css('.page-container__tab:nth-of-type(2)')); + await driver.clickElement('.page-container__tab:nth-of-type(2)'); await driver.delay(regularDelayMs); 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(); @@ -1468,68 +1332,60 @@ describe('MetaMask', function () { await driver.delay(1000); - await driver.clickElement(By.css('.page-container__footer-button')); + await driver.clickElement('.page-container__footer-button'); await driver.wait(until.stalenessOf(gasModal)); const gasFeeInEth = await driver.findElement( - By.css( - '.confirm-approve-content__transaction-details-content__secondary-fee', - ), + '.confirm-approve-content__transaction-details-content__secondary-fee', ); assert.equal(await gasFeeInEth.getText(), '0.0006 ETH'); }); it('edits the permission', async function () { const editButtons = await driver.findClickableElements( - By.css('.confirm-approve-content__small-blue-text.cursor-pointer'), + '.confirm-approve-content__small-blue-text.cursor-pointer', ); await editButtons[1].click(); await driver.delay(regularDelayMs); - const permissionModal = await driver.findElement(By.css('span .modal')); + const permissionModal = await driver.findElement('span .modal'); const radioButtons = await driver.findClickableElements( - By.css('.edit-approval-permission__edit-section__radio-button'), + '.edit-approval-permission__edit-section__radio-button', ); await radioButtons[1].click(); - const customInput = await driver.findElement(By.css('input')); + const customInput = await driver.findElement('input'); await driver.delay(50); await customInput.sendKeys('5'); await driver.delay(regularDelayMs); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`)); + await driver.clickElement({ text: 'Save', tag: 'button' }); await driver.delay(regularDelayMs); await driver.wait(until.stalenessOf(permissionModal)); const permissionInfo = await driver.findElements( - By.css('.confirm-approve-content__medium-text'), + '.confirm-approve-content__medium-text', ); const amountDiv = permissionInfo[0]; assert.equal(await amountDiv.getText(), '5 TST'); }); it('submits 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.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 === 3; }, 10000); - const txStatuses = await driver.findElements( - By.css('.list-item__heading'), - ); + const txStatuses = await driver.findElements('.list-item__heading'); await driver.wait( until.elementTextMatches(txStatuses[0], /Approve TST spend limit/u), ); @@ -1549,55 +1405,48 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Transfer Tokens Without Gas')]`), - ); + await driver.clickElement({ + text: 'Transfer Tokens Without Gas', + tag: 'button', + }); await driver.switchToWindow(extension); await driver.delay(regularDelayMs); await driver.wait(async () => { const pendingTxes = await driver.findElements( - By.css( - '.transaction-list__pending-transactions .transaction-list-item', - ), + '.transaction-list__pending-transactions .transaction-list-item', ); return pendingTxes.length === 1; }, 10000); const [txListValue] = await driver.findElements( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait(until.elementTextMatches(txListValue, /-1.5\s*TST/u)); - await driver.clickElement(By.css('.transaction-list-item')); + await driver.clickElement('.transaction-list-item'); await driver.delay(regularDelayMs); }); it('submits the transaction', async function () { await driver.delay(largeDelayMs * 2); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`), - ); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.delay(largeDelayMs * 2); }); it('finds the transaction in the transactions list', async function () { 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 === 4; }, 10000); const txValues = await driver.findElements( - By.css('.transaction-list-item__primary-currency'), + '.transaction-list-item__primary-currency', ); await driver.wait(until.elementTextMatches(txValues[0], /-1.5\s*TST/u)); - const txStatuses = await driver.findElements( - By.css('.list-item__heading'), - ); + const txStatuses = await driver.findElements('.list-item__heading'); await driver.wait(until.elementTextMatches(txStatuses[0], /Send TST/u)); }); }); @@ -1616,40 +1465,39 @@ describe('MetaMask', function () { await driver.switchToWindow(dapp); await driver.delay(tinyDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Approve Tokens Without Gas')]`), - ); + await driver.clickElement({ + text: 'Approve Tokens Without Gas', + tag: 'button', + }); await driver.switchToWindow(extension); await driver.delay(regularDelayMs); await driver.wait(async () => { const pendingTxes = await driver.findElements( - By.css( - '.transaction-list__pending-transactions .transaction-list-item', - ), + '.transaction-list__pending-transactions .transaction-list-item', ); return pendingTxes.length === 1; }, 10000); const [txtListHeading] = await driver.findElements( - By.css('.transaction-list-item .list-item__heading'), + '.transaction-list-item .list-item__heading', ); await driver.wait( until.elementTextMatches(txtListHeading, /Approve TST spend limit/u), ); - await driver.clickElement(By.css('.transaction-list-item')); + await driver.clickElement('.transaction-list-item'); await driver.delay(regularDelayMs); }); it('shows the correct recipient', async function () { await driver.clickElement( - By.css('.confirm-approve-content__view-full-tx-button'), + '.confirm-approve-content__view-full-tx-button', ); await driver.delay(regularDelayMs); const permissionInfo = await driver.findElements( - By.css('.confirm-approve-content__medium-text'), + '.confirm-approve-content__medium-text', ); const recipientDiv = permissionInfo[1]; assert.equal(await recipientDiv.getText(), '0x2f318C33...C970'); @@ -1657,25 +1505,19 @@ describe('MetaMask', function () { it('submits the transaction', async function () { await driver.delay(1000); - 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.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 === 5; }, 10000); - const txStatuses = await driver.findElements( - By.css('.list-item__heading'), - ); + const txStatuses = await driver.findElements('.list-item__heading'); await driver.wait( until.elementTextMatches(txStatuses[0], /Approve TST spend limit/u), ); @@ -1684,16 +1526,14 @@ describe('MetaMask', function () { describe('Hide token', function () { it('hides the token when clicked', async function () { - await driver.clickElement( - By.css('[data-testid="token-options__button"]'), - ); + await driver.clickElement('[data-testid="token-options__button"]'); - await driver.clickElement(By.css('[data-testid="token-options__hide"]')); + await driver.clickElement('[data-testid="token-options__hide"]'); - const confirmHideModal = await driver.findElement(By.css('span .modal')); + const confirmHideModal = await driver.findElement('span .modal'); await driver.clickElement( - By.css('[data-testid="hide-token-confirmation__hide"]'), + '[data-testid="hide-token-confirmation__hide"]', ); await driver.wait(until.stalenessOf(confirmHideModal)); @@ -1702,32 +1542,28 @@ describe('MetaMask', function () { describe('Add existing token using search', function () { it('clicks on the Add Token button', async function () { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Add Token')]`), - ); + await driver.clickElement({ text: 'Add Token', tag: 'button' }); await driver.delay(regularDelayMs); }); it('can pick a token from the existing options', async function () { - const tokenSearch = await driver.findElement(By.css('#search-tokens')); + const tokenSearch = await driver.findElement('#search-tokens'); await tokenSearch.sendKeys('BAT'); await driver.delay(regularDelayMs); - await driver.clickElement(By.xpath("//span[contains(text(), 'BAT')]")); + await driver.clickElement({ text: 'BAT', tag: 'span' }); await driver.delay(regularDelayMs); - await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`)); + await driver.clickElement({ text: 'Next', tag: 'button' }); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Add Tokens')]`), - ); + await driver.clickElement({ text: 'Add Tokens', tag: 'button' }); await driver.delay(largeDelayMs); }); it('renders the balance for the chosen token', async function () { const balance = await driver.findElement( - By.css('.token-overview__primary-balance'), + '.token-overview__primary-balance', ); await driver.wait(until.elementTextMatches(balance, /0\s*BAT/u)); await driver.delay(regularDelayMs); @@ -1739,19 +1575,15 @@ describe('MetaMask', function () { const rpcUrl = 'http://127.0.0.1:8545/1'; const chainId = '0x539'; // Ganache default, decimal 1337 - await driver.clickElement(By.css('.network-display')); + await driver.clickElement('.network-display'); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//span[contains(text(), 'Custom RPC')]`), - ); + await driver.clickElement({ text: 'Custom RPC', tag: 'span' }); await driver.delay(regularDelayMs); - await driver.findElement(By.css('.settings-page__sub-header-text')); + await driver.findElement('.settings-page__sub-header-text'); - const customRpcInputs = await driver.findElements( - By.css('input[type="text"]'), - ); + const customRpcInputs = await driver.findElements('input[type="text"]'); const rpcUrlInput = customRpcInputs[1]; const chainIdInput = customRpcInputs[2]; @@ -1761,29 +1593,23 @@ describe('MetaMask', function () { await chainIdInput.clear(); await chainIdInput.sendKeys(chainId); - await driver.clickElement(By.css('.network-form__footer .btn-secondary')); - await driver.findElement( - By.xpath(`//div[contains(text(), '${rpcUrl}')]`), - ); + await driver.clickElement('.network-form__footer .btn-secondary'); + await driver.findElement({ text: rpcUrl, tag: 'div' }); }); it(`creates second custom RPC entry`, async function () { const rpcUrl = 'http://127.0.0.1:8545/2'; const chainId = '0x539'; // Ganache default, decimal 1337 - await driver.clickElement(By.css('.network-display')); + await driver.clickElement('.network-display'); await driver.delay(regularDelayMs); - await driver.clickElement( - By.xpath(`//span[contains(text(), 'Custom RPC')]`), - ); + await driver.clickElement({ text: 'Custom RPC', tag: 'span' }); await driver.delay(regularDelayMs); - await driver.findElement(By.css('.settings-page__sub-header-text')); + await driver.findElement('.settings-page__sub-header-text'); - const customRpcInputs = await driver.findElements( - By.css('input[type="text"]'), - ); + const customRpcInputs = await driver.findElements('input[type="text"]'); const rpcUrlInput = customRpcInputs[1]; const chainIdInput = customRpcInputs[2]; @@ -1793,63 +1619,55 @@ describe('MetaMask', function () { await chainIdInput.clear(); await chainIdInput.sendKeys(chainId); - await driver.clickElement(By.css('.network-form__footer .btn-secondary')); - await driver.findElement( - By.xpath(`//div[contains(text(), '${rpcUrl}')]`), - ); + await driver.clickElement('.network-form__footer .btn-secondary'); + await driver.findElement({ text: rpcUrl, tag: 'div' }); }); it('selects another provider', 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(), 'Ethereum Mainnet')]`), - ); + await driver.clickElement({ text: 'Ethereum Mainnet', tag: 'span' }); await driver.delay(largeDelayMs * 2); }); it('finds all recent RPCs in history', async function () { - await driver.clickElement(By.css('.network-display')); + await driver.clickElement('.network-display'); await driver.delay(regularDelayMs); // only recent 3 are found and in correct order (most recent at the top) - const customRpcs = await driver.findElements( - By.xpath(`//span[contains(text(), 'http://127.0.0.1:8545/')]`), - ); + const customRpcs = await driver.findElements({ + text: 'http://127.0.0.1:8545/', + tag: 'span', + }); // click Mainnet to dismiss network dropdown - await driver.clickElement( - By.xpath(`//span[contains(text(), 'Ethereum Mainnet')]`), - ); + await driver.clickElement({ text: 'Ethereum Mainnet', tag: 'span' }); assert.equal(customRpcs.length, 2); }); it('deletes a custom RPC', async function () { const networkListItems = await driver.findClickableElements( - By.css('.networks-tab__networks-list-name'), + '.networks-tab__networks-list-name', ); const lastNetworkListItem = networkListItems[networkListItems.length - 1]; await lastNetworkListItem.click(); await driver.delay(100); - await driver.clickElement(By.css('.btn-danger')); + await driver.clickElement('.btn-danger'); await driver.delay(regularDelayMs); - const confirmDeleteNetworkModal = await driver.findElement( - By.css('span .modal'), - ); + const confirmDeleteNetworkModal = await driver.findElement('span .modal'); - const byConfirmDeleteNetworkButton = By.css( + await driver.clickElement( '.button.btn-danger.modal-container__footer-button', ); - await driver.clickElement(byConfirmDeleteNetworkButton); await driver.wait(until.stalenessOf(confirmDeleteNetworkModal)); const newNetworkListItems = await driver.findElements( - By.css('.networks-tab__networks-list-name'), + '.networks-tab__networks-list-name', ); assert.equal(networkListItems.length - 1, newNetworkListItems.length); diff --git a/test/e2e/metrics.spec.js b/test/e2e/metrics.spec.js index 4346f59b1..279c8ba19 100644 --- a/test/e2e/metrics.spec.js +++ b/test/e2e/metrics.spec.js @@ -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); diff --git a/test/e2e/tests/address-book.spec.js b/test/e2e/tests/address-book.spec.js index c8581cfee..1037cc694 100644 --- a/test/e2e/tests/address-book.spec.js +++ b/test/e2e/tests/address-book.spec.js @@ -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), diff --git a/test/e2e/tests/localization.spec.js b/test/e2e/tests/localization.spec.js index 27b93a269..3c898e9e0 100644 --- a/test/e2e/tests/localization.spec.js +++ b/test/e2e/tests/localization.spec.js @@ -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 diff --git a/test/e2e/tests/permissions.spec.js b/test/e2e/tests/permissions.spec.js index e273a9c5d..d5235ac08 100644 --- a/test/e2e/tests/permissions.spec.js +++ b/test/e2e/tests/permissions.spec.js @@ -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(), diff --git a/test/e2e/tests/personal-sign.spec.js b/test/e2e/tests/personal-sign.spec.js index ef4c0be7b..97c875319 100644 --- a/test/e2e/tests/personal-sign.spec.js +++ b/test/e2e/tests/personal-sign.spec.js @@ -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); }, diff --git a/test/e2e/tests/provider-events.spec.js b/test/e2e/tests/provider-events.spec.js index 417eb021e..055bff92a 100644 --- a/test/e2e/tests/provider-events.spec.js +++ b/test/e2e/tests/provider-events.spec.js @@ -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'); diff --git a/test/e2e/tests/send-edit.spec.js b/test/e2e/tests/send-edit.spec.js index 3f9846060..d27f0d95f 100644 --- a/test/e2e/tests/send-edit.spec.js +++ b/test/e2e/tests/send-edit.spec.js @@ -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())); diff --git a/test/e2e/tests/signature-request.spec.js b/test/e2e/tests/signature-request.spec.js index 29e186750..c3d03f5a2 100644 --- a/test/e2e/tests/signature-request.spec.js +++ b/test/e2e/tests/signature-request.spec.js @@ -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); }, diff --git a/test/e2e/tests/simple-send.spec.js b/test/e2e/tests/simple-send.spec.js index e7564a071..8a04c2505 100644 --- a/test/e2e/tests/simple-send.spec.js +++ b/test/e2e/tests/simple-send.spec.js @@ -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'); }, ); }); diff --git a/test/e2e/threebox.spec.js b/test/e2e/threebox.spec.js index 207f15afd..a77e76b10 100644 --- a/test/e2e/threebox.spec.js +++ b/test/e2e/threebox.spec.js @@ -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); }); });