-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add Playwright E2E testing infrastructure with tree listing #1674
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
Open
WilsonNet
wants to merge
1
commit into
main
Choose a base branch
from
feat/playwright
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+346
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,12 +21,45 @@ pnpm dev | |||||
| ``` | ||||||
|
|
||||||
| ## Running unit tests | ||||||
|
|
||||||
| The frontend includes unit tests covering some parts of the source code. To run the tests, use the following command: | ||||||
|
|
||||||
| ```sh | ||||||
| pnpm test | ||||||
| ``` | ||||||
|
|
||||||
| ## Running end-to-end (e2e) tests | ||||||
|
|
||||||
| The project includes Playwright-based end-to-end tests. To run the tests, first set the test environment URL in your .env file: | ||||||
|
|
||||||
| ```sh | ||||||
| # Copy the example file | ||||||
| cp .env.example .env | ||||||
|
|
||||||
| # Edit the .env file to set PLAYWRIGHT_TEST_BASE_URL to your desired environment | ||||||
| # Available environments: | ||||||
| # - Staging: https://staging.dashboard.kernelci.org:9000 (default) | ||||||
| # - Production: https://dashboard.kernelci.org | ||||||
| # - Local: http://localhost:5173 | ||||||
|
|
||||||
| # Install Playwright browsers if you don't have them them | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| pnpm exec playwright install | ||||||
| ``` | ||||||
|
|
||||||
| Then run the e2e tests: | ||||||
|
|
||||||
| ```sh | ||||||
| # Run all e2e tests | ||||||
| pnpm run e2e | ||||||
|
|
||||||
| # Run e2e tests with UI mode for debugging | ||||||
| pnpm run e2e-ui | ||||||
| ``` | ||||||
|
|
||||||
| ## E2E Test Selectors | ||||||
|
|
||||||
| To avoid complex css selectors, you can add a data-test-id attribute to elements that you want to target in your e2e tests. That way you don't need to fight with complex selectors. | ||||||
|
|
||||||
| # Routing and State Management | ||||||
|
|
||||||
| A big part of this project is to have shareable links | ||||||
|
|
@@ -37,5 +70,5 @@ Also, we are using file based routing in the tanstack router, only files that st | |||||
| # Feature Flags | ||||||
|
|
||||||
| They are used when we want to hide a feature for some users, without having to do branch manipulation. | ||||||
| Right now the only feature flag is for Dev only and it is controlled by the env | ||||||
| Right now the only feature flag is for Dev only and it is controlled by the env | ||||||
| `FEATURE_FLAG_SHOW_DEV=false` it is a boolean. | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| export const TREE_LISTING_SELECTORS = { | ||
| table: 'table', | ||
| treeColumnHeader: 'th button:has-text("Tree")', | ||
| branchColumnHeader: 'th button:has-text("Branch")', | ||
|
|
||
| intervalInput: 'input[type="number"][min="1"]', | ||
|
|
||
| // This requires nth() selector which can't be stored as string | ||
| itemsPerPageDropdown: '[role="listbox"]', | ||
| itemsPerPageOption: (value: string) => `[role="option"]:has-text("${value}")`, | ||
|
|
||
| searchInput: 'input[type="text"]', | ||
|
|
||
| nextPageButton: '[role="button"]:has-text(">")', | ||
| previousPageButton: '[role="button"]:has-text("<")', | ||
|
|
||
| treeNameCell: (treeName: string) => `td a:has-text("${treeName}")`, | ||
| firstTreeCell: 'td a', | ||
|
|
||
| breadcrumbTreesLink: '[data-test-id="breadcrumb-link"]:has-text("Trees")', | ||
| } as const; | ||
|
|
||
| export const COMMON_SELECTORS = { | ||
| tableRow: 'tr', | ||
| tableHeader: 'th', | ||
|
|
||
| originDropdown: '[data-test-id="origin-dropdown"]', | ||
| originOption: (origin: string) => `[data-test-id="origin-option-${origin}"]`, | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| import { TREE_LISTING_SELECTORS, COMMON_SELECTORS } from './e2e-selectors'; | ||
|
|
||
| const PAGE_LOAD_TIMEOUT = 5000; | ||
| const DEFAULT_ACTION_TIMEOUT = 1000; | ||
| const SEARCH_UPDATE_TIMEOUT = 2000; | ||
| const NAVIGATION_TIMEOUT = 5000; | ||
| const GO_BACK_TIMEOUT = 3000; | ||
|
|
||
| test.describe('Tree Listing Page Tests', () => { | ||
MarceloRobert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/tree'); | ||
| await page.waitForTimeout(PAGE_LOAD_TIMEOUT); | ||
| }); | ||
|
|
||
| test('loads tree listing page correctly', async ({ page }) => { | ||
| await expect(page).toHaveTitle(/KernelCI/); | ||
| await expect(page).toHaveURL(/\/tree/); | ||
|
|
||
| await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); | ||
|
|
||
| await expect( | ||
| page.locator(TREE_LISTING_SELECTORS.treeColumnHeader), | ||
| ).toBeVisible(); | ||
| await expect( | ||
| page.locator(TREE_LISTING_SELECTORS.branchColumnHeader), | ||
| ).toBeVisible(); | ||
| }); | ||
|
|
||
| test('change time interval', async ({ page }) => { | ||
| await expect(page.locator(COMMON_SELECTORS.tableRow).first()).toBeVisible(); | ||
|
|
||
| const intervalInput = page | ||
| .locator(TREE_LISTING_SELECTORS.intervalInput) | ||
| .first(); | ||
| await expect(intervalInput).toBeVisible(); | ||
|
|
||
| await intervalInput.fill('14'); | ||
|
|
||
| await page.waitForTimeout(DEFAULT_ACTION_TIMEOUT); | ||
|
|
||
| await expect(intervalInput).toHaveValue('14'); | ||
| }); | ||
|
|
||
| test('change table size', async ({ page }) => { | ||
| await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); | ||
|
|
||
| const tableSizeSelector = page.locator('[role="combobox"]').nth(1); | ||
| await expect(tableSizeSelector).toBeVisible(); | ||
|
|
||
| await tableSizeSelector.click(); | ||
|
|
||
| await expect( | ||
| page.locator(TREE_LISTING_SELECTORS.itemsPerPageDropdown), | ||
| ).toBeVisible(); | ||
|
|
||
| await page.locator(TREE_LISTING_SELECTORS.itemsPerPageOption('20')).click(); | ||
|
|
||
| await page.waitForTimeout(DEFAULT_ACTION_TIMEOUT); | ||
|
|
||
| await expect(tableSizeSelector).toContainText('20'); | ||
| }); | ||
|
|
||
| test('search for trees', async ({ page }) => { | ||
| const searchInput = page.locator(TREE_LISTING_SELECTORS.searchInput).nth(0); | ||
| await expect(searchInput).toBeVisible(); | ||
| await searchInput.fill('main'); | ||
|
|
||
| await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); | ||
|
|
||
| const tableRows = page.locator(COMMON_SELECTORS.tableRow); | ||
| const count = await tableRows.count(); | ||
| expect(count).toBeGreaterThan(1); | ||
| }); | ||
|
|
||
| test('navigate to tree details and back via breadcrumb', async ({ page }) => { | ||
| await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); | ||
|
|
||
| const firstTreeLink = page.locator('td a').first(); | ||
| await expect(firstTreeLink).toBeVisible(); | ||
|
|
||
| await firstTreeLink.click(); | ||
|
|
||
| await page.waitForTimeout(NAVIGATION_TIMEOUT); | ||
|
|
||
| const url = page.url(); | ||
| expect(url).toMatch(/\/tree\/[^/]+\/[^/]+\/[^/]+$/); | ||
|
|
||
| const breadcrumbLink = page.locator( | ||
| TREE_LISTING_SELECTORS.breadcrumbTreesLink, | ||
| ); | ||
| await expect(breadcrumbLink).toBeVisible(); | ||
| await breadcrumbLink.click(); | ||
| await page.waitForTimeout(GO_BACK_TIMEOUT); | ||
|
|
||
| await expect(page).toHaveURL(/\/tree$/); | ||
| }); | ||
|
|
||
| test('pagination navigation', async ({ page }) => { | ||
| await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); | ||
|
|
||
| const nextPageButton = page | ||
| .locator(TREE_LISTING_SELECTORS.nextPageButton) | ||
| .first(); | ||
| const hasNextPage = | ||
| (await nextPageButton.count()) > 0 && | ||
| !(await nextPageButton.isDisabled()); | ||
|
|
||
| if (hasNextPage) { | ||
| const originalPageUrl = page.url(); | ||
| await nextPageButton.click(); | ||
|
|
||
| await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); | ||
|
|
||
| const newPageUrl = page.url(); | ||
| expect(newPageUrl).not.toBe(originalPageUrl); | ||
| } | ||
| }); | ||
|
|
||
| test('change origin', async ({ page }) => { | ||
| await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); | ||
|
|
||
| await expect(page.locator('text="Origin"')).toBeVisible(); | ||
|
|
||
| const originDropdown = page.locator(COMMON_SELECTORS.originDropdown); | ||
| await expect(originDropdown).toBeVisible({ timeout: 10000 }); | ||
|
|
||
| await originDropdown.click(); | ||
|
|
||
| await expect( | ||
| page.locator(COMMON_SELECTORS.originOption('linaro')), | ||
|
Collaborator
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. I have a feeling that relying on a fixed name for the tests is not the best move, it could change and break the tests... but for now I think it's ok |
||
| ).toBeVisible(); | ||
|
|
||
| await page.locator(COMMON_SELECTORS.originOption('linaro')).click(); | ||
|
|
||
| await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); | ||
|
|
||
| await expect(originDropdown).toContainText('linaro'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineConfig } from '@playwright/test'; | ||
| import dotenv from 'dotenv'; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './e2e', | ||
| use: { | ||
| baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:5173', | ||
| }, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.