From c7e64adb686e8f1d6f73b6d969809acb55d2d963 Mon Sep 17 00:00:00 2001 From: wklos-iohk Date: Sat, 25 Jan 2025 16:42:59 +0100 Subject: [PATCH 1/2] test(extension): remove redundant DApp connector POM --- .../src/assert/dAppConnectorAssert.ts | 8 +- .../dappConnector/authorizeDAppModal.ts | 7 ++ .../dappConnector/authorizeDAppPage.ts | 5 ++ .../dappConnector/confirmTransactionPage.ts | 45 ++++++----- .../elements/dappConnector/noWalletModal.ts | 5 ++ .../elements/dappConnector/removeDAppModal.ts | 5 ++ packages/e2e-tests/src/steps/commonSteps.ts | 4 +- .../e2e-tests/src/steps/dAppConnectorSteps.ts | 76 ++++++++++--------- .../e2e-tests/src/steps/governanceSteps.ts | 4 +- .../DAppConnectorUtils.ts} | 43 ++--------- .../e2e-tests/src/utils/cucumberDataHelper.ts | 27 +++++++ .../e2e-tests/src/utils/dappConnectorUtils.ts | 27 ------- 12 files changed, 129 insertions(+), 127 deletions(-) rename packages/e2e-tests/src/{pageobject/dAppConnectorPageObject.ts => utils/DAppConnectorUtils.ts} (70%) delete mode 100644 packages/e2e-tests/src/utils/dappConnectorUtils.ts diff --git a/packages/e2e-tests/src/assert/dAppConnectorAssert.ts b/packages/e2e-tests/src/assert/dAppConnectorAssert.ts index 2f722924de..a8157bfd4e 100644 --- a/packages/e2e-tests/src/assert/dAppConnectorAssert.ts +++ b/packages/e2e-tests/src/assert/dAppConnectorAssert.ts @@ -20,8 +20,8 @@ import { browser } from '@wdio/globals'; import InsufficientFundsDAppPage from '../elements/dappConnector/insufficientFundsDAppPage'; import ErrorDAppModal from '../elements/dappConnector/errorDAppModal'; import { getTextFromElementArray } from '../utils/getTextFromArray'; -import DAppConnectorPageObject from '../pageobject/dAppConnectorPageObject'; -import { parseDappCucumberAssetList } from '../utils/dappConnectorUtils'; +import DAppConnectorPageObject from '../utils/DAppConnectorUtils'; +import { parseDAppCucumberAssetList } from '../utils/cucumberDataHelper'; export type ExpectedDAppDetails = { hasLogo: boolean; @@ -289,7 +289,7 @@ class DAppConnectorAssert { ); await ConfirmTransactionPage.transactionFeeValueAda.waitForDisplayed(); - const parsedAssetsList = await parseDappCucumberAssetList(assetsDetails); + const parsedAssetsList = await parseDAppCucumberAssetList(assetsDetails); expect(await getTextFromElementArray(await ConfirmTransactionPage.transactionSummaryAssetsRows)).to.deep.equal( parsedAssetsList ); @@ -311,7 +311,7 @@ class DAppConnectorAssert { } async assertSeeConfirmFromAddressTransactionPage(section: 'To address' | 'From address', assets: string[]) { - const adjustedAssetsList = await parseDappCucumberAssetList(assets); + const adjustedAssetsList = await parseDAppCucumberAssetList(assets); const expectedAssets = section === 'To address' ? await ConfirmTransactionPage.getAssetsToAddressSection() diff --git a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts index dc4588fb20..54d61bd041 100644 --- a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts +++ b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts @@ -1,5 +1,6 @@ /* eslint-disable no-undef */ import { ChainablePromiseElement } from 'webdriverio'; +import { browser } from '@wdio/globals'; class AuthorizeDAppModal { private CONTAINER = '[data-testid="connect-modal-container"]'; @@ -27,6 +28,12 @@ class AuthorizeDAppModal { get onceButton(): ChainablePromiseElement { return $(this.ONCE_BUTTON); } + + async clickButton(button: 'Always' | 'Only once'): Promise { + await browser.pause(500); + await this.alwaysButton.waitForDisplayed(); + button === 'Always' ? await this.alwaysButton.click() : await this.onceButton.click(); + } } export default new AuthorizeDAppModal(); diff --git a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts index ecc3ddcb20..acd18445a3 100644 --- a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts +++ b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts @@ -33,6 +33,11 @@ class AuthorizeDAppPage extends CommonDappPageElements { get cancelButton(): ChainablePromiseElement { return $(this.CANCEL_BUTTON); } + + async clickButton(button: 'Authorize' | 'Cancel'): Promise { + await this.authorizeButton.waitForDisplayed(); + button === 'Authorize' ? await this.authorizeButton.click() : await this.cancelButton.click(); + } } export default new AuthorizeDAppPage(); diff --git a/packages/e2e-tests/src/elements/dappConnector/confirmTransactionPage.ts b/packages/e2e-tests/src/elements/dappConnector/confirmTransactionPage.ts index cd4d44d919..cf718dd66f 100644 --- a/packages/e2e-tests/src/elements/dappConnector/confirmTransactionPage.ts +++ b/packages/e2e-tests/src/elements/dappConnector/confirmTransactionPage.ts @@ -2,6 +2,8 @@ import CommonDappPageElements from './commonDappPageElements'; import { ChainablePromiseArray } from 'webdriverio/build/types'; import { getTextFromElementArray } from '../../utils/getTextFromArray'; +import testContext from '../../utils/testContext'; +import { ChainablePromiseElement } from 'webdriverio'; class ConfirmTransactionPage extends CommonDappPageElements { private TRANSACTION_TYPE_TITLE = '[data-testid="dapp-transaction-title"]'; @@ -33,71 +35,71 @@ class ConfirmTransactionPage extends CommonDappPageElements { '[data-testid="dapp-transaction-from-section-expander"] [data-testid="address-tag"]'; private ADDRESS_TAG_TO_SECTION = '[data-testid="dapp-transaction-to-section-expander"] [data-testid="address-tag"]'; - get transactionOrigin() { + get transactionOrigin(): ChainablePromiseElement { return $(this.TRANSACTION_ORIGIN); } - get transactionOriginLabel() { + get transactionOriginLabel(): ChainablePromiseElement { return $(this.TRANSACTION_ORIGIN_LABEL); } - get transactionFeeTitle() { + get transactionFeeTitle(): ChainablePromiseElement { return $(this.TRANSACTION_FEE_TITLE); } - get transactionFeeValueAda() { + get transactionFeeValueAda(): ChainablePromiseElement { return $(this.TRANSACTION_FEE_ADA); } - get transactionDepositTitle() { + get transactionDepositTitle(): ChainablePromiseElement { return $(this.TRANSACTION_DEPOSIT_TITLE); } - get transactionDepositValueAda() { + get transactionDepositValueAda(): ChainablePromiseElement { return $(this.TRANSACTION_DEPOSIT_ADA); } - get transactionReturnedDepositValueAda() { + get transactionReturnedDepositValueAda(): ChainablePromiseElement { return $(this.TRANSACTION_RETURNED_DEPOSIT_ADA); } - get transactionReturnedDepositTitle() { + get transactionReturnedDepositTitle(): ChainablePromiseElement { return $(this.TRANSACTION_RETURNED_DEPOSIT_TITLE); } - get transactionTypeTitle() { + get transactionTypeTitle(): ChainablePromiseElement { return $(this.TRANSACTION_TYPE_TITLE); } - get transactionType() { + get transactionType(): ChainablePromiseElement { return $(this.TRANSACTION_TYPE); } - get confirmButton() { + get confirmButton(): ChainablePromiseElement { return $(this.CONFIRM_BUTTON); } - get cancelButton() { + get cancelButton(): ChainablePromiseElement { return $(this.CANCEL_BUTTON); } - get transactionToSectionExpanderButton() { + get transactionToSectionExpanderButton(): ChainablePromiseElement { return $(this.TRANSACTION_TO_SECTION_EXPANDER_BUTTON); } - get transactionToSectionExpanderLabel() { + get transactionToSectionExpanderLabel(): ChainablePromiseElement { return $(this.TRANSACTION_TO_SECTION_EXPANDER_LABEL); } - get transactionFromSectionExpanderButton() { + get transactionFromSectionExpanderButton(): ChainablePromiseElement { return $(this.TRANSACTION_FROM_SECTION_EXPANDER_BUTTON); } - get transactionFromSectionExpanderLabel() { + get transactionFromSectionExpanderLabel(): ChainablePromiseElement { return $(this.TRANSACTION_FROM_SECTION_EXPANDER_LABEL); } - get transactionOriginSectionExpanderButton() { + get transactionOriginSectionExpanderButton(): ChainablePromiseElement { return $(this.TRANSACTION_ORIGIN_EXPANDER_BUTTON); } @@ -113,11 +115,11 @@ class ConfirmTransactionPage extends CommonDappPageElements { return $$(this.TRANSACTION_TO_ROW); } - get addressTagToSection() { + get addressTagToSection(): ChainablePromiseElement { return $(this.ADDRESS_TAG_TO_SECTION); } - get addressTagFromSection() { + get addressTagFromSection(): ChainablePromiseElement { return $(this.ADDRESS_TAG_FROM_SECTION); } @@ -148,6 +150,11 @@ class ConfirmTransactionPage extends CommonDappPageElements { throw new Error(`Unsupported section name: ${section}`); } } + + async saveDAppTransactionFeeValue() { + const [feeValue] = (await this.transactionFeeValueAda.getText()).split(' '); + await testContext.save('feeValueDAppTx', feeValue); + } } export default new ConfirmTransactionPage(); diff --git a/packages/e2e-tests/src/elements/dappConnector/noWalletModal.ts b/packages/e2e-tests/src/elements/dappConnector/noWalletModal.ts index d6b0e95dcb..f90c079eb0 100644 --- a/packages/e2e-tests/src/elements/dappConnector/noWalletModal.ts +++ b/packages/e2e-tests/src/elements/dappConnector/noWalletModal.ts @@ -27,6 +27,11 @@ class NoWalletModal { get createRestoreButton(): ChainablePromiseElement { return $(this.CREATE_RESTORE_BUTTON); } + + async clickCreateRestoreButton(): Promise { + await this.createRestoreButton.waitForClickable(); + await this.createRestoreButton.click(); + } } export default new NoWalletModal(); diff --git a/packages/e2e-tests/src/elements/dappConnector/removeDAppModal.ts b/packages/e2e-tests/src/elements/dappConnector/removeDAppModal.ts index 9b0bdc2026..9a9a8b0db5 100644 --- a/packages/e2e-tests/src/elements/dappConnector/removeDAppModal.ts +++ b/packages/e2e-tests/src/elements/dappConnector/removeDAppModal.ts @@ -27,6 +27,11 @@ class RemoveDAppModal { get cancelButton(): ChainablePromiseElement { return $(this.CANCEL_BUTTON); } + + async clickButton(button: 'Back' | 'Disconnect DApp'): Promise { + await this.cancelButton.waitForClickable(); + button === 'Back' ? await this.cancelButton.click() : await this.confirmButton.click(); + } } export default new RemoveDAppModal(); diff --git a/packages/e2e-tests/src/steps/commonSteps.ts b/packages/e2e-tests/src/steps/commonSteps.ts index bcfd8668a5..1137a30efd 100755 --- a/packages/e2e-tests/src/steps/commonSteps.ts +++ b/packages/e2e-tests/src/steps/commonSteps.ts @@ -38,7 +38,7 @@ import { browser } from '@wdio/globals'; import faqPageAssert from '../assert/faqPageAssert'; import { visit } from '../utils/pageUtils'; import CommonDrawerElements from '../elements/CommonDrawerElements'; -import DAppConnectorPageObject from '../pageobject/dAppConnectorPageObject'; +import DAppConnectorUtils from '../utils/DAppConnectorUtils'; import settingsExtendedPageObject from '../pageobject/settingsExtendedPageObject'; import consoleManager from '../utils/consoleManager'; import consoleAssert from '../assert/consoleAssert'; @@ -290,7 +290,7 @@ Then(/^I close all remaining tabs except current one$/, async () => { }); Then(/^I switch to window with (Lace|DApp)$/, async (window: 'Lace' | 'DApp') => { - await (window === 'Lace' ? switchToWindowWithLace() : DAppConnectorPageObject.switchToTestDAppWindow()); + await (window === 'Lace' ? switchToWindowWithLace() : DAppConnectorUtils.switchToTestDAppWindow()); }); When(/^I resize the window to a width of: ([^"]*) and a height of: ([^"]*)$/, async (width: number, height: number) => { diff --git a/packages/e2e-tests/src/steps/dAppConnectorSteps.ts b/packages/e2e-tests/src/steps/dAppConnectorSteps.ts index 3f7e863295..566fb68435 100755 --- a/packages/e2e-tests/src/steps/dAppConnectorSteps.ts +++ b/packages/e2e-tests/src/steps/dAppConnectorSteps.ts @@ -1,6 +1,6 @@ import { Then, When } from '@cucumber/cucumber'; import DAppConnectorAssert, { ExpectedDAppDetails, ExpectedTransactionData } from '../assert/dAppConnectorAssert'; -import DAppConnectorPageObject from '../pageobject/dAppConnectorPageObject'; +import DAppConnectorUtils from '../utils/DAppConnectorUtils'; import { browser } from '@wdio/globals'; import { waitUntilExpectedNumberOfHandles } from '../utils/window'; import { getTestWallet } from '../support/walletConfiguration'; @@ -18,63 +18,67 @@ import InsufficientFundsDAppPage from '../elements/dappConnector/insufficientFun import { dataTableAsStringArray } from '../utils/cucumberDataHelper'; import { parseWalletAddress } from '../utils/parseWalletAddress'; import { AddressTag } from '../assert/transactionDetailsAssert'; +import NoWalletModal from '../elements/dappConnector/noWalletModal'; +import AuthorizeDAppPage from '../elements/dappConnector/authorizeDAppPage'; +import AuthorizeDAppModal from '../elements/dappConnector/authorizeDAppModal'; +import RemoveDAppModal from '../elements/dappConnector/removeDAppModal'; const testDAppDetails: ExpectedDAppDetails = { hasLogo: true, - name: DAppConnectorPageObject.TEST_DAPP_NAME, - url: DAppConnectorPageObject.TEST_DAPP_URL + name: DAppConnectorUtils.TEST_DAPP_NAME, + url: DAppConnectorUtils.TEST_DAPP_URL }; When(/^I open test DApp$/, async () => { - await DAppConnectorPageObject.openTestDApp(); + await DAppConnectorUtils.openTestDApp(); }); Then(/^I see DApp authorization window$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAuthorizeDAppPage(testDAppDetails); }); Then(/^I see DApp collateral window$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeCollateralDAppPage(testDAppDetails); }); Then(/^I see DApp insufficient funds window$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeInsufficientFundsDAppPage(); }); Then(/^I see DApp authorization window in (dark|light) mode$/, async (mode: 'dark' | 'light') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAuthorizeDAppPage(testDAppDetails); await CommonAssert.assertSeeThemeMode(mode); }); Then(/^I see DApp collateral window in (dark|light) mode$/, async (mode: 'dark' | 'light') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeCollateralDAppPage(testDAppDetails); await CommonAssert.assertSeeThemeMode(mode); }); Then(/^I see DApp connector "All done" page in (dark|light) mode$/, async (mode: 'dark' | 'light') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAllDonePage(); await CommonAssert.assertSeeThemeMode(mode); }); Then(/^I see DApp connector "Confirm transaction" page in (dark|light) mode$/, async (mode: 'dark' | 'light') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await CommonAssert.assertSeeThemeMode(mode); }); Then(/^I see DApp connector Sign data "Confirm transaction" page$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); }); Then( /^I see DApp connector "Confirm transaction" page with all UI elements and with following data in "Transaction Summary" section:$/, async (dataTable) => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); const expectedTransactionData: ExpectedTransactionData = { typeOfTransaction: 'Send', assetsDetails: dataTableAsStringArray(dataTable) @@ -100,7 +104,7 @@ Then( Then( /^I see DApp connector "(Confirm transaction|Something went wrong|All done)" page on (\d) window handle$/, async (expectedPage: 'Confirm transaction' | 'Something went wrong' | 'All done', handleNumber: number) => { - await DAppConnectorPageObject.waitAndSwitchToHandle(4, handleNumber); + await DAppConnectorUtils.waitAndSwitchToHandle(4, handleNumber); const defaultDAppTransactionData: ExpectedTransactionData = { typeOfTransaction: 'Send', @@ -124,12 +128,12 @@ Then( ); Then(/^I see DApp connector "Sign transaction" page$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeSignTransactionPage(); }); Then(/^I see DApp connector "All done" page(?: from "(data sign)")?$/, async (signType?: 'data sign' | 'tx sign') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAllDonePage(signType); }); @@ -143,12 +147,12 @@ Then(/^I see DApp connection modal$/, async () => { }); Then(/^I see DApp no wallet page$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeNoWalletPage(); }); Then(/^I see DApp unlock page$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await WalletUnlockScreenAssert.assertSeeWalletUnlockScreen(); }); @@ -157,7 +161,7 @@ Then(/^I see DApp removal confirmation window$/, async () => { }); Then(/^I click "(Authorize|Cancel)" button in DApp authorization window$/, async (button: 'Authorize' | 'Cancel') => { - await DAppConnectorPageObject.clickButtonInDAppAuthorizationWindow(button); + await AuthorizeDAppPage.clickButton(button); }); Then( @@ -168,18 +172,18 @@ Then( ); Then(/^I click "(Always|Only once)" button in DApp authorization window$/, async (button: 'Always' | 'Only once') => { - await DAppConnectorPageObject.clickButtonInDAppAuthorizationModal(button); + await AuthorizeDAppModal.clickButton(button); }); Then(/^I click "(Confirm|Cancel)" button in DApp collateral window/, async (button: 'Confirm' | 'Cancel') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await (button === 'Confirm' ? collateralDAppPage.clickAcceptButton() : collateralDAppPage.clickCancelButton()); }); Then( /^I click "(Add funds|Cancel)" button in DApp insufficient funds window/, async (button: 'Add funds' | 'Cancel') => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await (button === 'Add funds' ? InsufficientFundsDAppPage.clickAddFundsButton() : InsufficientFundsDAppPage.clickCancelButton()); @@ -187,20 +191,20 @@ Then( ); When(/^I click "Create or restore a wallet" button in DApp no wallet modal$/, async () => { - await DAppConnectorPageObject.clickCreateRestoreButtonInDAppNoWalletModal(); + await NoWalletModal.clickCreateRestoreButton(); }); Then( /^I click "(Back|Disconnect DApp)" button in DApp removal confirmation modal$/, async (button: 'Back' | 'Disconnect DApp') => { - await DAppConnectorPageObject.clickButtonInDAppRemovalConfirmationModal(button); + await RemoveDAppModal.clickButton(button); } ); Then( /^I see Lace wallet info in DApp when (not connected|connected)$/, async (isConnected: 'not connected' | 'connected') => { - await DAppConnectorPageObject.switchToTestDAppWindow(); + await DAppConnectorUtils.switchToTestDAppWindow(); isConnected === 'connected' ? await DAppConnectorAssert.assertWalletFoundAndConnectedInTestDApp() : await DAppConnectorAssert.assertWalletFoundButNotConnectedInTestDApp(); @@ -218,28 +222,28 @@ Then(/^I see "Authorized DApps" section empty state in (extended|popup) mode$/, Then(/^I see test DApp on the Authorized DApps list$/, async () => { const expectedDApp: ExpectedDAppDetails = { hasLogo: true, - name: DAppConnectorPageObject.TEST_DAPP_NAME, - url: DAppConnectorPageObject.TEST_DAPP_URL.split('/')[2] + name: DAppConnectorUtils.TEST_DAPP_NAME, + url: DAppConnectorUtils.TEST_DAPP_URL.split('/')[2] }; await DAppConnectorAssert.assertSeeAuthorizedDAppsOnTheList([expectedDApp]); }); When(/^I open and authorize test DApp with "(Always|Only once)" setting$/, async (mode: 'Always' | 'Only once') => { - await DAppConnectorPageObject.openTestDApp(); - await DAppConnectorPageObject.switchToDappConnectorPopupAndAuthorizeWithRetry(testDAppDetails, mode); + await DAppConnectorUtils.openTestDApp(); + await DAppConnectorUtils.switchToDappConnectorPopupAndAuthorizeWithRetry(testDAppDetails, mode); }); Then(/^I de-authorize all DApps in (extended|popup) mode$/, async (mode: 'extended' | 'popup') => { - await DAppConnectorPageObject.deauthorizeAllDApps(mode); + await DAppConnectorUtils.deauthorizeAllDApps(mode); mode === 'extended' ? await extendedView.visit() : await popupView.visit(); }); Then(/^I de-authorize test DApp in (extended|popup) mode$/, async (mode: 'extended' | 'popup') => { - await DAppConnectorPageObject.deauthorizeDApp(DAppConnectorPageObject.TEST_DAPP_NAME, mode); + await DAppConnectorUtils.deauthorizeDApp(DAppConnectorUtils.TEST_DAPP_NAME, mode); }); When(/^I click "(Set Collateral|Sign data)" button in test DApp$/, async (button: 'Set Collateral' | 'Sign data') => { - await DAppConnectorPageObject.switchToTestDAppWindow(); + await DAppConnectorUtils.switchToTestDAppWindow(); await browser.pause(1000); switch (button) { case 'Set Collateral': @@ -254,7 +258,7 @@ When(/^I click "(Set Collateral|Sign data)" button in test DApp$/, async (button }); Then(/^I click "(Send ADA|Send Token)" "Run" button in test DApp$/, async (runButton: 'Send ADA' | 'Send Token') => { - await DAppConnectorPageObject.switchToTestDAppWindow(); + await DAppConnectorUtils.switchToTestDAppWindow(); await browser.pause(1000); const handlesBeforeClick = (await browser.getWindowHandles()).length; @@ -288,13 +292,13 @@ Then(/^I click "(Send ADA|Send Token)" "Run" button in test DApp$/, async (runBu }); Then(/^I click "Send ADA" "Run" button in test DApp without retry$/, async () => { - await DAppConnectorPageObject.switchToTestDAppWindow(); + await DAppConnectorUtils.switchToTestDAppWindow(); await browser.pause(1000); await TestDAppPage.sendAdaRunButton.click(); }); Then(/^I click "(Send ADA|Send Token)" button in test DApp$/, async (buttonId: 'Send ADA' | 'Send Token') => { - await DAppConnectorPageObject.switchToTestDAppWindow(); + await DAppConnectorUtils.switchToTestDAppWindow(); switch (buttonId) { case 'Send ADA': await TestDAppPage.sendAdaOption.click(); @@ -325,7 +329,7 @@ Then(/^I click "Close" button on DApp "All done" page$/, async () => { }); Then(/^I save fee value on DApp "Confirm transaction" page$/, async () => { - await DAppConnectorPageObject.saveDappTransactionFeeValue(); + await ConfirmTransactionPage.saveDAppTransactionFeeValue(); }); Then(/^I set send to wallet address to: "([^"]*)" in test DApp$/, async (walletName: string) => { diff --git a/packages/e2e-tests/src/steps/governanceSteps.ts b/packages/e2e-tests/src/steps/governanceSteps.ts index 7bcdebee9d..16c1efab33 100644 --- a/packages/e2e-tests/src/steps/governanceSteps.ts +++ b/packages/e2e-tests/src/steps/governanceSteps.ts @@ -2,7 +2,7 @@ import { DataTable, Then, When } from '@cucumber/cucumber'; import CIP95TestDApp from '../elements/CIP95TestDApp'; import DAppConnectorAssert, { ExpectedDAppDetails } from '../assert/dAppConnectorAssert'; import CIP95StaticMethodsAssert from '../assert/CIP95StaticMethodsAssert'; -import DAppConnectorPageObject from '../pageobject/dAppConnectorPageObject'; +import DAppConnectorUtils from '../utils/DAppConnectorUtils'; import { browser } from '@wdio/globals'; const testDAppDetails: ExpectedDAppDetails = { @@ -16,7 +16,7 @@ When(/^I open CIP-95 test DApp$/, async () => { }); Then(/^I see CIP-95 test DApp authorization window$/, async () => { - await DAppConnectorPageObject.waitAndSwitchToDAppConnectorWindow(3); + await DAppConnectorUtils.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAuthorizeDAppPage(testDAppDetails); }); diff --git a/packages/e2e-tests/src/pageobject/dAppConnectorPageObject.ts b/packages/e2e-tests/src/utils/DAppConnectorUtils.ts similarity index 70% rename from packages/e2e-tests/src/pageobject/dAppConnectorPageObject.ts rename to packages/e2e-tests/src/utils/DAppConnectorUtils.ts index e3f94b8683..44e4724212 100644 --- a/packages/e2e-tests/src/pageobject/dAppConnectorPageObject.ts +++ b/packages/e2e-tests/src/utils/DAppConnectorUtils.ts @@ -1,21 +1,18 @@ import { browser } from '@wdio/globals'; -import { waitUntilExpectedNumberOfHandles } from '../utils/window'; +import { waitUntilExpectedNumberOfHandles } from './window'; import AuthorizeDappPage from '../elements/dappConnector/authorizeDAppPage'; import AuthorizeDappModal from '../elements/dappConnector/authorizeDAppModal'; import extendedView from '../page/extendedView'; -import settingsExtendedPageObject from './settingsExtendedPageObject'; +import settingsExtendedPageObject from '../pageobject/settingsExtendedPageObject'; import AuthorizedDappsPage from '../elements/dappConnector/authorizedDAppsPage'; import popupView from '../page/popupView'; import ToastMessage from '../elements/toastMessage'; import RemoveDAppModal from '../elements/dappConnector/removeDAppModal'; -import testContext from '../utils/testContext'; -import ConfirmTransactionPage from '../elements/dappConnector/confirmTransactionPage'; -import NoWalletModal from '../elements/dappConnector/noWalletModal'; import DAppConnectorAssert, { ExpectedDAppDetails } from '../assert/dAppConnectorAssert'; import { Logger } from '../support/logger'; import TestDAppPage from '../elements/dappConnector/testDAppPage'; -class DAppConnectorPageObject { +class DAppConnectorUtils { TEST_DAPP_URL = this.getTestDAppUrl(); TEST_DAPP_NAME = 'React App'; DAPP_CONNECTOR_WINDOW_HANDLE = 'dappConnector.html'; @@ -51,29 +48,6 @@ class DAppConnectorPageObject { await browser.switchWindow(this.TEST_DAPP_NAME); } - async clickButtonInDAppAuthorizationWindow(button: 'Authorize' | 'Cancel') { - await AuthorizeDappPage.authorizeButton.waitForDisplayed(); - button === 'Authorize' - ? await AuthorizeDappPage.authorizeButton.click() - : await AuthorizeDappPage.cancelButton.click(); - } - - async clickButtonInDAppAuthorizationModal(button: 'Always' | 'Only once') { - await browser.pause(500); - await AuthorizeDappModal.alwaysButton.waitForDisplayed(); - button === 'Always' ? await AuthorizeDappModal.alwaysButton.click() : await AuthorizeDappModal.onceButton.click(); - } - - async clickButtonInDAppRemovalConfirmationModal(button: 'Back' | 'Disconnect DApp') { - await RemoveDAppModal.cancelButton.waitForDisplayed(); - button === 'Back' ? await RemoveDAppModal.cancelButton.click() : await RemoveDAppModal.confirmButton.click(); - } - - async clickCreateRestoreButtonInDAppNoWalletModal() { - await NoWalletModal.createRestoreButton.waitForDisplayed(); - await NoWalletModal.createRestoreButton.click(); - } - async deauthorizeAllDApps(mode: 'extended' | 'popup') { mode === 'extended' ? await extendedView.visitSettings() : await popupView.visitSettings(); await settingsExtendedPageObject.clickSettingsItem('Authorized DApps'); @@ -101,16 +75,11 @@ class DAppConnectorPageObject { } } - async saveDappTransactionFeeValue() { - const [feeValue] = (await ConfirmTransactionPage.transactionFeeValueAda.getText()).split(' '); - await testContext.save('feeValueDAppTx', feeValue); - } - async switchToDappConnectorPopupAndAuthorize(testDAppDetails: ExpectedDAppDetails, mode: 'Always' | 'Only once') { await this.waitAndSwitchToDAppConnectorWindow(3); await DAppConnectorAssert.assertSeeAuthorizeDAppPage(testDAppDetails); - await this.clickButtonInDAppAuthorizationWindow('Authorize'); - await this.clickButtonInDAppAuthorizationModal(mode); + await AuthorizeDappPage.clickButton('Authorize'); + await AuthorizeDappModal.clickButton(mode); await this.switchToTestDAppWindow(); await DAppConnectorAssert.waitUntilBalanceNotEmpty(); } @@ -140,4 +109,4 @@ class DAppConnectorPageObject { } } -export default new DAppConnectorPageObject(); +export default new DAppConnectorUtils(); diff --git a/packages/e2e-tests/src/utils/cucumberDataHelper.ts b/packages/e2e-tests/src/utils/cucumberDataHelper.ts index e2d6c9231d..bcfd9ed417 100644 --- a/packages/e2e-tests/src/utils/cucumberDataHelper.ts +++ b/packages/e2e-tests/src/utils/cucumberDataHelper.ts @@ -1,3 +1,30 @@ import { DataTable } from '@cucumber/cucumber'; +import ConfirmTransactionPage from '../elements/dappConnector/confirmTransactionPage'; +import { getTestWallet } from '../support/walletConfiguration'; export const dataTableAsStringArray = (options: DataTable): string[] => options.raw().map((array) => array[0]); + +const subtractFeeFromCucumberListElement = async (entry: string) => { + const fee = Number((await ConfirmTransactionPage.transactionFeeValueAda.getText()).split(' ')[0]); + const [amount, currency] = entry.split(' '); + const amountIncludingFee = (Number(amount) - fee).toFixed(2); + return `${amountIncludingFee} ${currency}`; +}; + +const shortenAddressFromCucumberListElement = (wallet: string) => { + const [addressLabel, walletValue, source] = wallet.split(' '); + const fullAddress = String(getTestWallet(walletValue).accounts[0].address); + return `${addressLabel} ${fullAddress.slice(0, 8)}...${fullAddress.slice(-8)} ${source}`; +}; + +export const parseDAppCucumberAssetList = async (assetsList: string[]): Promise => + await Promise.all( + assetsList.map(async (asset) => { + if (asset.includes('- FEE')) { + return await subtractFeeFromCucumberListElement(asset); + } else if (asset.includes('Address')) { + return shortenAddressFromCucumberListElement(asset); + } + return asset; + }) + ); diff --git a/packages/e2e-tests/src/utils/dappConnectorUtils.ts b/packages/e2e-tests/src/utils/dappConnectorUtils.ts deleted file mode 100644 index 5720e2b602..0000000000 --- a/packages/e2e-tests/src/utils/dappConnectorUtils.ts +++ /dev/null @@ -1,27 +0,0 @@ -import ConfirmTransactionPage from '../elements/dappConnector/confirmTransactionPage'; -import { getTestWallet } from '../support/walletConfiguration'; - -const subtractFeeFromCucumberListElement = async (entry: string) => { - const fee = Number((await ConfirmTransactionPage.transactionFeeValueAda.getText()).split(' ')[0]); - const [amount, currency] = entry.split(' '); - const amountIncludingFee = (Number(amount) - fee).toFixed(2); - return `${amountIncludingFee} ${currency}`; -}; - -const shortenAddressFromCucumberListElement = (wallet: string) => { - const [addressLabel, walletValue, source] = wallet.split(' '); - const fullAddress = String(getTestWallet(walletValue).accounts[0].address); - return `${addressLabel} ${fullAddress.slice(0, 8)}...${fullAddress.slice(-8)} ${source}`; -}; - -export const parseDappCucumberAssetList = async (assetsList: string[]): Promise => - await Promise.all( - assetsList.map(async (asset) => { - if (asset.includes('- FEE')) { - return await subtractFeeFromCucumberListElement(asset); - } else if (asset.includes('Address')) { - return shortenAddressFromCucumberListElement(asset); - } - return asset; - }) - ); From b3fd96434fad1d22850fb2517aaa776b362649bb Mon Sep 17 00:00:00 2001 From: wklos-iohk Date: Wed, 29 Jan 2025 10:05:54 +0100 Subject: [PATCH 2/2] test(extension): adjust waiting for button clickability --- .../e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts | 2 +- .../e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts index 54d61bd041..92493336fc 100644 --- a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts +++ b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppModal.ts @@ -31,7 +31,7 @@ class AuthorizeDAppModal { async clickButton(button: 'Always' | 'Only once'): Promise { await browser.pause(500); - await this.alwaysButton.waitForDisplayed(); + await this.alwaysButton.waitForClickable(); button === 'Always' ? await this.alwaysButton.click() : await this.onceButton.click(); } } diff --git a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts index acd18445a3..3468b1fd1f 100644 --- a/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts +++ b/packages/e2e-tests/src/elements/dappConnector/authorizeDAppPage.ts @@ -35,7 +35,7 @@ class AuthorizeDAppPage extends CommonDappPageElements { } async clickButton(button: 'Authorize' | 'Cancel'): Promise { - await this.authorizeButton.waitForDisplayed(); + await this.authorizeButton.waitForClickable(); button === 'Authorize' ? await this.authorizeButton.click() : await this.cancelButton.click(); } }