From 14e3c1a64c105a9f4f208b3c544d2a0cc8ba9378 Mon Sep 17 00:00:00 2001 From: Ryuji Eguchi Date: Wed, 20 Dec 2023 12:28:18 +1100 Subject: [PATCH] fulfill smoke test --- e2e/production.spec.ts | 182 ++++++++++++++++++++++++++++++++++++++--- e2e/utils.ts | 48 +++++++++++ playwright.config.ts | 18 ++-- 3 files changed, 227 insertions(+), 21 deletions(-) create mode 100644 e2e/utils.ts diff --git a/e2e/production.spec.ts b/e2e/production.spec.ts index 78c717332..90016a8b7 100644 --- a/e2e/production.spec.ts +++ b/e2e/production.spec.ts @@ -1,51 +1,209 @@ import { test, expect } from '@playwright/test' +import { clickLinkAndVerify, getFirstLink, verifyOpeningNewPage } from './utils' + +const baseUrl = 'https://steexp.com' test('top page', async ({ page }) => { - await page.goto('https://steexp.com/') + 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', + ) }) test('operations', async ({ page }) => { - await page.goto('https://steexp.com/operations') + 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 }) => { - await page.goto('https://steexp.com/txs') + 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', + ) }) test('ledgers', async ({ page }) => { - await page.goto('https://steexp.com/ledgers') + 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 }) => { - await page.goto('https://steexp.com/assets') +test('assets', async ({ page, context }) => { + const targetUrl = `${baseUrl}/assets` + + await page.goto(targetUrl) await expect(page).toHaveTitle('Stellar Explorer | Assets') + + // Click asset link + const assetLink = await getFirstLink(page, 0) + await verifyOpeningNewPage(page, context, assetLink) }) test('anchors', async ({ page }) => { - await page.goto('https://steexp.com/anchors') + 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 }) => { - await page.goto('https://steexp.com/exchanges') +test('exchanges', async ({ page, context }) => { + const targetUrl = `${baseUrl}/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) }) test('effects', async ({ page }) => { - await page.goto('https://steexp.com/effects') + 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 }) => { - await page.goto('https://steexp.com/payments') + 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 }) => { - await page.goto('https://steexp.com/trades') + 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', + ) +}) + +test('pools', async ({ page }) => { + const targetUrl = `${baseUrl}/pools` + + await page.goto(targetUrl) + await expect(page).toHaveTitle('Stellar Explorer | Liquidity Pools') }) diff --git a/e2e/utils.ts b/e2e/utils.ts new file mode 100644 index 000000000..c00d1be7d --- /dev/null +++ b/e2e/utils.ts @@ -0,0 +1,48 @@ +import type { BrowserContext, Locator, Page } from '@playwright/test' +import { expect } from '@playwright/test' + +export const getFirstLink = async ( + 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) + } + + return row.locator('td').nth(columnNum).locator('a') +} + +export const clickLinkAndVerify = async ( + 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) + + await expect(page).toHaveTitle(expectedTitle) + expect(await page.textContent('body')).toContain(expectedText) +} + +export const verifyOpeningNewPage = async ( + page: Page, + context: BrowserContext, + linkLocator: Locator, +): Promise => { + 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() +} diff --git a/playwright.config.ts b/playwright.config.ts index 411e40a7f..dc7eaa67e 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -37,15 +37,15 @@ export default defineConfig({ use: { ...devices['Desktop Chrome'] }, }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, + // { + // name: 'firefox', + // use: { ...devices['Desktop Firefox'] }, + // }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, + // { + // name: 'webkit', + // use: { ...devices['Desktop Safari'] }, + // }, /* Test against mobile viewports. */ // { @@ -74,5 +74,5 @@ export default defineConfig({ // url: 'http://127.0.0.1:3000', // reuseExistingServer: !process.env.CI, // }, - timeout: 5 * 1000, + timeout: 30 * 1000, })