Skip to content

Commit

Permalink
feat: avoid metamask getting stuck if account already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed May 2, 2023
1 parent 6aadbfc commit d3aa21e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,26 @@ const metamask = {
accountName,
);
}
await playwright.waitAndClick(mainPageElements.createAccount.createButton);
const formErrorEl = await playwright.waitFor(
mainPageElements.createAccount.createAccountError,
);
const formErrorTxt = await formErrorEl.innerText();
const accountExists = 'This account name already exists' === formErrorTxt;

if (accountExists) {
log(`[error] ${formErrorTxt}`);
await playwright.waitAndClick(
mainPageElements.createAccount.cancelButton,
);
} else {
await playwright.waitAndClick(
mainPageElements.createAccount.createButton,
);
}

await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
return accountExists ? formErrorTxt : true;
},
async switchAccount(accountNameOrAccountNumber) {
if (typeof accountNameOrAccountNumber === 'string') {
Expand Down
1 change: 1 addition & 0 deletions pages/metamask/main-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const createAccount = {
input: `${importAccountSelector} .new-account-create-form__input`,
cancelButton: `${importAccountSelector} .new-account-create-form__button:nth-child(1)`,
createButton: `${importAccountSelector} .new-account-create-form__button:nth-child(2)`,
createAccountError: `${importAccountSelector} .new-account-create-form__error`,
};

const importTokenFormSelector = '.import-token__custom-token-form';
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/specs/metamask-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ describe('Metamask', () => {
cy.createMetamaskAccount('custom-wallet').then(created => {
expect(created).to.be.true;
});
cy.createMetamaskAccount('custom-wallet').then(created => {
expect(created).to.be.eq('This account name already exists');
});
});

it(`switchMetamaskAccount should switch to another account using order number`, () => {
cy.switchMetamaskAccount(2).then(switched => {
expect(switched).to.be.true;
Expand Down

0 comments on commit d3aa21e

Please sign in to comment.