diff --git a/package.json b/package.json index 1d9363b7..2551a1ea 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "npm run locale && vue-cli-service build", "lint": "vue-cli-service lint", "prepare": "husky install", - "test": "npx playwright test --config=playwright.config.ts --workers=1", + "test": "npx playwright test --config=playwright.config.ts --workers=10", "test:browserstack": "npx playwright test --config=playwright-browserstack.config.ts --workers=1", "test:controller": "npx mocha ./tests/controller/**.ts", "test:report": "rm -rf .nyc_output && rm -rf coverage && npx nyc --reporter=text --reporter=html npm run test:controller", diff --git a/src/utils/const.ts b/src/utils/const.ts index e771fdd8..df97ab98 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -4,7 +4,7 @@ export const WALLET_SUPPORTED_NETWORKS = { ...SUPPORTED_NETWORKS, mainnet: { ...SUPPORTED_NETWORKS.mainnet, - rpcTarget: "https://green-dark-sky.solana-mainnet.quiknode.pro/0b4b99540b7930cf590dc7fb0a2d1c9a906fd53c/", + rpcTarget: "https://green-dark-sky.solana-mainnet.quiknode.pro/97c87069b81ef4ec0765a267525c82153e5404fc/", }, testnet: { ...SUPPORTED_NETWORKS.testnet, diff --git a/tests/auth-helper.ts b/tests/auth-helper.ts index b39dcee7..b8b13dcd 100644 --- a/tests/auth-helper.ts +++ b/tests/auth-helper.ts @@ -9,7 +9,7 @@ import { memoize } from "lodash-es"; import type { OpenLoginBackendState } from "@/utils/enums"; import TorusStorageLayer from "@/utils/tkey/storageLayer"; -import { getBackendDomain, getDomain, getStateDomain, wait } from "./utils"; +import { getBackendDomain, getDomain, getStateDomain } from "./utils"; const ec = new EC("secp256k1"); export const EPHEMERAL_KEYPAIR = ec.genKeyPair({ entropy: "ad1238470128347018934701983470183478sfa" }); @@ -75,7 +75,6 @@ export const createRedisKey = memoize(async () => { export async function login(context: BrowserContext, browserName: "chromium" | "webkit" | "firefox"): Promise { await createRedisKey(); - const keyFunction = `window.localStorage.setItem( "controllerModule-ephemeral", JSON.stringify({ @@ -142,8 +141,5 @@ export async function login(context: BrowserContext, browserName: "chromium" | " await context.addInitScript({ content: stateFunction }); const page = await context.newPage(); await page.goto(getDomain()); - // await changeLanguage(page, "english"); - await wait(500); - // await page.locator("text=Account Balance").waitFor(); return page; } diff --git a/tests/e2e/activity/activity.test.ts b/tests/e2e/activity/activity.test.ts index bf3707b0..f5c7d868 100644 --- a/tests/e2e/activity/activity.test.ts +++ b/tests/e2e/activity/activity.test.ts @@ -9,7 +9,7 @@ import { selectTransactionTypeFilter, } from "../../activity.utils"; import { IMPORT_ACC_SECRET_KEY, login } from "../../auth-helper"; -import { ensureTextualElementExists, getLastWeeksDate, getOlderDate, importAccount, switchNetwork, switchTab, wait } from "../../utils"; +import { ensureTextualElementExists, getLastWeeksDate, getOlderDate, importAccount, switchNetwork, switchTab } from "../../utils"; import test, { markResult, setBrowserStackTestTitle } from "../fixtures"; test.describe("Activity Page", async () => { @@ -34,7 +34,6 @@ test.describe("Activity Page", async () => { test("Activities should work with network=mainnet", async () => { // see navigation works correctly await switchTab(page, "activity"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -49,7 +48,6 @@ test.describe("Activity Page", async () => { // see navigation works correctly await switchTab(page, "activity"); await switchNetwork(page, "testnet"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -64,7 +62,6 @@ test.describe("Activity Page", async () => { // see navigation works correctly await switchTab(page, "activity"); await switchNetwork(page, "devnet"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -80,7 +77,6 @@ test.describe("Activity Page", async () => { await switchTab(page, "activity"); // Last 1 week filter await selectTimeFilter(page, "Last 1 week"); - await wait(1000); // getting list of dates on activity page let activityDates = await getDateOfActivities(page); let elements = await activityDates.elementHandles(); @@ -96,7 +92,6 @@ test.describe("Activity Page", async () => { // Last 1 month filter await selectTimeFilter(page, "Last 1 month"); - await wait(1000); // getting list of dates on activity page activityDates = await getDateOfActivities(page); elements = await activityDates.elementHandles(); @@ -112,7 +107,6 @@ test.describe("Activity Page", async () => { // Last 6 months filter await selectTimeFilter(page, "Last 6 months"); - await wait(1000); // getting list of dates on activity page activityDates = await getDateOfActivities(page); elements = await activityDates.elementHandles(); @@ -134,7 +128,6 @@ test.describe("Activity Page", async () => { // Send filter await selectTransactionTypeFilter(page, "Send"); - await wait(1000); // getting list on activities let activitiesList = await getActivities(page); let elements = await activitiesList.elementHandles(); @@ -148,7 +141,6 @@ test.describe("Activity Page", async () => { // Receive filter await selectTransactionTypeFilter(page, "Receive"); - await wait(1000); // getting list on activities activitiesList = await getActivities(page); elements = await activitiesList.elementHandles(); @@ -162,7 +154,6 @@ test.describe("Activity Page", async () => { // Topup filter await selectTransactionTypeFilter(page, "Topup"); - await wait(1000); // getting list on activities activitiesList = await getActivities(page); elements = await activitiesList.elementHandles(); @@ -233,7 +224,6 @@ test.skip("Activity Page with Imported Account", async () => { test("Activities should work with network=mainnet", async () => { // see navigation works correctly await switchTab(page, "activity"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -248,7 +238,6 @@ test.skip("Activity Page with Imported Account", async () => { // see navigation works correctly await switchTab(page, "activity"); await switchNetwork(page, "testnet"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -263,7 +252,6 @@ test.skip("Activity Page with Imported Account", async () => { // see navigation works correctly await switchTab(page, "activity"); await switchNetwork(page, "devnet"); - await wait(1000); // getting list of activities on activity page const activities = await getActivities(page); @@ -279,7 +267,6 @@ test.skip("Activity Page with Imported Account", async () => { await switchTab(page, "activity"); // Last 1 week filter await selectTimeFilter(page, "Last 1 week"); - await wait(1000); // getting list of dates on activity page let activityDates = await getDateOfActivities(page); let elements = await activityDates.elementHandles(); @@ -295,7 +282,6 @@ test.skip("Activity Page with Imported Account", async () => { // Last 1 month filter await selectTimeFilter(page, "Last 1 month"); - await wait(1000); // getting list of dates on activity page activityDates = await getDateOfActivities(page); elements = await activityDates.elementHandles(); @@ -311,7 +297,6 @@ test.skip("Activity Page with Imported Account", async () => { // Last 6 months filter await selectTimeFilter(page, "Last 6 months"); - await wait(1000); // getting list of dates on activity page activityDates = await getDateOfActivities(page); elements = await activityDates.elementHandles(); @@ -333,7 +318,6 @@ test.skip("Activity Page with Imported Account", async () => { // Send filter await selectTransactionTypeFilter(page, "Send"); - await wait(1000); // getting list on activities let activitiesList = await getActivities(page); let elements = await activitiesList.elementHandles(); @@ -347,7 +331,6 @@ test.skip("Activity Page with Imported Account", async () => { // Receive filter await selectTransactionTypeFilter(page, "Receive"); - await wait(1000); // getting list on activities activitiesList = await getActivities(page); elements = await activitiesList.elementHandles(); @@ -361,7 +344,6 @@ test.skip("Activity Page with Imported Account", async () => { // Topup filter await selectTransactionTypeFilter(page, "Topup"); - await wait(1000); // getting list on activities activitiesList = await getActivities(page); elements = await activitiesList.elementHandles(); diff --git a/tests/e2e/home/home.test.ts b/tests/e2e/home/home.test.ts index 893246a0..da872e07 100644 --- a/tests/e2e/home/home.test.ts +++ b/tests/e2e/home/home.test.ts @@ -15,7 +15,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures"; test.describe("Home Page", async () => { let page: Page; - test.beforeAll(async ({ browser, browserName }) => { + test.beforeEach(async ({ browser, browserName }) => { page = await login(await browser.newContext(), browserName); }); test.afterAll(async () => { @@ -37,7 +37,8 @@ test.describe("Home Page", async () => { await switchTab(page, "home"); // ENSURE TopUp button click should take to topup page - await clickTopupButton(page); + // await clickTopupButton(page); + await page.click("button >> text=Top up"); await wait(1000); await ensureTextualElementExists(page, "Select a Provider"); }); @@ -55,20 +56,17 @@ test.describe("Home Page", async () => { test("Currency Change should work correctly", async () => { // see navigation works correctly await switchTab(page, "home"); - await wait(1000); // Switching to testnet as it has > 0 balance await switchNetwork(page, "testnet"); expect(await getInnerText(page, "#selected_network")).toContain("Solana Testnet"); // ENSURE On selecting EUR as currency, conversion rate has a positive value await selectCurrency(page, "EUR"); - await wait(1000); const eurRate = Number(await getInnerText(page, "#conversionRate")); expect(eurRate).toBeGreaterThan(0); // ENSURE On selecting USD as currency, conversion rate has a positive value await selectCurrency(page, "USD"); - await wait(1000); const usdRate = Number(await getInnerText(page, "#conversionRate")); expect(usdRate).toBeGreaterThan(0); @@ -83,7 +81,6 @@ test.describe("Home Page", async () => { await switchNetwork(page, "testnet"); // Ensure Tokens are displayed await ensureTextualElementExists(page, "Tokens"); - await wait(1000); await clickTokenIfAvailable(page); }); diff --git a/tests/e2e/login/login.test.ts b/tests/e2e/login/login.test.ts index 81034707..9dc4f5cd 100644 --- a/tests/e2e/login/login.test.ts +++ b/tests/e2e/login/login.test.ts @@ -12,24 +12,24 @@ test("Should Login successfully", async ({ context, browserName }) => { const page = await login(context, browserName); await page.click("text=Home"); - await wait(1000); + await wait(500); expect(page.url().includes("/wallet/home")).toBeTruthy(); await page.click("text=NFTs"); - await wait(1000); + await wait(500); expect(page.url().includes("/wallet/nfts")).toBeTruthy(); await page.click("text=Activity"); - await wait(1000); + await wait(500); expect(page.url().includes("/wallet/activity")).toBeTruthy(); // Click text=Settings await page.click("text=Settings"); - await wait(1000); + await wait(500); expect(page.url().includes("/wallet/settings")).toBeTruthy(); await page.click("text=Discover"); - await wait(1000); + await wait(500); expect(page.url().includes("/wallet/discover")).toBeTruthy(); await page.close(); }); diff --git a/tests/e2e/mobile-screen/mobile-screen.test.ts b/tests/e2e/mobile-screen/mobile-screen.test.ts index 3ba408f0..9af3c6d0 100644 --- a/tests/e2e/mobile-screen/mobile-screen.test.ts +++ b/tests/e2e/mobile-screen/mobile-screen.test.ts @@ -28,8 +28,9 @@ test.describe("Mobile screens", async () => { test("Should have all the tabs", async () => { // eslint-disable-next-line no-restricted-syntax for (const key of tabs) { - await wait(200); + await wait(1000); expect(await page.locator(`#${key}_link`).count()).toBeGreaterThan(0); + await wait(200); } }); diff --git a/tests/e2e/nfts/nfts.test.ts b/tests/e2e/nfts/nfts.test.ts index 420bc2ef..7d6637e3 100644 --- a/tests/e2e/nfts/nfts.test.ts +++ b/tests/e2e/nfts/nfts.test.ts @@ -14,7 +14,6 @@ test.describe("Nfts Page", async () => { }); test.beforeEach(async () => { await switchTab(page, "nfts"); - await wait(2000); }); test.afterAll(() => { @@ -27,7 +26,6 @@ test.describe("Nfts Page", async () => { }); test("If no NFTs project eventually load popular NFTs project", async () => { - await wait(1000); await ensureTextualElementExists(page, "You might be keen to check out some of the popular NFT projects"); expect(await page.locator(".popular-nft").count()).toBeGreaterThan(0); }); @@ -43,8 +41,9 @@ test.describe("Nfts Page", async () => { }); test("Click on NFT should open page with correct information, clicking on Send should take on transfer page", async () => { + test.slow(); + await switchNetwork(page, "testnet"); await page.locator(".nft-item").first().click(); - await wait(5000); await page.locator(".send-nft").first().click(); await wait(1000); await ensureTextualElementExists(page, "Transfer Details"); diff --git a/tests/e2e/settings/settings.test.ts b/tests/e2e/settings/settings.test.ts index 22417ffd..88486353 100644 --- a/tests/e2e/settings/settings.test.ts +++ b/tests/e2e/settings/settings.test.ts @@ -8,7 +8,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures"; test.describe("Settings Page", async () => { let page: Page; - test.beforeAll(async ({ browser, browserName }) => { + test.beforeEach(async ({ browser, browserName }) => { page = await login(await browser.newContext(), browserName); }); test.afterAll(async () => { @@ -47,13 +47,13 @@ test.describe("Settings Page", async () => { test("Theme Change should work", async () => { // // see navigation works correctly await switchTab(page, "settings"); + await wait(1000); // **************DISPLAY CHANGES******** // CHOOSE LIGHT await page.click("text=Light"); - await wait(1000); await expect(await page.locator(".light").elementHandles()).toHaveLength(0); - + await wait(1000); // CHOOSE DARK await page.click("text=Dark"); await wait(1000); @@ -152,7 +152,6 @@ test.describe("Settings Page", async () => { test("Language change should work", async () => { // see navigation works correctly await switchTab(page, "settings"); - await changeLanguage(page, "german"); await wait(500); await ensureTextualElementExists(page, "die Einstellungen"); diff --git a/tests/e2e/topup/topup.test.ts b/tests/e2e/topup/topup.test.ts index 93a500f8..af848735 100644 --- a/tests/e2e/topup/topup.test.ts +++ b/tests/e2e/topup/topup.test.ts @@ -8,9 +8,8 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures"; test.describe("Topup page", async () => { let page: Page; - test.beforeAll(async ({ browser, browserName }) => { + test.beforeEach(async ({ browser, browserName }) => { page = await login(await browser.newContext(), browserName); - await wait(3000); }); test.afterAll(() => { page.close(); @@ -22,53 +21,46 @@ test.describe("Topup page", async () => { test("Topup Page Should render", async () => { // // see navigation works correctly await page.click("button:has-text('Top up')"); - await wait(1000); // ENSURE UI IS INTACT + await wait(500); await ensureTextualElementExists(page, "Select a Provider"); }); test("Changing amount changes received value", async () => { // // see navigation works correctly await page.click("button:has-text('Top up')"); - await wait(1000); // MoonPay SHOULD WORK AS EXPECTED // set amount to be transferred as 100 US Dollars, expect a positive value for expected SOL await page.click("img[alt=moonpay]"); await page.fill("input[type='number']", "100"); - await wait(2000); const usdToSol100 = Number(await getInnerText(page, "#resCryptoAmt")); expect(usdToSol100).toBeGreaterThan(0); // set amount to be transferred as 200 US Dollars, expect a positive value for expected SOL await page.fill("input[type='number']", "200"); - await wait(1000); const usdToSol200 = Number(await getInnerText(page, "#resCryptoAmt")); - await wait(2000); expect(usdToSol200).toBeGreaterThan(usdToSol100); }); test("Pop up page should show for top up", async () => { // // see navigation works correctly await page.click("button:has-text('Top up')"); - await wait(1000); // MoonPay SHOULD WORK AS EXPECTED // set amount to be transferred as 100 US Dollars, expect a positive value for expected SOL await page.click("img[alt=moonpay]"); await page.fill("input[type='number']", "100"); - await wait(2000); // ensure that on clicking Top up, it is redirected to MoonPay Payment page const [page2] = await Promise.all([page.waitForEvent("popup"), page.click("button:has-text('Top up')")]); // closing moonpay page, will show an error on top up page page2.close(); - await wait(500); + await wait(1000); await ensureTextualElementExists(page, "Transaction could not complete."); }); test("Changing of crypto/fiat currency changes the value you receive correctly", async () => { // see navigation works correctly await page.click("button:has-text('Top up')"); - await wait(1000); // change crypto currency to SOL await switchCryptoCurrency(page, "SOL"); // change fiat currency EUR diff --git a/tests/e2e/transfer/transfer.test.ts b/tests/e2e/transfer/transfer.test.ts index c7239484..63385e76 100644 --- a/tests/e2e/transfer/transfer.test.ts +++ b/tests/e2e/transfer/transfer.test.ts @@ -7,7 +7,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures"; test.describe("Transfer page", async () => { let page: Page; - test.beforeAll(async ({ browser, browserName }) => { + test.beforeEach(async ({ browser, browserName }) => { page = await login(await browser.newContext(), browserName); }); test.afterAll(async () => { @@ -25,7 +25,7 @@ test.describe("Transfer page", async () => { await ensureTextualElementExists(page, "Transfer Details"); }); - test("Checks before transaction should be correct", async () => { + test("Prevents transaction to an invalid solana address", async () => { // see navigation works correctly await page.click("button:has-text('Transfer')"); await wait(1000); @@ -35,25 +35,40 @@ test.describe("Transfer page", async () => { await page.fill("input[type='number']", "0.01"); await page.click("button >> text=Transfer"); expect(await page.locator("text=Invalid SOL Address").elementHandles()).toHaveLength(1); + }); - // using testnet as we poor on mainnet - await switchNetwork(page, "testnet"); + test("Prevents sending zero value transactions", async () => { + // see navigation works correctly + await page.click("button:has-text('Transfer')"); + await wait(1000); // if address is a valid sol address, should show popup await page.fill("input[type='text']", PUB_ADDRESS); // if amount is not valid, should show error await page.fill("input[type='number']", "0"); + await wait(500); await page.click("button >> text=Transfer"); await wait(1000); expect(await page.locator("text=Must be greater than 0.0001").elementHandles()).toHaveLength(1); - // entering valid amount + }); + + test("Check if total cost is displayed before confirming", async () => { + // see navigation works correctly + await page.click("button:has-text('Transfer')"); + await page.fill("input[type='text']", PUB_ADDRESS); await page.fill("input[type='number']", "0.01"); await page.click("button >> text=Transfer"); await wait(1000); expect(await page.locator("text=Total Cost").elementHandles()).toHaveLength(1); await page.click("button >> text=Cancel"); + }); + + test("Prevents empty field in the amount", async () => { + // see navigation works correctly + await page.click("button:has-text('Transfer')"); // entering no amount, empty field + await page.fill("input[type='text']", PUB_ADDRESS); await page.fill("input[type='number']", ""); - await wait(1000); + await page.click("button >> text=Transfer"); expect(await page.locator("text=Must be greater than 0.0001").elementHandles()).toHaveLength(1); expect(await page.locator("button >> text=Transfer").isDisabled()).toBeTruthy(); }); @@ -64,17 +79,20 @@ test.describe("Transfer page", async () => { await page.click("button:has-text('Transfer')"); await wait(1000); const transferAmount = (Math.random() / 100).toFixed(4); + // global.console.log("amount to transfer is : ", transferAmount); // using testnet as we poor on mainnet await switchNetwork(page, "testnet"); // Click transfer tab - await Promise.all([page.click("text=Transfer"), wait(1000)]); + // await Promise.all([page.click("text=Transfer"), wait(1000)]); // Fill a valid sol address - await page.fill(".combo-input-field[aria-label='Select field']", PUB_ADDRESS); + // await page.fill(".combo-input-field[aria-label='Select field']", PUB_ADDRESS); + await page.fill("input[type='text']", PUB_ADDRESS); // Fill a unique random amount + // await page.fill("input[type='number']", transferAmount); await page.fill("input[type='number']", transferAmount); // Click transfer, wait for popup @@ -185,7 +203,7 @@ test.describe("Transfer page", async () => { /** *****************IMPORT ACCOUNT TESTS********************** */ -test.skip("Transfer page using imported account", async () => { +test.skip(" ", async () => { let page: Page; test.beforeAll(async ({ browser, browserName }) => { page = await login(await browser.newContext(), browserName); @@ -216,7 +234,7 @@ test.skip("Transfer page using imported account", async () => { await page.click("button >> text=Cancel"); }); - test("Transaction should happen correctly", async () => { + test.only("Transaction should happen correctly", async () => { test.slow(); // see navigation works correctly await page.click("button:has-text('Transfer')"); diff --git a/tests/home.utils.ts b/tests/home.utils.ts index fd0a0126..543d9fcd 100644 --- a/tests/home.utils.ts +++ b/tests/home.utils.ts @@ -1,7 +1,7 @@ import { Page } from "@playwright/test"; import * as dotenv from "dotenv"; -import { ensureTextualElementExists, wait } from "./utils"; +import { ensureTextualElementExists } from "./utils"; dotenv.config({ path: ".env.testing" }); @@ -9,7 +9,6 @@ export async function clickTokenIfAvailable(page: Page) { const token_locator = page.locator("text=/\\s\\≈\\s/"); if ((await token_locator.count()) > 1) { await token_locator.nth(1).click(); - await wait(1000); await ensureTextualElementExists(page, "Transfer Details"); } } diff --git a/tests/utils.ts b/tests/utils.ts index 5c7677c4..a5d02a27 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -74,7 +74,6 @@ export async function changeLanguage(page: Page, language: "english" | "german" mandarin: "Mandarin (中文)", spanish: "Spanish (Español)", }; - await page.click("nav button[id^='headlessui-listbox-button'][aria-haspopup='true']"); await page.click(`nav ul[role='listbox'] div >> text=${languageLabels[language]}`); if (test.info().project.name.match(/browserstack/)) {