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/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 5102e7c..cd37f55 100644 --- a/pages/TradeTradePage.page.ts +++ b/pages/TradeTradePage.page.ts @@ -3,14 +3,77 @@ 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 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; 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', { 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.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(){ 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/pages/WithdrawPage.ts b/pages/WithdrawPage.ts index fd22630..16812c6 100644 --- a/pages/WithdrawPage.ts +++ b/pages/WithdrawPage.ts @@ -3,22 +3,28 @@ 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 readonly memoTextbox: Locator readonly withdrawBtn: Locator readonly transactionSuccess: Locator + readonly invalidAddressErrorMsg: Locator + readonly invalidAmountErrorMsg: Locator 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() 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 97% rename from tests/ConnectWalletsAndDeposit/ConnectByViewOnlyMode.spec.ts rename to tests/ConnectWallets/ConnectByViewOnlyMode.spec.ts index 0e8474b..27ac68c 100644 --- a/tests/ConnectWalletsAndDeposit/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/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 97% rename from tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts rename to tests/ConnectWallets/ConnectEncryptedKeyWallet.spec.ts index 2430c8e..080960b 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectEncryptedKeyWallet.spec.ts +++ b/tests/ConnectWallets/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/ConnectKeplrWallet.spec.ts b/tests/ConnectWallets/ConnectKeplrWallet.spec.ts similarity index 98% rename from tests/ConnectWalletsAndDeposit/ConnectKeplrWallet.spec.ts rename to tests/ConnectWallets/ConnectKeplrWallet.spec.ts index 816e268..7ae2969 100644 --- a/tests/ConnectWalletsAndDeposit/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/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts b/tests/ConnectWallets/ConnectLeapWallet.spec.ts similarity index 96% rename from tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts rename to tests/ConnectWallets/ConnectLeapWallet.spec.ts index b1a4e91..34ed7b7 100644 --- a/tests/ConnectWalletsAndDeposit/ConnectLeapWallet.spec.ts +++ b/tests/ConnectWallets/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) @@ -113,13 +113,13 @@ test.describe.serial('Connect Phantom wallet & Verify withdraw', () => { 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/ConnectWallets/ConnectMetaMaskWallet.spec.ts similarity index 70% rename from tests/ConnectWalletsAndDeposit/ConnectMetaMaskWallet.spec.ts rename to tests/ConnectWallets/ConnectMetaMaskWallet.spec.ts index 88a404a..754c7c9 100644 --- a/tests/ConnectWalletsAndDeposit/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,41 +103,30 @@ 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 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/ConnectWallets/ConnectPhantomWallet.spec.ts similarity index 78% rename from tests/ConnectWalletsAndDeposit/ConnectPhantomWallet.spec.ts rename to tests/ConnectWallets/ConnectPhantomWallet.spec.ts index 602e362..3311f23 100644 --- a/tests/ConnectWalletsAndDeposit/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 @@ -42,7 +41,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) @@ -76,6 +75,7 @@ test.describe.serial('Connect Phantom wallet & Verify deposit', () => { 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) @@ -102,31 +102,5 @@ test.describe.serial('Connect Phantom wallet & Verify deposit', () => { 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.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() - }) -}) \ No newline at end of file + +}) 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 new file mode 100644 index 0000000..e9bfdc9 --- /dev/null +++ b/tests/TradingToken/TradingOnPhantom.spec.ts @@ -0,0 +1,210 @@ +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'; + +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" + +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(' 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.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() + + 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.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) + + 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 }) + }) + + 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.orderPlacedPopup).toBeVisible({ timeout: 10_000 }) + + const expectedTableData = [ + { + 'Market': 'SWTH / USD', + 'Type': 'Limit|Sell', + 'Filled': '0 SWTH$0.00', + } + ] + 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.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 }) + + 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) { } + +}) \ No newline at end of file diff --git a/tests/WithdrawToken/WithdrawOnPhantom.spec.ts b/tests/WithdrawToken/WithdrawOnPhantom.spec.ts new file mode 100644 index 0000000..ba43065 --- /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('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() + }) + +})