Skip to content

Commit fe259b9

Browse files
committed
Updated helper functions and config
1 parent fca2a4a commit fe259b9

10 files changed

+161
-151
lines changed

.github/workflows/stageTestAction.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141

4242
- name: Create .env file
4343
run: |
44-
echo "USER1USERNAME=$USER1USERNAME" >> .env
45-
echo "USER1PASSWORD=$USER1PASSWORD" >> .env
44+
echo "ADMIN_USERNAME=$ADMIN_USERNAME" >> .env
45+
echo "ADMIN_PASSWORD=$ADMIN_PASSWORD" >> .env
4646
echo "BASE_URL=$BASE_URL" >> .env
4747
echo "PROXY=$PROXY" >> .env
4848
echo "TOKEN=apple" >> .env

example.env

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#skus for qe user contentPlaywrightUserAdmin:
22
# MCT4022,MCT3718,MCT3695,ES0113909
33

4-
USER1USERNAME="contentPlaywrightUserAdmin" # Required
5-
USER1PASSWORD="" # Required (Ask Andrew if needed)
4+
ADMIN_USERNAME="contentPlaywrightUserAdmin"
5+
ADMIN_PASSWORD=SOMETHINGSECRET
6+
7+
READONLY_USERNAME="contentPlaywrightReader"
8+
READONLY_PASSWORD=SOMETHINGSECRET
69
ORG_ID_1="1234" #org id to register for registration tests
710
ACTIVATION_KEY_1="MyKey" #activation Key used for testing
811

playwright.config.ts

+11-27
Original file line numberDiff line numberDiff line change
@@ -52,45 +52,29 @@ export default defineConfig({
5252
: {}),
5353
},
5454
projects: [
55-
{ name: "setup", testMatch: /.*\.setup\.ts/ },
55+
{ name: "setup", testMatch: /auth\.setup\.ts/ },
5656
{
57-
name: "chromium", // 'Run admin user tests',
57+
name: "AdminTests", // 'Run admin user tests',
5858
grepInvert: [/read-only/], // !!process.env.PROD ? [/preview-only/, /switch-to-preview/], ] : [/switch-to-preview/],
5959
use: {
6060
...devices["Desktop Chrome"],
61-
storageState: `.auth/${process.env.USER1USERNAME}.json`,
61+
storageState: `./.auth/${process.env.ADMIN_USERNAME}.json`, // Thise is setting the cookies
6262
},
6363
dependencies: ["setup"],
6464
},
65-
6665
{
67-
name: "chromium", // 'Run read-only user tests',
66+
name: "SwitchToUser2",
67+
testMatch: /.switchToUser2\.setup\.ts/,
68+
dependencies: ["setup"],
69+
},
70+
{
71+
name: "ReadOnlyTests", // 'Run read-only user tests',
6872
grep: [/read-only/],
6973
use: {
7074
...devices["Desktop Chrome"],
71-
storageState: `.auth/${process.env.RO_USER_USERNAME}.json`,
75+
storageState: `.auth/${process.env.READONLY_USERNAME}.json`,
7276
},
73-
dependencies: ["setup"],
77+
dependencies: ["SwitchToUser2"],
7478
},
75-
// ...!!process.env.PROD ?
76-
// [{
77-
// name: 'Switch to preview',
78-
// grep: [/switch-to-preview/],
79-
// use: {
80-
// ...devices['Desktop Chrome'],
81-
// storageState: `.auth/${process.env.USER1USERNAME}.json`,
82-
83-
// },
84-
// dependencies: ['setup'],//'chromium',
85-
// },
86-
// {
87-
// name: 'Run preview only',
88-
// grep: [/preview-only/],
89-
// use: {
90-
// ...devices['Desktop Chrome'],
91-
// storageState: `.auth/${process.env.USER1USERNAME}.json`,
92-
// },
93-
// dependencies: ['Switch to preview'],
94-
// }] : [],
9579
],
9680
});

readme.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ yarn get-tests
1919
## Podman
2020

2121
As your user, run podman to serve the api:
22+
2223
```
2324
podman system service -t 0 unix:///tmp/podman.sock
2425
```
2526

