Skip to content

Commit

Permalink
Chore/fe tests metamask update (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariuszSzpyt authored Oct 15, 2024
1 parent bc85d55 commit f4ba6ec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
6 changes: 2 additions & 4 deletions test/rollup-test/rollup-main.deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import {
connectWallet,
setupPage,
setupPageWithState,
waitForActionNotification,
} from "../../utils/frontend/rollup-utils/Handlers";
import { WalletWrapper } from "../../utils/frontend/rollup-pages/WalletWrapper";
import {
DepositActionType,
DepositModal,
} from "../../utils/frontend/rollup-utils/DepositModal";
import { TransactionType } from "../../utils/frontend/rollup-pages/NotificationToast";

jest.spyOn(console, "log").mockImplementation(jest.fn());

Expand Down Expand Up @@ -84,7 +82,7 @@ describe("Gasp UI deposit tests", () => {
// await waitForActionNotification(driver, TransactionType.ApproveContract);

await depositModal.clickDepositButtonByText(DepositActionType.Deposit);
await waitForActionNotification(driver, TransactionType.Deposit);
// await waitForActionNotification(driver, TransactionType.Deposit);
});

test("User can deposit ETH - rejected", async () => {
Expand All @@ -111,7 +109,7 @@ describe("Gasp UI deposit tests", () => {
expect(isOriginFeeDisplayed).toBeTruthy();

await depositModal.clickDepositButtonByText(DepositActionType.Deposit);
await waitForActionNotification(driver, TransactionType.Deposit, true);
// await waitForActionNotification(driver, TransactionType.Deposit, true);
});

afterEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/rollup-test/rollup-main.metamask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Gasp UI wallet tests", () => {
}

driver = await DriverBuilder.getInstance();
acc_addr = await importMetamaskExtension(driver);
acc_addr = await importMetamaskExtension(driver, true);
acc_addr_short = acc_addr.slice(-4);

await setupPage(driver);
Expand Down
2 changes: 2 additions & 0 deletions test/rollup-test/rollup-main.my-positions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe("Gasp UI swap tests", () => {
await myPositionsPage.clickPoolPosition(GASP_ASSET_NAME, ETH_ASSET_NAME);

await myPositionsPage.clickAddLiquidity();
await myPositionsPage.waitForAddPoolFieldsVisible();
const isFirstTokenNameSet =
await myPositionsPage.isFirstTokenNameSet(GASP_ASSET_NAME);
expect(isFirstTokenNameSet).toBeTruthy();
Expand Down Expand Up @@ -187,6 +188,7 @@ describe("Gasp UI swap tests", () => {
await myPositionsPage.clickPoolPosition(GASP_ASSET_NAME, ETH_ASSET_NAME);

await myPositionsPage.clickAddLiquidity();
await myPositionsPage.waitForAddPoolFieldsVisible();
const isFirstTokenNameSet =
await myPositionsPage.isFirstTokenNameSet(GASP_ASSET_NAME);
expect(isFirstTokenNameSet).toBeTruthy();
Expand Down
27 changes: 22 additions & 5 deletions utils/frontend/pages/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ const BTN_CONNECT_ACCOUNT = "page-container-footer-next";
const BTN_ACC_SELECTION = "account-menu-icon";
const BTN_IMPORT_ACCOUNT = "multichain-account-menu-popover-action-button";
const BTN_IMPORT_ACCOUNT_CONFIRM = "import-account-confirm-button";
const BTN_FOOTER_NEXT = "page-container-footer-next";
const BTN_FOOTER_NEXT = "confirm-footer-button";
const BTN_GENERIC_CONFIRMATION = "confirmation-submit-button";
const BTN_CONFIRM_TRANSACTION = "confirm-footer-confirm-button";
const BTN_REJECT_TRANSACTION = "page-container-footer-cancel";
const BTN_CONFIRM_TRANSACTION = "confirm-footer-button";
const BTN_REJECT_TRANSACTION = "confirm-footer-cancel-button";
let originalWindowHandle: string;

export class MetaMask {
Expand Down Expand Up @@ -256,7 +256,13 @@ export class MetaMask {

async openAccountSelection() {
const XPATH_BTN_ACC_SELECTIONS = buildDataTestIdXpath(BTN_ACC_SELECTION);
await clickElement(this.driver, XPATH_BTN_ACC_SELECTIONS);
try {
await waitForElementEnabled(this.driver, XPATH_BTN_ACC_SELECTIONS, 10000);
await clickElement(this.driver, XPATH_BTN_ACC_SELECTIONS);
} catch (e) {
await sleep(3000);
await clickElement(this.driver, XPATH_BTN_ACC_SELECTIONS);
}
}

async importAccount(privKey: string) {
Expand Down Expand Up @@ -385,7 +391,18 @@ export class MetaMask {
}

private static async signDeposit(driver: WebDriver) {
const XPATH_BTN_SIGN_TRANSACTION = buildDataTestIdXpath(BTN_FOOTER_NEXT);
const XPATH_SCROLL_DOWN = "//*[@aria-label='Scroll down']";

await waitForElement(driver, XPATH_SCROLL_DOWN, 5000);
if (await isDisplayed(driver, XPATH_SCROLL_DOWN)) {
await clickElement(driver, XPATH_SCROLL_DOWN);
}

//const XPATH_BTN_SIGN_TRANSACTION = buildDataTestIdXpath(BTN_FOOTER_NEXT);
const XPATH_BTN_SIGN_TRANSACTION = buildXpathByElementText(
"button",
"Confirm",
);
await waitForElement(driver, XPATH_BTN_SIGN_TRANSACTION);
await waitForElementEnabled(driver, XPATH_BTN_SIGN_TRANSACTION);
await clickElement(driver, XPATH_BTN_SIGN_TRANSACTION);
Expand Down
9 changes: 9 additions & 0 deletions utils/frontend/rollup-pages/MyPositionsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
writeText,
getAttribute,
isEnabled,
waitForElementEnabled,
} from "../utils/Helper";
import toNumber from "lodash-es/toNumber";

Expand Down Expand Up @@ -288,4 +289,12 @@ export class MyPositionsPage {
const floatValue = parseFloat(text);
return floatValue;
}

async waitForAddPoolFieldsVisible() {
const firstItemXpath = buildDataTestIdXpath(DIV_FIRST_TOKEN_CONTAINER);
const secondItemXpath = buildDataTestIdXpath(DIV_SECOND_TOKEN_CONTAINER);
await waitForElementVisible(this.driver, firstItemXpath);
await waitForElementEnabled(this.driver, firstItemXpath);
await waitForElementEnabled(this.driver, secondItemXpath);
}
}

0 comments on commit f4ba6ec

Please sign in to comment.