From be840764cd2142102d4b3c9f597ef2b3f8dd40df Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Tue, 4 Mar 2025 00:45:34 +0700 Subject: [PATCH 1/6] add Place a buy order test script when using Phantom wallet --- .github/workflows/playwright.yml | 4 +-- pages/TradeTradePage.page.ts | 16 ++++++++++++ .../ConnectLeapWallet.spec.ts | 2 +- .../ConnectPhantomWallet.spec.ts | 26 +++++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index dd150db..6bb8c36 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,9 +1,9 @@ name: Playwright Tests on: push: - branches: [ main, master, feature/withdraw-token ] + branches: [ main, master, feature/trading ] pull_request: - branches: [ main, master, feature/withdraw-token ] + branches: [ main, master, feature/trading ] jobs: test: timeout-minutes: 60 diff --git a/pages/TradeTradePage.page.ts b/pages/TradeTradePage.page.ts index 5102e7c..be8fd35 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -3,11 +3,27 @@ export class TradeTradePage{ readonly page: Page; readonly headerConnectWallet; readonly rightSideConnectWallet; + readonly opTokenOption: Locator + readonly spotTab: Locator + readonly searchToken: Locator + readonly swthUSDOption: Locator + readonly amountToken: Locator + readonly buyBtn: Locator + readonly confirmBtn: Locator + readonly orderedPopup: Locator constructor(page: Page){ this.page=page; this.headerConnectWallet=this.page.getByRole('button', { name: 'Connect Wallet' }).first(); this.rightSideConnectWallet=this.page.getByRole('button', { name: 'Connect Wallet' }).nth(1); + this.opTokenOption = this.page.getByRole('img', { name: 'OP' }) + this.spotTab = this.page.getByRole('button', { name: 'Spot', exact: true }) + this.searchToken = this.page.getByRole('textbox', { name: 'e.g. “SWTH” or “BTC”' }) + this.swthUSDOption = this.page.locator('#root').getByText('SWTH / USD') + this.amountToken = this.page.getByRole('spinbutton').nth(1) + this.buyBtn = this.page.getByRole('button', { name: 'Buy SWTH', exact: true }) + this.confirmBtn = this.page.getByRole('button', { name: 'Confirm' }) + this.orderedPopup = this.page.getByText('Order Placed') } async goToTradePage(){ diff --git a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts index b1a4e91..5c1c17d 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts @@ -54,7 +54,7 @@ test.beforeAll('Add extension: Leap', async () => { }) -test.describe.serial('Connect Phantom wallet & Verify withdraw', () => { +test.describe.serial('Leap wallet ', () => { test('Connect Leap wallet', async () => { test.setTimeout(150_000) const homePage = new HomePage(page) diff --git a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts index 602e362..aae9e1e 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts @@ -42,7 +42,7 @@ test.beforeAll('Add extension: Phantom', async () => { await page.bringToFront() }) -test.describe.serial('Connect Phantom wallet & Verify deposit', () => { +test.describe.serial(' Phantom wallet ', () => { test('Connect Phantom wallet', async () => { test.setTimeout(180_000) const homePage = new HomePage(page) @@ -103,7 +103,7 @@ test.describe.serial('Connect Phantom wallet & Verify deposit', () => { await expect(depositPage.errorAmountMsg).toBeVisible() }) - test('Verify that the withdraw can be executed with other wallets address', async () => { + test.skip('Verify that the withdraw can be executed with other wallets address', async () => { const depositPage = new DepositPage(page) await depositPage.depositBtn.click() await depositPage.myBrowerWallet.click() @@ -129,4 +129,26 @@ test.describe.serial('Connect Phantom wallet & Verify deposit', () => { await expect(withdrawPage.transactionSuccess).toBeVisible() }) + + test('Place a buy order, verify appearance in order book', async () => { + const tradePage = new TradeTradePage(page) + await tradePage.opTokenOption.click() + await tradePage.spotTab.click() + await tradePage.searchToken.fill('SWTH') + await tradePage.swthUSDOption.click() + await tradePage.amountToken.fill('1000') + await tradePage.buyBtn.click() + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.confirmBtn.click() + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.orderedPopup).toBeVisible() + + }) }) \ No newline at end of file From cf7de0ec88ccd54a6fa3d49a6b3a00e9546fc2d8 Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Wed, 5 Mar 2025 01:52:51 +0700 Subject: [PATCH 2/6] done tc TC_DEMEX_TO_1: Buy order & TC_DEMEX_TO_4: Cancel order with Phantom wallet --- pages/TradeTradePage.page.ts | 37 +++++++++++++++++++ .../ConnectPhantomWallet.spec.ts | 31 +++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/pages/TradeTradePage.page.ts b/pages/TradeTradePage.page.ts index be8fd35..ade12ce 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -11,6 +11,9 @@ export class TradeTradePage{ readonly buyBtn: Locator readonly confirmBtn: Locator readonly orderedPopup: Locator + readonly orderedCancelledPopup: Locator + readonly cancelBtn: Locator + readonly cancelAllBtn: Locator constructor(page: Page){ this.page=page; @@ -24,9 +27,43 @@ export class TradeTradePage{ this.buyBtn = this.page.getByRole('button', { name: 'Buy SWTH', exact: true }) this.confirmBtn = this.page.getByRole('button', { name: 'Confirm' }) this.orderedPopup = this.page.getByText('Order Placed') + this.orderedCancelledPopup = this.page.getByText('Order Cancelled') + this.cancelBtn = this.page.getByRole('button', { name: 'Cancel', exact: true }) + this.cancelAllBtn = this.page.getByRole('columnheader', { name: 'Cancel All' }) } async goToTradePage(){ await this.page.goto('https://beta-app.dem.exchange/trade'); } + + async verifyTableData(expectedData: Array<{ [key: string]: string }>) { + const table = this.page.locator('//table[thead//th[contains(text(), "Date")]]'); + await expect(table).toBeVisible(); + + const headers = await table.locator('thead tr th').allInnerTexts(); + console.log('Column headers:', headers); + + const columnIndexes: { [key: string]: number } = {}; + headers.forEach((header, index) => { + columnIndexes[header.trim()] = index + 1; + }); + console.log('Column Index:', columnIndexes) + + for (let rowIndex = 0; rowIndex < expectedData.length; rowIndex++) { + const row = table.locator(`tbody tr:nth-child(${rowIndex + 1})`); + + for (const [columnName, expectedValue] of Object.entries(expectedData[rowIndex])) { + if (columnIndexes[columnName] !== undefined) { + const columnIndex = columnIndexes[columnName]; + const cellLocator = row.locator(`td:nth-child(${columnIndex})`); + + await expect(cellLocator).toHaveText(expectedValue); + console.log(`Row ${rowIndex + 1}, column "${columnName}" verified: "${expectedValue}"`); + } else { + console.warn(`Column "${columnName}" not found!`); + } + } + } + } + } \ No newline at end of file diff --git a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts index aae9e1e..939c566 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts @@ -130,7 +130,7 @@ test.describe.serial(' Phantom wallet ', () => { await expect(withdrawPage.transactionSuccess).toBeVisible() }) - test('Place a buy order, verify appearance in order book', async () => { + test('TC_DEMEX_TO_1: Place a buy order, verify appearance in order book', async () => { const tradePage = new TradeTradePage(page) await tradePage.opTokenOption.click() await tradePage.spotTab.click() @@ -146,9 +146,36 @@ test.describe.serial(' Phantom wallet ', () => { await newPage2.waitForLoadState() const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) await phantomPage2.connectBtn.click({ delay: 1000 }) - await expect(tradePage.orderedPopup).toBeVisible() + await expect(tradePage.orderedPopup).toBeVisible({ timeout: 10_000}) + const expectedTableData = [ + { + 'Market': 'SWTH / USD', + 'Type': 'Limit|Buy', + 'Size': '1,000 SWTH$1.24', + 'Filled': '0 SWTH$0.00', + } + ] + await tradePage.verifyTableData(expectedTableData) + + }) + + test('TC_DEMEX_TO_4: Cancel an active order and confirm removal', async () => { + const tradePage = new TradeTradePage(page) + + const [newPage3] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.cancelBtn.click() + ]); + await newPage3.waitForLoadState() + + const phantomPage3 = new PhantomPage(newPage3) + await phantomPage3.connectBtn.waitFor({ state: 'visible' }) + await phantomPage3.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000}) }) }) \ No newline at end of file From f6845a49bc0b7932ded8dd208bcf35e0e1468a2e Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Thu, 6 Mar 2025 01:05:34 +0700 Subject: [PATCH 3/6] update withdraw flow & done TC_DEMEX_TO_2 Sell order with Phantom wallet --- pages/TradeTradePage.page.ts | 4 + pages/WithdrawPage.ts | 4 +- .../ConnectEncryptedKeyWallet.spec.ts | 4 +- .../ConnectLeapWallet.spec.ts | 4 +- .../ConnectMetaMaskWallet.spec.ts | 74 +++++++++---------- .../ConnectPhantomWallet.spec.ts | 63 +++++++++++++++- 6 files changed, 107 insertions(+), 46 deletions(-) diff --git a/pages/TradeTradePage.page.ts b/pages/TradeTradePage.page.ts index ade12ce..81186d8 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -14,6 +14,8 @@ export class TradeTradePage{ readonly orderedCancelledPopup: Locator readonly cancelBtn: Locator readonly cancelAllBtn: Locator + readonly switchingBtn: Locator + readonly sellBtn: Locator constructor(page: Page){ this.page=page; @@ -30,6 +32,8 @@ export class TradeTradePage{ this.orderedCancelledPopup = this.page.getByText('Order Cancelled') this.cancelBtn = this.page.getByRole('button', { name: 'Cancel', exact: true }) this.cancelAllBtn = this.page.getByRole('columnheader', { name: 'Cancel All' }) + this.switchingBtn = this.page.locator("button:has(span:has-text('Buy SWTH'))").locator("xpath=following-sibling::button") + this.sellBtn = this.page.getByRole('button', { name: 'Sell SWTH', exact: true }) } async goToTradePage(){ diff --git a/pages/WithdrawPage.ts b/pages/WithdrawPage.ts index fd22630..6c833eb 100644 --- a/pages/WithdrawPage.ts +++ b/pages/WithdrawPage.ts @@ -3,6 +3,7 @@ import { type Locator, type Page } from '@playwright/test'; export class WithdrawPage{ readonly page: Page; readonly carbonGroupUSD: Locator + readonly selectToken: Locator readonly swthTokenOption: Locator readonly recipientAddrTextbox: Locator readonly amountTextbox: Locator @@ -12,7 +13,8 @@ export class WithdrawPage{ constructor (page:Page){ this.page=page; - this.carbonGroupUSD = this.page.getByRole('button', { name: 'cUSD USD Carbon Grouped USD' }) + //this.carbonGroupUSD = this.page.getByRole('button', { name: 'cUSD USD Carbon Grouped USD' }) + this.selectToken = this.page.getByRole('button', { name: 'Select Token' }) this.swthTokenOption = this.page.getByRole('cell', { name: 'SWTH SWTH Carbon Token' }) this.recipientAddrTextbox = this.page.getByRole('textbox', { name: 'swth1q...' }) this.amountTextbox = this.page.getByRole('spinbutton').first() diff --git a/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts index 2430c8e..080960b 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts @@ -78,13 +78,13 @@ test.describe.serial('Connect Leap wallet by Encrypted Key & Verify deposit', ( test('Verify that the withdraw can be executed with other wallets address', async () => { const depositPage = new DepositPage(page) await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() + //await depositPage.myBrowerWallet.click() const homePage = new HomePage(page) await homePage.withdrawnTab.click() const withdrawPage = new WithdrawPage(page) - await withdrawPage.carbonGroupUSD.click() + await withdrawPage.selectToken.click() await withdrawPage.swthTokenOption.click() await withdrawPage.recipientAddrTextbox.fill(phantomSwthAddress) await withdrawPage.amountTextbox.fill('1') diff --git a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts index 5c1c17d..34ed7b7 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts @@ -113,13 +113,13 @@ test.describe.serial('Leap wallet ', () => { test('Verify that the withdraw can be executed with other wallets address', async () => { const depositPage = new DepositPage(page) await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() + //await depositPage.myBrowerWallet.click() const homePage = new HomePage(page) await homePage.withdrawnTab.click() const withdrawPage = new WithdrawPage(page) - await withdrawPage.carbonGroupUSD.click() + await withdrawPage.selectToken.click() await withdrawPage.swthTokenOption.click() await withdrawPage.recipientAddrTextbox.fill(phantomSwthAddress) await withdrawPage.amountTextbox.fill('1') diff --git a/tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts index 88a404a..ce41dff 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts @@ -103,41 +103,41 @@ test.describe.serial('Connect MetaMask wallet & Verify deposit', () => { }) - test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() - await depositPage.selectNetworkBtn.click() - await depositPage.networkOption('Ethereum').click() - await depositPage.amountTextbox.fill('0') - await depositPage.metaMaskDepositBtn.click() - await expect(depositPage.errorAmountMsg).toBeVisible() - }) - - test('Verify that the withdraw can be executed with other wallets address', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() - - const homePage = new HomePage(page) - await homePage.withdrawnTab.click() - - const withdrawPage = new WithdrawPage(page) - await withdrawPage.carbonGroupUSD.click() - await withdrawPage.swthTokenOption.click() - await withdrawPage.recipientAddrTextbox.fill(phantomSwthAddress) - await withdrawPage.amountTextbox.fill('1') - - const [popup] = await Promise.all([ - browserContext.waitForEvent('page'), - await withdrawPage.withdrawBtn.click() - ]); - await popup.waitForLoadState() - - const confirmPage = new MetaMaskPage(popup) - await confirmPage.confirmFooterBtn.waitFor({ state: 'visible' }) - await confirmPage.confirmFooterBtn.click({ delay: 1000 }) - - await expect(withdrawPage.transactionSuccess).toBeVisible() - }) + test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + await depositPage.myBrowerWallet.click() + await depositPage.selectNetworkBtn.click() + await depositPage.networkOption('Ethereum').click() + await depositPage.amountTextbox.fill('0') + await depositPage.metaMaskDepositBtn.click() + await expect(depositPage.errorAmountMsg).toBeVisible() + }) + + test('Verify that the withdraw can be executed with other wallets address', async () => { + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + //await depositPage.myBrowerWallet.click() + + const homePage = new HomePage(page) + await homePage.withdrawnTab.click() + + const withdrawPage = new WithdrawPage(page) + await withdrawPage.selectToken.click() + await withdrawPage.swthTokenOption.click() + await withdrawPage.recipientAddrTextbox.fill(phantomSwthAddress) + await withdrawPage.amountTextbox.fill('1') + + const [popup] = await Promise.all([ + browserContext.waitForEvent('page'), + await withdrawPage.withdrawBtn.click() + ]); + await popup.waitForLoadState() + + const confirmPage = new MetaMaskPage(popup) + await confirmPage.confirmFooterBtn.waitFor({ state: 'visible' }) + await confirmPage.confirmFooterBtn.click({ delay: 1000 }) + + await expect(withdrawPage.transactionSuccess).toBeVisible() + }) }) \ No newline at end of file diff --git a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts index 939c566..0c126c9 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts @@ -76,6 +76,7 @@ test.describe.serial(' Phantom wallet ', () => { await newPage2.waitForLoadState() const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) await phantomPage2.connectBtn.click({ delay: 1000 }) await page.waitForTimeout(10_000) @@ -103,16 +104,17 @@ test.describe.serial(' Phantom wallet ', () => { await expect(depositPage.errorAmountMsg).toBeVisible() }) - test.skip('Verify that the withdraw can be executed with other wallets address', async () => { + test('Verify that the withdraw can be executed with other wallets address', async () => { const depositPage = new DepositPage(page) await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() + //await depositPage.myBrowerWallet.click() const homePage = new HomePage(page) await homePage.withdrawnTab.click() const withdrawPage = new WithdrawPage(page) - await withdrawPage.carbonGroupUSD.click() + //await withdrawPage.carbonGroupUSD.click() + await withdrawPage.selectToken.click() await withdrawPage.swthTokenOption.click() await withdrawPage.recipientAddrTextbox.fill(leapSwthAddress) await withdrawPage.amountTextbox.fill('1') @@ -131,6 +133,8 @@ test.describe.serial(' Phantom wallet ', () => { }) test('TC_DEMEX_TO_1: Place a buy order, verify appearance in order book', async () => { + const homePage = new HomePage(page) + await homePage.goToHomePage() const tradePage = new TradeTradePage(page) await tradePage.opTokenOption.click() await tradePage.spotTab.click() @@ -155,7 +159,6 @@ test.describe.serial(' Phantom wallet ', () => { { 'Market': 'SWTH / USD', 'Type': 'Limit|Buy', - 'Size': '1,000 SWTH$1.24', 'Filled': '0 SWTH$0.00', } ] @@ -164,6 +167,8 @@ test.describe.serial(' Phantom wallet ', () => { }) test('TC_DEMEX_TO_4: Cancel an active order and confirm removal', async () => { + await page.reload() + await page.waitForLoadState() const tradePage = new TradeTradePage(page) const [newPage3] = await Promise.all([ @@ -178,4 +183,54 @@ test.describe.serial(' Phantom wallet ', () => { await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000}) }) + + test('TC_DEMEX_TO_2: Place a sell order, verify appearance in order book', async () => { + await page.reload() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) + await tradePage.amountToken.fill('1000') + await tradePage.switchingBtn.click() + await tradePage.sellBtn.click() + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.confirmBtn.click() + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.orderedPopup).toBeVisible({ timeout: 10_000}) + + const expectedTableData = [ + { + 'Market': 'SWTH / USD', + 'Type': 'Limit|Sell', + 'Filled': '0 SWTH$0.00', + } + ] + await tradePage.verifyTableData(expectedTableData) + + }) +}) + +test.afterAll('Reset data', async () => { + const tradePage = new TradeTradePage(page) + try { + await tradePage.cancelAllBtn.click({timeout: 5000}) + } catch (e) {} + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.confirmBtn.click() + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000}) }) \ No newline at end of file From 9de39339ab719353a69aeef0b30be0bfc13332f3 Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Fri, 7 Mar 2025 00:23:55 +0700 Subject: [PATCH 4/6] add TC_DEMEX_TO_3: Test limit and market orders for a range of assets with Phantom wallet --- pages/PhantomPage.ts | 1 - pages/TradeTradePage.page.ts | 12 +- .../ConnectPhantomWallet.spec.ts | 142 +++++++++++------- 3 files changed, 96 insertions(+), 59 deletions(-) diff --git a/pages/PhantomPage.ts b/pages/PhantomPage.ts index c90c15e..5a499f1 100644 --- a/pages/PhantomPage.ts +++ b/pages/PhantomPage.ts @@ -19,7 +19,6 @@ export class PhantomPage{ readonly amountTextbox: Locator readonly depositBtnn: Locator readonly errorAmountMsg: Locator - constructor (page:Page){ this.page=page; diff --git a/pages/TradeTradePage.page.ts b/pages/TradeTradePage.page.ts index 81186d8..cd37f55 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -10,12 +10,15 @@ export class TradeTradePage{ readonly amountToken: Locator readonly buyBtn: Locator readonly confirmBtn: Locator - readonly orderedPopup: Locator + readonly orderPlacedPopup: Locator readonly orderedCancelledPopup: Locator readonly cancelBtn: Locator readonly cancelAllBtn: Locator readonly switchingBtn: Locator readonly sellBtn: Locator + readonly marketBtn: Locator + readonly amountOnMarket: Locator + readonly tradeExecutedPopup: Locator constructor(page: Page){ this.page=page; @@ -24,16 +27,19 @@ export class TradeTradePage{ this.opTokenOption = this.page.getByRole('img', { name: 'OP' }) this.spotTab = this.page.getByRole('button', { name: 'Spot', exact: true }) this.searchToken = this.page.getByRole('textbox', { name: 'e.g. “SWTH” or “BTC”' }) - this.swthUSDOption = this.page.locator('#root').getByText('SWTH / USD') + this.swthUSDOption = this.page.locator('#root').getByText('SWTH / USD', { exact: true }) this.amountToken = this.page.getByRole('spinbutton').nth(1) + this.amountOnMarket = this.page.getByRole('spinbutton').first() this.buyBtn = this.page.getByRole('button', { name: 'Buy SWTH', exact: true }) this.confirmBtn = this.page.getByRole('button', { name: 'Confirm' }) - this.orderedPopup = this.page.getByText('Order Placed') + this.orderPlacedPopup = this.page.getByText('Order Placed', { exact: true }) this.orderedCancelledPopup = this.page.getByText('Order Cancelled') this.cancelBtn = this.page.getByRole('button', { name: 'Cancel', exact: true }) this.cancelAllBtn = this.page.getByRole('columnheader', { name: 'Cancel All' }) this.switchingBtn = this.page.locator("button:has(span:has-text('Buy SWTH'))").locator("xpath=following-sibling::button") this.sellBtn = this.page.getByRole('button', { name: 'Sell SWTH', exact: true }) + this.marketBtn = this.page.getByRole('button', { name: 'Market', exact: true }) + this.tradeExecutedPopup = this.page.getByText('Trade Executed', { exact: true }) } async goToTradePage(){ diff --git a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts index 0c126c9..738239b 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts +++ b/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts @@ -93,52 +93,15 @@ test.describe.serial(' Phantom wallet ', () => { }) - test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() - await depositPage.selectNetworkBtn.click() - await depositPage.networkOption('Ethereum').click() - await depositPage.amountTextbox.fill('0') - await depositPage.phantomDepositBtn.click() - await expect(depositPage.errorAmountMsg).toBeVisible() - }) - - test('Verify that the withdraw can be executed with other wallets address', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - //await depositPage.myBrowerWallet.click() - - const homePage = new HomePage(page) - await homePage.withdrawnTab.click() - - const withdrawPage = new WithdrawPage(page) - //await withdrawPage.carbonGroupUSD.click() - await withdrawPage.selectToken.click() - await withdrawPage.swthTokenOption.click() - await withdrawPage.recipientAddrTextbox.fill(leapSwthAddress) - await withdrawPage.amountTextbox.fill('1') - - const [popup] = await Promise.all([ - browserContext.waitForEvent('page'), - await withdrawPage.withdrawBtn.click() - ]); - await popup.waitForLoadState() - - const confirmPage = new PhantomPage(popup) - await confirmPage.connectBtn.waitFor({ state: 'visible' }) - await confirmPage.connectBtn.click({ delay: 1000 }) - - await expect(withdrawPage.transactionSuccess).toBeVisible() - }) - test('TC_DEMEX_TO_1: Place a buy order, verify appearance in order book', async () => { const homePage = new HomePage(page) await homePage.goToHomePage() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) await tradePage.opTokenOption.click() await tradePage.spotTab.click() - await tradePage.searchToken.fill('SWTH') + await tradePage.searchToken.fill('SWTH / USD') await tradePage.swthUSDOption.click() await tradePage.amountToken.fill('1000') await tradePage.buyBtn.click() @@ -153,7 +116,7 @@ test.describe.serial(' Phantom wallet ', () => { await phantomPage2.connectBtn.waitFor({ state: 'visible' }) await phantomPage2.connectBtn.click({ delay: 1000 }) - await expect(tradePage.orderedPopup).toBeVisible({ timeout: 10_000}) + await expect(tradePage.orderPlacedPopup).toBeVisible({ timeout: 10_000 }) const expectedTableData = [ { @@ -181,7 +144,7 @@ test.describe.serial(' Phantom wallet ', () => { await phantomPage3.connectBtn.waitFor({ state: 'visible' }) await phantomPage3.connectBtn.click({ delay: 1000 }) - await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000}) + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) }) test('TC_DEMEX_TO_2: Place a sell order, verify appearance in order book', async () => { @@ -202,7 +165,7 @@ test.describe.serial(' Phantom wallet ', () => { await phantomPage2.connectBtn.waitFor({ state: 'visible' }) await phantomPage2.connectBtn.click({ delay: 1000 }) - await expect(tradePage.orderedPopup).toBeVisible({ timeout: 10_000}) + await expect(tradePage.orderPlacedPopup).toBeVisible({ timeout: 10_000 }) const expectedTableData = [ { @@ -214,23 +177,92 @@ test.describe.serial(' Phantom wallet ', () => { await tradePage.verifyTableData(expectedTableData) }) + + test('TC_DEMEX_TO_3: Test limit and market orders for a range of assets', async () => { + await page.reload() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) + await tradePage.marketBtn.click() + await tradePage.buyBtn.waitFor({ state: 'visible' }) + await tradePage.amountOnMarket.fill('1000') + await tradePage.buyBtn.click() + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.confirmBtn.click() + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.tradeExecutedPopup).toBeVisible({ timeout: 10_000 }) + + }) + + test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + await depositPage.myBrowerWallet.click() + await depositPage.selectNetworkBtn.click() + await depositPage.networkOption('Ethereum').click() + await depositPage.amountTextbox.fill('0') + await depositPage.phantomDepositBtn.click() + await expect(depositPage.errorAmountMsg).toBeVisible() + }) + + test('Verify that the withdraw can be executed with other wallets address', async () => { + await page.reload() + await page.waitForLoadState() + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + //await depositPage.myBrowerWallet.click() + + const homePage = new HomePage(page) + await homePage.withdrawnTab.click() + + const withdrawPage = new WithdrawPage(page) + //await withdrawPage.carbonGroupUSD.click() + await withdrawPage.selectToken.click() + await withdrawPage.swthTokenOption.click() + await withdrawPage.recipientAddrTextbox.fill(leapSwthAddress) + await withdrawPage.amountTextbox.fill('1') + + const [popup] = await Promise.all([ + browserContext.waitForEvent('page'), + await withdrawPage.withdrawBtn.click() + ]); + await popup.waitForLoadState() + + const confirmPage = new PhantomPage(popup) + await confirmPage.connectBtn.waitFor({ state: 'visible' }) + await confirmPage.connectBtn.click({ delay: 1000 }) + + await expect(withdrawPage.transactionSuccess).toBeVisible() + }) }) test.afterAll('Reset data', async () => { + const homePage = new HomePage(page) + await homePage.goToHomePage() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) try { - await tradePage.cancelAllBtn.click({timeout: 5000}) - } catch (e) {} - - const [newPage2] = await Promise.all([ - browserContext.waitForEvent('page'), - await tradePage.confirmBtn.click() - ]); - await newPage2.waitForLoadState() + await tradePage.cancelAllBtn.click({ timeout: 15_000 }) - const phantomPage2 = new PhantomPage(newPage2) - await phantomPage2.connectBtn.waitFor({ state: 'visible' }) - await phantomPage2.connectBtn.click({ delay: 1000 }) + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + await tradePage.confirmBtn.click() + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + } catch (e) { } - await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000}) }) \ No newline at end of file From 9efc90aa246631e491cfdd0a6b4e2ddf27ca6cbd Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Sat, 8 Mar 2025 13:38:45 +0700 Subject: [PATCH 5/6] add DEPOSIT_UI_V2_08: Check the active Withdraw button --- pages/WithdrawPage.ts | 4 + playwright.config.ts | 3 +- .../ConnectByGoogle.spec.ts | 0 .../ConnectByViewOnlyMode.spec.ts | 0 .../ConnectByX.spec.ts | 0 .../ConnectEncryptedKeyWallet.spec.ts | 0 .../ConnectKeplrWallet.spec.ts | 0 .../ConnectLeapWallet.spec.ts | 0 .../ConnectMetaMaskWallet.spec.ts | 0 .../ConnectPhantomWallet.spec.ts | 107 +++++++++++++++ .../TradingOnPhantom.spec.ts} | 119 +++++----------- tests/WithdrawToken/WithdrawOnPhantom.spec.ts | 127 ++++++++++++++++++ 12 files changed, 272 insertions(+), 88 deletions(-) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectByGoogle.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectByViewOnlyMode.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectByX.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectEncryptedKeyWallet.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectKeplrWallet.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectLeapWallet.spec.ts (100%) rename tests/{ConnectWalletsAndDeposit => ConnectWallets}/ConnectMetaMaskWallet.spec.ts (100%) create mode 100644 tests/ConnectWallets/ConnectPhantomWallet.spec.ts rename tests/{ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts => TradingToken/TradingOnPhantom.spec.ts} (62%) create mode 100644 tests/WithdrawToken/WithdrawOnPhantom.spec.ts diff --git a/pages/WithdrawPage.ts b/pages/WithdrawPage.ts index 6c833eb..16812c6 100644 --- a/pages/WithdrawPage.ts +++ b/pages/WithdrawPage.ts @@ -10,6 +10,8 @@ export class WithdrawPage{ readonly memoTextbox: Locator readonly withdrawBtn: Locator readonly transactionSuccess: Locator + readonly invalidAddressErrorMsg: Locator + readonly invalidAmountErrorMsg: Locator constructor (page:Page){ this.page=page; @@ -21,6 +23,8 @@ export class WithdrawPage{ this.memoTextbox = this.page.getByRole('textbox', { name: 'Enter message' }) this.transactionSuccess = this.page.locator('div').filter({ hasText: /^Transaction Success$/ }) this.withdrawBtn = this.page.getByRole('button', { name: 'Withdraw' }).nth(1) + this.invalidAddressErrorMsg = this.page.getByText('Invalid address. Only enter a') + this.invalidAmountErrorMsg = this.page.getByText('Invalid amount. Please enter') } diff --git a/playwright.config.ts b/playwright.config.ts index c0ef5e2..9ec0643 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,7 +12,8 @@ import { defineConfig, devices } from '@playwright/test'; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - testDir: './tests/ConnectWalletsAndDeposit', + testDir: './tests', + testMatch: '**/*.spec.ts', timeout: 60_000, /* Run tests in files in parallel */ fullyParallel: true, diff --git a/tests/ConnectWalletsAndDeposit/ConnectByGoogle.spec.ts b/tests/ConnectWallets/ConnectByGoogle.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectByGoogle.spec.ts rename to tests/ConnectWallets/ConnectByGoogle.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectByViewOnlyMode.spec.ts b/tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectByViewOnlyMode.spec.ts rename to tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectByX.spec.ts b/tests/ConnectWallets/ConnectByX.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectByX.spec.ts rename to tests/ConnectWallets/ConnectByX.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts b/tests/ConnectWallets/ConnectEncryptedKeyWallet.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts rename to tests/ConnectWallets/ConnectEncryptedKeyWallet.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectKeplrWallet.spec.ts b/tests/ConnectWallets/ConnectKeplrWallet.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectKeplrWallet.spec.ts rename to tests/ConnectWallets/ConnectKeplrWallet.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts b/tests/ConnectWallets/ConnectLeapWallet.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts rename to tests/ConnectWallets/ConnectLeapWallet.spec.ts diff --git a/tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts b/tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts similarity index 100% rename from tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts rename to tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts diff --git a/tests/ConnectWallets/ConnectPhantomWallet.spec.ts b/tests/ConnectWallets/ConnectPhantomWallet.spec.ts new file mode 100644 index 0000000..4f0117c --- /dev/null +++ b/tests/ConnectWallets/ConnectPhantomWallet.spec.ts @@ -0,0 +1,107 @@ +import { test, expect, Page, BrowserContext } from '@playwright/test' +import { createBrowserContext } from "../../utils/create-browser-context"; +import { HomePage } from '../../pages/HomePage.page'; +import { TradeTradePage } from '../../pages/TradeTradePage.page'; +import { ConnectWalletPage } from '../../pages/ConnectWalletPage'; +import { PhantomPage } from '../../pages/PhantomPage'; +import { DepositPage } from '../../pages/DepositPage'; +import { WithdrawPage } from '../../pages/WithdrawPage'; + +let page: Page +let browserContext: BrowserContext +const srpArr = ["doll", "injury", "material", "wise", "matrix", "pet", "debate", "asset", "forest", "online", "toss", "holiday"] +const password = 'Abc123456789' +const extensionName = "phantom" +const leapSwthAddress = 'tswth1mw6zu5y7dxdhcrej4jqct95xxf7j5lgh6dyhfn' + +test.beforeAll('Add extension: Phantom', async () => { + test.setTimeout(90_000) + browserContext = await createBrowserContext(extensionName) + page = await browserContext.newPage() + + const [newPage] = await Promise.all([ + browserContext.waitForEvent('page'), + ]); + await newPage.waitForLoadState() + + const phantomPage = new PhantomPage(newPage) + await phantomPage.alreadyHaveWalletBtn.click() + await phantomPage.importSecretRecoveryPhraseBtn.click() + + for (let i = 0; i < srpArr.length; i++) { + await phantomPage.secretRecoveryPhrases(i).fill(srpArr[i]) + } + await phantomPage.importWalletBtn.click() + await phantomPage.continueBtn.click() + await phantomPage.newPasswordTextBox.fill(password) + await phantomPage.confirmPasswordTextBox.fill(password) + await phantomPage.termServiceCheckbox.click() + await phantomPage.continueBtn.click() + //await phantomPage.submitBtn.click({ delay: 1000 }) + + await page.bringToFront() + +}) +test.describe.serial(' Phantom wallet ', () => { + test('Connect Phantom wallet', async () => { + test.setTimeout(180_000) + const homePage = new HomePage(page) + await homePage.goToHomePage() + page.waitForLoadState() + expect(homePage.spotHistory).toBeTruthy(); + //await homePage.carbonTestnet.click(); + //await homePage.mantle.click() + await page.waitForLoadState() + + await page.waitForTimeout(10_000) + const tradePage = new TradeTradePage(page); + await tradePage.headerConnectWallet.click(); + + const connectWalletPage = new ConnectWalletPage(page) + await connectWalletPage.selectWallet.isVisible() + await connectWalletPage.phantomBtn.waitFor({ state: 'visible' }) + + const [newPage1] = await Promise.all([ + browserContext.waitForEvent('page'), + await connectWalletPage.phantomBtn.click({ delay: 1000 }) + ]); + await newPage1.waitForLoadState() + + const phantomPage1 = new PhantomPage(newPage1) + await phantomPage1.connectBtn.click({ delay: 1000 }) + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + + await page.waitForTimeout(10_000) + await homePage.addressPhantomDropBtn.waitFor({ state: 'visible' }) + await homePage.addressPhantomDropBtn.click({ delay: 100 }) + await homePage.dropAddress2.waitFor({ state: 'visible' }) + await homePage.dropAddress2.click({ delay: 100 }) + + await homePage.copyEVMAddressBtn.click() + const copiedEVMAddressText = await page.evaluate(() => navigator.clipboard.readText()) + console.log(copiedEVMAddressText) + const evmPattern = /^0x[a-fA-F0-9]{40}$/ + expect(copiedEVMAddressText.trim()).toMatch(evmPattern) + + }) + + test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + await depositPage.myBrowerWallet.click() + await depositPage.selectNetworkBtn.click() + await depositPage.networkOption('Ethereum').click() + await depositPage.amountTextbox.fill('0') + await depositPage.phantomDepositBtn.click() + await expect(depositPage.errorAmountMsg).toBeVisible() + }) + +}) diff --git a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts b/tests/TradingToken/TradingOnPhantom.spec.ts similarity index 62% rename from tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts rename to tests/TradingToken/TradingOnPhantom.spec.ts index 738239b..e68983e 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts +++ b/tests/TradingToken/TradingOnPhantom.spec.ts @@ -40,59 +40,44 @@ test.beforeAll('Add extension: Phantom', async () => { //await phantomPage.submitBtn.click({ delay: 1000 }) await page.bringToFront() + test.setTimeout(180_000) + const homePage = new HomePage(page) + await homePage.goToHomePage() + page.waitForLoadState() + expect(homePage.spotHistory).toBeTruthy(); + //await homePage.carbonTestnet.click(); + //await homePage.mantle.click() + await page.waitForLoadState() -}) -test.describe.serial(' Phantom wallet ', () => { - test('Connect Phantom wallet', async () => { - test.setTimeout(180_000) - const homePage = new HomePage(page) - await homePage.goToHomePage() - page.waitForLoadState() - expect(homePage.spotHistory).toBeTruthy(); - //await homePage.carbonTestnet.click(); - //await homePage.mantle.click() - await page.waitForLoadState() - - await page.waitForTimeout(10_000) - const tradePage = new TradeTradePage(page); - await tradePage.headerConnectWallet.click(); - - const connectWalletPage = new ConnectWalletPage(page) - await connectWalletPage.selectWallet.isVisible() - await connectWalletPage.phantomBtn.waitFor({ state: 'visible' }) - - const [newPage1] = await Promise.all([ - browserContext.waitForEvent('page'), - await connectWalletPage.phantomBtn.click({ delay: 1000 }) - ]); - await newPage1.waitForLoadState() - - const phantomPage1 = new PhantomPage(newPage1) - await phantomPage1.connectBtn.click({ delay: 1000 }) + await page.waitForTimeout(10_000) + const tradePage = new TradeTradePage(page); + await tradePage.headerConnectWallet.click(); - const [newPage2] = await Promise.all([ - browserContext.waitForEvent('page'), - ]); - await newPage2.waitForLoadState() + const connectWalletPage = new ConnectWalletPage(page) + await connectWalletPage.selectWallet.isVisible() + await connectWalletPage.phantomBtn.waitFor({ state: 'visible' }) - const phantomPage2 = new PhantomPage(newPage2) - await phantomPage2.connectBtn.waitFor({ state: 'visible' }) - await phantomPage2.connectBtn.click({ delay: 1000 }) + const [newPage1] = await Promise.all([ + browserContext.waitForEvent('page'), + await connectWalletPage.phantomBtn.click({ delay: 1000 }) + ]); + await newPage1.waitForLoadState() - await page.waitForTimeout(10_000) - await homePage.addressPhantomDropBtn.waitFor({ state: 'visible' }) - await homePage.addressPhantomDropBtn.click({ delay: 100 }) - await homePage.dropAddress2.waitFor({ state: 'visible' }) - await homePage.dropAddress2.click({ delay: 100 }) + const phantomPage1 = new PhantomPage(newPage1) + await phantomPage1.connectBtn.click({ delay: 1000 }) - await homePage.copyEVMAddressBtn.click() - const copiedEVMAddressText = await page.evaluate(() => navigator.clipboard.readText()) - console.log(copiedEVMAddressText) - const evmPattern = /^0x[a-fA-F0-9]{40}$/ - expect(copiedEVMAddressText.trim()).toMatch(evmPattern) + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + ]); + await newPage2.waitForLoadState() - }) + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + await homePage.addressPhantomDropBtn.waitFor({ state: 'visible' }) +}) +test.describe(' Trading Token with Phantom wallet ', () => { test('TC_DEMEX_TO_1: Place a buy order, verify appearance in order book', async () => { const homePage = new HomePage(page) await homePage.goToHomePage() @@ -200,47 +185,7 @@ test.describe.serial(' Phantom wallet ', () => { await expect(tradePage.tradeExecutedPopup).toBeVisible({ timeout: 10_000 }) }) - - test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() - await depositPage.selectNetworkBtn.click() - await depositPage.networkOption('Ethereum').click() - await depositPage.amountTextbox.fill('0') - await depositPage.phantomDepositBtn.click() - await expect(depositPage.errorAmountMsg).toBeVisible() - }) - test('Verify that the withdraw can be executed with other wallets address', async () => { - await page.reload() - await page.waitForLoadState() - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - //await depositPage.myBrowerWallet.click() - - const homePage = new HomePage(page) - await homePage.withdrawnTab.click() - - const withdrawPage = new WithdrawPage(page) - //await withdrawPage.carbonGroupUSD.click() - await withdrawPage.selectToken.click() - await withdrawPage.swthTokenOption.click() - await withdrawPage.recipientAddrTextbox.fill(leapSwthAddress) - await withdrawPage.amountTextbox.fill('1') - - const [popup] = await Promise.all([ - browserContext.waitForEvent('page'), - await withdrawPage.withdrawBtn.click() - ]); - await popup.waitForLoadState() - - const confirmPage = new PhantomPage(popup) - await confirmPage.connectBtn.waitFor({ state: 'visible' }) - await confirmPage.connectBtn.click({ delay: 1000 }) - - await expect(withdrawPage.transactionSuccess).toBeVisible() - }) }) test.afterAll('Reset data', async () => { @@ -250,7 +195,7 @@ test.afterAll('Reset data', async () => { const tradePage = new TradeTradePage(page) try { - await tradePage.cancelAllBtn.click({ timeout: 15_000 }) + await tradePage.cancelAllBtn.click({ timeout: 10_000 }) const [newPage2] = await Promise.all([ browserContext.waitForEvent('page'), diff --git a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts new file mode 100644 index 0000000..e302cc3 --- /dev/null +++ b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts @@ -0,0 +1,127 @@ +import { test, expect, Page, BrowserContext } from '@playwright/test' +import { createBrowserContext } from "../../utils/create-browser-context"; +import { HomePage } from '../../pages/HomePage.page'; +import { TradeTradePage } from '../../pages/TradeTradePage.page'; +import { ConnectWalletPage } from '../../pages/ConnectWalletPage'; +import { PhantomPage } from '../../pages/PhantomPage'; +import { DepositPage } from '../../pages/DepositPage'; +import { WithdrawPage } from '../../pages/WithdrawPage'; + +let page: Page +let browserContext: BrowserContext +const srpArr = ["doll", "injury", "material", "wise", "matrix", "pet", "debate", "asset", "forest", "online", "toss", "holiday"] +const password = 'Abc123456789' +const extensionName = "phantom" +const leapSwthAddress = 'tswth1mw6zu5y7dxdhcrej4jqct95xxf7j5lgh6dyhfn' + +test.beforeAll('Add extension: Phantom', async () => { + test.setTimeout(90_000) + browserContext = await createBrowserContext(extensionName) + page = await browserContext.newPage() + + const [newPage] = await Promise.all([ + browserContext.waitForEvent('page'), + ]); + await newPage.waitForLoadState() + + const phantomPage = new PhantomPage(newPage) + await phantomPage.alreadyHaveWalletBtn.click() + await phantomPage.importSecretRecoveryPhraseBtn.click() + + for (let i = 0; i < srpArr.length; i++) { + await phantomPage.secretRecoveryPhrases(i).fill(srpArr[i]) + } + await phantomPage.importWalletBtn.click() + await phantomPage.continueBtn.click() + await phantomPage.newPasswordTextBox.fill(password) + await phantomPage.confirmPasswordTextBox.fill(password) + await phantomPage.termServiceCheckbox.click() + await phantomPage.continueBtn.click() + //await phantomPage.submitBtn.click({ delay: 1000 }) + + await page.bringToFront() + test.setTimeout(180_000) + const homePage = new HomePage(page) + await homePage.goToHomePage() + page.waitForLoadState() + expect(homePage.spotHistory).toBeTruthy(); + //await homePage.carbonTestnet.click(); + //await homePage.mantle.click() + await page.waitForLoadState() + + await page.waitForTimeout(10_000) + const tradePage = new TradeTradePage(page); + await tradePage.headerConnectWallet.click(); + + const connectWalletPage = new ConnectWalletPage(page) + await connectWalletPage.selectWallet.isVisible() + await connectWalletPage.phantomBtn.waitFor({ state: 'visible' }) + + const [newPage1] = await Promise.all([ + browserContext.waitForEvent('page'), + await connectWalletPage.phantomBtn.click({ delay: 1000 }) + ]); + await newPage1.waitForLoadState() + + const phantomPage1 = new PhantomPage(newPage1) + await phantomPage1.connectBtn.click({ delay: 1000 }) + + const [newPage2] = await Promise.all([ + browserContext.waitForEvent('page'), + ]); + await newPage2.waitForLoadState() + + const phantomPage2 = new PhantomPage(newPage2) + await phantomPage2.connectBtn.waitFor({ state: 'visible' }) + await phantomPage2.connectBtn.click({ delay: 1000 }) + await homePage.addressPhantomDropBtn.waitFor({ state: 'visible' }) + +}) +test.describe(' Withdraw Token with Phantom wallet ', () => { + test('DEPOSIT_UI_V2_08: Check the active Withdraw button on the Deposit page', async () => { + await page.reload() + await page.waitForLoadState() + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + + const homePage = new HomePage(page) + await homePage.withdrawnTab.click() + + const withdrawPage = new WithdrawPage(page) + await withdrawPage.selectToken.click() + await withdrawPage.swthTokenOption.click() + await withdrawPage.withdrawBtn.click() + await expect(withdrawPage.invalidAddressErrorMsg).toBeVisible() + await expect(withdrawPage.invalidAmountErrorMsg).toBeVisible() + + }) + + test('Verify that the withdraw can be executed with other wallets address', async () => { + await page.reload() + await page.waitForLoadState() + const depositPage = new DepositPage(page) + await depositPage.depositBtn.click() + + const homePage = new HomePage(page) + await homePage.withdrawnTab.click() + + const withdrawPage = new WithdrawPage(page) + await withdrawPage.selectToken.click() + await withdrawPage.swthTokenOption.click() + await withdrawPage.recipientAddrTextbox.fill(leapSwthAddress) + await withdrawPage.amountTextbox.fill('1') + + const [popup] = await Promise.all([ + browserContext.waitForEvent('page'), + await withdrawPage.withdrawBtn.click() + ]); + await popup.waitForLoadState() + + const confirmPage = new PhantomPage(popup) + await confirmPage.connectBtn.waitFor({ state: 'visible' }) + await confirmPage.connectBtn.click({ delay: 1000 }) + + await expect(withdrawPage.transactionSuccess).toBeVisible() + }) + +}) From 4fe09e17ed334cbc57d4148e3905c7ec8683e0ad Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Tue, 11 Mar 2025 00:17:54 +0700 Subject: [PATCH 6/6] add test scripts Trading token when connect wallet by Encrypted Key --- .../ConnectByViewOnlyMode.spec.ts | 2 +- .../ConnectWallets/ConnectKeplrWallet.spec.ts | 2 +- .../ConnectMetaMaskWallet.spec.ts | 15 +- .../ConnectPhantomWallet.spec.ts | 1 - .../TradingByEncryptedKey.spec.ts | 138 ++++++++++++++++++ tests/TradingToken/TradingOnPhantom.spec.ts | 3 - tests/WithdrawToken/WithdrawOnPhantom.spec.ts | 2 +- 7 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 tests/TradingToken/TradingByEncryptedKey.spec.ts diff --git a/tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts b/tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts index 0e8474b..27ac68c 100644 --- a/tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts +++ b/tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts @@ -17,7 +17,7 @@ test.beforeAll('Launch browser context with permission', async () => { }) -test('Connect wallet by View Only Mode', async () => { +test.skip('Connect wallet by View Only Mode', async () => { test.setTimeout(90_000) const homePage = new HomePage(page) await homePage.goToHomePage() diff --git a/tests/ConnectWallets/ConnectKeplrWallet.spec.ts b/tests/ConnectWallets/ConnectKeplrWallet.spec.ts index 816e268..7ae2969 100644 --- a/tests/ConnectWallets/ConnectKeplrWallet.spec.ts +++ b/tests/ConnectWallets/ConnectKeplrWallet.spec.ts @@ -45,7 +45,7 @@ test.beforeAll('Add extension: Keplr', async () => { await page.bringToFront() }) -test('Connect Keplr wallet', async () => { +test.skip('Connect Keplr wallet', async () => { test.setTimeout(120_000) const homePage = new HomePage(page) await homePage.goToHomePage() diff --git a/tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts b/tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts index ce41dff..754c7c9 100644 --- a/tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts +++ b/tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts @@ -50,7 +50,7 @@ test.beforeAll('Add extension: MetaMask', async () => { }) test.describe.serial('Connect MetaMask wallet & Verify deposit', () => { - test('Connect MetaMask wallet', async () => { + test.skip('Connect MetaMask wallet', async () => { test.setTimeout(200_000) const homePage = new HomePage(page) await homePage.goToHomePage() @@ -103,18 +103,7 @@ test.describe.serial('Connect MetaMask wallet & Verify deposit', () => { }) - test.skip('Verify that the validation form is presented when user performed deposit amount = 0', async () => { - const depositPage = new DepositPage(page) - await depositPage.depositBtn.click() - await depositPage.myBrowerWallet.click() - await depositPage.selectNetworkBtn.click() - await depositPage.networkOption('Ethereum').click() - await depositPage.amountTextbox.fill('0') - await depositPage.metaMaskDepositBtn.click() - await expect(depositPage.errorAmountMsg).toBeVisible() - }) - - test('Verify that the withdraw can be executed with other wallets address', async () => { + test.skip('Verify that the withdraw can be executed with other wallets address', async () => { const depositPage = new DepositPage(page) await depositPage.depositBtn.click() //await depositPage.myBrowerWallet.click() diff --git a/tests/ConnectWallets/ConnectPhantomWallet.spec.ts b/tests/ConnectWallets/ConnectPhantomWallet.spec.ts index 4f0117c..3311f23 100644 --- a/tests/ConnectWallets/ConnectPhantomWallet.spec.ts +++ b/tests/ConnectWallets/ConnectPhantomWallet.spec.ts @@ -5,7 +5,6 @@ import { TradeTradePage } from '../../pages/TradeTradePage.page'; import { ConnectWalletPage } from '../../pages/ConnectWalletPage'; import { PhantomPage } from '../../pages/PhantomPage'; import { DepositPage } from '../../pages/DepositPage'; -import { WithdrawPage } from '../../pages/WithdrawPage'; let page: Page let browserContext: BrowserContext diff --git a/tests/TradingToken/TradingByEncryptedKey.spec.ts b/tests/TradingToken/TradingByEncryptedKey.spec.ts new file mode 100644 index 0000000..834bdce --- /dev/null +++ b/tests/TradingToken/TradingByEncryptedKey.spec.ts @@ -0,0 +1,138 @@ +import { test, expect, Page, BrowserContext, chromium } from '@playwright/test' +import { HomePage } from '../../pages/HomePage.page'; +import { TradeTradePage } from '../../pages/TradeTradePage.page'; +import { ConnectWalletPage } from '../../pages/ConnectWalletPage'; +import { EncryptedKeyPage } from '../../pages/EncryptedKeyPage'; + +let page: Page +let browserContext: BrowserContext +const encryptedLeapKey = "2SrrmLXhu2W3rX4jcELNY4GLoo6wGRVB2U7bG7uN58vokMEw8xugKW7ZdzMog2zmEGeqRx6EYfGfPEjeSGWPaebR6sECyX4Yfuo8rc1v773M3yowpKNRqJ3M5QoNbHQqCmqk59sYHVrJM8wqpZe5hvA2cak7M5oLMsLAs1rbBndsLw6fQ7FJUe3quawE8hts77aBv9RLSTRsHeLGuQcQxL15Ukgw2YxbvpGfYpheSGKDfdCJRjW9iZuw4AQwvLec9etS4a5WAZ6LkHC8kcovvaogUwyfHcKDf8w1Bz9pxZwniVvqDn6zaMF7bknJFjbPA69T7aJPQbeTqp9VEApN1r2nJYX3dCyqFJF6NcD2h2JJz" +const passworld = 'Abc123456789' + +test.beforeAll('Launch browser context with permission', async () => { + const browser = await chromium.launch() + browserContext = await browser.newContext({ + permissions: ['clipboard-read', 'clipboard-write'] + }); + page = await browserContext.newPage() + + const homePage = new HomePage(page) + await homePage.goToHomePage() + expect(homePage.spotHistory).toBeTruthy(); + //await homePage.carbonTestnet.click(); + //await homePage.mantle.click() + await page.waitForTimeout(10_000) + + const tradePage = new TradeTradePage(page); + await tradePage.headerConnectWallet.click(); + + const connectWalletPage = new ConnectWalletPage(page) + await connectWalletPage.selectWallet.isVisible() + + await connectWalletPage.encryptedKeyBtn.click({ delay: 2000 }) + const encryptedKeyPage = new EncryptedKeyPage(page) + + await encryptedKeyPage.encryptedKeyTextbox.waitFor({ state: 'visible' }) + await encryptedKeyPage.encryptedKeyTextbox.click() + await encryptedKeyPage.encryptedKeyTextbox.fill(encryptedLeapKey) + await encryptedKeyPage.encryptedKeyTextbox.press('Tab') + await encryptedKeyPage.passwordTextbox.fill(passworld) + await encryptedKeyPage.passwordTextbox.press('Tab') + await encryptedKeyPage.connectBtn.waitFor({ state: 'visible' }) + await encryptedKeyPage.connectBtn.click({ delay: 2000 }) + await encryptedKeyPage.connectBtn.waitFor({ state: 'detached' }) + + await homePage.addressDropBtn.waitFor({ state: 'visible' }) + +}) + +test.describe('Trading Token by Encrypted Key', () => { + test('TC_DEMEX_TO_1: Place a buy order, verify appearance in order book', async () => { + const homePage = new HomePage(page) + await homePage.goToHomePage() + await page.waitForLoadState() + + const tradePage = new TradeTradePage(page) + await tradePage.opTokenOption.click() + await tradePage.spotTab.click() + await tradePage.searchToken.fill('SWTH / USD') + await tradePage.swthUSDOption.click() + await tradePage.amountToken.fill('1000') + await tradePage.buyBtn.click() + await tradePage.confirmBtn.click() + + await expect(tradePage.orderPlacedPopup).toBeVisible({ timeout: 10_000 }) + + const expectedTableData = [ + { + 'Market': 'SWTH / USD', + 'Type': 'Limit|Buy', + 'Filled': '0 SWTH$0.00', + } + ] + await tradePage.verifyTableData(expectedTableData) + + }) + + test('TC_DEMEX_TO_4: Cancel an active order and confirm removal', async () => { + await page.reload() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) + await tradePage.cancelBtn.click() + + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + }) + + test('TC_DEMEX_TO_2: Place a sell order, verify appearance in order book', async () => { + await page.reload() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) + await tradePage.amountToken.fill('1000') + await tradePage.switchingBtn.click() + await tradePage.sellBtn.click() + await tradePage.confirmBtn.click() + + await expect(tradePage.orderPlacedPopup).toBeVisible({ timeout: 10_000 }) + + const expectedTableData = [ + { + 'Market': 'SWTH / USD', + 'Type': 'Limit|Sell', + 'Filled': '0 SWTH$0.00', + } + ] + await tradePage.verifyTableData(expectedTableData) + + await tradePage.cancelBtn.click() + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + + }) + + test('TC_DEMEX_TO_3: Test limit and market orders for a range of assets', async () => { + await page.reload() + await page.waitForLoadState() + const tradePage = new TradeTradePage(page) + await tradePage.marketBtn.click() + await tradePage.buyBtn.waitFor({ state: 'visible' }) + await tradePage.amountOnMarket.fill('1000') + await tradePage.buyBtn.click() + await tradePage.confirmBtn.click() + + await expect(tradePage.tradeExecutedPopup).toBeVisible({ timeout: 10_000 }) + + }) +}) + +test.afterAll('Reset data', async () => { + const homePage = new HomePage(page) + await homePage.goToHomePage() + await page.waitForLoadState() + + const tradePage = new TradeTradePage(page) + try { + await tradePage.cancelAllBtn.click({ timeout: 10_000 }) + await tradePage.confirmBtn.click() + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + } catch (e) { } + +}) \ No newline at end of file diff --git a/tests/TradingToken/TradingOnPhantom.spec.ts b/tests/TradingToken/TradingOnPhantom.spec.ts index e68983e..e9bfdc9 100644 --- a/tests/TradingToken/TradingOnPhantom.spec.ts +++ b/tests/TradingToken/TradingOnPhantom.spec.ts @@ -4,15 +4,12 @@ import { HomePage } from '../../pages/HomePage.page'; import { TradeTradePage } from '../../pages/TradeTradePage.page'; import { ConnectWalletPage } from '../../pages/ConnectWalletPage'; import { PhantomPage } from '../../pages/PhantomPage'; -import { DepositPage } from '../../pages/DepositPage'; -import { WithdrawPage } from '../../pages/WithdrawPage'; let page: Page let browserContext: BrowserContext const srpArr = ["doll", "injury", "material", "wise", "matrix", "pet", "debate", "asset", "forest", "online", "toss", "holiday"] const password = 'Abc123456789' const extensionName = "phantom" -const leapSwthAddress = 'tswth1mw6zu5y7dxdhcrej4jqct95xxf7j5lgh6dyhfn' test.beforeAll('Add extension: Phantom', async () => { test.setTimeout(90_000) diff --git a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts index e302cc3..ba43065 100644 --- a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts +++ b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts @@ -96,7 +96,7 @@ test.describe(' Withdraw Token with Phantom wallet ', () => { }) - test('Verify that the withdraw can be executed with other wallets address', async () => { + test('TC_WTD_MW_001: Verify that the withdraw can be executed with other wallets address', async () => { await page.reload() await page.waitForLoadState() const depositPage = new DepositPage(page)