From ac358a026fd52fd1bfbc5c2c6e59729e9b1237cb Mon Sep 17 00:00:00 2001 From: seaona Date: Tue, 9 Jan 2024 12:36:44 +0100 Subject: [PATCH] test: migrate simple send spec to POM --- test/e2e/components/header-navbar.js | 14 ++++++++++ test/e2e/page-objects/base.page.js | 10 +++++++ test/e2e/page-objects/confirm-tx.page.js | 16 +++++++++++ test/e2e/page-objects/home.page.js | 26 ++++++++++++++++++ test/e2e/page-objects/login.page.js | 21 +++++++++++++++ test/e2e/page-objects/send-amount.page.js | 21 +++++++++++++++ test/e2e/page-objects/send-to.page.js | 16 +++++++++++ test/e2e/processes/unlock-wallet.js | 11 ++++++++ test/e2e/tests/simple-send.spec.js | 33 ++++++++++++++++++----- 9 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 test/e2e/components/header-navbar.js create mode 100644 test/e2e/page-objects/base.page.js create mode 100644 test/e2e/page-objects/confirm-tx.page.js create mode 100644 test/e2e/page-objects/home.page.js create mode 100644 test/e2e/page-objects/login.page.js create mode 100644 test/e2e/page-objects/send-amount.page.js create mode 100644 test/e2e/page-objects/send-to.page.js create mode 100644 test/e2e/processes/unlock-wallet.js diff --git a/test/e2e/components/header-navbar.js b/test/e2e/components/header-navbar.js new file mode 100644 index 000000000000..fbf1c6abf1fd --- /dev/null +++ b/test/e2e/components/header-navbar.js @@ -0,0 +1,14 @@ +class HeaderNavbar { + constructor(driver) { + // Selectors + this.driver = driver; + this.btnAccountMenu = '[data-testid="account-menu-icon"]'; + } + + // Methods + async openAccountMenu() { + await this.driver.clickElement(this.btnAccountDetailsMenu); + } +} + +module.exports = HeaderNavbar; diff --git a/test/e2e/page-objects/base.page.js b/test/e2e/page-objects/base.page.js new file mode 100644 index 000000000000..00d7b083a5c4 --- /dev/null +++ b/test/e2e/page-objects/base.page.js @@ -0,0 +1,10 @@ +const HeaderNavbar = require('../components/header-navbar'); + +class BasePage { + constructor(driver) { + this.driver = driver; + this.headerNavbar = new HeaderNavbar(driver); + } +} + +module.exports = BasePage; diff --git a/test/e2e/page-objects/confirm-tx.page.js b/test/e2e/page-objects/confirm-tx.page.js new file mode 100644 index 000000000000..66993bebc8f7 --- /dev/null +++ b/test/e2e/page-objects/confirm-tx.page.js @@ -0,0 +1,16 @@ +const BasePage = require('./base.page'); + +class ConfirmTxPage extends BasePage { + constructor(driver) { + // Selectors + super(driver); + this.btnConfirm = '[data-testid="page-container-footer-next"]'; + } + + // Methods + async confirmTx() { + await this.driver.clickElement(this.btnConfirm); + } +} + +module.exports = ConfirmTxPage; diff --git a/test/e2e/page-objects/home.page.js b/test/e2e/page-objects/home.page.js new file mode 100644 index 000000000000..c9f56b97aef1 --- /dev/null +++ b/test/e2e/page-objects/home.page.js @@ -0,0 +1,26 @@ +const BasePage = require('./base.page'); + +class HomePage extends BasePage { + constructor(driver) { + // Selectors + super(driver); + this.btnSend = '[data-testid="eth-overview-send"]'; + this.btnActivity = '[data-testid="home__activity-tab"]'; + this.confirmedTx = '.transaction-status-label--confirmed'; + } + + // Methods + async startSendFlow() { + await this.driver.clickElement(this.btnSend); + } + + async goToActivityList() { + await this.driver.clickElement(this.btnActivity); + } + + async isConfirmedTxInActivity() { + return await this.driver.isElementPresent(this.confirmedTx); + } +} + +module.exports = HomePage; diff --git a/test/e2e/page-objects/login.page.js b/test/e2e/page-objects/login.page.js new file mode 100644 index 000000000000..0960742b5426 --- /dev/null +++ b/test/e2e/page-objects/login.page.js @@ -0,0 +1,21 @@ +const BasePage = require('./base.page'); + +class LoginPage extends BasePage { + constructor(driver) { + // Selectors + super(driver); + this.inputPassword = '#password'; + this.btnUnlock = '[data-testid="unlock-submit"]'; + } + + // Methods + async addPassword(password) { + await this.driver.fill(this.inputPassword, password); + } + + async unlock() { + await this.driver.clickElement(this.btnUnlock); + } +} + +module.exports = LoginPage; diff --git a/test/e2e/page-objects/send-amount.page.js b/test/e2e/page-objects/send-amount.page.js new file mode 100644 index 000000000000..2709f73a7be6 --- /dev/null +++ b/test/e2e/page-objects/send-amount.page.js @@ -0,0 +1,21 @@ +const BasePage = require('./base.page'); + +class SendToPage extends BasePage { + constructor(driver) { + // Selectors + super(driver); + this.inputAmount = '[data-testid="currency-input"]'; + this.btnNext = '[data-testid="page-container-footer-next"]'; + } + + // Methods + async addAmount(amount) { + await this.driver.fill(this.inputAmount, amount); + } + + async goToNextScreen() { + await this.driver.clickElement(this.btnNext); + } +} + +module.exports = SendToPage; diff --git a/test/e2e/page-objects/send-to.page.js b/test/e2e/page-objects/send-to.page.js new file mode 100644 index 000000000000..7bc3c363ca10 --- /dev/null +++ b/test/e2e/page-objects/send-to.page.js @@ -0,0 +1,16 @@ +const BasePage = require('./base.page'); + +class SendToPage extends BasePage { + constructor(driver) { + // Selectors + super(driver); + this.inputRecipient = '[data-testid="ens-input"]'; + } + + // Methods + async addRecipient(recipientAddress) { + await this.driver.fill(this.inputRecipient, recipientAddress); + } +} + +module.exports = SendToPage; diff --git a/test/e2e/processes/unlock-wallet.js b/test/e2e/processes/unlock-wallet.js new file mode 100644 index 000000000000..c7b9718676da --- /dev/null +++ b/test/e2e/processes/unlock-wallet.js @@ -0,0 +1,11 @@ +const LoginPage = require('../page-objects/login.page'); + +const unlockWallet = async (driver, password) => { + const loginPage = new LoginPage(driver); + + await driver.navigate(); + await loginPage.addPassword(password); + await loginPage.unlock(); +}; + +module.exports = unlockWallet; diff --git a/test/e2e/tests/simple-send.spec.js b/test/e2e/tests/simple-send.spec.js index 9132ea171d0c..444e5fabbdd5 100644 --- a/test/e2e/tests/simple-send.spec.js +++ b/test/e2e/tests/simple-send.spec.js @@ -1,10 +1,15 @@ +const { strict: assert } = require('assert'); const { defaultGanacheOptions, withFixtures, - sendTransaction, - logInWithBalanceValidation, + WALLET_PASSWORD, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); +const ConfirmTxPage = require('../page-objects/confirm-tx.page'); +const HomePage = require('../page-objects/home.page'); +const SendToPage = require('../page-objects/send-to.page'); +const SendAmountPage = require('../page-objects/send-amount.page'); +const unlockWallet = require('../processes/unlock-wallet'); describe('Simple send', function () { it('can send a simple transaction from one account to another', async function () { @@ -14,14 +19,28 @@ describe('Simple send', function () { ganacheOptions: defaultGanacheOptions, title: this.test.fullTitle(), }, - async ({ driver, ganacheServer }) => { - await logInWithBalanceValidation(driver, ganacheServer); + async ({ driver }) => { + // Process + await unlockWallet(driver, WALLET_PASSWORD); - await sendTransaction( - driver, + // Page Objects and Components + const confirmTxPage = new ConfirmTxPage(driver); + const homePage = new HomePage(driver); + const sendAmountPage = new SendAmountPage(driver); + const sendToPage = new SendToPage(driver); + + // Actions and Assertions + await homePage.startSendFlow(); + await sendToPage.addRecipient( '0x985c30949c92df7a0bd42e0f3e3d539ece98db24', - '1', ); + await sendAmountPage.addAmount('1'); + await sendAmountPage.goToNextScreen(); + await confirmTxPage.confirmTx(); + await homePage.goToActivityList(); + + const confirmedTx = await homePage.isConfirmedTxInActivity(); + assert.equal(confirmedTx, true, 'Confirmed tx is not found'); }, ); });