Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/stageTestAction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:

- name: Create .env file
run: |
echo "USER1USERNAME=$USER1USERNAME" >> .env
echo "USER1PASSWORD=$USER1PASSWORD" >> .env
echo "ADMIN_USERNAME=$ADMIN_USERNAME" >> .env
echo "ADMIN_PASSWORD=$ADMIN_PASSWORD" >> .env
echo "BASE_URL=$BASE_URL" >> .env
echo "PROXY=$PROXY" >> .env
echo "TOKEN=apple" >> .env
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules/
.DS_Store
.env
.auth
bin
bin
repoName.txt
7 changes: 5 additions & 2 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#skus for qe user contentPlaywrightUserAdmin:
# MCT4022,MCT3718,MCT3695,ES0113909

USER1USERNAME="contentPlaywrightUserAdmin" # Required
USER1PASSWORD="" # Required (Ask Andrew if needed)
ADMIN_USERNAME="contentPlaywrightUserAdmin"
ADMIN_PASSWORD=SOMETHINGSECRET

READONLY_USERNAME="contentPlaywrightReader"
READONLY_PASSWORD=SOMETHINGSECRET
ORG_ID_1="1234" #org id to register for registration tests
ACTIVATION_KEY_1="MyKey" #activation Key used for testing

Expand Down
146 changes: 73 additions & 73 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
import { defineConfig, devices } from '@playwright/test';
import 'dotenv/config';
import { defineConfig, devices } from "@playwright/test";
import "dotenv/config";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
fullyParallel: false,
forbidOnly: false,
retries: process.env.CI ? 1 : 0,
workers: 1,
reporter: process.env.CI
? [
[
'playwright-ctrf-json-reporter',
{ useDetails: true, outputDir: 'playwright-ctrf', outputFile: 'playwright-ctrf.json' },
],
['html', { outputFolder: 'playwright-report' }],
['@currents/playwright'],
]
: 'list',
timeout: process.env.CI ? 60000 : 30000,
expect: { timeout: process.env.CI ? 60000 : 20000 },
use: {
testIdAttribute: 'data-ouia-component-id',
launchOptions: {
args: ['--use-fake-device-for-media-stream'],
},
...(process.env.TOKEN
? {
extraHTTPHeaders: {
Authorization: process.env.TOKEN,
},
}
: {}),
baseURL: process.env.BASE_URL,
trace: 'on',
screenshot: 'on',
video: 'on',
ignoreHTTPSErrors: true,
...process.env.PROXY ? {
proxy: {
server: process.env.PROXY,
}
} : {}
testDir: "./tests",
fullyParallel: false,
forbidOnly: false,
retries: process.env.CI ? 1 : 0,
workers: 1,
reporter: process.env.CI
? [
[
"playwright-ctrf-json-reporter",
{
useDetails: true,
outputDir: "playwright-ctrf",
outputFile: "playwright-ctrf.json",
},
],
["html", { outputFolder: "playwright-report" }],
["@currents/playwright"],
]
: "list",
timeout: process.env.CI ? 60000 : 30000,
expect: { timeout: process.env.CI ? 60000 : 20000 },
use: {
testIdAttribute: "data-ouia-component-id",
launchOptions: {
args: ["--use-fake-device-for-media-stream"],
},
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{
name: 'chromium',
grepInvert: !!process.env.PROD ? [/preview-only/, /switch-to-preview/, /local-only/] : [/switch-to-preview/, /local-only/],
use: {
...devices['Desktop Chrome'],
storageState: `.auth/${process.env.USER1USERNAME}.json`,
},
dependencies: ['setup'],
},
...!!process.env.PROD ?
[{
name: 'Switch to preview',
grep: [/switch-to-preview/],
use: {
...devices['Desktop Chrome'],
storageState: `.auth/${process.env.USER1USERNAME}.json`,

},
dependencies: ['setup'],//'chromium',
},
{
name: 'Run preview only',
grep: [/preview-only/],
use: {
...devices['Desktop Chrome'],
storageState: `.auth/${process.env.USER1USERNAME}.json`,
},
dependencies: ['Switch to preview'],
}] : [],
],
...(process.env.TOKEN
? {
extraHTTPHeaders: {
Authorization: process.env.TOKEN,
},
}
: {}),
baseURL: process.env.BASE_URL,
trace: "on",
screenshot: "on",
video: "on",
ignoreHTTPSErrors: true,
...(process.env.PROXY
? {
proxy: {
server: process.env.PROXY,
},
}
: {}),
},
projects: [
{ name: "setup", testMatch: /auth\.setup\.ts/ },
{
name: "AdminTests", // 'Run admin user tests',
grepInvert: [/read-only/], // !!process.env.PROD ? [/preview-only/, /switch-to-preview/], ] : [/switch-to-preview/],
use: {
...devices["Desktop Chrome"],
storageState: `./.auth/${process.env.ADMIN_USERNAME}.json`, // This is setting the cookies
},
dependencies: ["setup"],
},
{
name: "SwitchToUser2",
testMatch: /.switchToUser2\.setup\.ts/,
dependencies: ["setup"],
},
{
name: "ReadOnlyTests", // 'Run read-only user tests',
grep: [/read-only/],
use: {
...devices["Desktop Chrome"],
storageState: `.auth/${process.env.READONLY_USERNAME}.json`,
},
dependencies: ["SwitchToUser2"],
},
],
});
15 changes: 8 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@ yarn get-tests
## Podman

