diff --git a/.github/workflows/playwright-production.yml b/.github/workflows/playwright-production.yml index 382554676..15a9db2ba 100644 --- a/.github/workflows/playwright-production.yml +++ b/.github/workflows/playwright-production.yml @@ -23,5 +23,5 @@ jobs: if: always() with: name: playwright-report-production - path: playwright-report-production/ + path: playwright-report/ retention-days: 30 diff --git a/e2e/production.spec.ts b/e2e/production.spec.ts index eaf511068..c40c5f21c 100644 --- a/e2e/production.spec.ts +++ b/e2e/production.spec.ts @@ -1,237 +1,184 @@ import { test, expect } from '@playwright/test' -import { clickLinkAndVerify, getFirstLink, verifyOpeningNewPage } from './utils' +import { clickLinkAndVerify, getFirstLink, getRowCount, verifyOpeningNewPage } from './utils' const baseUrl = 'https://steexp.com' // const baseUrl = 'http://publicnet.local:3000' // for test on local test('top page', async ({ page }) => { - await page.goto(`${baseUrl}/`) - await expect(page).toHaveTitle('Stellar Explorer | Home') - - // Click account link - const accountLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Account Balances', - ) + await page.goto(`${baseUrl}/`) + + expect(await getRowCount(page, `operation-table`)).toEqual(25) + expect(await getRowCount(page, `transaction-table`)).toEqual(10) + expect(await getRowCount(page, `ledger-table`)).toEqual(10) + + await expect(page).toHaveTitle('Stellar Explorer | Home') }) test('operations', async ({ page }) => { - const targetUrl = `${baseUrl}/operations` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Operations') - - // Click account link - const accountLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Account Balances', - ) - - // Click transaction link - await page.goto(targetUrl) - const transactionLink = await getFirstLink(page, 2) - await clickLinkAndVerify( - baseUrl, - page, - transactionLink, - 'Stellar Explorer | Transaction', - ) + const targetUrl = `${baseUrl}/operations` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Operations') + + // Click account link + const accountLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + accountLink, + 'Stellar Explorer | Account Balances', + ) + + // Click transaction link + await page.goto(targetUrl) + const transactionLink = await getFirstLink(page, 2) + await clickLinkAndVerify( + baseUrl, + page, + transactionLink, + 'Stellar Explorer | Transaction', + ) }) test('transactions', async ({ page }) => { - const targetUrl = `${baseUrl}/txs` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Transactions') - - // Click transaction link - const transactionLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - transactionLink, - 'Stellar Explorer | Transaction', - ) - - // Click account link - await page.goto(targetUrl) - const accountLink = await getFirstLink(page, 1) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Account Balances', - ) - - // Click ledger link - await page.goto(targetUrl) - const ledgerLink = await getFirstLink(page, 2) - await clickLinkAndVerify( - baseUrl, - page, - ledgerLink, - 'Stellar Explorer | Ledger', - ) + const targetUrl = `${baseUrl}/txs` + await page.goto(targetUrl) + expect(await getRowCount(page, `transaction-table`)).toEqual(20) + await expect(page).toHaveTitle('Stellar Explorer | Transactions') }) test('ledgers', async ({ page }) => { - const targetUrl = `${baseUrl}/ledgers` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Ledgers') - - // Click ledger link - const ledgerLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - ledgerLink, - 'Stellar Explorer | Ledger', - ) + const targetUrl = `${baseUrl}/ledgers` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Ledgers') + + // Click ledger link + const ledgerLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + ledgerLink, + 'Stellar Explorer | Ledger', + ) }) test('assets', async ({ page, context }) => { - const targetUrl = `${baseUrl}/assets` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Assets') + const targetUrl = `${baseUrl}/assets` + await page.goto(targetUrl) - expect((await page.locator('tbody tr').all()).length).toBe(50) + expect(await getRowCount(page, `assets-table`)).toEqual(50) + await expect(page).toHaveTitle('Stellar Explorer | Assets') }) test('anchors', async ({ page }) => { - const targetUrl = `${baseUrl}/anchors` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Anchors') - - // Click anchors link - const anchorLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - anchorLink, - 'Stellar Explorer | Anchor', - ) + const targetUrl = `${baseUrl}/anchors` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Anchors') + + // Click anchors link + const anchorLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + anchorLink, + 'Stellar Explorer | Anchor', + ) }) test('exchanges', async ({ page, context }) => { - const targetUrl = `${baseUrl}/exchanges` + const targetUrl = `${baseUrl}/exchanges` - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Exchanges') + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Exchanges') - // Click asset link - const exchangeLink = await getFirstLink(page, 0) - await verifyOpeningNewPage(page, context, exchangeLink) + // Click asset link + const exchangeLink = await getFirstLink(page, 0) + await verifyOpeningNewPage(page, context, exchangeLink) }) test('effects', async ({ page }) => { - const targetUrl = `${baseUrl}/effects` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Effects') - - // Click account link - const accountLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Account Balances', - ) + const targetUrl = `${baseUrl}/effects` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Effects') + + // Click account link + const accountLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + accountLink, + 'Stellar Explorer | Account Balances', + ) }) test('payments', async ({ page }) => { - const targetUrl = `${baseUrl}/payments` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Payments') - - // Click account link - const accountLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Account Balances', - ) - - // Click transaction link - await page.goto(targetUrl) - const transactionLink = await getFirstLink(page, 2) - await clickLinkAndVerify( - baseUrl, - page, - transactionLink, - 'Stellar Explorer | Transaction', - ) + const targetUrl = `${baseUrl}/payments` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Payments') + + // Click account link + const accountLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + accountLink, + 'Stellar Explorer | Account Balances', + ) + + // Click transaction link + await page.goto(targetUrl) + const transactionLink = await getFirstLink(page, 2) + await clickLinkAndVerify( + baseUrl, + page, + transactionLink, + 'Stellar Explorer | Transaction', + ) }) test('trades', async ({ page }) => { - const targetUrl = `${baseUrl}/trades` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Trades') - - // Click account 1 link - const account1Link = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - account1Link, - 'Stellar Explorer | Account Balances', - ) - - // Click account 2 link - await page.goto(targetUrl) - const account2Link = await getFirstLink(page, 2) - await clickLinkAndVerify( - baseUrl, - page, - account2Link, - 'Stellar Explorer | Account Balances', - ) + const targetUrl = `${baseUrl}/trades` + await page.goto(targetUrl) + expect(await getRowCount(page, `trade-table`)).toEqual(20) + await expect(page).toHaveTitle('Stellar Explorer | Trades') }) test('pools', async ({ page }) => { - const targetUrl = `${baseUrl}/pools` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Liquidity Pools') - - // Click pool link - const accountLink = await getFirstLink(page, 0) - await clickLinkAndVerify( - baseUrl, - page, - accountLink, - 'Stellar Explorer | Effects for Liquidity Pool', - ) + const targetUrl = `${baseUrl}/pools` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Liquidity Pools') + + // Click pool link + const accountLink = await getFirstLink(page, 0) + await clickLinkAndVerify( + baseUrl, + page, + accountLink, + 'Stellar Explorer | Effects for Liquidity Pool', + ) }) test('claimable-balances', async ({ page }) => { - const targetUrl = `${baseUrl}/claimable-balances` - - await page.goto(targetUrl) - await expect(page).toHaveTitle('Stellar Explorer | Claimable Balances') - - // Execute search - const searchInput = page.getByPlaceholder('Search by Account') - await searchInput.fill( - // arbitrary address is used - 'GB5YEYTFL2VKQTY34XUTYAS24BGNHHEUEGNLPMQZNJULGCZ2C5UIBMLC', - ) - await searchInput.press('Enter') - - await page.getByRole('tab', { name: 'Sponsor' }).click() - await expect(page.getByRole('cell', { name: 'Claimant' })).toBeVisible() - await page.getByRole('tab', { name: 'Claimant' }).click() - await expect(page.getByRole('cell', { name: 'Sponsor' })).toBeVisible() + const targetUrl = `${baseUrl}/claimable-balances` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Claimable Balances') + + // Execute search + const searchInput = page.getByPlaceholder('Search by Account') + await searchInput.fill( + // arbitrary address is used + 'GB5YEYTFL2VKQTY34XUTYAS24BGNHHEUEGNLPMQZNJULGCZ2C5UIBMLC', + ) + await searchInput.press('Enter') + + await page.getByRole('tab', { name: 'Sponsor' }).click() + await expect(page.getByRole('cell', { name: 'Claimant' })).toBeVisible() + await page.getByRole('tab', { name: 'Claimant' }).click() + await expect(page.getByRole('cell', { name: 'Sponsor' })).toBeVisible() }) diff --git a/e2e/utils.ts b/e2e/utils.ts index c00d1be7d..f051ef7a2 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -2,47 +2,56 @@ import type { BrowserContext, Locator, Page } from '@playwright/test' import { expect } from '@playwright/test' export const getFirstLink = async ( - page: Page, - columnNum: number, + page: Page, + columnNum: number, ): Promise => { - let rowNum = 0 - let row = page.locator('tbody tr').nth(rowNum) - while (await row.locator('td').nth(columnNum).locator('a').isHidden()) { - rowNum++ - row = page.locator('tbody tr').nth(rowNum) - } + let rowNum = 0 + let row = page.locator('tbody tr').nth(rowNum) + while (await row.locator('td').nth(columnNum).locator('a').isHidden()) { + rowNum++ + row = page.locator('tbody tr').nth(rowNum) + } - return row.locator('td').nth(columnNum).locator('a') + return row.locator('td').nth(columnNum).locator('a') +} + +export const getRowCount = async ( + page: Page, + tableId: string +): Promise => { + const tableSelector = `table#${tableId} tbody tr` + await page.waitForSelector(tableSelector) + return page.locator(tableSelector).count() } export const clickLinkAndVerify = async ( - baseUrl: string, - page: Page, - linkLocator: Locator, - title: string, + baseUrl: string, + page: Page, + linkLocator: Locator, + title: string, ): Promise => { - const linkUrl = (await linkLocator.getAttribute('href')) || '' - const expectedText = linkUrl?.split('/').pop() - const expectedTitle = `${title} ${expectedText}` - await linkLocator.click() - await page.waitForTimeout(3000) - const expectedUrl = new URL(linkUrl, baseUrl).toString() - expect(page.url()).toBe(expectedUrl) + const linkUrl = (await linkLocator.getAttribute('href')) || '' + const expectedText = linkUrl?.split('/').pop() + const expectedTitle = `${title} ${expectedText}` + await linkLocator.click() + await page.waitForTimeout(3000) + const expectedUrl = new URL(linkUrl, baseUrl).toString() + expect(page.url()).toBe(expectedUrl) - await expect(page).toHaveTitle(expectedTitle) - expect(await page.textContent('body')).toContain(expectedText) + await expect(page).toHaveTitle(expectedTitle) + expect(await page.textContent('body')).toContain(expectedText) } export const verifyOpeningNewPage = async ( - page: Page, - context: BrowserContext, - linkLocator: Locator, + page: Page, + context: BrowserContext, + linkLocator: Locator, ): Promise => { - const linkUrl = await linkLocator.getAttribute('href') + const linkUrl = await linkLocator.getAttribute('href') - await linkLocator.click() - await page.waitForTimeout(3000) - const allPages = context.pages() - const allPageUrls = allPages.map((p: Page) => p.url()) - expect(allPageUrls.includes(`${linkUrl}/`)).toBeTruthy() + await linkLocator.click() + await page.waitForTimeout(3000) + const allPages = context.pages() + const allPageUrls = allPages.map((p: Page) => p.url()) + expect(allPageUrls.includes(`${linkUrl}/`)).toBeTruthy() }