-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add playwright tests to sample vite app #1549
base: main
Are you sure you want to change the base?
Changes from all commits
62f0707
a36b0e7
bc0efb2
613702c
2dad7f4
25727fc
5322b1b
93e56a1
95d19cb
21b60e3
d4c7045
14c7c30
55254cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# playwright | ||
test-results/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { | ||
Blake2b256, | ||
Keccak256, | ||
Sha256, | ||
Txt | ||
} from '@vechain/sdk-core/dist/index.mjs'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I would try to use the normal import. Probably you are doing this because of the issue you described during these days, but I would double-check if you can somehow specify something in the |
||
|
||
test('Hash example', async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
const hashLink = page.getByTestId('hash-link'); | ||
|
||
// Expect link to be visible | ||
await expect(hashLink).toBeVisible(); | ||
|
||
// Click on link | ||
await hashLink.click(); | ||
|
||
// Enter content to hash | ||
const content = "SDK is awesome!"; | ||
const hashInput = page.getByTestId('contentToHash'); | ||
await hashInput.clear(); | ||
await hashInput.fill(content); | ||
|
||
// Expect hash component to be visible with expected text | ||
const blake2bHash = page.getByTestId('blake2b256HashLabel'); | ||
const keccak256Hash = page.getByTestId('keccak256HashLabel'); | ||
const sha256Hash = page.getByTestId('sha256HashLabel'); | ||
await expect(blake2bHash).toBeVisible(); | ||
await expect(keccak256Hash).toBeVisible(); | ||
await expect(sha256Hash).toBeVisible(); | ||
|
||
// Assert hash value for blake2b256 | ||
const expectedBlake2b256Hash = Blake2b256.of(Txt.of(content).bytes) | ||
await expect(blake2bHash).toContainText('Blake2b256'); | ||
await expect(blake2bHash).toContainText(expectedBlake2b256Hash.toString()); | ||
|
||
// Assert hash value for keccak256 | ||
const expectedKeccak256Hash = Keccak256.of(Txt.of(content).bytes) | ||
await expect(keccak256Hash).toContainText('Keccak256'); | ||
await expect(keccak256Hash).toContainText(expectedKeccak256Hash.toString()); | ||
|
||
// Assert hash value for sha256 | ||
const expectedSha256Hash = Sha256.of(Txt.of(content).bytes) | ||
await expect(sha256Hash).toContainText('Sha256'); | ||
await expect(sha256Hash).toContainText(expectedSha256Hash.toString()); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('Latest block example', async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
const latestBlockLink = page.getByTestId('latest-block-link'); | ||
|
||
// Expect link to be visible | ||
await expect(latestBlockLink).toBeVisible(); | ||
|
||
// Click on link | ||
await latestBlockLink.click(); | ||
|
||
// Click get last block button | ||
const getLastBlockButton = page.getByTestId('getlastblock'); | ||
await expect(getLastBlockButton).toBeVisible(); | ||
await getLastBlockButton.click(); | ||
|
||
// Assert last block details | ||
const lastBlockDetails = page.getByTestId('last-block-details'); | ||
await expect(lastBlockDetails).toBeVisible(); | ||
await expect(lastBlockDetails).toContainText('number'); | ||
await expect(lastBlockDetails).toContainText('id'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('Transfer logs example', async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
const logsLink = page.getByTestId('transfers-link'); | ||
|
||
// Expect link to be visible | ||
await expect(logsLink).toBeVisible(); | ||
|
||
// Click on link | ||
await logsLink.click(); | ||
|
||
// Enter details to get transfer logs | ||
const addressInput = page.getByTestId('address'); | ||
const fromBlockInput = page.getByTestId('fromblock'); | ||
const toBlockInput = page.getByTestId('toblock'); | ||
|
||
await addressInput.clear(); | ||
await addressInput.fill('0xc3bE339D3D20abc1B731B320959A96A08D479583'); | ||
await fromBlockInput.clear(); | ||
await fromBlockInput.fill('1'); | ||
await toBlockInput.clear(); | ||
await toBlockInput.fill('19251959'); | ||
|
||
// expect logs table to be populated | ||
const tableRows = page.locator('css=[data-testid="logs-table"] tr'); | ||
await expect(tableRows).toHaveCount(8); // 8 rows in the table, this is a retryable assertion | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// playwright.config.ts | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
// Look for test files in the "tests" directory, relative to this configuration file. | ||
testDir: 'e2e', | ||
|
||
// Run all tests in parallel. | ||
fullyParallel: true, | ||
|
||
// Fail the build on CI if you accidentally left test.only in the source code. | ||
forbidOnly: !!process.env.CI, | ||
|
||
// Retry on CI only. | ||
retries: process.env.CI ? 2 : 0, | ||
|
||
// Opt out of parallel tests on CI. | ||
workers: process.env.CI ? 1 : undefined, | ||
|
||
// Reporter to use, see https://playwright.dev/docs/test-reporters | ||
reporter: 'html', | ||
|
||
use: { | ||
// Base URL to use in actions like `await page.goto('/')`. | ||
baseURL: 'http://localhost:5173', | ||
|
||
// Collect trace when retrying the failed test. | ||
trace: 'on-first-retry', | ||
}, | ||
// Configure projects for major browsers. | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
// Run your local dev server before starting the tests. | ||
webServer: { | ||
command: 'yarn dev', | ||
url: 'http://localhost:5173', | ||
timeout: 120 * 1000, | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"root":["./vite.config.ts","./vitest.jsdom.config.ts","./vitest.node.config.ts","./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/components/getlastblock.tsx","./src/components/hash.tsx","./src/components/transferlogs.tsx","./src/const/const.tsx","./src/const/index.tsx","./src/types/index.tsx","./src/types/types.d.tsx","./tests/hash.spec.tsx"],"version":"5.6.3"} | ||
{"root":["./playwright.config.ts","./vite.config.ts","./vitest.workspace.ts","./e2e/hash.spec.ts","./e2e/lastblock.spec.ts","./e2e/logs.spec.ts","./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/components/getlastblock.tsx","./src/components/hash.tsx","./src/components/transferlogs.tsx","./src/const/const.tsx","./src/const/index.tsx","./src/types/index.tsx","./src/types/types.d.tsx","./tests/hash.spec.tsx"],"errors":true,"version":"5.6.3"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we are duplicating the execution for the
apps
because they are included inworkspaces
inpackage.json
. I created this ticket because of that #1500.I would place this snippet either in a separate
yml
or (maybe) just get rid of the rest and use this file just for this test so you can also complete the other ticket. Otherwise this new part will be moved eventually.