-
Notifications
You must be signed in to change notification settings - Fork 746
CONSOLE-5233: Playwright-test-migration-for-console/app #16449
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
Closed
Cragsmann
wants to merge
10
commits into
openshift:main
from
Cragsmann:CONSOLE-5233--Playwright-test-migration-for-console/app
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f9dc72a
CONSOLE-5233: Playwright-test-migration-for-console/app
Cragsmann 0d06cfb
CONSOLE-5233: remove migrated cypress tests
Cragsmann 76346aa
CONSOLE-5233: Address PR review comments for Playwright e2e tests
Cragsmann e5b5758
CONSOLE-5233: Fix "Model does not exist" test failures with auto-retry
Cragsmann 87b9881
CONSOLE-5233: Fix ESLint warnings and align with updated Playwright s…
rhamilto ac6dc62
CONSOLE-5233: Harden page objects from pre-push review findings
rhamilto a33e4f1
CONSOLE-5233: Remove duplicated code across page objects
rhamilto 965e9b9
CONSOLE-5233: Replace remaining waitFor calls with expect assertions …
rhamilto fa59c39
CONSOLE-5233: Revert upstream page objects and adapt tests to use the…
rhamilto dff9387
CONSOLE-5233: Fix review findings from pre-push review
rhamilto 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,5 +12,6 @@ Godeps | |
| dynamic-demo-plugin | ||
| .eslintrc.js | ||
| tsconfig.json | ||
| e2e/.eslintrc.json | ||
| e2e/tsconfig.json | ||
| e2e/package.json | ||
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,43 @@ | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import BasePage from './base-page'; | ||
|
|
||
| export class LoginPage extends BasePage { | ||
| private readonly loginButton = this.page.getByTestId('login'); | ||
| private readonly usernameInput = this.page.locator('#inputUsername'); | ||
| private readonly passwordInput = this.page.locator('#inputPassword'); | ||
| private readonly submitButton = this.page.locator('button[type="submit"]'); | ||
| private readonly userDropdownToggle = this.page.getByTestId('user-dropdown-toggle'); | ||
|
|
||
| providerButton(provider: string) { | ||
| return this.page.getByText(provider, { exact: true }); | ||
| } | ||
|
|
||
| async loginAs(provider: string, username: string, password: string): Promise<boolean> { | ||
| await this.page.goto('./', { timeout: 90_000, waitUntil: 'domcontentloaded' }); | ||
|
|
||
| const authDisabled = await this.page | ||
| .evaluate(() => (window as any).SERVER_FLAGS?.authDisabled) | ||
| .catch(() => false); | ||
|
|
||
| if (authDisabled) { | ||
| return false; | ||
| } | ||
|
|
||
| const providerBtn = this.providerButton(provider); | ||
| await expect( | ||
| this.loginButton.or(this.usernameInput).or(providerBtn).first(), | ||
| ).toBeVisible({ timeout: 30_000 }); | ||
|
|
||
| if (await providerBtn.isVisible()) { | ||
| await providerBtn.click(); | ||
| await expect(this.usernameInput).toBeVisible({ timeout: 30_000 }); | ||
| } | ||
|
|
||
| await this.usernameInput.fill(username); | ||
| await this.passwordInput.fill(password); | ||
| await this.submitButton.click(); | ||
| await expect(this.userDropdownToggle).toBeVisible({ timeout: 60_000 }); | ||
| return true; | ||
| } | ||
| } |
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,26 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import type { Locator } from '@playwright/test'; | ||
|
|
||
| import { DetailsPage } from './details-page'; | ||
|
|
||
| export class MachineConfigPage extends DetailsPage { | ||
| readonly configFilePath = this.page.getByTestId('config-file-path-0'); | ||
| readonly copyToClipboard = this.page.locator('.co-copy-to-clipboard__text'); | ||
|
|
||
| sectionHeading(heading: string): Locator { | ||
| return this.page.locator(`[data-test-section-heading="${heading}"]`); | ||
| } | ||
|
|
||
| async checkConfigFileDetails(mode: number, overwrite: boolean, content: string): Promise<void> { | ||
| await this.configFilePath.scrollIntoViewIfNeeded(); | ||
| await this.page.locator('button[aria-label="Info"]').first().click(); | ||
| const descriptionList = this.page.locator('[class*="description-list"]'); | ||
| await expect(descriptionList.getByText(String(mode), { exact: true })).toBeVisible(); | ||
| await expect(descriptionList.getByText(String(overwrite), { exact: true })).toBeVisible(); | ||
| const decoded = decodeURIComponent(content) | ||
| .replace(/^(data:,)/, '') | ||
| .slice(0, 30); | ||
| const codeBlock = this.page.locator('code').first(); | ||
| await expect(codeBlock).toContainText(decoded); | ||
| } | ||
|
Cragsmann marked this conversation as resolved.
|
||
| } | ||
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,83 @@ | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import BasePage from './base-page'; | ||
|
|
||
| export class NavPage extends BasePage { | ||
| readonly clusterSettingsHeading = this.page.locator( | ||
| '[data-test-id="cluster-settings-page-heading"]', | ||
| ); | ||
|
|
||
| private get sidebar() { | ||
| return this.page.locator('#page-sidebar'); | ||
| } | ||
|
|
||
| private get perspectiveSwitcherToggle() { | ||
| return this.page.locator('[data-test-id="perspective-switcher-toggle"]'); | ||
| } | ||
|
|
||
| async perspectiveSwitcherShouldHaveText(text: string): Promise<void> { | ||
| const toggle = this.perspectiveSwitcherToggle; | ||
| await toggle.scrollIntoViewIfNeeded(); | ||
|
|
||
| const isSinglePerspective = (await toggle.getAttribute('id')) === 'core-platform-perspective'; | ||
| if (isSinglePerspective) { | ||
| await expect(toggle).toContainText(text, { timeout: 30_000 }); | ||
| } else { | ||
| await expect(toggle.locator('.pf-v6-c-menu-toggle__text')).toContainText(text, { | ||
| timeout: 30_000, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| async changePerspectiveTo(perspective: string): Promise<void> { | ||
| await this.page.waitForLoadState('domcontentloaded'); | ||
| const toggle = this.perspectiveSwitcherToggle; | ||
| await toggle.scrollIntoViewIfNeeded(); | ||
| await expect(toggle).toBeVisible(); | ||
|
|
||
| const isSinglePerspective = (await toggle.getAttribute('id')) === 'core-platform-perspective'; | ||
| if (isSinglePerspective) { | ||
| return; | ||
| } | ||
|
|
||
| const currentText = await toggle.locator('.pf-v6-c-menu-toggle__text').textContent(); | ||
|
|
||
| if (currentText?.trim() === perspective) { | ||
| return; | ||
| } | ||
|
|
||
| await this.robustClick(toggle); | ||
| await expect(toggle).toHaveAttribute('aria-expanded', 'true', { timeout: 5_000 }); | ||
| const option = this.page | ||
| .locator('[data-test-id="perspective-switcher-menu-option"]') | ||
| .filter({ hasText: perspective }); | ||
| await this.robustClick(option); | ||
| } | ||
|
|
||
| async shouldHaveNavSection(path: string[]): Promise<void> { | ||
| for (const item of path) { | ||
| await expect(this.sidebar).toContainText(item); | ||
| } | ||
| } | ||
|
|
||
| async shouldNotHaveNavSection(path: string[]): Promise<void> { | ||
| const target = path[path.length - 1]; | ||
| await expect(this.sidebar.getByText(target, { exact: true })).toBeHidden(); | ||
| } | ||
|
|
||
| async clickNavLink(path: string[]): Promise<void> { | ||
| if (!path.length) { | ||
| throw new Error('clickNavLink requires at least one path element'); | ||
| } | ||
| const navItem = this.sidebar.getByText(path[0]); | ||
| if (path.length === 1) { | ||
| await this.robustClick(navItem); | ||
| return; | ||
| } | ||
| const expanded = await navItem.getAttribute('aria-expanded'); | ||
| if (expanded !== 'true') { | ||
| await this.robustClick(navItem); | ||
| } | ||
| await this.robustClick(this.sidebar.getByText(path[1])); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
201 changes: 201 additions & 0 deletions
201
frontend/e2e/tests/console/app/admission-webhook-warning-notifications.spec.ts
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,201 @@ | ||
| import { test, expect } from '../../../fixtures'; | ||
| import { YamlEditorPage } from '../../../pages/yaml-editor-page'; | ||
|
|
||
| const POD_NAME = 'pod1'; | ||
| const DEPLOY_NAME = 'deploy1'; | ||
| const CONTAINER_NAME = 'container1'; | ||
| const WARNING_FOO = '299 - "[pod-must-have-label-foo] you must provide labels: {"foo"}"'; | ||
| const WARNING_BAR = '299 - "[deployment-must-have-label-bar] you must provide labels: {"bar"}"'; | ||
| const LEARN_MORE_ID = 'admission-webhook-warning-learn-more'; | ||
| const WARNING_ID = 'admission-webhook-warning'; | ||
|
|
||
| test.describe('Admission Webhook warning notification', { tag: ['@admin'] }, () => { | ||
| const testNs = `e2e-admission-${Date.now()}`; | ||
|
|
||
| const pod1ReqObj = `apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: ${POD_NAME}-a | ||
| labels: | ||
| app: httpd | ||
| namespace: ${testNs} | ||
| spec: | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| containers: | ||
| - name: ${CONTAINER_NAME} | ||
| image: 'image-registry.openshift-image-registry.svc:5000/openshift/httpd:latest' | ||
| ports: | ||
| - containerPort: 8080 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL`; | ||
|
|
||
| const bulkResourcesReqObj = `apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: ${POD_NAME}-b | ||
| labels: | ||
| app: httpd | ||
| namespace: ${testNs} | ||
| spec: | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| containers: | ||
| - name: ${CONTAINER_NAME} | ||
| image: 'image-registry.openshift-image-registry.svc:5000/openshift/httpd:latest' | ||
| ports: | ||
| - containerPort: 8080 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: ${DEPLOY_NAME} | ||
| annotations: {} | ||
| namespace: ${testNs} | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: deploy1 | ||
| replicas: 3 | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: deploy1 | ||
| spec: | ||
| containers: | ||
| - name: ${CONTAINER_NAME} | ||
| image: >- | ||
| image-registry.openshift-image-registry.svc:5000/openshift/httpd:latest | ||
| ports: | ||
| - containerPort: 8080 | ||
| protocol: TCP | ||
| env: | ||
| - name: app | ||
| value: frontennd | ||
| imagePullSecrets: [] | ||
| strategy: | ||
| type: RollingUpdate | ||
| rollingUpdate: | ||
| maxSurge: 25% | ||
| maxUnavailable: 25% | ||
| paused: false | ||
| `; | ||
|
|
||
| test.beforeAll(async ({ k8sClient }) => { | ||
| await k8sClient.createNamespace(testNs); | ||
| await k8sClient.waitForNamespaceReady(testNs); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ k8sClient }) => { | ||
| await k8sClient.deleteNamespace(testNs); | ||
| }); | ||
|
|
||
| test('Create a pod and display Admission Webhook warning notification', async ({ page }) => { | ||
| const yamlEditor = new YamlEditorPage(page); | ||
|
|
||
| await page.goto(`/k8s/ns/${testNs}/import`); | ||
| await yamlEditor.waitForEditorReady(); | ||
| await yamlEditor.setEditorContent(pod1ReqObj); | ||
|
|
||
| await page.route(`**/api/kubernetes/api/v1/namespaces/${testNs}/pods`, async (route) => { | ||
| if (route.request().method() !== 'POST') { | ||
| await route.continue(); | ||
| return; | ||
| } | ||
| const response = await route.fetch(); | ||
| await route.fulfill({ | ||
| response, | ||
| headers: { | ||
| ...response.headers(), | ||
| Warning: WARNING_FOO, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| await yamlEditor.clickSave(); | ||
| await expect(page.locator('[data-test-section-heading="Pod details"]')).toBeVisible(); | ||
|
|
||
| const warning = page.getByTestId(WARNING_ID); | ||
| await expect(warning).toContainText('Admission Webhook Warning'); | ||
| await expect(warning).toContainText(`Pod ${POD_NAME}-a violates policy ${WARNING_FOO}`); | ||
|
|
||
| const learnMore = page.getByTestId(LEARN_MORE_ID); | ||
| await expect(learnMore).toContainText('Learn more'); | ||
| await learnMore.click(); | ||
| }); | ||
|
Cragsmann marked this conversation as resolved.
|
||
|
|
||
| test('Create bulk resources and display Admission Webhook warning notifications', async ({ | ||
| page, | ||
| }) => { | ||
| const yamlEditor = new YamlEditorPage(page); | ||
|
|
||
| await page.goto(`/k8s/ns/${testNs}/import`); | ||
| await yamlEditor.waitForEditorReady(); | ||
| await yamlEditor.setEditorContent(bulkResourcesReqObj); | ||
|
|
||
| await page.route(`**/api/kubernetes/api/v1/namespaces/${testNs}/pods`, async (route) => { | ||
| if (route.request().method() !== 'POST') { | ||
| await route.continue(); | ||
| return; | ||
| } | ||
| const response = await route.fetch(); | ||
| await route.fulfill({ | ||
| response, | ||
| headers: { | ||
| ...response.headers(), | ||
| Warning: WARNING_FOO, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| await page.route( | ||
| `**/api/kubernetes/apis/apps/v1/namespaces/${testNs}/deployments`, | ||
| async (route) => { | ||
| if (route.request().method() !== 'POST') { | ||
| await route.continue(); | ||
| return; | ||
| } | ||
| const response = await route.fetch(); | ||
| await route.fulfill({ | ||
| response, | ||
| headers: { | ||
| ...response.headers(), | ||
| Warning: WARNING_BAR, | ||
| }, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| await yamlEditor.clickSave(); | ||
|
|
||
| await expect(page.getByTestId('resources-successfully-created')).toContainText( | ||
| 'Resources successfully created', | ||
| ); | ||
|
|
||
| const warning = page.getByTestId(WARNING_ID); | ||
| await expect(warning).toHaveCount(2); | ||
| await expect(warning.first()).toContainText('Admission Webhook Warning'); | ||
| await expect( | ||
| warning.filter({ hasText: `Pod ${POD_NAME}-b violates policy ${WARNING_FOO}` }), | ||
| ).toBeVisible(); | ||
| await expect( | ||
| warning.filter({ hasText: `Deployment ${DEPLOY_NAME} violates policy ${WARNING_BAR}` }), | ||
| ).toBeVisible(); | ||
|
|
||
| const learnMore = page.getByTestId(LEARN_MORE_ID); | ||
| await expect(learnMore.first()).toContainText('Learn more'); | ||
| await learnMore.first().click(); | ||
| }); | ||
| }); | ||
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.
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.
.eslintignoreno longer exists