Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [POM] Migrate contract interaction with snap account e2e tests to page object modal #27924

Merged
merged 48 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
81823d8
Migrate create-snap-account.spec.ts to POM and move to test/e2e/tests…
devin-ai-integration[bot] Oct 8, 2024
bed4ad9
Merge remote-tracking branch 'origin/develop' into migrate-create-sna…
devin-ai-integration[bot] Oct 8, 2024
4943472
Migrate snap-account-transfers.spec.ts to Page Object Model
devin-ai-integration[bot] Oct 9, 2024
15c8b72
Move snap-account-transfers.spec.ts to account directory
devin-ai-integration[bot] Oct 9, 2024
d3daa11
fix
chloeYue Oct 9, 2024
f49961b
fix
chloeYue Oct 9, 2024
8dcd039
fix
chloeYue Oct 9, 2024
37edff5
fix
chloeYue Oct 9, 2024
6eaa27e
fix
chloeYue Oct 10, 2024
42a858c
fix
chloeYue Oct 10, 2024
7c3a90f
Merge branch 'develop' into migrate-snap-account-transfers-to-pom
chloeYue Oct 10, 2024
bf88ab1
fix lint
chloeYue Oct 10, 2024
b5add2b
use methods in pom
chloeYue Oct 10, 2024
eaa2163
Merge branch 'develop' into migrate-snap-account-transfers-to-pom
chloeYue Oct 10, 2024
b459736
fix
chloeYue Oct 10, 2024
a6a002c
fix
chloeYue Oct 10, 2024
6fa2d2e
fix
chloeYue Oct 10, 2024
eea19fc
fix firefox
chloeYue Oct 10, 2024
2c6e483
fix firefox
chloeYue Oct 10, 2024
6aa78c2
fix
chloeYue Oct 10, 2024
c4a9ce6
Migrate snap-account-signatures test to page object model
devin-ai-integration[bot] Oct 11, 2024
70e1279
Update dependencies after test migration
devin-ai-integration[bot] Oct 11, 2024
16b94f9
Revert commit 70e12791feb733d57cd76a5662c1e5022d7fffd4
devin-ai-integration[bot] Oct 11, 2024
abc245d
fix
chloeYue Oct 11, 2024
b94627a
corrections
chloeYue Oct 14, 2024
44b3bcf
Migrate snap account tests to page object model
devin-ai-integration[bot] Oct 15, 2024
8b51ec7
Revert changes in yarn.lock, tsconfig.json, and package.json
devin-ai-integration[bot] Oct 15, 2024
d1b8c6a
fix
chloeYue Oct 15, 2024
d88b0ba
fix
chloeYue Oct 15, 2024
54eb775
Merge branch 'develop' into migrate-snap-account-contract-interaction
chloeYue Oct 16, 2024
1918dac
fix
chloeYue Oct 17, 2024
896208e
remove unused code
chloeYue Oct 17, 2024
840f1e7
Merge branch 'develop' into migrate-snap-account-contract-interaction
chloeYue Oct 17, 2024
93ee205
fix
chloeYue Oct 17, 2024
1704229
Move createBtcAccount function to common-btc.ts
devin-ai-integration[bot] Oct 17, 2024
f064a64
Resolve merge conflicts and update common-btc.ts
devin-ai-integration[bot] Oct 17, 2024
abf0810
fix lint
chloeYue Oct 17, 2024
cd3a625
Merge branch 'migrate-snap-account-contract-interaction' of https://g…
chloeYue Oct 17, 2024
418b5f0
fix
chloeYue Oct 17, 2024
e70582e
fix
chloeYue Oct 17, 2024
ba0a9ff
fix
chloeYue Oct 17, 2024
21405dd
fix
chloeYue Oct 17, 2024
4f0a9c2
fix
chloeYue Oct 17, 2024
790fc30
Merge branch 'develop' into migrate-snap-account-contract-interaction
chloeYue Oct 17, 2024
becd0ca
lint
chloeYue Oct 17, 2024
aa28e03
fix
chloeYue Oct 17, 2024
8affa54
reduce flakiness
chloeYue Oct 17, 2024
fb83141
reduce flakiness
chloeYue Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
400 changes: 0 additions & 400 deletions test/e2e/accounts/common.ts

This file was deleted.

90 changes: 0 additions & 90 deletions test/e2e/accounts/snap-account-contract-interaction.spec.ts

This file was deleted.

This file was deleted.

23 changes: 22 additions & 1 deletion test/e2e/flask/btc/common-btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@ import { withFixtures, unlockWallet } from '../../helpers';
import { DEFAULT_BTC_ACCOUNT, DEFAULT_BTC_BALANCE } from '../../constants';
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
import { Driver } from '../../webdriver/driver';
import { createBtcAccount } from '../../accounts/common';
import messages from '../../../../app/_locales/en/messages.json';

export async function createBtcAccount(driver: Driver) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this method from accounts/common file to this file

await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
'[data-testid="multichain-account-menu-popover-action-button"]',
);
await driver.clickElement({
text: messages.addNewBitcoinAccount.message,
tag: 'button',
});
await driver.clickElementAndWaitToDisappear(
{
text: 'Add account',
tag: 'button',
},
// Longer timeout than usual, this reduces the flakiness
// around Bitcoin account creation (mainly required for
// Firefox)
5000,
);
}

