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: Added e2e for switch network #27967

Merged
merged 15 commits into from
Oct 24, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Driver } from '../../../webdriver/driver';

class networkSwitchModalConfirmation {
private driver: Driver;

private submitButton: string;

constructor(driver: Driver) {
this.driver = driver;
this.submitButton = '[data-testid="confirmation-submit-button"]';
}

async clickApproveButton(): Promise<void> {
console.log('Click Approve Button');
await this.driver.clickElementAndWaitToDisappear(this.submitButton);
}
}

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

class SelectNetwork {
private driver: Driver;

private networkName: string | undefined;

private addNetworkButton: object;

private closeButton: string;

private toggleButton: string;

private searchInput: string;

constructor(driver: Driver) {
this.driver = driver;
this.addNetworkButton = {
tag: 'button',
text: 'Add a custom network',
};
this.closeButton = 'button[aria-label="Close"]';
this.toggleButton = '.toggle-button > div';
this.searchInput = '[data-testid="network-redesign-modal-search-input"]';
}

async clickNetworkName(networkName: string): Promise<void> {
console.log(`Click ${networkName}`);
this.networkName = `[data-testid="${networkName}"]`;
await this.driver.clickElement(this.networkName);
}

async addNewNetwork(): Promise<void> {
console.log('Click Add network');
await this.driver.clickElement(this.addNetworkButton);
}

async clickCloseButton(): Promise<void> {
console.log('Click Close Button');
await this.driver.clickElementAndWaitToDisappear(this.closeButton);
}

async clickToggleButton(): Promise<void> {
console.log('Click Toggle Button');
await this.driver.clickElement(this.toggleButton);
}

async fillNetworkSearchInput(networkName: string): Promise<void> {
console.log(`Fill network search input with ${networkName}`);
await this.driver.fill(this.searchInput, networkName);
}

async clickAddButton(): Promise<void> {
console.log('Click Add Button');
await this.driver.clickElementAndWaitToDisappear(
'[data-testid="test-add-button"]',
);
}
}

export default SelectNetwork;
19 changes: 15 additions & 4 deletions test/e2e/page-objects/pages/header-navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class HeaderNavbar {

private readonly settingsButton = '[data-testid="global-menu-settings"]';

private readonly switchNetworkDropDownButton =
'[data-testid="network-display"]';
private readonly switchNetworkDropDown = '[data-testid="network-display"]';

constructor(driver: Driver) {
this.driver = driver;
Expand Down Expand Up @@ -71,14 +70,26 @@ class HeaderNavbar {
await this.driver.clickElement(this.settingsButton);
}

async clickSwitchNetworkDropDown(): Promise<void> {
console.log(`Click switch network menu`);
await this.driver.clickElement(this.switchNetworkDropDown);
}

async check_currentSelectedNetwork(networkName: string): Promise<void> {
console.log(`Validate the Switch network to ${networkName}`);
await this.driver.waitForSelector(
`button[data-testid="network-display"][aria-label="Network Menu ${networkName}"]`,
);
}

/**
* Switches to the specified network.
*
* @param networkName - The name of the network to switch to.
*/
async switchToNetwork(networkName: string): Promise<void> {
console.log(`Switch to network ${networkName} in header bar`);
await this.driver.clickElement(this.switchNetworkDropDownButton);
await this.driver.clickElement(this.switchNetworkDropDown);
await this.driver.waitForSelector(this.selectNetworkMessage);
await this.driver.clickElementAndWaitToDisappear(
`[data-testid="${networkName}"]`,
Expand All @@ -89,7 +100,7 @@ class HeaderNavbar {
text: `“${networkName}” was successfully added!`,
});
await this.driver.waitForSelector(
`${this.switchNetworkDropDownButton}[aria-label="Network Menu ${networkName}"]`,
`${this.switchNetworkDropDown}[aria-label="Network Menu ${networkName}"]`,
);
}

Expand Down
66 changes: 66 additions & 0 deletions test/e2e/tests/network/switch-network.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Suite } from 'mocha';
import { Driver } from '../../webdriver/driver';
import { withFixtures, defaultGanacheOptions } from '../../helpers';
import FixtureBuilder from '../../fixture-builder';
import { Ganache } from '../../seeder/ganache';
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
import HomePage from '../../page-objects/pages/homepage';
import ModalConfirmation from '../../page-objects/pages/dialog/network-switch-modal-confirmation';
import HeaderNavbar from '../../page-objects/pages/header-navbar';
import SelectNetwork from '../../page-objects/pages/dialog/select-network';

describe('Switch network - ', function (this: Suite) {
it('Switch networks to existing and new networks', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({
driver,
ganacheServer,
}: {
driver: Driver;
ganacheServer?: Ganache;
}) => {
await loginWithBalanceValidation(driver, ganacheServer);
const homePage = new HomePage(driver);
const headerNavbar = new HeaderNavbar(driver);
const selectNetwork = new SelectNetwork(driver);
const networkSwitchConfirmation = new ModalConfirmation(driver);

// Validate the default network is Localhost 8545
await headerNavbar.check_currentSelectedNetwork('Localhost 8545');

// Validate the switch network functionality to Ethereum Mainnet
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetwork.clickNetworkName('Ethereum Mainnet');
await homePage.check_expectedBalanceIsDisplayed('25');
await headerNavbar.check_currentSelectedNetwork('Ethereum Mainnet');
// Validate the switch network functionality to test network
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetwork.clickToggleButton();
await selectNetwork.clickNetworkName('Localhost 8545');
await homePage.check_expectedBalanceIsDisplayed('25');
await headerNavbar.check_currentSelectedNetwork('Localhost 8545');

// Add Arbitrum network and perform the switch network functionality
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetwork.fillNetworkSearchInput('Arbitrum One');
await selectNetwork.clickAddButton();
await networkSwitchConfirmation.clickApproveButton();
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetwork.clickNetworkName('Arbitrum One');
await homePage.check_expectedBalanceIsDisplayed('25');
await headerNavbar.check_currentSelectedNetwork('Arbitrum One');

// Validate the switch network functionality back to Ethereum Mainnet
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetwork.clickNetworkName('Ethereum Mainnet');
await homePage.check_expectedBalanceIsDisplayed('25');
await headerNavbar.check_currentSelectedNetwork('Ethereum Mainnet');
},
);
});
});