-
Notifications
You must be signed in to change notification settings - Fork 726
CONSOLE-5417: Migrate dev-console Cypress tests to Playwright (batch 4) #16767
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
shahsahil264
wants to merge
10
commits into
openshift:main
Choose a base branch
from
shahsahil264:CONSOLE-5417
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a64fe49
CONSOLE-5417: Migrate dev-console Cypress tests to Playwright (batch 4)
shahsahil264 b2124a2
fix: Add exact:true to Create button to avoid strict mode violation
shahsahil264 734f726
fix: Add privileged namespace label for quarkus image on OCP 5.0
shahsahil264 6f819f3
fix: Fix batch 4 vulnerability tests for OCP 5.0
shahsahil264 f99fbe2
Merge remote-tracking branch 'origin/main' into CONSOLE-5417
shahsahil264 6eab3f5
fix: Address batch 4 PR review feedback
shahsahil264 b89437e
fix: Remove dead hasCSVReady function and unnecessary JSDoc
shahsahil264 be13f30
fix: Restore vulnerability-po.ts and fix 404 detection in hasOperator…
shahsahil264 c682a5d
fix: Remove broad message-based 404 fallback in hasOperatorSubscription
shahsahil264 337c199
fix: Address rhamilto review comments on batch 4
shahsahil264 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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import type { Locator } from '@playwright/test'; | ||
|
|
||
| import BasePage from '../base-page'; | ||
|
|
||
| export class VulnerabilityPage extends BasePage { | ||
| private readonly vulnerabilitiesTab = this.page.getByTestId( | ||
| 'horizontal-link-Vulnerabilities', | ||
| ); | ||
| private readonly detailsTab = this.page.getByTestId('horizontal-link-Details'); | ||
| private readonly yamlTab = this.page.getByTestId('horizontal-link-YAML'); | ||
| private readonly affectedPodsTab = this.page.getByTestId('horizontal-link-Affected Pods'); | ||
| private readonly vulnerabilityTable = this.page.locator( | ||
| '[aria-label="Image Manifest Vulnerabilities"]', | ||
| ); | ||
| private readonly filterMenuToggle = this.page.getByTestId('console-select-menu-toggle'); | ||
| private readonly vulnPopup = this.page.getByTestId('vul popup'); | ||
| private readonly vulnAlertLink = this.page.getByTestId('Image Vulnerabilities'); | ||
| private readonly viewAllLink = this.page.getByTestId('view-all'); | ||
| private readonly vulnerabilityTypeSection = this.page.getByRole('group', { | ||
| name: 'Vulnerability type', | ||
| }); | ||
|
|
||
| async navigateToProjectOverview(namespace: string): Promise<void> { | ||
| await this.goTo(`/project-details/ns/${namespace}`); | ||
| } | ||
|
|
||
| getVulnerabilitiesTab(): Locator { | ||
| return this.vulnerabilitiesTab; | ||
| } | ||
|
|
||
| getDetailsTab(): Locator { | ||
| return this.detailsTab; | ||
| } | ||
|
|
||
| getYamlTab(): Locator { | ||
| return this.yamlTab; | ||
| } | ||
|
|
||
| getAffectedPodsTab(): Locator { | ||
| return this.affectedPodsTab; | ||
| } | ||
|
|
||
| async clickVulnerabilitiesTab(): Promise<void> { | ||
| await this.robustClick(this.vulnerabilitiesTab); | ||
| } | ||
|
|
||
| getVulnerabilityTable(): Locator { | ||
| return this.vulnerabilityTable; | ||
| } | ||
|
|
||
| getFilterMenuToggle(): Locator { | ||
| return this.filterMenuToggle; | ||
| } | ||
|
|
||
| async clickFilterMenuToggle(): Promise<void> { | ||
| await this.robustClick(this.filterMenuToggle); | ||
| } | ||
|
|
||
| getVulnPopup(): Locator { | ||
| return this.vulnPopup; | ||
| } | ||
|
|
||
| getVulnAlertLink(): Locator { | ||
| return this.vulnAlertLink; | ||
| } | ||
|
|
||
| async clickVulnAlert(): Promise<void> { | ||
| await this.robustClick(this.vulnAlertLink); | ||
| } | ||
|
|
||
| async clickViewAll(): Promise<void> { | ||
| await this.robustClick(this.viewAllLink); | ||
| } | ||
|
|
||
| getVulnLink(index: number): Locator { | ||
| return this.page.getByTestId(`vuln-${index}`); | ||
| } | ||
|
|
||
| async clickVulnLink(index: number): Promise<void> { | ||
| await this.robustClick(this.getVulnLink(index)); | ||
| } | ||
|
|
||
| getVulnImageLink(imageName: string): Locator { | ||
| return this.page.getByRole('link', { name: imageName }); | ||
| } | ||
|
|
||
| async clickVulnImageLink(imageName: string): Promise<void> { | ||
| await this.robustClick(this.getVulnImageLink(imageName)); | ||
| } | ||
|
|
||
| getVulnerabilityTypeSection(): Locator { | ||
| return this.vulnerabilityTypeSection; | ||
| } | ||
|
|
||
| getVulnerabilityTypeButton(typeName: string): Locator { | ||
| return this.page.getByRole('button', { name: typeName, exact: true }); | ||
| } | ||
|
|
||
| async clickVulnerabilityType(typeName: string): Promise<void> { | ||
| await this.robustClick(this.getVulnerabilityTypeButton(typeName)); | ||
| } | ||
|
|
||
| getSectionHeading(text: string): Locator { | ||
| return this.page.locator(`[data-test-section-heading="${text}"]`); | ||
| } | ||
|
|
||
| async selectFilterOption(optionId: string): Promise<void> { | ||
| const option = this.page.getByTestId('console-select-item').filter({ hasText: optionId }); | ||
| await this.robustClick(option); | ||
| } | ||
|
|
||
| getFilterOption(text: string): Locator { | ||
| return this.page.getByTestId('console-select-item').filter({ hasText: text }); | ||
| } | ||
| } |
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,233 @@ | ||
| import type KubernetesClient from '../../clients/kubernetes-client'; | ||
| import { test, expect } from '../../fixtures'; | ||
| import { warmupSPA } from '../../pages/base-page'; | ||
| import { VulnerabilityPage } from '../../pages/dev-console/vulnerability-page'; | ||
|
|
||
| import { hasOperatorSubscription } from '../../utils/operator-check'; | ||
|
|
||
| const DEPLOYMENT_NAME = 'test-vulnerability'; | ||
| const QUAY_CSO_SUBSCRIPTION = 'quay-container-security-operator'; | ||
|
|
||
| const IMV_GROUP = 'secscan.quay.redhat.com'; | ||
| const IMV_VERSION = 'v1alpha1'; | ||
| const IMV_PLURAL = 'imagemanifestvulns'; | ||
|
|
||
| async function waitForIMVData( | ||
| k8sClient: KubernetesClient, | ||
| namespace: string, | ||
| timeoutMs = 180_000, | ||
| ): Promise<void> { | ||
| const start = Date.now(); | ||
| while (Date.now() - start < timeoutMs) { | ||
| try { | ||
| const items = await k8sClient.listCustomResources(IMV_GROUP, IMV_VERSION, namespace, IMV_PLURAL); | ||
| if (items.length > 0) return; | ||
| } catch { | ||
| // CRD may not be registered yet — retry | ||
| } | ||
| await new Promise((r) => setTimeout(r, 10_000)); | ||
| } | ||
| throw new Error(`ImageManifestVuln data not found in ${namespace} after ${timeoutMs}ms`); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test.describe( | ||
| 'Image Vulnerability in Project', | ||
| { tag: ['@vulnerability', '@dev-console', '@regression'] }, | ||
| () => { | ||
| let testNs: string; | ||
|
|
||
| test.beforeAll(async ({ k8sClient }) => { | ||
| const hasQuay = await hasOperatorSubscription(k8sClient, QUAY_CSO_SUBSCRIPTION); | ||
| // eslint-disable-next-line playwright/no-skipped-test | ||
| test.skip(!hasQuay, 'Requires Quay Container Security Operator'); | ||
|
|
||
| testNs = `aut-image-vulnerability-${Date.now()}`; | ||
| await k8sClient.createNamespace(testNs, { | ||
| 'pod-security.kubernetes.io/enforce': 'restricted', | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
shahsahil264 marked this conversation as resolved.
|
||
| await k8sClient.createCustomResource('apps', 'v1', testNs, 'deployments', { | ||
| apiVersion: 'apps/v1', | ||
| kind: 'Deployment', | ||
| metadata: { name: DEPLOYMENT_NAME, namespace: testNs }, | ||
| spec: { | ||
| selector: { matchLabels: { app: 'quarkus' } }, | ||
| replicas: 1, | ||
| template: { | ||
| metadata: { labels: { app: 'quarkus' } }, | ||
| spec: { | ||
| automountServiceAccountToken: false, | ||
| containers: [{ | ||
| name: 'quarkus', | ||
| image: 'quay.io/redhat-appstudio-qe/quarkus:7dd062e2e8cb4ba599185e48d628b65a', | ||
| command: ['sleep', 'infinity'], | ||
| ports: [{ containerPort: 8080 }], | ||
| resources: { | ||
| requests: { cpu: '10m', memory: '32Mi' }, | ||
| limits: { cpu: '100m', memory: '128Mi' }, | ||
| }, | ||
| securityContext: { | ||
| allowPrivilegeEscalation: false, | ||
| readOnlyRootFilesystem: true, | ||
| runAsNonRoot: true, | ||
| seccompProfile: { type: 'RuntimeDefault' }, | ||
| capabilities: { drop: ['ALL'] }, | ||
| }, | ||
| }], | ||
| }, | ||
|
shahsahil264 marked this conversation as resolved.
|
||
| }, | ||
| }, | ||
| }); | ||
| await waitForIMVData(k8sClient, testNs); | ||
| }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await warmupSPA(page); | ||
| const vulnPage = new VulnerabilityPage(page); | ||
| await vulnPage.switchPerspective('Developer'); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ k8sClient }) => { | ||
| if (testNs) { | ||
| await k8sClient.deleteNamespace(testNs); | ||
| } | ||
| }); | ||
|
|
||
| test('PV-01-TC01: Vulnerability tab shows Image Manifest vulnerabilities', async ({ | ||
| page, | ||
| }) => { | ||
| const vulnPage = new VulnerabilityPage(page); | ||
|
|
||
| await test.step('Navigate to project overview and click Vulnerabilities tab', async () => { | ||
| await vulnPage.navigateToProjectOverview(testNs); | ||
| await expect(vulnPage.getVulnerabilitiesTab()).toBeVisible({ timeout: 60_000 }); | ||
| await vulnPage.clickVulnerabilitiesTab(); | ||
| }); | ||
|
|
||
| await test.step('Verify vulnerability table is visible with expected columns', async () => { | ||
| const table = vulnPage.getVulnerabilityTable(); | ||
| await expect(table).toBeVisible({ timeout: 60_000 }); | ||
|
|
||
| for (const column of [ | ||
| 'Image name', | ||
| 'Highest severity', | ||
| 'Affected Pods', | ||
| 'Fixable', | ||
| 'Total', | ||
| 'Manifest', | ||
| ]) { | ||
| await expect(table).toContainText(column); | ||
| } | ||
| }); | ||
|
|
||
| await test.step('Verify Name filter is selected by default', async () => { | ||
| await expect(vulnPage.getFilterMenuToggle()).toHaveText('Name'); | ||
| }); | ||
| }); | ||
|
|
||
| test('PV-01-TC03: Filter in vulnerability tab', async ({ page }) => { | ||
| const vulnPage = new VulnerabilityPage(page); | ||
|
|
||
| await test.step('Navigate to project overview', async () => { | ||
| await vulnPage.navigateToProjectOverview(testNs); | ||
| }); | ||
|
|
||
| await test.step('Click Image Vulnerabilities alert in Status section', async () => { | ||
| await expect(vulnPage.getVulnAlertLink()).toBeVisible({ timeout: 60_000 }); | ||
| await vulnPage.clickVulnAlert(); | ||
| await expect(vulnPage.getVulnPopup()).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('Click View all link and change filter to Label', async () => { | ||
| await vulnPage.clickViewAll(); | ||
| await expect(vulnPage.getFilterMenuToggle()).toBeVisible(); | ||
| await vulnPage.clickFilterMenuToggle(); | ||
| await vulnPage.selectFilterOption('Label'); | ||
| }); | ||
|
|
||
| await test.step('Verify Label filter is now selected', async () => { | ||
| await expect(vulnPage.getFilterMenuToggle()).toHaveText('Label'); | ||
| }); | ||
| }); | ||
|
|
||
| test('PV-01-TC04: Image manifests vulnerability details page', async ({ page }) => { | ||
| const vulnPage = new VulnerabilityPage(page); | ||
|
|
||
| await test.step('Navigate to project overview', async () => { | ||
| await vulnPage.navigateToProjectOverview(testNs); | ||
| }); | ||
|
|
||
| await test.step('Click Image Vulnerabilities in Status section', async () => { | ||
| await expect(vulnPage.getVulnAlertLink()).toBeVisible({ timeout: 60_000 }); | ||
| await vulnPage.clickVulnAlert(); | ||
| await expect(vulnPage.getVulnPopup()).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('Click on the first vulnerability image name', async () => { | ||
| await vulnPage.clickVulnLink(0); | ||
| }); | ||
|
|
||
| await test.step('Click on Base image vulnerability type', async () => { | ||
| await expect(vulnPage.getVulnerabilityTypeSection()).toBeVisible({ timeout: 30_000 }); | ||
| await vulnPage.clickVulnerabilityType('Base image'); | ||
| }); | ||
|
|
||
| await test.step('Verify Details, YAML, and Affected Pods tabs are visible', async () => { | ||
| await expect(vulnPage.getDetailsTab()).toBeVisible(); | ||
| await expect(vulnPage.getYamlTab()).toBeVisible(); | ||
| await expect(vulnPage.getAffectedPodsTab()).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('Verify Base image tab is selected', async () => { | ||
| await expect(vulnPage.getVulnerabilityTypeButton('Base image')).toHaveAttribute( | ||
| 'aria-pressed', | ||
| 'true', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('PV-01-TC05: Filters of vulnerability section in Image manifests vulnerability details page', async ({ | ||
| page, | ||
| }) => { | ||
| test.slow(); | ||
| const vulnPage = new VulnerabilityPage(page); | ||
|
|
||
| await test.step('Navigate to vulnerability details via project tab', async () => { | ||
| await vulnPage.navigateToProjectOverview(testNs); | ||
| await expect(vulnPage.getVulnerabilitiesTab()).toBeVisible({ timeout: 60_000 }); | ||
| await vulnPage.clickVulnerabilitiesTab(); | ||
|
|
||
| const vulnLink = vulnPage.getVulnImageLink('redhat-appstudio-qe/quarkus'); | ||
| await expect(vulnLink).toBeVisible({ timeout: 120_000 }); | ||
| await vulnPage.clickVulnImageLink('redhat-appstudio-qe/quarkus'); | ||
| await expect( | ||
| vulnPage.getSectionHeading('Image Manifest Vulnerabilities details'), | ||
| ).toBeVisible({ timeout: 30_000 }); | ||
| }); | ||
|
|
||
| await test.step('Click App dependency type filter', async () => { | ||
| await expect(vulnPage.getVulnerabilityTypeSection()).toBeVisible({ timeout: 30_000 }); | ||
| await vulnPage.clickVulnerabilityType('App dependency'); | ||
| }); | ||
|
|
||
| await test.step('Verify App dependency filter is selected', async () => { | ||
| await expect(vulnPage.getVulnerabilityTypeButton('App dependency')).toHaveAttribute( | ||
| 'aria-pressed', | ||
| 'true', | ||
| ); | ||
| }); | ||
|
|
||
| await test.step('Verify vulnerability details section is visible', async () => { | ||
| await expect( | ||
| vulnPage.getSectionHeading('Image Manifest Vulnerabilities details'), | ||
| ).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('Verify severity filter is available', async () => { | ||
| await vulnPage.clickFilterMenuToggle(); | ||
| for (const severity of ['Critical', 'High', 'Medium', 'Low']) { | ||
| await expect(vulnPage.getFilterOption(severity)).toBeVisible(); | ||
| } | ||
| }); | ||
| }); | ||
| }, | ||
| ); | ||
|
shahsahil264 marked this conversation as resolved.
|
||
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.