export async function mockBtcBalanceQuote(
mockServer: Mockttp,
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/flask/btc/create-btc-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
removeSelectedAccount,
tapAndHoldToRevealSRP,
} from '../../helpers';
import { createBtcAccount } from '../../accounts/common';
import { withBtcAccountSnap } from './common-btc';
import { createBtcAccount, withBtcAccountSnap } from './common-btc';

describe('Create BTC Account', function (this: Suite) {
it('create BTC account from the menu', async function () {
Expand Down
109 changes: 101 additions & 8 deletions test/e2e/page-objects/pages/test-dapp.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
import { WINDOW_TITLES } from '../../helpers';
import { Driver } from '../../webdriver/driver';
import { RawLocator } from '../common';

const DAPP_HOST_ADDRESS = '127.0.0.1:8080';
const DAPP_URL = `http://${DAPP_HOST_ADDRESS}`;

class TestDapp {
private driver: Driver;

private readonly confirmDepositButton =
'[data-testid="confirm-footer-button"]';

private readonly confirmDialogButton = '[data-testid="confirm-btn"]';

private readonly confirmDialogScrollButton =
'[data-testid="signature-request-scroll-button"]';

private readonly confirmSignatureButton =
'[data-testid="page-container-footer-next"]';

private readonly connectAccountButton = '#connectButton';

private readonly connectMetaMaskMessage = {
text: 'Connect with MetaMask',
tag: 'h2',
};

private readonly connectedAccount = '#accounts';

private readonly depositPiggyBankContractButton = '#depositButton';

private readonly editConnectButton = {
text: 'Edit',
tag: 'button',
};

private readonly erc1155RevokeSetApprovalForAllButton =
'#revokeERC1155Button';

private readonly erc1155SetApprovalForAllButton =
'#setApprovalForAllERC1155Button';

private readonly erc20WatchAssetButton = '#watchAssets';

private readonly erc721RevokeSetApprovalForAllButton = '#revokeButton';

private readonly erc721SetApprovalForAllButton = '#setApprovalForAllButton';

private readonly localhostCheckbox = {
text: 'Localhost 8545',
tag: 'p',
};

private readonly localhostNetworkMessage = {
css: '#chainId',
text: '0x539',
};

private readonly mmlogo = '#mm-logo';

private readonly personalSignButton = '#personalSign';
Expand All @@ -37,6 +69,8 @@ class TestDapp {

private readonly personalSignVerifyButton = '#personalSignVerify';

private readonly revokePermissionButton = '#revokeAccountsPermission';

private readonly signPermitButton = '#signPermit';

private readonly signPermitResult = '#signPermitResult';
Expand Down Expand Up @@ -84,16 +118,18 @@ class TestDapp {

private readonly signTypedDataVerifyResult = '#signTypedDataVerifyResult';

private erc20WatchAssetButton: RawLocator;
private readonly transactionRequestMessage = {
text: 'Transaction request',
tag: 'h2',
};

private readonly updateNetworkButton = {
text: 'Update',
tag: 'button',
};

constructor(driver: Driver) {
this.driver = driver;

this.erc721SetApprovalForAllButton = '#setApprovalForAllButton';
this.erc1155SetApprovalForAllButton = '#setApprovalForAllERC1155Button';
this.erc721RevokeSetApprovalForAllButton = '#revokeButton';
this.erc1155RevokeSetApprovalForAllButton = '#revokeERC1155Button';
this.erc20WatchAssetButton = '#watchAssets';
}

async check_pageIsLoaded(): Promise<void> {
Expand Down Expand Up @@ -156,6 +192,63 @@ class TestDapp {
await this.driver.clickElement(this.erc20WatchAssetButton);
}

/**
* Connect account to test dapp.
*
* @param publicAddress - The public address to connect to test dapp.
*/
async connectAccount(publicAddress: string) {
console.log('Connect account to test dapp');
await this.driver.clickElement(this.connectAccountButton);
await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await this.driver.waitForSelector(this.connectMetaMaskMessage);

// TODO: Extra steps needed to preserve the current network.
// Following steps can be removed once the issue is fixed (#27891)
const editNetworkButton = await this.driver.findClickableElements(
this.editConnectButton,
);
await editNetworkButton[1].click();
await this.driver.clickElement(this.localhostCheckbox);
await this.driver.clickElement(this.updateNetworkButton);

await this.driver.clickElementAndWaitForWindowToClose(
this.confirmDialogButton,
);
await this.driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await this.driver.waitForSelector({
css: this.connectedAccount,
text: publicAddress.toLowerCase(),
});
await this.driver.waitForSelector(this.localhostNetworkMessage);
}

async createDepositTransaction() {
console.log('Create a deposit transaction on test dapp page');
await this.driver.clickElement(this.depositPiggyBankContractButton);
await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await this.driver.waitForSelector(this.transactionRequestMessage);
await this.driver.clickElementAndWaitForWindowToClose(
this.confirmDepositButton,
);
}

/**
* Disconnect current connected account from test dapp.
*
* @param publicAddress - The public address of the account to disconnect from test dapp.
*/
async disconnectAccount(publicAddress: string) {
console.log('Disconnect account from test dapp');
await this.driver.clickElement(this.revokePermissionButton);
await this.driver.refresh();
await this.check_pageIsLoaded();
await this.driver.assertElementNotPresent({
css: this.connectedAccount,
text: publicAddress.toLowerCase(),
});
}

/**
* Verify the failed personal sign signature.
*
Expand Down
Loading