-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [POM] Migrate Snap Account Settings to page object model (#27302)
## **Description** This pull request migrate snap account settings test to page object model(POM) pattern, enhancing code maintainability, and improving test reliability. Also improved the implementation of login methods so we query directly ganache, and there's no need to pass any balance manually. ## **Description** [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27155?quickstart=1) ## **Related issues** Fixes: #27343 ## **Manual testing steps** Check code readability, make sure tests pass. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Chloe Gao <[email protected]> Co-authored-by: chloeYue <[email protected]>
- Loading branch information
1 parent
fce2e8b
commit 7054c16
Showing
18 changed files
with
333 additions
and
176 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
import LoginPage from '../pages/login-page'; | ||
import HomePage from '../pages/homepage'; | ||
import { Driver } from '../../webdriver/driver'; | ||
import { DEFAULT_GANACHE_ETH_BALANCE_DEC } from '../../constants'; | ||
import { WALLET_PASSWORD } from '../../helpers'; | ||
import { Ganache } from '../../seeder/ganache'; | ||
|
||
/** | ||
* 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. | ||
* This method unlocks the wallet and lands the user on the homepage. | ||
* | ||
* @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. | ||
*/ | ||
export const loginWithBalanceValidation = async ( | ||
export const loginWithoutBalanceValidation = async ( | ||
driver: Driver, | ||
password: string = WALLET_PASSWORD, | ||
expectedBalance: string = DEFAULT_GANACHE_ETH_BALANCE_DEC, | ||
password?: string, | ||
) => { | ||
console.log('Navigate to unlock page and try to login with pasword'); | ||
console.log('Navigate to unlock page and try to login with password'); | ||
await driver.navigate(); | ||
const loginPage = new LoginPage(driver); | ||
await loginPage.check_pageIsLoaded(); | ||
await loginPage.fillPassword(password); | ||
await loginPage.clickUnlockButton(); | ||
await loginPage.loginToHomepage(password); | ||
|
||
// user should land on homepage after successfully logging in with password | ||
const homePage = new HomePage(driver); | ||
await homePage.check_pageIsLoaded(); | ||
await homePage.check_expectedBalanceIsDisplayed(expectedBalance); | ||
}; | ||
|
||
/** | ||
* 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 ganacheServer - The ganache server instance | ||
* @param password - The password used to unlock the wallet. | ||
*/ | ||
export const loginWithBalanceValidation = async ( | ||
driver: Driver, | ||
ganacheServer?: Ganache, | ||
password?: string, | ||
) => { | ||
await loginWithoutBalanceValidation(driver, password); | ||
// Verify the expected balance on the homepage | ||
if (ganacheServer) { | ||
await new HomePage(driver).check_ganacheBalanceIsDisplayed(ganacheServer); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Driver } from '../../webdriver/driver'; | ||
|
||
class ExperimentalSettings { | ||
private readonly driver: Driver; | ||
|
||
// Locators | ||
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> { | ||
try { | ||
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('Toggle Add Account Snap on experimental setting page'); | ||
await this.driver.clickElement(this.addAccountSnapToggle); | ||
} | ||
} | ||
|
||
export default ExperimentalSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.