Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

use waitForSelector instead of until #10852

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions test/e2e/from-import-ui.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const assert = require('assert');
const { until } = require('selenium-webdriver');

const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
Expand Down Expand Up @@ -126,11 +124,13 @@ describe('Using MetaMask with an existing account', function () {
'[data-testid="account-options-menu__account-details"]',
);
await driver.findVisibleElement('.qr-code__wrapper');
const detailModal = await driver.findElement('span .modal');
// wait for details modal to be visible
const detailsModal = await driver.findVisibleElement('span .modal');
await driver.delay(regularDelayMs);

await driver.clickElement('.account-modal__close');
await driver.wait(until.stalenessOf(detailModal));
// wait for details modal to be removed from DOM
await detailsModal.waitForElementState('hidden');
await driver.delay(regularDelayMs);
});
});
Expand Down Expand Up @@ -213,10 +213,11 @@ describe('Using MetaMask with an existing account', function () {
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);

const gasModal = await driver.findElement('span .modal');
// wait for gas modal to be visible
const gasModal = await driver.findVisibleElement('span .modal');
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.wait(until.stalenessOf(gasModal));
await driver.delay(regularDelayMs);
// wait for gas modal to be removed from DOM
await gasModal.waitForElementState('hidden');

// Continue to next screen
await driver.clickElement({ text: 'Next', tag: 'button' });
Expand Down
37 changes: 20 additions & 17 deletions test/e2e/incremental-security.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('assert');
const { until } = require('selenium-webdriver');

const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
Expand Down Expand Up @@ -109,11 +108,13 @@ describe('MetaMask', function () {
const addressInput = await driver.findElement('.readonly-input__input');
publicAddress = await addressInput.getAttribute('value');

const accountModal = await driver.findElement('span .modal');
// wait for account modal to be visible
const accountModal = await driver.findVisibleElement('span .modal');

await driver.clickElement('.account-modal__close');

await driver.wait(until.stalenessOf(accountModal));
// wait for account modal to be removed from DOM
await accountModal.waitForElementState('hidden');
await driver.delay(regularDelayMs);
});
});
Expand All @@ -134,22 +135,24 @@ describe('MetaMask', function () {
await driver.delay(regularDelayMs);
await driver.clickElement('#send');

const txStatus = await driver.findElement('#success');
await driver.wait(until.elementTextMatches(txStatus, /Success/u), 15000);
await driver.waitForSelector(
{ css: '#success', text: 'Success' },
{ timeout: 15000 },
);
});

it('switches back to MetaMask', async function () {
await driver.switchToWindow(extension);
});

it('should have the correct amount of eth', async function () {
const balances = await driver.findElements(
'.currency-display-component__text',
);
await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText();
const currencyDisplay = await driver.waitForSelector({
css: '.currency-display-component__text',
text: '1',
});
const balance = await currencyDisplay.getText();

assert.equal(balance, '1');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the intent of this assertion was to ensure this test doesn't pass if the balance is a number containing the digit 1 (e.g. 1.51, 100, etc.). It might be worth preserving this assertion, both here and below where a similar assertion was removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do! Thanks

assert.strictEqual(balance, '1');
});
});

Expand Down Expand Up @@ -213,13 +216,13 @@ describe('MetaMask', function () {
});

it('should have the correct amount of eth', async function () {
const balances = await driver.findElements(
'.currency-display-component__text',
);
await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText();
const currencyDisplay = await driver.waitForSelector({
css: '.currency-display-component__text',
text: '1',
});
const balance = await currencyDisplay.getText();

assert.equal(balance, '1');
assert.strictEqual(balance, '1');
});

