forked from redhat-developer/gitops-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-login.spec.ts
More file actions
52 lines (42 loc) · 1.78 KB
/
Copy pathadmin-login.spec.ts
File metadata and controls
52 lines (42 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { test, expect } from '@playwright/test';
import { execSync } from 'node:child_process';
test('Log into Argo CD as local admin', async ({ browser }) => {
let rawOutput: string;
let routeUrl: string;
try {
rawOutput = execSync(
'oc extract secret/openshift-gitops-cluster -n openshift-gitops --keys=admin.password --to=-',
{ timeout: 15000, stdio: 'pipe' }
).toString();
} catch (error) {
throw new Error("Failed to extract admin password. Please check your cluster connection and oc CLI.");
}
//get credentials
const password = rawOutput.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#'))[0];
try {
routeUrl = execSync(
'oc get route openshift-gitops-server -n openshift-gitops -o jsonpath="{.spec.host}"',
{ timeout: 15000, stdio: 'pipe' }
).toString().trim();
} catch (error) {
throw new Error("Failed to fetch Argo CD route. Please check your cluster connection and oc CLI.");
}
//Fresh context to avoid any cached state issues
const context = await browser.newContext({
storageState: { cookies: [], origins: [] },
ignoreHTTPSErrors: true
});
//Navigate and wait for the page to be loaded
const page = await context.newPage();
const loginUrl = `https://${routeUrl}/login?dex=none`;
await page.goto(loginUrl, { waitUntil: 'load' });
const userField = page.getByLabel(/username/i);
await userField.waitFor({ state: 'visible', timeout: 20000 });
//Fill and Sign In
await userField.fill('admin');
await page.locator('input[type="password"]').fill(password);
await page.getByRole('button', { name: /sign in/i }).click();
//Verify we're logged in
await expect(page.locator('.sidebar, [data-testid="sidebar"]').first()).toBeVisible({ timeout: 20000 });
await context.close();
});