forked from redhat-developer/podman-desktop-rhel-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrhel-extension.spec.ts
More file actions
269 lines (227 loc) · 10.7 KB
/
Copy pathrhel-extension.spec.ts
File metadata and controls
269 lines (227 loc) · 10.7 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Browser, Locator, Page } from '@playwright/test';
import type { ConfirmInputValue } from '@podman-desktop/tests-playwright';
import {
AuthenticationPage,
expect as playExpect,
findPageWithTitleInBrowser,
getEntryFromLogs,
NavigationBar,
performBrowserLogin,
ResourceConnectionCardPage,
ResourceElementActions,
ResourceElementState,
ResourcesPage,
RunnerOptions,
startChromium,
test,
waitForPodmanMachineStartup,
waitUntil,
} from '@podman-desktop/tests-playwright';
const extensionName = 'rhel-vms';
const extensionLabel = 'redhat.rhel-vms';
const extensionHeading = 'RHEL VMs';
let extensionInstalled = false;
const skipInstallation = process.env.SKIP_INSTALLATION;
const extensionURL = process.env.OCI_IMAGE ?? 'ghcr.io/redhat-developer/podman-desktop-rhel-ext:next';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const browserOutputPath = [__dirname, '..', 'output', 'browser'];
const expectedAuthPageTitle = 'Log In';
const regex = new RegExp(/((http|https):\/\/.*$)/);
let signInButton: Locator;
let browser: Browser;
let chromiumPage: Page;
const chromePort = '9222';
test.use({
runnerOptions: new RunnerOptions({
customFolder: 'rhel-e2e-tests',
customOutputFolder: 'tests/output',
autoUpdate: false,
autoCheckUpdates: false,
}),
});
test.beforeAll(async ({ runner, welcomePage, page }) => {
runner.setVideoAndTraceName('rhel-extension-e2e');
await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
});
test.afterAll(async ({ runner }) => {
await runner.close();
});
test.describe.serial('RHEL Extension E2E Tests', () => {
test.describe.serial('Authentication Extension', () => {
test('Go to settings and check if extension is already installed', async ({ navigationBar }) => {
const extensionsPage = await navigationBar.openExtensions();
if (await extensionsPage.extensionIsInstalled(extensionLabel)) extensionInstalled = true;
});
test('Uninstalled previous version of rhel extension', async ({ navigationBar }) => {
test.skip(!extensionInstalled || !!skipInstallation);
test.setTimeout(120_000);
console.log('Extension found already installed, trying to remove!');
await ensureRhelExtensionIsRemoved(navigationBar);
});
test('Install extension through Extension page', async ({ navigationBar }) => {
test.skip(!!skipInstallation);
test.setTimeout(200_000);
const extensionsPage = await navigationBar.openExtensions();
await extensionsPage.installExtensionFromOCIImage(extensionURL);
await playExpect
.poll(async () => await extensionsPage.extensionIsInstalled(extensionLabel), { timeout: 30_000 })
.toBeTruthy();
});
});
test.describe.serial('Red Hat Authentication extension installation', () => {
test('SSO provider is available in Authentication Page', async ({ page, navigationBar }) => {
const settingsBar = await navigationBar.openSettings();
await settingsBar.openTabPage(AuthenticationPage);
const authPage = new AuthenticationPage(page);
await playExpect(authPage.heading).toBeVisible({ timeout: 10_000 });
signInButton = page.getByRole('button', { name: 'Sign in' });
await playExpect(signInButton).toBeVisible();
});
test('Can open authentication page in browser', async ({ navigationBar, page }) => {
test.setTimeout(120_000);
const settingsBar = await navigationBar.openSettings();
await settingsBar.openTabPage(AuthenticationPage);
const authPage = new AuthenticationPage(page);
await playExpect(authPage.heading).toBeVisible({ timeout: 10_000 });
// start up chrome instance and return browser object
browser = await startChromium(chromePort, path.join(...browserOutputPath));
// open the link from PD
await page.bringToFront();
await playExpect(signInButton).toBeEnabled({ timeout: 10_000 });
await signInButton.click();
await page.waitForTimeout(5_000);
const urlMatch = await getEntryFromLogs(page, /\.*openid-connect.*/, regex, 'sso.redhat.com');
if (urlMatch) {
const context = await browser.newContext();
const newPage = await context.newPage();
await newPage.goto(urlMatch);
await newPage.waitForURL(/sso.redhat.com/);
chromiumPage = newPage;
const page = await findPageWithTitleInBrowser(browser, expectedAuthPageTitle);
console.log(`Found page with title: ${await page?.title()}`);
} else {
throw new Error('Did not find Initial SSO Login Page');
}
});
test('User can authenticate via browser', async () => {
// Activate the browser window and perform login
playExpect(chromiumPage).toBeDefined();
if (!chromiumPage) {
throw new Error('Chromium browser page was not initialized');
}
await chromiumPage.bringToFront();
console.log(`Switched to Chrome tab with title: ${await chromiumPage.title()}`);
const usernameAction: ConfirmInputValue = {
inputLocator: chromiumPage.getByRole('textbox', { name: 'Red Hat login or email' }),
inputValue: process.env.DVLPR_USERNAME ?? 'unknown',
confirmLocator: chromiumPage.getByRole('button', { name: 'Next' }),
};
const passwordAction: ConfirmInputValue = {
inputLocator: chromiumPage.getByRole('textbox', { name: 'Password' }),
inputValue: process.env.DVLPR_PASSWORD ?? 'unknown',
confirmLocator: chromiumPage.getByRole('button', { name: 'Log in' }),
};
await performBrowserLogin(chromiumPage, /Log In/, usernameAction, passwordAction, async chromiumPage => {
const backButton = chromiumPage.getByRole('button', { name: 'Go back to Podman Desktop' });
await playExpect(backButton).toBeEnabled();
await backButton.click();
});
await chromiumPage.close();
});
});
test.describe.serial('RHEL VMs Extension', () => {
test('Create RHEL VM', async ({ page }) => {
test.setTimeout(310_000);
await createRhelVM(page, 300_000);
const resourcesPage = new ResourcesPage(page);
await playExpect(resourcesPage.heading).toBeVisible({ timeout: 10_000 });
const machineCard = new ResourceConnectionCardPage(page, 'macadam', 'rhel');
await playExpect.poll(async () => machineCard.doesResourceElementExist(), { timeout: 30_000 }).toBeTruthy();
playExpect(await machineCard.resourceElementConnectionStatus.innerText()).toContain(ResourceElementState.Off);
});
test('Start RHEL VM', async ({ page }) => {
test.setTimeout(70_000);
const machineCard = new ResourceConnectionCardPage(page, 'macadam', 'rhel');
await machineCard.performConnectionAction(ResourceElementActions.Start);
await waitUntil(
async () =>
(await machineCard.resourceElementConnectionStatus.innerText()).includes(ResourceElementState.Running),
{ timeout: 60_000, sendError: true },
);
});
test('Stop RHEL VM', async ({ page }) => {
test.setTimeout(70_000);
const machineCard = new ResourceConnectionCardPage(page, 'macadam', 'rhel');
await machineCard.performConnectionAction(ResourceElementActions.Stop);
await waitUntil(
async () => (await machineCard.resourceElementConnectionStatus.innerText()).includes(ResourceElementState.Off),
{ timeout: 30_000, sendError: true },
);
});
test('Remove RHEL VM', async ({ page }) => {
test.setTimeout(70_000);
const machineCard = new ResourceConnectionCardPage(page, 'macadam', 'rhel');
await machineCard.performConnectionAction(ResourceElementActions.Delete);
await playExpect.poll(async () => machineCard.doesResourceElementExist(), { timeout: 30_000 }).toBeFalsy();
});
});
test('Remove RHEL extension through Settings', async ({ navigationBar }) => {
await ensureRhelExtensionIsRemoved(navigationBar);
});
});
async function ensureRhelExtensionIsRemoved(navigationBar: NavigationBar): Promise<void> {
let extensionsPage = await navigationBar.openExtensions();
if (!(await extensionsPage.extensionIsInstalled(extensionLabel))) return;
const rhelExtensionDetailsPage = await extensionsPage.openExtensionDetails(
extensionName,
extensionLabel,
extensionHeading,
);
await playExpect(rhelExtensionDetailsPage.heading).toBeVisible({ timeout: 10_000 });
await rhelExtensionDetailsPage.removeExtension();
extensionsPage = await navigationBar.openExtensions();
await playExpect(extensionsPage.heading).toBeVisible({ timeout: 10_000 });
await playExpect
.poll(async () => await extensionsPage.extensionIsInstalled(extensionLabel), { timeout: 30_000 })
.toBeFalsy();
}
async function createRhelVM(page: Page, timeout = 120_000): Promise<void> {
const navigationBar = new NavigationBar(page);
const rhelResourceCard = new ResourceConnectionCardPage(page, 'macadam');
const settingsPage = await navigationBar.openSettings();
const resourcesPage = await settingsPage.openTabPage(ResourcesPage);
await playExpect(resourcesPage.heading).toBeVisible({ timeout: 10_000 });
await playExpect.poll(async () => resourcesPage.resourceCardIsVisible('macadam')).toBeTruthy();
await playExpect(rhelResourceCard.createButton).toBeVisible();
await rhelResourceCard.createButton.click();
const rhelVMNameInput = page.getByLabel('Machine Name', { exact: true });
await playExpect(rhelVMNameInput).toBeVisible({ timeout: 10_000 });
await playExpect(rhelVMNameInput).toHaveValue('rhel');
const createRhelVMButton = page.getByRole('button', { name: 'Create', exact: true });
await playExpect(createRhelVMButton).toBeEnabled({ timeout: 10_000 });
await createRhelVMButton.click();
const goBackButton = page.getByRole('button', { name: 'Go back to resources' });
await playExpect(goBackButton).toBeEnabled({ timeout: timeout });
await goBackButton.click();
}