Skip to content

Commit 9fe1b3a

Browse files
trdoyle81Triona DoyleTriona Doyle
committed
Gitops 9592 local admin UI test with playwright (redhat-developer#1140)
* Add login via local credentials test Signed-off-by: Triona Doyle <bot@example.com> * address coderabbit feedback for timeouts and cross-version locators Signed-off-by: Triona Doyle <tekton@example.com> * Address coderabbit suggestion: ensure Playwright context closes cleanly on failure Signed-off-by: Triona Doyle <tekton@example.com> --------- Signed-off-by: Triona Doyle <bot@example.com> Signed-off-by: Triona Doyle <tekton@example.com> Co-authored-by: Triona Doyle <bot@example.com> Co-authored-by: Triona Doyle <tekton@example.com> Signed-off-by: Triona Doyle <tekton@example.com>
1 parent 2b779a2 commit 9fe1b3a

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

openshift-ci/build-root/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ FROM quay.io/devtools_gitops/go-toolset:1.26.2
44
USER root
55

66
ARG OPERATOR_SDK_VERSION=1.35.0
7+
ARG KUSTOMIZE_VERSION=v5.8.1
78

89
# Install kubectl tool which is used in e2e-tests
910
RUN curl -sSL -o /usr/local/bin/kubectl "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
@@ -14,8 +15,7 @@ RUN curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/relea
1415
chmod +x /usr/local/bin/argocd
1516

1617
# Install Kustomize
17-
RUN wget https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh && \
18-
bash install_kustomize.sh /usr/local/bin && rm install_kustomize.sh
18+
RUN curl -sSL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz | tar -xz -C /usr/local/bin
1919

2020
# Install operator-sdk
2121
RUN curl -L -o /usr/local/bin/operator-sdk https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_linux_amd64 && \
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { test, expect } from '@playwright/test';
2+
import { execSync } from 'node:child_process';
3+
4+
test('Log into Argo CD as local admin', async ({ browser }) => {
5+
let rawOutput: string;
6+
let routeUrl: string;
7+
8+
try {
9+
rawOutput = execSync(
10+
'oc extract secret/openshift-gitops-cluster -n openshift-gitops --keys=admin.password --to=-',
11+
{ timeout: 15000, stdio: 'pipe' }
12+
).toString();
13+
} catch (error) {
14+
throw new Error("Failed to extract admin password. Please check your cluster connection and oc CLI.");
15+
}
16+
17+
//get credentials
18+
const password = rawOutput.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#'))[0];
19+
20+
try {
21+
routeUrl = execSync(
22+
'oc get route openshift-gitops-server -n openshift-gitops -o jsonpath="{.spec.host}"',
23+
{ timeout: 15000, stdio: 'pipe' }
24+
).toString().trim();
25+
} catch (error) {
26+
throw new Error("Failed to fetch Argo CD route. Please check your cluster connection and oc CLI.");
27+
}
28+
29+
//Fresh context to avoid any cached state issues
30+
const context = await browser.newContext({
31+
storageState: { cookies: [], origins: [] },
32+
ignoreHTTPSErrors: true
33+
});
34+
35+
try {
36+
//Navigate and wait for the page to be loaded
37+
const page = await context.newPage();
38+
const loginUrl = `https://${routeUrl}/login?dex=none`;
39+
await page.goto(loginUrl, { waitUntil: 'load' });
40+
41+
const userField = page.getByLabel(/username/i);
42+
await userField.waitFor({ state: 'visible', timeout: 20000 });
43+
44+
//Fill and Sign In
45+
await userField.fill('admin');
46+
await page.locator('input[type="password"]').fill(password);
47+
await page.getByRole('button', { name: /sign in/i }).click();
48+
49+
//Verify we're logged in
50+
await expect(page.locator('.sidebar, [data-testid="sidebar"]').first()).toBeVisible({ timeout: 20000 });
51+
} finally {
52+
// This guarantees the context closes even if an assertion fails above!
53+
await context.close();
54+
}
55+
});

0 commit comments

Comments
 (0)