Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
chloeYue committed Sep 20, 2024
1 parent 637cad7 commit b5201e0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 52 deletions.
4 changes: 2 additions & 2 deletions test/e2e/page-objects/flows/login.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { WALLET_PASSWORD } from '../../helpers';
* This method unlocks the wallet and verifies that the user lands on the homepage with the expected balance. It is designed to be the initial step in setting up a test environment.
*
* @param driver - The webdriver instance.
* @param password - The password used to unlock the wallet. Defaults to WALLET_PASSWORD.
* @param expectedBalance - The expected balance to be displayed on the homepage after successful login. Defaults to DEFAULT_GANACHE_ETH_BALANCE_DEC, reflecting common usage in test setups.
* @param password - The password used to unlock the wallet. Defaults to WALLET_PASSWORD.
*/
export const loginWithBalanceValidation = async (
driver: Driver,
password: string = WALLET_PASSWORD,
expectedBalance: string = DEFAULT_GANACHE_ETH_BALANCE_DEC,
password: string = WALLET_PASSWORD,
) => {
console.log('Navigate to unlock page and try to login with pasword');
await driver.navigate();
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/page-objects/pages/account-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class AccountListPage {

async closeAccountModal(): Promise<void> {
console.log(`Open add account modal in account list`);
await this.driver.clickElementAndWaitToDisappear(this.closeAccountModalButton);
await this.driver.clickElementAndWaitToDisappear(
this.closeAccountModalButton,
);
}

async openAddAccountModal(): Promise<void> {
Expand Down Expand Up @@ -139,8 +141,6 @@ class AccountListPage {
console.log(`Check that hidden accounts list is displayed in account list`);
await this.driver.waitForSelector(this.hiddenAccountsList);
}


}

export default AccountListPage;
32 changes: 17 additions & 15 deletions test/e2e/page-objects/pages/experimental-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ class ExperimentalSettings {
private readonly driver: Driver;

// Locators
private readonly addAccountSnapToggle: string = '[data-testid="add-account-snap-toggle-div"]';
private readonly addAccountSnapToggle: string =
'[data-testid="add-account-snap-toggle-div"]';

private readonly experimentalPageTitle: object = {
text: 'Experimental',
css: '.h4',
};

constructor(driver: Driver) {
this.driver = driver;
}

async check_pageIsLoaded(): Promise<void> {
console.log('Checking if Experimental Settings page is loaded');
try {
await this.driver.waitForSelector(this.addAccountSnapToggle);
console.log('Experimental Settings page is loaded successfully');
} catch (error) {
console.error('Failed to load Experimental Settings page', error);
throw new Error(`Experimental Settings page failed to load: ${(error as Error).message}`);
await this.driver.waitForSelector(this.experimentalPageTitle);
} catch (e) {
console.log(
'Timeout while waiting for Experimental Settings page to be loaded',
e,
);
throw e;
}
console.log('Experimental Settings page is loaded');
}

async toggleAddAccountSnap(): Promise<void> {
console.log('Toggling Add Account Snap setting');
try {
await this.driver.clickElement(this.addAccountSnapToggle);
console.log('Add Account Snap setting toggled successfully');
} catch (error) {
console.error('Failed to toggle Add Account Snap setting', error);
throw new Error(`Unable to toggle Add Account Snap setting: ${(error as Error).message}`);
}
console.log('Toggle Add Account Snap on experimental setting page');
await this.driver.clickElement(this.addAccountSnapToggle);
}
}

Expand Down
15 changes: 5 additions & 10 deletions test/e2e/page-objects/pages/header-navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HeaderNavbar {
this.accountMenuButton = '[data-testid="account-menu-icon"]';
this.accountOptionMenu = '[data-testid="account-options-menu-button"]';
this.lockMetaMaskButton = '[data-testid="global-menu-lock"]';
this.settingsButton = '[data-testid="settings-button"]';
this.settingsButton = '[data-testid="global-menu-settings"]';
}

async openAccountMenu(): Promise<void> {
Expand All @@ -28,15 +28,10 @@ class HeaderNavbar {
await this.driver.clickElement(this.lockMetaMaskButton);
}

async clickSettingsButton(): Promise<void> {
console.log('Clicking settings button');
try {
await this.driver.clickElement(this.settingsButton);
console.log('Settings button clicked successfully');
} catch (error) {
console.error('Failed to click settings button', error);
throw new Error(`Unable to click settings button: ${(error as Error).message}`);
}
async openSettingsPage(): Promise<void> {
console.log('Open settings page');
await this.driver.clickElement(this.accountOptionMenu);
await this.driver.clickElement(this.settingsButton);
}
}

Expand Down
29 changes: 15 additions & 14 deletions test/e2e/page-objects/pages/settings-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@ class SettingsPage {
private readonly driver: Driver;

// Locators
private readonly experimentalSettingsButton: string = '[data-testid="experimental-settings-button"]';
private readonly experimentalSettingsButton: object = {
text: 'Experimental',
css: '.tab-bar__tab__content__title',
};

private readonly settingsPageTitle: object = {
text: 'Settings',
css: 'h3',
};

constructor(driver: Driver) {
this.driver = driver;
}

async check_pageIsLoaded(): Promise<void> {
console.log('Checking if Settings page is loaded');
try {
await this.driver.waitForSelector(this.experimentalSettingsButton);
console.log('Settings page is loaded successfully');
} catch (error) {
console.error('Failed to load Settings page', error);
throw new Error(`Settings page failed to load: ${(error as Error).message}`);
await this.driver.waitForSelector(this.settingsPageTitle);
} catch (e) {
console.log('Timeout while waiting for Settings page to be loaded', e);
throw e;
}
console.log('Settings page is loaded');
}

async goToExperimentalSettings(): Promise<void> {
console.log('Navigating to Experimental Settings');
try {
await this.driver.clickElement(this.experimentalSettingsButton);
console.log('Navigated to Experimental Settings successfully');
} catch (error) {
console.error('Failed to navigate to Experimental Settings', error);
throw new Error(`Unable to navigate to Experimental Settings: ${(error as Error).message}`);
}
await this.driver.clickElement(this.experimentalSettingsButton);
}
}

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/tests/account/snap-account-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Add snap account experimental settings', function (this: Suite) {
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await loginWithBalanceValidation(driver);
await loginWithBalanceValidation(driver, '0');

// Make sure the "Add snap account" button is not visible.
const headerNavbar = new HeaderNavbar(driver);
Expand All @@ -27,10 +27,13 @@ describe('Add snap account experimental settings', function (this: Suite) {
await accountListPage.closeAccountModal();

// Navigate to experimental settings and enable Add account Snap.
await headerNavbar.clickSettingsButton();
await headerNavbar.openSettingsPage();
const settingsPage = new SettingsPage(driver);
await settingsPage.check_pageIsLoaded();
await settingsPage.goToExperimentalSettings();

const experimentalSettings = new ExperimentalSettings(driver);
await settingsPage.check_pageIsLoaded();
await experimentalSettings.toggleAddAccountSnap();

// Make sure the "Add account Snap" button is visible.
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/tests/transaction/ens.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Suite } from 'mocha';
import { MockttpServer } from 'mockttp';
import {
defaultGanacheOptions,
withFixtures,
WALLET_PASSWORD,
} from '../../helpers';
import { defaultGanacheOptions, withFixtures } from '../../helpers';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
Expand Down Expand Up @@ -112,7 +108,7 @@ describe('ENS', function (this: Suite) {
testSpecificMock: mockInfura,
},
async ({ driver }: { driver: Driver }) => {
await loginWithBalanceValidation(driver, WALLET_PASSWORD, '<0.000001');
await loginWithBalanceValidation(driver, '<0.000001');

// click send button on homepage to start send flow
await new HomePage(driver).startSendFlow();
Expand Down

0 comments on commit b5201e0

Please sign in to comment.