it('should not show a backup reminder', async function () {
Expand Down
25 changes: 14 additions & 11 deletions test/e2e/metamask-responsive-ui.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('assert');
const { until } = require('selenium-webdriver');

const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
Expand Down Expand Up @@ -194,10 +193,10 @@ describe('MetaMask', function () {
});

it('balance renders', async function () {
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
await driver.wait(until.elementTextMatches(balance, /100\s*ETH/u));
await driver.waitForSelector({
css: '[data-testid="eth-overview__primary-currency"]',
text: '100 ETH',
});
await driver.delay(regularDelayMs);
});
});
Expand All @@ -224,10 +223,11 @@ describe('MetaMask', function () {
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);

const gasModal = await driver.findElement('span .modal');

// wait for gas modal to be visible
const gasModal = await driver.findVisibleElement('span .modal');
await driver.clickElement('.page-container__header-close-text');
await driver.wait(until.stalenessOf(gasModal), 10000);
// wait for gas modal to be removed from dom
await gasModal.waitForElementState('hidden');
await driver.delay(regularDelayMs);
});

Expand All @@ -250,10 +250,13 @@ describe('MetaMask', function () {
return confirmedTxes.length === 1;
}, 10000);

const txValues = await driver.findElement(
'.transaction-list-item__primary-currency',
await driver.waitForSelector(
{
css: '.transaction-list-item__primary-currency',
text: '-1 ETH',
},
{ timeout: 10000 },
);
await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/u), 10000);
});
});
});
68 changes: 30 additions & 38 deletions test/e2e/metamask-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ describe('MetaMask', function () {
await driver.delay(regularDelayMs);

// wait for permission modal to be visible.
await driver.waitForSelector('span .modal');
const permissionModal = await driver.findVisibleElement('span .modal');
await driver.clickElement('.account-modal__close');

// wait for account modal to be removed from DOM.
await driver.waitForSelector('span .modal', { state: 'detached' });
// wait for permission modal to be removed from DOM.
await permissionModal.waitForElementState('hidden');
await driver.delay(regularDelayMs);
});
});
Expand Down Expand Up @@ -377,12 +377,13 @@ describe('MetaMask', function () {
await driver.clickElement('.advanced-gas-options-btn');
await driver.delay(regularDelayMs);

// wait for gas modal to be visible
const gasModal = await driver.findVisibleElement('span .modal');

await driver.clickElement({ text: 'Save', tag: 'button' });

// Wait for gas modal to be removed from DOM
await driver.waitForSelector('span .modal', {
state: 'detached',
});
await gasModal.waitForElementState('hidden');
await driver.delay(regularDelayMs);

// Continue to next screen
Expand Down Expand Up @@ -854,8 +855,8 @@ describe('MetaMask', function () {

// Set the gas limit
await driver.clickElement('.confirm-detail-row__header-text--edit');
// wait for gas modal to be detached from DOM
await driver.waitForSelector('span .modal');
// wait for gas modal to be visible.
const gasModal = await driver.findVisibleElement('span .modal');
await driver.clickElement('.page-container__tab:nth-of-type(2)');
await driver.delay(regularDelayMs);

Expand All @@ -875,7 +876,7 @@ describe('MetaMask', function () {
await driver.clickElement({ text: 'Save', tag: 'button' });

// wait for gas modal to be detached from DOM
await driver.waitForSelector('span .modal', { state: 'detached' });
await gasModal.waitForElementState('hidden');

await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
Expand Down Expand Up @@ -1044,12 +1045,12 @@ describe('MetaMask', function () {
it('opens customize gas modal and saves options to continue', async function () {
await driver.clickElement('.advanced-gas-options-btn');

// Wait for gas modal to be visible
await driver.waitForSelector('span .modal');
// wait for gas modal to be visible
const gasModal = await driver.findVisibleElement('span .modal');
await driver.findElement('.page-container__title');
await driver.clickElement({ text: 'Save', tag: 'button' });
// wait for gas modal to be removed from DOM.
await driver.waitForSelector('span .modal', { state: 'detached' });
await gasModal.waitForElementState('hidden');
});

it('transitions to the confirm screen', async function () {
Expand Down Expand Up @@ -1152,16 +1153,14 @@ describe('MetaMask', function () {
);
const transactionAmount = transactionAmounts[0];
assert(await transactionAmount.getText(), '1.5 TST');
});

it('customizes gas', async function () {
// Set the gas limit
await driver.clickElement('.confirm-detail-row__header-text--edit');
await driver.delay(regularDelayMs);

// wait for gas modal to be visible
await driver.waitForSelector('span .modal');
});

it('customizes gas', async function () {
const gasModal = await driver.findVisibleElement('span .modal');
await driver.clickElement('.page-container__tab:nth-of-type(2)');
await driver.delay(regularDelayMs);

Expand All @@ -1178,10 +1177,8 @@ describe('MetaMask', function () {

await driver.clickElement('.page-container__footer-button');

// Wait for gas modal to be removed from DOM.
await driver.waitForSelector('span .modal', {
state: 'detached',
});
// wait for gas modal to be removed from DOM.
await gasModal.waitForElementState('hidden');

const gasFeeInputs = await driver.findElements(
'.confirm-detail-row__primary',
Expand Down Expand Up @@ -1286,17 +1283,14 @@ describe('MetaMask', function () {
);
});

it('opens the gas edit modal', async function () {
it('customizes gas', async function () {
await driver.clickElement(
'.confirm-approve-content__small-blue-text.cursor-pointer',
);
await driver.delay(regularDelayMs);

// Wait for the gas modal to be visible
await driver.waitForSelector('span .modal');
});

it('customizes gas', async function () {
// wait for gas modal to be visible
const gasModal = await driver.findVisibleElement('span .modal');
await driver.clickElement('.page-container__tab:nth-of-type(2)');
await driver.delay(regularDelayMs);

Expand All @@ -1313,10 +1307,8 @@ describe('MetaMask', function () {

await driver.clickElement('.page-container__footer-button');

// wait for the gas modal to be removed from DOM.
await driver.waitForSelector('span .modal', {
state: 'detached',
});
// wait for gas modal to be removed from DOM.
await gasModal.waitForElementState('hidden');

const gasFeeInEth = await driver.findElement(
'.confirm-approve-content__transaction-details-content__secondary-fee',
Expand All @@ -1331,7 +1323,7 @@ describe('MetaMask', function () {
await editButtons[1].click();

// wait for permission modal to be visible
await driver.waitForSelector('span .modal');
const permissionModal = await driver.findVisibleElement('span .modal');
const radioButtons = await driver.findClickableElements(
'.edit-approval-permission__edit-section__radio-button',
);
Expand All @@ -1343,7 +1335,7 @@ describe('MetaMask', function () {
await driver.clickElement({ text: 'Save', tag: 'button' });

// wait for permission modal to be removed from DOM.
await driver.waitForSelector('span .modal', { state: 'detached' });
await permissionModal.waitForElementState('hidden');

const permissionInfo = await driver.findElements(
'.confirm-approve-content__medium-text',
Expand Down Expand Up @@ -1521,14 +1513,14 @@ describe('MetaMask', function () {
await driver.clickElement('[data-testid="token-options__hide"]');

// wait for confirm hide modal to be visible
await driver.waitForSelector('span .modal');
const confirmHideModal = await driver.findVisibleElement('span .modal');

await driver.clickElement(
'[data-testid="hide-token-confirmation__hide"]',
);

// wait for confirm hide modal to be removed from DOM.
await driver.waitForSelector('span .modal', { state: 'detached' });
await confirmHideModal.waitForElementState('hidden');
});
});

Expand Down Expand Up @@ -1649,15 +1641,15 @@ describe('MetaMask', function () {
await driver.clickElement('.btn-danger');
await driver.delay(regularDelayMs);

// wait for confirm delete modal to be visible.
await driver.waitForSelector('span .modal');
// wait for confirm delete modal to be visible
const confirmDeleteModal = await driver.findVisibleElement('span .modal');

await driver.clickElement(
'.button.btn-danger.modal-container__footer-button',
);

// wait for confirm delete modal to be removed from DOM.
await driver.waitForSelector('span .modal', { state: 'detached' });
await confirmDeleteModal.waitForElementState('hidden');

const newNetworkListItems = await driver.findElements(
'.networks-tab__networks-list-name',
Expand Down
Loading