-
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
Merged
Merged
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
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,143 @@ | ||
| 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({ timeout: 15000 }); | ||
| 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 }) => { | ||
| const testOrigin = 'linaro'; | ||
|
|
||
| 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: 15000 }); | ||
|
|
||
| await originDropdown.click(); | ||
|
|
||
| await expect( | ||
| page.locator(COMMON_SELECTORS.originOption(testOrigin)), | ||
| ).toBeVisible(); | ||
|
|
||
| await page.locator(COMMON_SELECTORS.originOption(testOrigin)).click(); | ||
|
|
||
| await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); | ||
|
|
||
| await expect(originDropdown).toContainText(testOrigin); | ||
| }); | ||
| }); | ||
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.