From a4238d3b290667761766e28717f9e8dc6deebaa2 Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:41:15 +0700 Subject: [PATCH] add test scripts Trading token when connect Keplr by Encrypted Key --- pages/WithdrawPage.ts | 2 +- tests/TradingToken/TradingOnKeplrByEK.spec.ts | 140 ++++++++++++++++++ ...dKey.spec.ts => TradingOnLeapByEK.spec.ts} | 24 +-- tests/TradingToken/TradingOnPhantom.spec.ts | 32 +++- tests/WithdrawToken/WithdrawOnLeap.spec.ts | 91 ++++++------ tests/WithdrawToken/WithdrawOnPhantom.spec.ts | 90 +++++------ 6 files changed, 270 insertions(+), 109 deletions(-) create mode 100644 tests/TradingToken/TradingOnKeplrByEK.spec.ts rename tests/TradingToken/{TradingByEncryptedKey.spec.ts => TradingOnLeapByEK.spec.ts} (90%) diff --git a/pages/WithdrawPage.ts b/pages/WithdrawPage.ts index 16812c6..238b20d 100644 --- a/pages/WithdrawPage.ts +++ b/pages/WithdrawPage.ts @@ -17,7 +17,7 @@ export class WithdrawPage{ this.page=page; //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.swthTokenOption = this.page.getByRole('cell', { name: 'SWTH SWTH Demex Token' }) this.recipientAddrTextbox = this.page.getByRole('textbox', { name: 'swth1q...' }) this.amountTextbox = this.page.getByRole('spinbutton').first() this.memoTextbox = this.page.getByRole('textbox', { name: 'Enter message' }) diff --git a/tests/TradingToken/TradingOnKeplrByEK.spec.ts b/tests/TradingToken/TradingOnKeplrByEK.spec.ts new file mode 100644 index 0000000..a184796 --- /dev/null +++ b/tests/TradingToken/TradingOnKeplrByEK.spec.ts @@ -0,0 +1,140 @@ +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 encryptedKeplrKey = "ATkNagk48TArQzAvyB7FfqThoLq2NuXu1naRDqqJCN44hEEKULwJCGj2dHyepgMX1C3yUmknktxw3pJe1Z41zWpbE6SUfHhXvyeptoSgiRBPNpNqgKmmA824QFpP3XURoTDszYYL5MRWs1zoWZnHDjfvWJmTUtxdWBRqTfdiLYcipPKQYzRg1jdqXoAqpt51zydX6TfCTnfxBt61SFxsEgbgbb16w1puk9mGfFiysr9R3PystkTja6sX8AbNW9tMMALKQGHtuCjJCmjuBw9RZTfd4XnSmn1tHYEqTbKaBq6oRLJwyzVnyiqmAcmn2Pg7S2aUvWqwpyYe7KyqAQXVQY7vTjN8JtBBihA4TyWUYGhNimtWYw" +const passworld = 'Abc12345789' + +test.beforeAll('Launch browser context with permission', async () => { + const browser = await chromium.launch() + browserContext = await browser.newContext() + 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(encryptedKeplrKey) + 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' }) + + await tradePage.opTokenOption.click() + await tradePage.spotTab.click() + await tradePage.searchToken.fill('SWTH / USD') + await tradePage.swthUSDOption.click() + + try { + await tradePage.cancelAllBtn.click({ timeout: 10_000 }) + await tradePage.confirmBtn.click() + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + } catch (e) { } + +}) + +test.describe('Trading on Keplr by Encrypted Key', () => { + test('TC_DEMEX_TO_1: Place a buy 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.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 () => { + await page.reload() + 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/TradingByEncryptedKey.spec.ts b/tests/TradingToken/TradingOnLeapByEK.spec.ts similarity index 90% rename from tests/TradingToken/TradingByEncryptedKey.spec.ts rename to tests/TradingToken/TradingOnLeapByEK.spec.ts index 834bdce..14d4ea8 100644 --- a/tests/TradingToken/TradingByEncryptedKey.spec.ts +++ b/tests/TradingToken/TradingOnLeapByEK.spec.ts @@ -41,22 +41,27 @@ test.beforeAll('Launch browser context with permission', async () => { await encryptedKeyPage.connectBtn.waitFor({ state: 'visible' }) await encryptedKeyPage.connectBtn.click({ delay: 2000 }) await encryptedKeyPage.connectBtn.waitFor({ state: 'detached' }) - await homePage.addressDropBtn.waitFor({ state: 'visible' }) + await tradePage.opTokenOption.click() + await tradePage.spotTab.click() + await tradePage.searchToken.fill('SWTH / USD') + await tradePage.swthUSDOption.click() + + try { + await tradePage.cancelAllBtn.click({ timeout: 10_000 }) + await tradePage.confirmBtn.click() + await expect(tradePage.orderedCancelledPopup).toBeVisible({ timeout: 10_000 }) + } catch (e) { } + }) -test.describe('Trading Token by Encrypted Key', () => { +test.describe('Trading on Leap 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.reload() 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() @@ -124,8 +129,7 @@ test.describe('Trading Token by Encrypted Key', () => { }) test.afterAll('Reset data', async () => { - const homePage = new HomePage(page) - await homePage.goToHomePage() + await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) diff --git a/tests/TradingToken/TradingOnPhantom.spec.ts b/tests/TradingToken/TradingOnPhantom.spec.ts index d38930b..818cdbe 100644 --- a/tests/TradingToken/TradingOnPhantom.spec.ts +++ b/tests/TradingToken/TradingOnPhantom.spec.ts @@ -12,7 +12,7 @@ const password = 'Abc123456789' const extensionName = "phantom" test.beforeAll('Add extension: Phantom', async () => { - test.setTimeout(120_000) + test.setTimeout(150_000) browserContext = await createBrowserContext(extensionName) page = await browserContext.newPage() @@ -71,18 +71,33 @@ test.beforeAll('Add extension: Phantom', async () => { await phantomPage2.connectBtn.click({ delay: 1000 }) await homePage.addressPhantomDropBtn.waitFor({ state: 'visible' }) + await tradePage.opTokenOption.click() + await tradePage.spotTab.click() + await tradePage.searchToken.fill('SWTH / USD') + await tradePage.swthUSDOption.click() + + try { + await tradePage.cancelAllBtn.click({ timeout: 10_000 }) + + 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) { } + }) 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() + await page.reload() 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() @@ -113,6 +128,7 @@ test.describe(' Trading Token with Phantom wallet ', () => { await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.cancelBtn.waitFor({state: 'visible'}) const [newPage3] = await Promise.all([ browserContext.waitForEvent('page'), diff --git a/tests/WithdrawToken/WithdrawOnLeap.spec.ts b/tests/WithdrawToken/WithdrawOnLeap.spec.ts index 2a35596..b8b9ece 100644 --- a/tests/WithdrawToken/WithdrawOnLeap.spec.ts +++ b/tests/WithdrawToken/WithdrawOnLeap.spec.ts @@ -92,50 +92,51 @@ test.beforeAll('Add extension: Leap', async () => { }) test.describe(' Withdraw Token with Leap 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('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) - 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(phantomSwthAddress) - await withdrawPage.amountTextbox.fill('1') - - const [popup] = await Promise.all([ - browserContext.waitForEvent('page'), - await withdrawPage.withdrawBtn.click() - ]); - await popup.waitForLoadState() - - const approvalPage = new LeapPage(popup) - await approvalPage.approveBtn.waitFor({ state: 'visible' }) - await approvalPage.approveBtn.click({ delay: 1000 }) - - await expect(withdrawPage.transactionSuccess).toBeVisible() - }) + test('DEPOSIT_UI_V2_08: Check the active Withdraw button on the Deposit page', async () => { + test.setTimeout(90_000) + 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('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) + 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(phantomSwthAddress) + await withdrawPage.amountTextbox.fill('1') + + const [popup] = await Promise.all([ + browserContext.waitForEvent('page'), + await withdrawPage.withdrawBtn.click() + ]); + await popup.waitForLoadState() + + const approvalPage = new LeapPage(popup) + await approvalPage.approveBtn.waitFor({ state: 'visible' }) + await approvalPage.approveBtn.click({ delay: 1000 }) + + await expect(withdrawPage.transactionSuccess).toBeVisible() + }) }) diff --git a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts index b386426..b9b21ca 100644 --- a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts +++ b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts @@ -78,50 +78,50 @@ test.beforeAll('Add extension: Phantom', async () => { }) 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('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) - 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() - }) + 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('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) + 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() + }) })