|
| 1 | +import { extensionViewport } from '../utils/extensionTestExtend' |
| 2 | +import { warnSlowApi } from '../utils/warnSlowApi' |
| 3 | +import { mockApiMoreData } from '../utils/mockApi' |
| 4 | +import { ethAccount, privateKey } from '../../src/utils/__fixtures__/test-inputs' |
| 5 | +import { test, expect, Page } from '@playwright/test' |
| 6 | + |
| 7 | +const screenshotCss = ` |
| 8 | + * { scrollbar-width: none; } |
| 9 | + [data-testid="build-banner"] { display: none; } |
| 10 | +` |
| 11 | + |
| 12 | +const chromeWebStoreDimensions = { |
| 13 | + width: 1200, |
| 14 | + height: 800, |
| 15 | +} |
| 16 | + |
| 17 | +/** Scale for higher quality larger screenshots */ |
| 18 | +const deviceScaleFactor = (chromeWebStoreDimensions.height - 20) / extensionViewport.height |
| 19 | +test.use({ |
| 20 | + deviceScaleFactor: deviceScaleFactor, |
| 21 | + viewport: { |
| 22 | + width: Math.round(chromeWebStoreDimensions.width / deviceScaleFactor), |
| 23 | + height: Math.round(chromeWebStoreDimensions.height / deviceScaleFactor), |
| 24 | + }, |
| 25 | +}) |
| 26 | + |
| 27 | +async function setup(page: Page, url: string) { |
| 28 | + await page.goto('/app.webmanifest') |
| 29 | + await page.setContent(` |
| 30 | + <style> |
| 31 | + body { |
| 32 | + display: flex; |
| 33 | + justify-content: center; |
| 34 | + align-items: center; |
| 35 | + height: 100vh; |
| 36 | + } |
| 37 | + iframe { |
| 38 | + width: ${extensionViewport.width}px; |
| 39 | + height: ${extensionViewport.height}px; |
| 40 | + border: 5px solid #0500e2; |
| 41 | + } |
| 42 | + </style> |
| 43 | + <body style=""> |
| 44 | + <iframe src="${url}"></iframe> |
| 45 | + </body> |
| 46 | + `) |
| 47 | + return page.frameLocator('iframe')! |
| 48 | +} |
| 49 | + |
| 50 | +test.beforeEach(async ({ context }) => { |
| 51 | + await warnSlowApi(context) |
| 52 | + await mockApiMoreData(context) |
| 53 | +}) |
| 54 | + |
| 55 | +test('make screenshots for Chrome Web Store', async ({ page }) => { |
| 56 | + const frame = await setup(page, `/`) |
| 57 | + await page.screenshot({ |
| 58 | + path: './screenshots/extension-store-1.png', |
| 59 | + style: screenshotCss, |
| 60 | + animations: 'disabled', |
| 61 | + omitBackground: true, |
| 62 | + }) |
| 63 | + |
| 64 | + await frame.getByRole('button', { name: /Open wallet/ }).click() |
| 65 | + await frame.getByRole('button', { name: /Private key/ }).click() |
| 66 | + await frame.getByText('Create a profile').uncheck() |
| 67 | + await frame.getByPlaceholder('Enter your private key here').fill(privateKey) |
| 68 | + await page.keyboard.press('Enter') |
| 69 | + await expect(frame.getByText('Loading account')).toBeVisible() |
| 70 | + await expect(frame.getByText('Loading account')).toBeHidden() |
| 71 | + await page.screenshot({ |
| 72 | + path: './screenshots/extension-store-2.png', |
| 73 | + style: screenshotCss, |
| 74 | + animations: 'disabled', |
| 75 | + omitBackground: true, |
| 76 | + }) |
| 77 | + |
| 78 | + await frame.getByRole('link', { name: 'Stake' }).click() |
| 79 | + await frame.getByRole('columnheader', { name: 'Name' }).click() |
| 80 | + await frame.getByRole('img', { name: 'Status is okay' }).nth(3).click() |
| 81 | + await frame.getByRole('link', { name: 'Staked' }).scrollIntoViewIfNeeded() |
| 82 | + await page.waitForTimeout(1000) |
| 83 | + await page.screenshot({ |
| 84 | + path: './screenshots/extension-store-3.png', |
| 85 | + style: screenshotCss, |
| 86 | + animations: 'disabled', |
| 87 | + omitBackground: true, |
| 88 | + }) |
| 89 | + |
| 90 | + await frame.getByRole('link', { name: 'Staked' }).click() |
| 91 | + await page.screenshot({ |
| 92 | + path: './screenshots/extension-store-4.png', |
| 93 | + style: screenshotCss, |
| 94 | + animations: 'disabled', |
| 95 | + omitBackground: true, |
| 96 | + }) |
| 97 | + |
| 98 | + await frame.getByRole('link', { name: 'ParaTimes' }).click() |
| 99 | + await page.evaluate(() => { |
| 100 | + window.frames[0].scrollBy(0, 10000) |
| 101 | + }) |
| 102 | + await page.screenshot({ |
| 103 | + path: './screenshots/extension-store-5.png', |
| 104 | + style: screenshotCss, |
| 105 | + animations: 'disabled', |
| 106 | + omitBackground: true, |
| 107 | + }) |
| 108 | + |
| 109 | + await frame.getByRole('button', { name: 'Deposit to ParaTime' }).click() |
| 110 | + await frame.getByRole('textbox', { name: 'Select a ParaTime' }).click() |
| 111 | + await page.screenshot({ |
| 112 | + path: './screenshots/extension-store-6.png', |
| 113 | + style: screenshotCss, |
| 114 | + animations: 'disabled', |
| 115 | + omitBackground: true, |
| 116 | + }) |
| 117 | + |
| 118 | + await frame.getByRole('option', { name: 'Sapphire' }).click() |
| 119 | + await frame.getByRole('button', { name: 'Next' }).click() |
| 120 | + await frame.getByRole('textbox', { name: 'recipient' }).fill(ethAccount.address) |
| 121 | + await frame.getByRole('button', { name: 'Next' }).click() |
| 122 | + |
| 123 | + await frame.getByRole('textbox', { name: 'amount' }).fill('10.0') |
| 124 | + await page.screenshot({ |
| 125 | + path: './screenshots/extension-store-7.png', |
| 126 | + style: screenshotCss, |
| 127 | + animations: 'disabled', |
| 128 | + omitBackground: true, |
| 129 | + }) |
| 130 | + |
| 131 | + await frame.getByRole('button', { name: 'Next' }).click() |
| 132 | + await page.screenshot({ |
| 133 | + path: './screenshots/extension-store-8.png', |
| 134 | + style: screenshotCss, |
| 135 | + animations: 'disabled', |
| 136 | + omitBackground: true, |
| 137 | + }) |
| 138 | +}) |
0 commit comments