As your user, run podman to serve the api:

```
podman system service -t 0 unix:///tmp/podman.sock
```

Uncomment the DOCKER_SOCKET option in the .env file:

```
DOCKER_SOCKET="/tmp/podman.sock"
```

## Docker

* ensure the docker service is running
* ensure your user is part of the 'docker' user group

- ensure the docker service is running
- ensure your user is part of the 'docker' user group

# Option 1 Run local:

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

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

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

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

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

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

Expand Down
10 changes: 0 additions & 10 deletions tests/Integration/switchToPreview.spec.ts

This file was deleted.

105 changes: 105 additions & 0 deletions tests/Integration/twouserRBACTest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { expect, test } from "@playwright/test";
import { navigateToRepositories } from "../UI/helpers/navHelpers";
import { randomName, randomUrl } from "../UI/helpers/repoHelpers";
import { closePopupsIfExist, getRowByNameOrUrl } from "../UI/helpers/helpers";
import fs from "fs";
import { deleteAllRepos } from "../UI/helpers/deleteRepositories";
import { switchToUser } from "../helpers/loginHelpers";

const repoNamePrefix = "Repo-RBAC";
const repoNameFile = "repoName.txt";

// Function to get or generate repo name using file persistence
const getRepoName = (): string => {
if (fs.existsSync(repoNameFile)) {
const repoName = fs.readFileSync(repoNameFile, "utf8");
console.log(`Loaded repo name from file: ${repoName}`);
return repoName;
}
const repoName = `${repoNamePrefix}-${randomName()}`;
fs.writeFileSync(repoNameFile, repoName);
console.log(`Generated and saved repo name: ${repoName}`);
return repoName;
};



const url = randomUrl();

test.describe("Combined user tests", () => {
test("Login as user 1 (admin)", async ({ page }) => {
await test.step("Navigate to the repository page", async () => {
// Clean up the repo name file
if (fs.existsSync(repoNameFile)) {
fs.unlinkSync(repoNameFile);
};
console.log("Cleaned up repoName.txt");
console.log("\n Try to delete old repos\n");
await deleteAllRepos(page, `&search=${repoNamePrefix}`);
await navigateToRepositories(page);
await closePopupsIfExist(page);
});

await test.step("Create a repository", async () => {
await page
.getByRole("button", { name: "Add repositories" })
.first()
.click();
await expect(
page.getByRole("dialog", { name: "Add custom repositories" })
).toBeVisible();

const repoName = getRepoName();
await page.getByLabel("Name").fill(repoName);
await page.getByLabel("Introspect only").click();
await page.getByLabel("URL").fill(url);
await page.getByRole("button", { name: "Save", exact: true }).click();
});

await test.step("Read the repo", async () => {
const repoName = getRepoName();
const row = await getRowByNameOrUrl(page, repoName);
await expect(row.getByText("Valid")).toBeVisible();
await row.getByLabel("Kebab toggle").click();
await row.getByRole("menuitem", { name: "Edit" }).click();
await expect(
page.getByRole("dialog", { name: "Edit custom repository" })
).toBeVisible();
await expect(
page.getByPlaceholder("Enter name", { exact: true })
).toHaveValue(repoName);
await expect(
page.getByPlaceholder("https://", { exact: true })
).toHaveValue(url);
});

await test.step("Update the repository", async () => {
const repoName = getRepoName();
await page
.getByPlaceholder("Enter name", { exact: true })
.fill(`${repoName}-Edited`);
await page
.getByRole("button", { name: "Save changes", exact: true })
.click();
});
});

test(
"Login as user 2 (read-only)",
{ tag: "@read-only" },
async ({ page }) => {
await test.step("Navigate to the repository page", async () => {
await navigateToRepositories(page);
await closePopupsIfExist(page);
});

await test.step("Read the repo", async () => {
const repoName = getRepoName();
const row = await getRowByNameOrUrl(page, `${repoName}-Edited`);
await expect(row.getByText("Valid")).toBeVisible({ timeout: 60000 });
await row.getByLabel("Kebab toggle").click();
await expect(row.getByRole("menuitem", { name: "Edit" })).not.toBeVisible();
});
}
);
});
Loading
Loading