2627
Uncomment the DOCKER_SOCKET option in the .env file:
28+
2729
```
2830
DOCKER_SOCKET="/tmp/podman.sock"
2931
```
3032

3133
## Docker
3234

33-
* ensure the docker service is running
34-
* ensure your user is part of the 'docker' user group
35-
35+
- ensure the docker service is running
36+
- ensure your user is part of the 'docker' user group
3637

3738
# Option 1 Run local:
3839

3940
For local testing, make sure your front-end/backend servers are running and accessible, then:
4041

4142
- Ensure you do NOT specify a proxy in your .env file (put an empty value: "")
4243
- Make sure your .env's BASE_URL is pointed to the local front-end server "https://stage.foo.redhat.com:1337"
43-
- USER1USERNAME="<YOUR_STAGE_QE_USER>"
44-
- USER1PASSWORD="<YOUR_STAGE_QE_USER_PASSWORD>"
44+
- ADMIN_USERNAME="<YOUR_STAGE_QE_USER>"
45+
- ADMIN_PASSWORD="<YOUR_STAGE_QE_USER_PASSWORD>"
4546

4647
Note: For Ethel, your user will require the following skus: MCT4022,MCT3718,MCT3695,ES0113909
4748

@@ -51,8 +52,8 @@ For local stage testing, make sure the following:
5152

5253
- PROXY must be set correctly in your .env file.
5354
- Make sure your .env's BASE_URL is pointed to the targeted env, if targeting PROD, the proxy is not needed.
54-
- USER1USERNAME="<YOUR_STAGE_QE_USER>"
55-
- USER1PASSWORD="<YOUR_STAGE_QE_USER_PASSWORD>"
55+
- ADMIN_USERNAME="<YOUR_STAGE_QE_USER>"
56+
- ADMIN_PASSWORD="<YOUR_STAGE_QE_USER_PASSWORD>"
5657

5758
Note: For Ethel, your user will require the following skus: MCT4022,MCT3718,MCT3695,ES0113909
5859

repoName.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Repo-RBAC-hms2

tests/Integration/switchToPreview.spec.ts

-10
This file was deleted.
+70-49
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { expect, test } from "@playwright/test";
22
import { navigateToRepositories } from "../UI/helpers/navHelpers";
3+
import { randomName, randomUrl } from "../UI/helpers/repoHelpers";
4+
import { closePopupsIfExist, getRowByNameOrUrl } from "../UI/helpers/helpers";
5+
import fs from "fs";
6+
import { deleteAllRepos } from "../UI/helpers/deleteRepositories";
37
import { switchToUser } from "../helpers/loginHelpers";
4-
import { randomName, randomUrl } from '../UI/helpers/repoHelpers';
5-
import { closePopupsIfExist, getRowByNameOrUrl } from '../UI/helpers/helpers';
6-
import fs from 'fs';
7-
import { deleteAllRepos } from '../UI/helpers/deleteRepositories';
88

9-
10-
11-
const repoNamePrefix = 'Repo-RBAC';
12-
const repoNameFile = 'repoName.txt';
9+
const repoNamePrefix = "Repo-RBAC";
10+
const repoNameFile = "repoName.txt";
1311

