Skip to content

Commit 08a708b

Browse files
authored
test: speed up filling address input and metadata input (#1941)
1 parent a787b86 commit 08a708b

File tree

8 files changed

+59
-26
lines changed

8 files changed

+59
-26
lines changed

packages/e2e-tests/src/elements/AddressInput.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-undef */
22
import { ChainablePromiseElement } from 'webdriverio';
3+
import { browser } from '@wdio/globals';
4+
import { pasteValueIntoInputField } from '../utils/inputFieldUtils';
35

46
export class AddressInput {
57
protected CONTAINER = '//div[@data-testid="address-input"]';
@@ -47,9 +49,21 @@ export class AddressInput {
4749
return $(this.ADA_HANDLE_INPUT_ERROR);
4850
}
4951

50-
fillAddress = async (address: string): Promise<void> => {
52+
fillAddress = async (address: string, method: 'keys' | 'paste' | 'setValue' = 'setValue'): Promise<void> => {
5153
await this.input.waitForClickable();
52-
await this.input.setValue(address);
54+
switch (method) {
55+
case 'paste':
56+
await pasteValueIntoInputField(await this.input, address);
57+
break;
58+
case 'keys':
59+
await this.input.click();
60+
await browser.keys(address);
61+
break;
62+
case 'setValue':
63+
default:
64+
await this.input.setValue(address);
65+
break;
66+
}
5367
};
5468

5569
fillAddressWithFirstChars = async (address: string, characters: number): Promise<void> => {

packages/e2e-tests/src/elements/newTransaction/transactionNewPage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CommonDrawerElements from '../CommonDrawerElements';
88
import testContext from '../../utils/testContext';
99
import { generateRandomString } from '../../utils/textUtils';
1010
import { browser } from '@wdio/globals';
11+
import { pasteValueIntoInputField } from '../../utils/inputFieldUtils';
1112

1213
class TransactionNewPage extends CommonDrawerElements {
1314
private CONTAINER = '//div[@class="ant-drawer-body"]';
@@ -165,7 +166,7 @@ class TransactionNewPage extends CommonDrawerElements {
165166

166167
fillMetadata = async (characters: number) => {
167168
const text = await generateRandomString(characters);
168-
await this.metadataInputField.setValue(text);
169+
await pasteValueIntoInputField(await this.metadataInputField, text);
169170
};
170171

171172
saveMetadata = async () => {

packages/e2e-tests/src/helpers/NFTPageHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const progressWithSendUntilPasswordPage = async (
3737
const receiverAddress = extensionUtils.isMainnet()
3838
? String(receiverWallet.accounts[0].mainnetAddress)
3939
: String(receiverWallet.accounts[0].address);
40-
await new AddressInput().fillAddress(receiverAddress);
40+
await new AddressInput().fillAddress(receiverAddress, 'paste');
4141
await TransactionNewPage.coinConfigure(1).fillTokenValue(1);
4242
await TransactionNewPage.reviewTransactionButton.waitForClickable({ timeout: 15_000 });
4343
await TransactionNewPage.reviewTransactionButton.click();

packages/e2e-tests/src/pageobject/newTransactionExtendedPageObject.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { scrollToTheTop } from '../utils/scrollUtils';
1010

1111
export default new (class NewTransactionExtendedPageObject {
1212
async setTwoAssetsForBundle(bundleIndex: number, assetValue1: number, assetValue2: number) {
13-
await new AddressInput(bundleIndex).fillAddress(byron.getAddress());
13+
await new AddressInput(bundleIndex).fillAddress(byron.getAddress(), 'paste');
1414
await new AssetInput(bundleIndex).clickAddAssetButton();
1515
await TokenSelectionPage.clickOnToken(extensionUtils.isMainnet() ? Asset.HOSKY_TOKEN.name : Asset.LACE_COIN.name);
1616
await TransactionNewPage.coinConfigure(bundleIndex, Asset.CARDANO.ticker).fillTokenValue(assetValue1);
@@ -24,7 +24,7 @@ export default new (class NewTransactionExtendedPageObject {
2424
await this.setTwoAssetsForBundle(1, 2, 1);
2525
await TransactionNewPage.addBundleButton.waitForClickable();
2626
await TransactionNewPage.addBundleButton.click();
27-
await new AddressInput(2).fillAddress(shelley.getAddress());
27+
await new AddressInput(2).fillAddress(shelley.getAddress(), 'paste');
2828
await TransactionNewPage.coinConfigure(2, Asset.CARDANO.ticker).clickCoinSelectorName();
2929
await TokenSelectionPage.clickNFTsButton();
3030
await TokenSelectionPage.clickNftItemInAssetSelector(Asset.IBILECOIN.name);
@@ -43,7 +43,7 @@ export default new (class NewTransactionExtendedPageObject {
4343
}
4444

4545
async setOneBundleWithMultipleAssets() {
46-
await new AddressInput(1).fillAddress(shelley.getAddress());
46+
await new AddressInput(1).fillAddress(shelley.getAddress(), 'paste');
4747
await new AssetInput(1).clickAddAssetButton();
4848
await TokenSelectionPage.clickOnToken(extensionUtils.isMainnet() ? Asset.HOSKY_TOKEN.name : Asset.LACE_COIN.name);
4949
await new AssetInput(1).clickAddAssetButton();

packages/e2e-tests/src/steps/onboardingSteps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ Given(
263263
/^I enter wallet name: "([^"]*)", password: "([^"]*)" and password confirmation: "([^"]*)"$/,
264264
async (walletName: string, password: string, passwordConfirmation: string) => {
265265
await OnboardingWalletSetupPage.setWalletNameInput(walletName);
266-
await OnboardingWalletSetupPage.setWalletPasswordInput(password);
267-
await OnboardingWalletSetupPage.setWalletPasswordConfirmInput(passwordConfirmation);
266+
password.length > 0 && (await OnboardingWalletSetupPage.setWalletPasswordInput(password));
267+
passwordConfirmation.length > 0 &&
268+
(await OnboardingWalletSetupPage.setWalletPasswordConfirmInput(passwordConfirmation));
268269
}
269270
);
270271

packages/e2e-tests/src/steps/sendTransactionBundleSteps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ When(/^I remove bundle (\d)$/, async (index: number) => {
2525
});
2626

2727
When(/^I set multiple outputs for advanced transaction$/, async () => {
28-
await new AddressInput(1).fillAddress(shelley.getAddress());
28+
await new AddressInput(1).fillAddress(shelley.getAddress(), 'paste');
2929
await TransactionNewPage.coinConfigure(1, Asset.CARDANO.name).fillTokenValue(1);
3030
await TransactionNewPage.addBundleButton.click();
31-
await new AddressInput(2).fillAddress(shelley.getAddress());
31+
await new AddressInput(2).fillAddress(shelley.getAddress(), 'paste');
3232
await TransactionNewPage.coinConfigure(2, Asset.CARDANO.name).fillTokenValue(2);
3333
});
3434

3535
When(/^I set multiple outputs for advanced transaction with less than minimum value for Byron address$/, async () => {
36-
await new AddressInput(1).fillAddress(byron.getAddress());
36+
await new AddressInput(1).fillAddress(byron.getAddress(), 'paste');
3737
await TransactionNewPage.coinConfigure(1, Asset.CARDANO.ticker).fillTokenValue(1);
3838
await TransactionNewPage.addBundleButton.click();
39-
await new AddressInput(2).fillAddress(byron.getAddress());
39+
await new AddressInput(2).fillAddress(byron.getAddress(), 'paste');
4040
await TransactionNewPage.coinConfigure(2, Asset.CARDANO.ticker).fillTokenValue(2);
4141
});
4242

packages/e2e-tests/src/steps/sendTransactionSimpleSteps.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ When(
9898
addr = address;
9999
break;
100100
}
101-
await new AddressInput(inputIndex).fillAddress(addr);
101+
await new AddressInput(inputIndex).fillAddress(addr, 'paste');
102102
}
103103
);
104104

105105
When(/I enter "([^"]*)" in the bundle (\d+) recipient's address/, async (value: string, inputIndex: number) => {
106-
await new AddressInput(inputIndex).fillAddress(value);
106+
await new AddressInput(inputIndex).fillAddress(value, 'paste');
107107
});
108108

109109
When(/I enter the first characters of the contacts/, async () => {
@@ -164,13 +164,13 @@ Then(
164164
Then(
165165
/I enter an address that matches the amount of characters but does not match with the checksum into address input (\d+)/,
166166
async (inputIndex: number) => {
167-
await new AddressInput(inputIndex).fillAddress(shelleyInvalid.getAddress());
167+
await new AddressInput(inputIndex).fillAddress(shelleyInvalid.getAddress(), 'paste');
168168
}
169169
);
170170

171171
Then(/I enter more or less characters than the required for an address in the bundle recipient's address/, async () => {
172172
const addressInput = new AddressInput();
173-
await addressInput.fillAddress(shelley.getAddress());
173+
await addressInput.fillAddress(shelley.getAddress(), 'paste');
174174
await addressInput.addToAddress('a');
175175
});
176176

@@ -223,7 +223,7 @@ When(
223223
/^I fill bundle (\d+) with "([^"]*)" (main|other multiaddress|second account) address with following assets:$/,
224224
async (bundleIndex, walletName, addressType: AddressType, options) => {
225225
const addressInput = new AddressInput(bundleIndex);
226-
await addressInput.fillAddress(parseWalletAddress(walletName, addressType));
226+
await addressInput.fillAddress(parseWalletAddress(walletName, addressType), 'paste');
227227
await addressInput.searchLoader.waitForDisplayed({ reverse: true });
228228
// Close address dropdown menu if exists
229229
if (await TransactionNewPage.addressBookSearchResultRow(1).isExisting()) {
@@ -252,13 +252,13 @@ When(
252252

253253
When(/^I fill bundle with copied address and ([^"]*) ADA$/, async (adaValue: string) => {
254254
const addressInput = new AddressInput(1);
255-
await addressInput.fillAddress(await clipboard.read());
255+
await addressInput.fillAddress(await clipboard.read(), 'paste');
256256
await TransactionNewPage.coinConfigure(1, Asset.CARDANO.ticker).fillTokenValue(Number.parseFloat(adaValue));
257257
});
258258

259259
When(/^I fill bundle with saved unused address and ([^"]*) ADA$/, async (adaValue: string) => {
260260
const addressInput = new AddressInput(1);
261-
await addressInput.fillAddress(await walletAddressPage.getSavedLastAddress());
261+
await addressInput.fillAddress(await walletAddressPage.getSavedLastAddress(), 'paste');
262262
await TransactionNewPage.coinConfigure(1, Asset.CARDANO.ticker).fillTokenValue(Number.parseFloat(adaValue));
263263
});
264264

@@ -337,21 +337,21 @@ Then(
337337
);
338338

339339
Then(/^Ive entered accepted values for all fields of simple Tx$/, async () => {
340-
await new AddressInput().fillAddress(shelley.getAddress());
340+
await new AddressInput().fillAddress(shelley.getAddress(), 'paste');
341341
await TransactionNewPage.coinConfigure(1).fillTokenValue(1);
342342
});
343343

344344
Then(
345345
/^I've entered accepted values for all (Preprod|Mainnet) fields of simple Tx$/,
346346
async (network: 'Preprod' | 'Mainnet') => {
347347
const address = network === 'Mainnet' ? shelley.getMainnetAddress() : shelley.getTestnetAddress();
348-
await new AddressInput().fillAddress(address);
348+
await new AddressInput().fillAddress(address, 'paste');
349349
await TransactionNewPage.coinConfigure(1).fillTokenValue(1);
350350
}
351351
);
352352

353353
Then(/^Ive entered accepted values for all fields of simple Tx for Byron with less than minimum value$/, async () => {
354-
await new AddressInput().fillAddress(byron.getAddress());
354+
await new AddressInput().fillAddress(byron.getAddress(), 'paste');
355355
await TransactionNewPage.coinConfigure(1).fillTokenValue(0.5);
356356
});
357357

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
/* eslint-disable no-undef */
1+
/* global WebdriverIO */
22
import { browser } from '@wdio/globals';
3+
import clipboard from 'clipboardy';
34

45
export const clearInputFieldValue = async (element: string | WebdriverIO.Element): Promise<void> => {
5-
await (typeof element !== 'string' ? element.click() : $(element).click());
6-
process.platform === 'darwin' ? await browser.keys(['Command', 'a']) : await browser.keys(['Control', 'a']);
6+
const resolvedElement = typeof element === 'string' ? await $(element) : element;
7+
await resolvedElement.waitForClickable();
8+
await resolvedElement.click();
9+
const modifierKey = process.platform === 'darwin' ? 'Meta' : 'Control';
10+
await browser.keys([modifierKey, 'a']);
711
await browser.keys('Backspace');
812
};
913

1014
export const setInputFieldValue = async (element: string | WebdriverIO.Element, value: string): Promise<void> => {
1115
await clearInputFieldValue(element);
1216
await (typeof element !== 'string' ? element.setValue(value) : $(element).setValue(value));
1317
};
18+
19+
export const pasteValueIntoInputField = async (element: string | WebdriverIO.Element, value: string): Promise<void> => {
20+
try {
21+
await clipboard.write(value);
22+
const resolvedElement = typeof element === 'string' ? await $(element) : element;
23+
await resolvedElement.waitForClickable();
24+
await resolvedElement.click();
25+
const modifierKey = process.platform === 'darwin' ? 'Meta' : 'Control';
26+
await browser.keys([modifierKey, 'v']);
27+
} catch (error) {
28+
throw new Error(`Failed to paste value into input field: ${error}`);
29+
}
30+
};

0 commit comments

Comments
 (0)