Skip to content

Commit

Permalink
refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-dubinin committed Nov 28, 2024
1 parent a63c9b8 commit 85f145b
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 83 deletions.
6 changes: 3 additions & 3 deletions packages/web/e2e/pages/base-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import { expect, Locator, Page } from "@playwright/test";
import { expect, type Locator, type Page } from "@playwright/test";

export class BasePage {
readonly page: Page;
Expand Down Expand Up @@ -28,7 +28,7 @@ export class BasePage {
const newPage = await pagePromise;
await newPage.waitForLoadState("load", { timeout: 10000 });
const pageTitle = await newPage.title();
console.log("Title of the new page: " + pageTitle);
console.log(`Title of the new page: ${pageTitle}`);
await newPage.getByRole("button", { name: "Approve" }).click();
// PopUp page is auto-closed
// Handle Pop-up page <-
Expand All @@ -53,6 +53,6 @@ export class BasePage {

async printUrl() {
const currentUrl = this.page.url();
console.log("FE opened at: " + currentUrl);
console.log(`FE opened at: ${currentUrl}`);
}
}
2 changes: 1 addition & 1 deletion packages/web/e2e/pages/pool-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PoolPage extends BasePage {
}

async getBalance() {
let totalBalance: string = await this.balance.innerText();
const totalBalance: string = await this.balance.innerText();
console.log(`Total Balance for a Pool [${totalBalance}]`);
return totalBalance;
}
Expand Down
32 changes: 16 additions & 16 deletions packages/web/e2e/pages/pools-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import { Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

import { BasePage } from "~/e2e/pages/base-page";

Expand Down Expand Up @@ -55,45 +55,45 @@ export class PoolsPage extends BasePage {
async getPoolsNumber() {
const loc = '//tr/td//a[contains(@href, "/pool/")]/../..';
const num = await this.page.locator(loc).count();
console.log("Pools Count: " + num);
console.log(`Pools Count: ${num}`);
return num;
}

async getTopTenPoolsByLiquidity() {
const loc = '//tr/td//a[contains(@href, "/pool/")]/../..';
let liquidityList = [];
const liquidityList = [];
for (let i = 0; i < 10; i++) {
let tt = this.page.locator(loc).nth(i).locator("//td").nth(2);
let text: string = await tt.innerText();
let n: number = Number(text.replace(/[^0-9.-]+/g, ""));
const tt = this.page.locator(loc).nth(i).locator("//td").nth(2);
const text: string = await tt.innerText();
const n: number = Number(text.replace(/[^0-9.-]+/g, ""));
liquidityList.push(n);
}
console.log("Top 10 pools Liquidity: " + liquidityList);
console.log(`Top 10 pools Liquidity: ${liquidityList}`);
return liquidityList;
}

async getTopTenPoolsByVolume() {
const loc = '//tr/td//a[contains(@href, "/pool/")]/../..';
let volumeList = [];
const volumeList = [];
for (let i = 0; i < 10; i++) {
let tt = this.page.locator(loc).nth(i).locator("//td").nth(1);
let text: string = await tt.innerText();
let n: number = Number(text.replace(/[^0-9.-]+/g, ""));
const tt = this.page.locator(loc).nth(i).locator("//td").nth(1);
const text: string = await tt.innerText();
const n: number = Number(text.replace(/[^0-9.-]+/g, ""));
volumeList.push(n);
}
console.log("Top 10 pools Volume: " + volumeList);
console.log(`Top 10 pools Volume: ${volumeList}`);
return volumeList;
}

async getTopTenPoolsByAPR() {
const loc = '//tr/td//a[contains(@href, "/pool/")]/../..';
let aprList = [];
const aprList = [];
for (let i = 0; i < 10; i++) {
let tt = this.page.locator(loc).nth(i).locator("//td").nth(3);
let text: string = await tt.innerText();
const tt = this.page.locator(loc).nth(i).locator("//td").nth(3);
const text: string = await tt.innerText();
aprList.push(text);
}
console.log("Top 10 pools APRs: " + aprList);
console.log(`Top 10 pools APRs: ${aprList}`);
return aprList;
}
}
6 changes: 3 additions & 3 deletions packages/web/e2e/pages/portfolio-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import { Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

import { BasePage } from "~/e2e/pages/base-page";
import { TransactionsPage } from "~/e2e/pages/transactions-page";
Expand Down Expand Up @@ -30,15 +30,15 @@ export class PortfolioPage extends BasePage {
// we expect that after 2 seconds tokens are loaded and any failure after this point should be considered a bug.
await this.page.waitForTimeout(2000);
const currentUrl = this.page.url();
console.log("FE opened at: " + currentUrl);
console.log(`FE opened at: ${currentUrl}`);
}

async getBalanceFor(token: string) {
await this.page.evaluate(() => window.scrollBy(0, 250));
const bal = this.page
.locator(`//tbody/tr//a[contains(@href, "/assets/${token}")]`)
.nth(1);
let tokenBalance: string = await bal.innerText();
const tokenBalance: string = await bal.innerText();
console.log(`Balance for ${token}: ${tokenBalance}`);
return tokenBalance;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/web/e2e/pages/swap-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class SwapPage extends BasePage {
return await this.exchangeRate.innerText();
}

async isTransactionSuccesful(delay: number = 7) {
async isTransactionSuccesful(delay = 7) {
console.log("Wait for a transaction success for 7 seconds.");
return await this.trxSuccessful.isVisible({
timeout: delay * 1000,
Expand All @@ -164,7 +164,7 @@ export class SwapPage extends BasePage {
return trxUrl;
}

async isTransactionBroadcasted(delay: number = 5) {
async isTransactionBroadcasted(delay = 5) {
console.log("Wait for a transaction broadcasting for 5 seconds.");
return await this.trxBroadcasting.isVisible({ timeout: delay * 1000 });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/e2e/pages/trade-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class TradePage extends BasePage {
console.log(`FE opened at: ${currentUrl}`);
}

async gotoOrdersHistory(timeout: number = 1) {
async gotoOrdersHistory(timeout = 1) {
await this.page.waitForTimeout(1000);
await this.orderHistoryLink.click();
await this.page.waitForTimeout(1000);
Expand Down
26 changes: 14 additions & 12 deletions packages/web/e2e/pages/transactions-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { BrowserContext, expect, Locator, Page } from "@playwright/test";
import {
type BrowserContext,
expect,
type Locator,
type Page,
} from "@playwright/test";

import { BasePage } from "~/e2e/pages/base-page";
const TRANSACTION_CONFIRMATION_TIMEOUT = 2000;
Expand Down Expand Up @@ -38,12 +43,12 @@ export class TransactionsPage extends BasePage {
await this.page.waitForTimeout(1000);
}

async viewBySwapAmount(amount: any) {
async viewBySwapAmount(amount: number | string) {
// Transactions need some time to get loaded, wait for 30 seconds.
await this.page.waitForTimeout(30000);
await this.page.reload();
const loc = `//div/div[@class="subtitle1 text-osmoverse-100" and contains(text(), "${amount}")]`;
let isTransactionVisible = await this.page
const isTransactionVisible = await this.page
.locator(loc)
.isVisible({ timeout: 3000 });
if (!isTransactionVisible) {
Expand All @@ -64,7 +69,7 @@ export class TransactionsPage extends BasePage {

async getOnExplorerLink() {
const trxUrl = await this.viewExplorerLink.getAttribute("href");
console.log("Trx url: " + trxUrl);
console.log(`Trx url: ${trxUrl}`);
return trxUrl;
}

Expand All @@ -81,7 +86,7 @@ export class TransactionsPage extends BasePage {
context: BrowserContext
) {
const cancelBtn = `//td//span[.='${amount}']/../../../../..//td//p[.='$${price}']/../../..//button`;
console.log("Use locator for a cancel btn: " + cancelBtn);
console.log(`Use locator for a cancel btn: ${cancelBtn}`);
await this.page.locator(cancelBtn).first().click();
const pageApprove = context.waitForEvent("page");
const approvePage = await pageApprove;
Expand All @@ -93,7 +98,7 @@ export class TransactionsPage extends BasePage {
const msgContentAmount = await approvePage
.getByText("Execute contract")
.textContent();
console.log("Wallet is approving this msg: \n" + msgContentAmount);
console.log(`Wallet is approving this msg: \n${msgContentAmount}`);
// Approve trx
await approveBtn.click();
// Expect that this is a cancel limit call
Expand All @@ -102,9 +107,9 @@ export class TransactionsPage extends BasePage {
await this.page.waitForTimeout(TRANSACTION_CONFIRMATION_TIMEOUT);
}

async isFilledByLimitPrice(price: any) {
async isFilledByLimitPrice(price: number | string) {
const loc = `//td//span[.='Filled']/../../..//td//p[.='$${price}']`;
console.log("Use Limit Order locator: " + loc);
console.log(`Use Limit Order locator: ${loc}`);
await expect(this.page.locator(loc).first()).toBeVisible({
timeout: 120_000,
visible: true,
Expand Down Expand Up @@ -136,10 +141,7 @@ export class TransactionsPage extends BasePage {
.last()
.textContent();
console.log(
"Wallet is approving this msg: \n" +
msgContentAmount1 +
"---- \n" +
msgContentAmount2
`Wallet is approving this msg: \n${msgContentAmount1}---- \n${msgContentAmount2}`
);
// Approve trx
await approveBtn.click();
Expand Down
7 changes: 2 additions & 5 deletions packages/web/e2e/pages/wallet-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import { expect, Locator, Page } from "@playwright/test";
import { expect, type Locator, type Page } from "@playwright/test";

export class WalletPage {
readonly page: Page;
Expand Down Expand Up @@ -49,10 +49,7 @@ export class WalletPage {
await this.importBtn.click();
}

async setWalletNameAndPassword(
name: string,
password: string = "TestPassword2024."
) {
async setWalletNameAndPassword(name: string, password = "TestPassword2024.") {
await this.walletNameInput.fill(name);
await this.walletPassInput.fill(password);
await this.walletRePassInput.fill(password);
Expand Down
4 changes: 1 addition & 3 deletions packages/web/e2e/tests/claim.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { BrowserContext, chromium, test } from "@playwright/test";
import process from "process";
import { type BrowserContext, chromium, test } from "@playwright/test";

import { TransactionsPage } from "~/e2e/pages/transactions-page";
import { TestConfig } from "~/e2e/test-config";
Expand Down
9 changes: 7 additions & 2 deletions packages/web/e2e/tests/pools.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { BrowserContext, chromium, expect, Page, test } from "@playwright/test";
import {
type BrowserContext,
chromium,
expect,
type Page,
test,
} from "@playwright/test";

import { TestConfig } from "~/e2e/test-config";

Expand Down
10 changes: 0 additions & 10 deletions packages/web/e2e/tests/portfolio.wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type Page,
test,
} from "@playwright/test";
import { addCoverageReport, attachCoverageReport } from "monocart-reporter";

import { TestConfig } from "~/e2e/test-config";
import { UnzipExtension } from "~/e2e/unzip-extension";
Expand Down Expand Up @@ -40,9 +39,6 @@ test.describe("Test Portfolio feature", () => {
await walletPage.finish();
// Switch to Application
page = context.pages()[0];
await page.coverage.startJSCoverage({
resetOnNavigation: false,
});
portfolioPage = new PortfolioPage(page);
await portfolioPage.goto();
await portfolioPage.connectWallet();
Expand All @@ -51,12 +47,6 @@ test.describe("Test Portfolio feature", () => {
});

test.afterAll(async () => {
const coverage = await page.coverage.stopJSCoverage();
// coverage report
const report = await attachCoverageReport(coverage, test.info());
console.log(report.summary);

await addCoverageReport(coverage, test.info());
await context.close();
});

Expand Down
11 changes: 1 addition & 10 deletions packages/web/e2e/tests/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type Page,
test,
} from "@playwright/test";
import { addCoverageReport, attachCoverageReport } from "monocart-reporter";

import { TradePage } from "~/e2e/pages/trade-page";
import { TestConfig } from "~/e2e/test-config";
Expand All @@ -22,20 +21,12 @@ test.describe("Test Select Swap Pair feature", () => {
new TestConfig().getBrowserConfig(true)
);
page = context.pages()[0];
await page.coverage.startJSCoverage({
resetOnNavigation: false,
});
swapPage = new TradePage(page);
await swapPage.goto();
});

test.afterAll(async () => {
const coverage = await page.coverage.stopJSCoverage();
// coverage report
const report = await attachCoverageReport(coverage, test.info());
console.log(report.summary);

await addCoverageReport(coverage, test.info());
console.log(test.info());
await context.close();
});

Expand Down
2 changes: 0 additions & 2 deletions packages/web/e2e/tests/stables.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { type BrowserContext, chromium, expect, test } from "@playwright/test";
import process from "process";

import { TradePage } from "~/e2e/pages/trade-page";
import { TestConfig } from "~/e2e/test-config";
Expand Down
3 changes: 1 addition & 2 deletions packages/web/e2e/tests/swap.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { type BrowserContext, chromium, expect, test } from "@playwright/test";
import process from "process";

import { TradePage } from "~/e2e/pages/trade-page";
import { TestConfig } from "~/e2e/test-config";
Expand Down Expand Up @@ -51,6 +49,7 @@ test.describe("Test Swap feature", () => {
});

test.afterAll(async () => {
console.log(test.info());
await context.close();
});

Expand Down
1 change: 0 additions & 1 deletion packages/web/e2e/tests/trade.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */
import { type BrowserContext, chromium, expect, test } from "@playwright/test";

import { TransactionsPage } from "~/e2e/pages/transactions-page";
Expand Down
2 changes: 0 additions & 2 deletions packages/web/e2e/tests/transactions.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
type BrowserContext,
chromium,
expect,
type Page,
test,
} from "@playwright/test";
import process from "process";

import { SwapPage } from "~/e2e/pages/swap-page";
import { TransactionsPage } from "~/e2e/pages/transactions-page";
Expand Down
1 change: 0 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
"jest-in-case": "^1.0.2",
"jest-launchdarkly-mock": "^2.1.0",
"knip": "^5.17.4",
"monocart-reporter": "^2.6.0",
"msw-trpc": "1.3.3",
"postcss": "^8.4.5",
"prettier": "^2.8.8",
Expand Down
7 changes: 0 additions & 7 deletions packages/web/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ export default defineConfig({
reporter: [
["html", { open: "never" }],
["junit", { outputFile: "./playwright-report/test-results.xml" }],
[
"monocart-reporter",
{
name: "Test Coverage Report",
outputFile: "./playwright-report/cov-report.html",
},
],
],
timeout: 45000,
testDir: "./e2e/tests",
Expand Down

0 comments on commit 85f145b

Please sign in to comment.