1412
// Function to get or generate repo name using file persistence
1513
const getRepoName = (): string => {
1614
if (fs.existsSync(repoNameFile)) {
17-
const repoName = fs.readFileSync(repoNameFile, 'utf8');
15+
const repoName = fs.readFileSync(repoNameFile, "utf8");
1816
console.log(`Loaded repo name from file: ${repoName}`);
1917
return repoName;
2018
}
@@ -28,66 +26,89 @@ const getRepoName = (): string => {
2826
test.beforeAll(async () => {
2927
if (fs.existsSync(repoNameFile)) {
3028
fs.unlinkSync(repoNameFile);
31-
console.log('Cleaned up repoName.txt');
29+
console.log("Cleaned up repoName.txt");
3230
}
3331
});
3432

3533
const url = randomUrl();
3634

37-
test.describe.serial("Combined user tests", () => {
38-
test("Login as user 1 (admin)", { tag: "@admin" }, async ({ page }) => {
39-
await test.step('Navigate to the repository page', async () => {
40-
await switchToUser(page, process.env.USER1USERNAME!);
41-
console.log('\n Try to delete old repos\n');
35+
test.describe("Combined user tests", () => {
36+
test("Login as user 1 (admin)", async ({ page }) => {
37+
await test.step("Navigate to the repository page", async () => {
38+
console.log("\n Try to delete old repos\n");
4239
await deleteAllRepos(page, `&search=${repoNamePrefix}`);
4340
await navigateToRepositories(page);
4441
await closePopupsIfExist(page);
4542
});
4643

47-
await test.step('Create a repository', async () => {
48-
await page.getByRole('button', { name: 'Add repositories' }).first().click();
49-
await expect(page.getByRole('dialog', { name: 'Add custom repositories' })).toBeVisible();
44+
await test.step("Create a repository", async () => {
45+
await page
46+
.getByRole("button", { name: "Add repositories" })
47+
.first()
48+
.click();
49+
await expect(
50+
page.getByRole("dialog", { name: "Add custom repositories" })
51+
).toBeVisible();
5052

5153
const repoName = getRepoName();
52-
await page.getByLabel('Name').fill(repoName);
53-
await page.getByLabel('Introspect only').click();
54-
await page.getByLabel('URL').fill(url);
55-
await page.getByRole('button', { name: 'Save', exact: true }).click();
54+
await page.getByLabel("Name").fill(repoName);
55+
await page.getByLabel("Introspect only").click();
56+
await page.getByLabel("URL").fill(url);
57+
await page.getByRole("button", { name: "Save", exact: true }).click();
5658
});
5759

58-
await test.step('Read the repo', async () => {
60+
await test.step("Read the repo", async () => {
5961
const repoName = getRepoName();
6062
const row = await getRowByNameOrUrl(page, repoName);
61-
await expect(row.getByText('Valid')).toBeVisible();
62-
await row.getByLabel('Kebab toggle').click();
63-
await row.getByRole('menuitem', { name: 'Edit' }).click();
64-
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).toBeVisible();
65-
await expect(page.getByPlaceholder('Enter name', { exact: true })).toHaveValue(repoName);
66-
await expect(page.getByPlaceholder('https://', { exact: true })).toHaveValue(url);
63+
await expect(row.getByText("Valid")).toBeVisible();
64+
await row.getByLabel("Kebab toggle").click();
65+
await row.getByRole("menuitem", { name: "Edit" }).click();
66+
await expect(
67+
page.getByRole("dialog", { name: "Edit custom repository" })
68+
).toBeVisible();
69+
await expect(
70+
page.getByPlaceholder("Enter name", { exact: true })
71+
).toHaveValue(repoName);
72+
await expect(
73+
page.getByPlaceholder("https://", { exact: true })
74+
).toHaveValue(url);
6775
});
6876

69-
await test.step('Update the repository', async () => {
77+
await test.step("Update the repository", async () => {
7078
const repoName = getRepoName();
71-
await page.getByPlaceholder('Enter name', { exact: true }).fill(`${repoName}-Edited`);
72-
await page.getByRole('button', { name: 'Save changes', exact: true }).click();
79+
await page
80+
.getByPlaceholder("Enter name", { exact: true })
81+
.fill(`${repoName}-Edited`);
82+
await page
83+
.getByRole("button", { name: "Save changes", exact: true })
84+
.click();
7385
});
7486
});
7587

76-
test("Login as user 2 (read-only)", { tag: "@read-only" }, async ({ page }) => {
77-
await test.step('Navigate to the repository page', async () => {
78-
await switchToUser(page, process.env.RO_USER_USERNAME!);
79-
await navigateToRepositories(page);
80-
await closePopupsIfExist(page);
81-
});
88+
test(
89+
"Login as user 2 (read-only)",
90+
{ tag: "@read-only" },
91+
async ({ page }) => {
92+
await test.step("Navigate to the repository page", async () => {
93+
await navigateToRepositories(page);
94+
await closePopupsIfExist(page);
95+
});
8296

83-
await test.step('Read the repo', async () => {
84-
const repoName = getRepoName();
85-
const row = await getRowByNameOrUrl(page, `${repoName}-Edited`);
86-
await expect(row.getByText('Valid')).toBeVisible({ timeout: 60000 });
87-
await row.getByLabel('Kebab toggle').click();
88-
await row.getByRole('menuitem', { name: 'Edit' }).click();
89-
await expect(page.getByText('You do not have the required permissions to perform this action')).toBeVisible();
90-
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).not.toBeVisible();
91-
});
92-
});
93-
});
97+
await test.step("Read the repo", async () => {
98+
const repoName = getRepoName();
99+
const row = await getRowByNameOrUrl(page, `${repoName}-Edited`);
100+
await expect(row.getByText("Valid")).toBeVisible({ timeout: 60000 });
101+
await row.getByLabel("Kebab toggle").click();
102+
await row.getByRole("menuitem", { name: "Edit" }).click();
103+
await expect(
104+
page.getByText(
105+
"You do not have the required permissions to perform this action"
106+
)
107+
).toBeVisible();
108+
await expect(
109+
page.getByRole("dialog", { name: "Edit custom repository" })
110+
).not.toBeVisible();
111+
});
112+
}
113+
);
114+
});

tests/auth.setup.ts

+9-32
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,34 @@ import {
44
closePopupsIfExist,
55
switchToUser,
66
logInWithUsernameAndPassword,
7-
ensureNotInPreview,
87
logout,
98
} from "./helpers/loginHelpers";
109
import { describe } from "node:test";
1110

12-
const authFile = '.auth/contentPlaywrightUserAdmin.json';
13-
const authFileRO = '.auth/contentPlaywrightReader.json';
14-
1511
describe("Setup", async () => {
1612
setup("Ensure needed ENV variables exist", async ({}) => {
1713
expect(() => throwIfMissingEnvVariables()).not.toThrow();
1814
});
1915

2016
setup("Authenticate all the users", async ({ page }) => {
2117
await closePopupsIfExist(page);
22-
await expect(page.locator('body')).toBeVisible();
23-
console.log('Page URL before login:', page.url());
18+
2419
await logInWithUsernameAndPassword(
2520
page,
26-
process.env.USER1USERNAME,
27-
process.env.USER1PASSWORD
21+
process.env.READONLY_USERNAME,
22+
process.env.READONLY_PASSWORD
2823
);
29-
const cookies = await page.context().cookies();
30-
console.log('Cookies after Admin login:', cookies);
31-
// wait longer to see if cookie is available
32-
await expect(
33-
page.getByRole('heading', { name: 'Repositories', exact: false }),
34-
).toBeVisible();
35-
await page.context().storageState({ path: authFile });
3624

37-
console.log('Cookies before Admin logout:', await page.context().cookies());
3825
await logout(page);
39-
console.log('Cookies after Admin logout:', await page.context().cookies());
4026

4127
await logInWithUsernameAndPassword(
4228
page,
43-
process.env.RO_USER_USERNAME,
44-
process.env.RO_USER_PASSWORD
29+
process.env.ADMIN_USERNAME,
30+
process.env.ADMIN_PASSWORD
4531
);
46-
await page.context().storageState({ path: authFileRO });
47-
await logout(page);
48-
// Example of how to add another user
49-
// await logout(page)
50-
// await logInWithUsernameAndPassword(
51-
// page,
52-
// process.env.USER2USERNAME,
53-
// process.env.USER2PASSWORD
54-
// );
55-
// Example of how to switch to said user
56-
// await switchToUser(page, process.env.USER1USERNAME!);
57-
// await ensureNotInPreview(page);
58-
// Other users for other tests can be added below after logging out
32+
33+
await switchToUser(page, process.env.ADMIN_USERNAME!);
34+
35+
// We do this as we run admin tests first.
5936
});
6037
});

0 commit comments

Comments
 (0)