Skip to content

Commit

Permalink
test(extension): refactor Transaction Bundle class POM
Browse files Browse the repository at this point in the history
  • Loading branch information
wklos-iohk committed Apr 16, 2024
1 parent d7d5505 commit 4b9543b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 93 deletions.
36 changes: 0 additions & 36 deletions packages/e2e-tests/src/actor/webTester.ts
Expand Up @@ -7,42 +7,6 @@ import { Logger } from '../support/logger';
export type LocatorStrategy = 'css selector' | 'xpath';

export default new (class WebTester {
async seeElement(selector: string, reverseOrder = false, timeoutMs = 3000) {
Logger.log(`Assert see element ${selector}, reverse = ${reverseOrder}`);
const shouldBeFound = reverseOrder ? 'should not be found' : 'should be found';
await $(selector).waitForDisplayed({
timeout: timeoutMs,
interval: 500,
reverse: reverseOrder,
timeoutMsg: `element: ${selector} ${shouldBeFound} after: ${timeoutMs}ms`
});
}

async seeWebElement(element: WebElement) {
await this.seeElement(element.toJSLocator());
}

async clickOnElement(selector: string, locatorStrategy?: LocatorStrategy): Promise<void> {
Logger.log(`Click on ${selector} [strategy=${locatorStrategy ?? 'css selector'}]`);
const element = await $(selector);
await element.waitForDisplayed();
await element
.waitForClickable({ timeout: 5000 })
.then(async () => await $(element).click())
.catch(() => {
throw new Error(`Element ${selector} not clickable`);
});
}

async clickElement(element: WebElement, retries?: number): Promise<void> {
if (retries && retries > 0 && (await (await $(element.toJSLocator())).isDisplayed())) {
await browser.pause(500);
await this.clickElement(element, retries - 1);
} else {
await this.clickOnElement(element.toJSLocator(), element.locatorStrategy());
}
}

async getTextValueFromElement(element: WebElement): Promise<string | number> {
return await this.getTextValue(element.toJSLocator());
}
Expand Down
18 changes: 7 additions & 11 deletions packages/e2e-tests/src/assert/drawerSendExtendedAssert.ts
Expand Up @@ -206,8 +206,7 @@ class DrawerSendExtendedAssert {

async assertDefaultInputsDoNotContainValues() {
const coinConfigure = new CoinConfigure();
const addressInput = new AddressInput();
expect(await addressInput.input.getValue()).to.be.empty;
expect(await new AddressInput().input.getValue()).to.be.empty;
expect(await coinConfigure.input.getValue()).to.equal('0.00');
}

Expand Down Expand Up @@ -304,10 +303,10 @@ class DrawerSendExtendedAssert {
expect(await TransactionNewPage.metadataInputField.getValue()).to.be.empty;
}

async assertSeeIncorrectAddressError(shouldSee: boolean) {
await new TransactionBundle().bundleAddressInputError.waitForDisplayed({ reverse: !shouldSee });
async assertSeeIncorrectAddressError(bundleIndex: number, shouldSee: boolean) {
await new TransactionBundle(bundleIndex).bundleAddressInputError.waitForDisplayed({ reverse: !shouldSee });
if (shouldSee) {
expect(await new TransactionBundle().bundleAddressInputError.getText()).to.equal(
expect(await new TransactionBundle(bundleIndex).bundleAddressInputError.getText()).to.equal(
await t('general.errors.incorrectAddress')
);
}
Expand Down Expand Up @@ -368,8 +367,7 @@ class DrawerSendExtendedAssert {
}

async assertSeeIconForInvalidAdaHandle(shouldBeDisplayed: boolean) {
const addressInput = new AddressInput();
await addressInput.invalidAdaHandleIcon.waitForDisplayed({ reverse: !shouldBeDisplayed });
await new AddressInput().invalidAdaHandleIcon.waitForDisplayed({ reverse: !shouldBeDisplayed });
}

async assertSeeAdaHandleError(shouldBeDisplayed: boolean) {
Expand All @@ -381,13 +379,11 @@ class DrawerSendExtendedAssert {
}

async assertSeeSearchLoader(shouldBeDisplayed: boolean) {
const addressInput = new AddressInput();
await addressInput.searchLoader.waitForDisplayed({ reverse: !shouldBeDisplayed, interval: 50 });
await new AddressInput().searchLoader.waitForDisplayed({ reverse: !shouldBeDisplayed, interval: 50 });
}

async assertAddressBookButtonEnabled(bundleIndex: number, shouldBeEnabled: boolean) {
const addressInput = new AddressInput(bundleIndex);
await addressInput.ctaButton.waitForEnabled({ reverse: !shouldBeEnabled });
await new AddressInput(bundleIndex).ctaButton.waitForEnabled({ reverse: !shouldBeEnabled });
}

async assertSeeReviewAddressBanner(handle: string) {
Expand Down
@@ -1,41 +1,37 @@
import { expect } from 'chai';
import webTester from '../../actor/webTester';
import { TransactionBundle } from '../../elements/newTransaction/transactionBundle';
import coinConfigureAssert from '../coinConfigureAssert';
import assetInputAssert from '../assetInputAssert';
import TransactionNewPage from '../../elements/newTransaction/transactionNewPage';
import { t } from '../../utils/translationService';
import { CoinConfigure } from '../../elements/newTransaction/coinConfigure';
import { AssetInput } from '../../elements/newTransaction/assetInput';
import { AddressInput } from '../../elements/AddressInput';

class TransactionBundleAssert {
assertSeeBundles = async (expectedNumberOfBundles: number) => {
for (let i = 1; i <= expectedNumberOfBundles; i++) {
const bundle = new TransactionBundle(i);
if (expectedNumberOfBundles > 1) {
expect(await webTester.getTextValueFromElement(bundle.bundleTitle())).to.equal(
`${await t('core.outputSummaryList.output')} ${i}`
);
await webTester.seeWebElement(bundle.bundleRemoveButton());
await bundle.bundleTitle.waitForDisplayed();
expect(await bundle.bundleTitle.getText()).to.equal(`${await t('core.outputSummaryList.output')} ${i}`);
await bundle.bundleRemoveButton.waitForDisplayed();
}
await new AddressInput(i).input.waitForDisplayed();
await bundle.bundleAddressInput.input.waitForDisplayed();
await coinConfigureAssert.assertSeeCoinConfigure();
await assetInputAssert.assertSeeAssetInput(i);
}
};

async assertSeeTokenNameInBundleAndCoinConfigure(expectedName: string, bundleIndex: number) {
await TransactionNewPage.cancelTransactionButton.waitForStable();
const tokenName = await new TransactionBundle(bundleIndex)
.bundleAssetInput()
const tokenName = await new TransactionBundle(bundleIndex).bundleAssetInput
.coinConfigure(bundleIndex, expectedName.replace('...', ''))
.nameElement.getText();
expect(tokenName).to.contain(expectedName);
}

async assertSeeAssetNameAndValueInBundle(expectedName: string, expectedValue: number, bundleIndex: number) {
const asset = new TransactionBundle(bundleIndex).bundleAssetInput().coinConfigure(bundleIndex, expectedName);
const asset = new TransactionBundle(bundleIndex).bundleAssetInput.coinConfigure(bundleIndex, expectedName);

const tokenName = await asset.nameElement.getText();
const tokenValue = await asset.getAmount();
Expand Down
42 changes: 19 additions & 23 deletions packages/e2e-tests/src/elements/newTransaction/transactionBundle.ts
@@ -1,50 +1,46 @@
/* eslint-disable no-undef */
import { LocatorStrategy } from '../../actor/webTester';
import { WebElement, WebElementFactory as Factory } from '../webElement';
import { AddressInput } from '../AddressInput';
import { AssetInput } from './assetInput';
import { ChainablePromiseElement } from 'webdriverio';

export class TransactionBundle extends WebElement {
export class TransactionBundle {
protected CONTAINER = '//div[@data-testid="asset-bundle-container"]';
private BUNDLE_TITLE = '//h5[@data-testid="asset-bundle-title"]';
private BUNDLE_REMOVE_BUTTON = '//button[@data-testid="asset-bundle-remove-button"]';
private ADDRESS_INPUT_ERROR = '[data-testid="address-input-error"]';
readonly index: number = 1;

constructor(index?: number) {
super();
this.CONTAINER = typeof index === 'undefined' ? this.CONTAINER : `(${this.CONTAINER})[${index}]`;
constructor(index = 1) {
this.index = index;
this.CONTAINER = `(${this.CONTAINER})[${index}]`;
}

container(): WebElement {
return Factory.fromSelector(`${this.CONTAINER}`, 'xpath');
get container(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.CONTAINER);
}

bundleTitle(): WebElement {
return Factory.fromSelector(`${this.CONTAINER}${this.BUNDLE_TITLE}`, 'xpath');
get bundleTitle(): ChainablePromiseElement<WebdriverIO.Element> {
return $(`${this.CONTAINER}${this.BUNDLE_TITLE}`);
}

bundleAddressInput(): AddressInput {
return new AddressInput();
get bundleAddressInput(): AddressInput {
return new AddressInput(this.index);
}

get bundleAddressInputError(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.CONTAINER).$(this.ADDRESS_INPUT_ERROR);
}

bundleAssetInput(): AssetInput {
return new AssetInput();
get bundleAssetInput(): AssetInput {
return new AssetInput(this.index);
}

bundleRemoveButton(): WebElement {
return Factory.fromSelector(`${this.CONTAINER}${this.BUNDLE_REMOVE_BUTTON}`, 'xpath');
get bundleRemoveButton(): ChainablePromiseElement<WebdriverIO.Element> {
return $(`${this.CONTAINER}${this.BUNDLE_REMOVE_BUTTON}`);
}

toJSLocator(): string {
return this.CONTAINER;
}

locatorStrategy(): LocatorStrategy {
return 'xpath';
}
clickRemoveBundleButton = async (): Promise<void> => {
await this.bundleRemoveButton.waitForClickable();
await this.bundleRemoveButton.click();
};
}
@@ -1,7 +1,6 @@
/* eslint-disable no-undef */
import { CoinConfigure } from './coinConfigure';
import { AddressInput } from '../AddressInput';
import { TransactionBundle } from './transactionBundle';
import { Asset } from '../../data/Asset';
import { ChainablePromiseElement } from 'webdriverio';
import Banner from '../banner';
Expand Down Expand Up @@ -40,10 +39,6 @@ class TransactionNewPage extends CommonDrawerElements {
return new CoinConfigure(bundleIndex, assetName);
}

transactionBundle(index?: number): TransactionBundle {
return new TransactionBundle(index);
}

get title() {
return this.drawerNavigationTitle;
}
Expand Down
@@ -1,6 +1,4 @@
import webTester from '../actor/webTester';
import TransactionNewPage from '../elements/newTransaction/transactionNewPage';
import { TransactionBundle } from '../elements/newTransaction/transactionBundle';
import TokenSelectionPage from '../elements/newTransaction/tokenSelectionPage';
import { Asset } from '../data/Asset';
import extensionUtils from '../utils/utils';
Expand All @@ -9,10 +7,6 @@ import { AssetInput } from '../elements/newTransaction/assetInput';
import { AddressInput } from '../elements/AddressInput';

export default new (class NewTransactionExtendedPageObject {
clickRemoveBundleButton = async (outputIndex: number) => {
await webTester.clickElement(new TransactionBundle(outputIndex).bundleRemoveButton());
};

async setTwoAssetsForBundle(bundleIndex: number, assetValue1: number, assetValue2: number) {
await new AddressInput(bundleIndex).fillAddress(byron.getAddress());
await new AssetInput(bundleIndex).clickAddAssetButton();
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/src/steps/sendTransactionBundleSteps.ts
Expand Up @@ -11,13 +11,14 @@ import TransactionNewPage from '../elements/newTransaction/transactionNewPage';
import { AssetInput } from '../elements/newTransaction/assetInput';
import { AddressInput } from '../elements/AddressInput';
import TransactionSubmittedPage from '../elements/newTransaction/transactionSubmittedPage';
import { TransactionBundle } from '../elements/newTransaction/transactionBundle';

Then(/^I see (\d) bundle rows$/, async (expectedNumberOfBundles: number) => {
await transactionBundlesAssert.assertSeeBundles(expectedNumberOfBundles);
});

When(/^I remove bundle (\d)$/, async (index: number) => {
await transactionExtendedPageObject.clickRemoveBundleButton(index);
await new TransactionBundle(index).clickRemoveBundleButton();
});

When(/^I set multiple outputs for advanced transaction$/, async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/src/steps/sendTransactionSimpleSteps.ts
Expand Up @@ -534,7 +534,7 @@ Then(/^Metadata input is empty$/, async () => {
});

Then(/^"Incorrect address" error (is|is not) displayed under address input field$/, async (state: 'is' | 'is not') => {
await drawerSendExtendedAssert.assertSeeIncorrectAddressError(state === 'is');
await drawerSendExtendedAssert.assertSeeIncorrectAddressError(1, state === 'is');
});

Then(/^"Review transaction" button is (enabled|disabled) on "Send" page$/, async (state: 'enabled' | 'disabled') => {
Expand Down

0 comments on commit 4b9543b

Please sign in to comment.