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

test: [POM] create ResetPasswordPage for e2e tests and migrate 2 test files to POM #27244

Merged
merged 6 commits into from
Sep 20, 2024
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
65 changes: 0 additions & 65 deletions test/e2e/accounts/forgot-password.spec.ts

This file was deleted.

13 changes: 13 additions & 0 deletions test/e2e/page-objects/pages/account-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ class AccountListPage {
'.multichain-account-menu-popover__list--menu-item-hidden-account [data-testid="account-list-item-menu-button"]';
}

async check_pageIsLoaded(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe to follow the same as what we did in the other PR, I would suggest to place the checks at the end

Copy link
Contributor

Choose a reason for hiding this comment

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

oh or maybe is it better to order everything alphabetically? As I see that in other places it is ordered alphabetically including the checks. In that case we can leave this as it is, but we can modify the order of the other page (linked PR above), in another PR

Copy link
Contributor

@chloeYue chloeYue Sep 18, 2024

Choose a reason for hiding this comment

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

Thanks for pointing out @seaona ! What I'm thinking for the order is: check_pageIsLoaded() first, followed by action methods ordered alphabetically, and then all check_ methods ordered alphabetically(as they all start with check_).
The reason for placing check_pageIsLoaded() first is that all page classes will have this specific method, and when we create an object for the page, we usually need to call it before performing other actions. Thus, putting this specific method at the beginning will make it easier to find.
What do you think about this approach? If you agree, we can make it a standard.

try {
await this.driver.waitForMultipleSelectors([
this.accountListItem,
this.accountOptionsMenuButton,
]);
} catch (e) {
console.log('Timeout while waiting for account list to be loaded', e);
throw e;
}
console.log('Account list is loaded');
}

async hideAccount(): Promise<void> {
console.log(`Hide account in account list`);
await this.driver.clickElement(this.hideUnhideAccountButton);
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/page-objects/pages/login-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class LoginPage {

private welcomeBackMessage: object;

private forgotPasswordButton: object;

constructor(driver: Driver) {
this.driver = driver;
this.passwordInput = '[data-testid="unlock-password"]';
Expand All @@ -17,6 +19,10 @@ class LoginPage {
css: '[data-testid="unlock-page-title"]',
text: 'Welcome back!',
};
this.forgotPasswordButton = {
text: 'Forgot password?',
tag: 'a',
};
}

async check_pageIsLoaded(): Promise<void> {
Expand All @@ -40,6 +46,11 @@ class LoginPage {
async clickUnlockButton(): Promise<void> {
await this.driver.clickElement(this.unlockButton);
}

async gotoResetPasswordPage(): Promise<void> {
console.log('Navigating to reset password page');
await this.driver.clickElement(this.forgotPasswordButton);
}
}

export default LoginPage;
53 changes: 53 additions & 0 deletions test/e2e/page-objects/pages/reset-password-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Driver } from '../../webdriver/driver';

class ResetPasswordPage {
private driver: Driver;

private seedPhraseInput: string;

private passwordInput: string;

private confirmPasswordInput: string;

private restoreButton: string;

constructor(driver: Driver) {
this.driver = driver;
this.seedPhraseInput = '[data-testid="import-srp__srp-word-0"]';
this.passwordInput = '[data-testid="create-vault-password"]';
this.confirmPasswordInput = '[data-testid="create-vault-confirm-password"]';
this.restoreButton = '[data-testid="create-new-vault-submit-button"]';
}

async check_pageIsLoaded(): Promise<void> {
try {
await this.driver.waitForMultipleSelectors([
this.passwordInput,
this.confirmPasswordInput,
]);
} catch (e) {
console.log(
'Timeout while waiting for reset password page to be loaded',
e,
);
throw e;
}
console.log('Reset password page is loaded');
}

/**
* Resets the password using the provided seed phrase and new password.
*
* @param seedPhrase - The seed phrase to verify account ownership
* @param newPassword - The new password to set for the account
*/
async resetPassword(seedPhrase: string, newPassword: string): Promise<void> {
console.log(`Resetting password with new password: ${newPassword}`);
await this.driver.pasteIntoField(this.seedPhraseInput, seedPhrase);
await this.driver.fill(this.passwordInput, newPassword);
await this.driver.fill(this.confirmPasswordInput, newPassword);
await this.driver.clickElement(this.restoreButton);
}
}

export default ResetPasswordPage;
1 change: 1 addition & 0 deletions test/e2e/tests/account/account-hide-unhide.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Account list - hide/unhide functionality', function (this: Suite) {

// hide account
const accountListPage = new AccountListPage(driver);
await accountListPage.check_pageIsLoaded();
await accountListPage.openAccountOptionsMenu();
await accountListPage.hideAccount();
await accountListPage.check_hiddenAccountsListExists();
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/tests/account/account-pin-unpin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Account list - pin/unpin functionality', function (this: Suite) {

// pin account
const accountListPage = new AccountListPage(driver);
await accountListPage.check_pageIsLoaded();
await accountListPage.openAccountOptionsMenu();
await accountListPage.pinAccount();
await accountListPage.check_accountIsPinned();
Expand All @@ -45,6 +46,7 @@ describe('Account list - pin/unpin functionality', function (this: Suite) {

// pin account
const accountListPage = new AccountListPage(driver);
await accountListPage.check_pageIsLoaded();
await accountListPage.openAccountOptionsMenu();
await accountListPage.pinAccount();
await accountListPage.check_accountIsPinned();
Expand Down
42 changes: 42 additions & 0 deletions test/e2e/tests/account/forgot-password.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { withFixtures, defaultGanacheOptions } from '../../helpers';
import FixtureBuilder from '../../fixture-builder';
import { E2E_SRP } from '../../default-fixture';
import { Driver } from '../../webdriver/driver';
import HomePage from '../../page-objects/pages/homepage';
import LoginPage from '../../page-objects/pages/login-page';
import ResetPasswordPage from '../../page-objects/pages/reset-password-page';
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';

const newPassword = 'this is the best password ever';

describe('Forgot password', function () {
it('resets password and then unlock wallet with new password', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await loginWithBalanceValidation(driver);

// Lock Wallet
const homePage = new HomePage(driver);
await homePage.headerNavbar.lockMetaMask();

// Click forgot password button and reset password
await new LoginPage(driver).gotoResetPasswordPage();

const resetPasswordPage = new ResetPasswordPage(driver);
await resetPasswordPage.check_pageIsLoaded();
await resetPasswordPage.resetPassword(E2E_SRP, newPassword);

// Lock wallet again
await homePage.headerNavbar.lockMetaMask();

// Check user can log in with new password
await loginWithBalanceValidation(driver, newPassword);
},
);
});
});
39 changes: 0 additions & 39 deletions test/e2e/tests/account/migrate-old-vault.spec.js

This file was deleted.

24 changes: 24 additions & 0 deletions test/e2e/tests/account/migrate-old-vault.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Suite } from 'mocha';
import { defaultGanacheOptions, withFixtures } from '../../helpers';
import FixtureBuilder from '../../fixture-builder';
import { Driver } from '../../webdriver/driver';
import HomePage from '../../page-objects/pages/homepage';
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';

describe('Migrate vault with old encryption', function (this: Suite) {
it('successfully unlocks an old vault, locks it, and unlocks again', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().withKeyringControllerOldVault().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await loginWithBalanceValidation(driver);
const homePage = new HomePage(driver);
await homePage.headerNavbar.lockMetaMask();
await loginWithBalanceValidation(driver);
},
);
});
});