From 477b5ca651755dd1fa753c2ce4e2709d76dc0745 Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Fri, 14 Mar 2025 08:21:19 +0700 Subject: [PATCH 1/2] add Trading token when connect Metamask by EK --- pages/TradeTradePage.page.ts | 4 + tests/TradingToken/TradingOnKeplrByEK.spec.ts | 7 + tests/TradingToken/TradingOnLeapByEK.spec.ts | 7 + .../TradingOnMetaMaskByEK.spec.ts | 147 ++++++++++++++++++ tests/TradingToken/TradingOnPhantom.spec.ts | 6 + 5 files changed, 171 insertions(+) create mode 100644 tests/TradingToken/TradingOnMetaMaskByEK.spec.ts diff --git a/pages/TradeTradePage.page.ts b/pages/TradeTradePage.page.ts index cd37f55..9bd402b 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -19,6 +19,8 @@ export class TradeTradePage{ readonly marketBtn: Locator readonly amountOnMarket: Locator readonly tradeExecutedPopup: Locator + readonly priceOrderTextBox: Locator + readonly priceForm: Locator constructor(page: Page){ this.page=page; @@ -40,6 +42,8 @@ export class TradeTradePage{ 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 }) + this.priceOrderTextBox = this.page.locator('form div').filter({ hasText: 'MidUSD' }).nth(2) + this.priceForm = this.page.locator('#priceFormField') } async goToTradePage(){ diff --git a/tests/TradingToken/TradingOnKeplrByEK.spec.ts b/tests/TradingToken/TradingOnKeplrByEK.spec.ts index a184796..561a7e2 100644 --- a/tests/TradingToken/TradingOnKeplrByEK.spec.ts +++ b/tests/TradingToken/TradingOnKeplrByEK.spec.ts @@ -10,6 +10,7 @@ const encryptedKeplrKey = "ATkNagk48TArQzAvyB7FfqThoLq2NuXu1naRDqqJCN44hEEKULwJC const passworld = 'Abc12345789' test.beforeAll('Launch browser context with permission', async () => { + test.setTimeout(120_000) const browser = await chromium.launch() browserContext = await browser.newContext() page = await browserContext.newPage() @@ -60,6 +61,9 @@ test.describe('Trading on Keplr by Encrypted Key', () => { await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('0.01') await tradePage.amountToken.fill('1000') await tradePage.buyBtn.click() await tradePage.confirmBtn.click() @@ -90,6 +94,9 @@ test.describe('Trading on Keplr by Encrypted Key', () => { await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('10') await tradePage.amountToken.fill('1000') await tradePage.switchingBtn.click() await tradePage.sellBtn.click() diff --git a/tests/TradingToken/TradingOnLeapByEK.spec.ts b/tests/TradingToken/TradingOnLeapByEK.spec.ts index 14d4ea8..5305bb7 100644 --- a/tests/TradingToken/TradingOnLeapByEK.spec.ts +++ b/tests/TradingToken/TradingOnLeapByEK.spec.ts @@ -10,6 +10,7 @@ const encryptedLeapKey = "2SrrmLXhu2W3rX4jcELNY4GLoo6wGRVB2U7bG7uN58vokMEw8xugKW const passworld = 'Abc123456789' test.beforeAll('Launch browser context with permission', async () => { + test.setTimeout(120_000) const browser = await chromium.launch() browserContext = await browser.newContext({ permissions: ['clipboard-read', 'clipboard-write'] @@ -62,6 +63,9 @@ test.describe('Trading on Leap by Encrypted Key', () => { await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('0.01') await tradePage.amountToken.fill('1000') await tradePage.buyBtn.click() await tradePage.confirmBtn.click() @@ -92,6 +96,9 @@ test.describe('Trading on Leap by Encrypted Key', () => { await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('10') await tradePage.amountToken.fill('1000') await tradePage.switchingBtn.click() await tradePage.sellBtn.click() diff --git a/tests/TradingToken/TradingOnMetaMaskByEK.spec.ts b/tests/TradingToken/TradingOnMetaMaskByEK.spec.ts new file mode 100644 index 0000000..7f5677a --- /dev/null +++ b/tests/TradingToken/TradingOnMetaMaskByEK.spec.ts @@ -0,0 +1,147 @@ +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 encryptedMetaMaskKey = "3uQMeX7XfUJGGxC5J3deTBPDemwZYsaziyEXPJMpTqLEwztgb5kQtf3ChJ5Lq6HGGs9oKNsTuWw2VdC3m8uLsy6WKSYx5eosXBa8Sxq17kUqSNrFiav5kyTmD9QCLNvxY1Nj9tZ9UBq3hJ5xZifZY4QUeQyWJxZeZw8BH8nLaw1zhEsEjBrBEpHGQHdHdX8mfCjrZKHs1Z4gJDjALQFRkCVRws7Dogaw3VZWXRSy6zDDEPpDDKorKztvc2mwnV5vvaXsEcxVpTbwxTPGnKdWxvYJ6gha95DMt96oLvSdsUjatiyDXtdmSmvW8k668Sa6pJcDjhiFZfFJzMxv1jmnHFQZk6RmZQD39G2ThS" +const passworld = 'Abc12345789' + +test.beforeAll('Launch browser context with permission', async () => { + test.setTimeout(120_000) + 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(encryptedMetaMaskKey) + 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 MetaMask 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.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('0.01') + 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.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('10') + 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/TradingOnPhantom.spec.ts b/tests/TradingToken/TradingOnPhantom.spec.ts index 818cdbe..114ab8e 100644 --- a/tests/TradingToken/TradingOnPhantom.spec.ts +++ b/tests/TradingToken/TradingOnPhantom.spec.ts @@ -98,6 +98,9 @@ test.describe(' Trading Token with Phantom wallet ', () => { await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('0.01') await tradePage.amountToken.fill('1000') await tradePage.buyBtn.click() @@ -147,6 +150,9 @@ test.describe(' Trading Token with Phantom wallet ', () => { await page.reload() await page.waitForLoadState() const tradePage = new TradeTradePage(page) + await tradePage.buyBtn.waitFor({state: 'visible'}) + await tradePage.priceForm.clear() + await tradePage.priceForm.fill('10') await tradePage.amountToken.fill('1000') await tradePage.switchingBtn.click() await tradePage.sellBtn.click() From 5fdf96530ae467f04c72b9181c415716cc1ea5f5 Mon Sep 17 00:00:00 2001 From: KimieTran <34021222+KimieTran@users.noreply.github.com> Date: Fri, 14 Mar 2025 08:21:40 +0700 Subject: [PATCH 2/2] add withdraw token when connect Keplr by EK --- tests/WithdrawToken/WithdrawOnKeplr.spec.ts | 87 +++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/WithdrawToken/WithdrawOnKeplr.spec.ts diff --git a/tests/WithdrawToken/WithdrawOnKeplr.spec.ts b/tests/WithdrawToken/WithdrawOnKeplr.spec.ts new file mode 100644 index 0000000..98540c1 --- /dev/null +++ b/tests/WithdrawToken/WithdrawOnKeplr.spec.ts @@ -0,0 +1,87 @@ +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 { PhantomPage } from '../../pages/PhantomPage'; +import { DepositPage } from '../../pages/DepositPage'; +import { WithdrawPage } from '../../pages/WithdrawPage'; +import { EncryptedKeyPage } from '../../pages/EncryptedKeyPage'; + +let page: Page +let browserContext: BrowserContext +const encryptedKeplrKey = "ATkNagk48TArQzAvyB7FfqThoLq2NuXu1naRDqqJCN44hEEKULwJCGj2dHyepgMX1C3yUmknktxw3pJe1Z41zWpbE6SUfHhXvyeptoSgiRBPNpNqgKmmA824QFpP3XURoTDszYYL5MRWs1zoWZnHDjfvWJmTUtxdWBRqTfdiLYcipPKQYzRg1jdqXoAqpt51zydX6TfCTnfxBt61SFxsEgbgbb16w1puk9mGfFiysr9R3PystkTja6sX8AbNW9tMMALKQGHtuCjJCmjuBw9RZTfd4XnSmn1tHYEqTbKaBq6oRLJwyzVnyiqmAcmn2Pg7S2aUvWqwpyYe7KyqAQXVQY7vTjN8JtBBihA4TyWUYGhNimtWYw" +const passworld = 'Abc12345789' +const phantomSwthAddress = 'tswth1r5kh40kknhw7e02qyzyz50zsfj8xyvfsq9lvxp' + +test.beforeAll('Connect Keplr wallet by Encrypted Key', async () => { + test.setTimeout(120_000) + 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' }) + +}) +test.describe(' Withdraw Token with Keplr 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') + + await expect(withdrawPage.transactionSuccess).toBeVisible() + }) + +})