Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS-5287: Playwright POC (Do NOT merge) #950

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9d27b87
Running
Andrewgdewar Jan 20, 2025
dd43aa8
Initial yaml (this will probably fail miserably)
Andrewgdewar Jan 21, 2025
e4786be
Update test name
Andrewgdewar Jan 21, 2025
e07bf17
Update playwright
Andrewgdewar Jan 22, 2025
3a8bdd1
Update file
Andrewgdewar Jan 22, 2025
ae69ee6
add empty build spec.yml
Andrewgdewar Jan 22, 2025
ef610ff
Test
Andrewgdewar Jan 22, 2025
e70763a
Trying to run with other jobs
Andrewgdewar Jan 22, 2025
2f385f6
Running without codebuild
Andrewgdewar Jan 22, 2025
2cdf0e1
switch to apt-get
Andrewgdewar Jan 22, 2025
c0a533e
comment out unneeded workflows
Andrewgdewar Jan 22, 2025
caf29d5
sudo
Andrewgdewar Jan 22, 2025
c9bf236
Add concurrency checks
Andrewgdewar Jan 22, 2025
53abbaa
fix typo
Andrewgdewar Jan 22, 2025
97f985f
Wrong folder scope
Andrewgdewar Jan 22, 2025
a803e00
Try running with codebuild (docker installed)
Andrewgdewar Jan 22, 2025
4ecfbc7
testing installing docker
Andrewgdewar Jan 23, 2025
1762667
remove -it
Andrewgdewar Jan 23, 2025
95c620e
remove unneeded commands
Andrewgdewar Jan 23, 2025
63fe156
try service
Andrewgdewar Jan 23, 2025
f0a7758
correct syntax
Andrewgdewar Jan 23, 2025
7f5efb3
More complicated approach
Andrewgdewar Jan 23, 2025
34b8662
agree to all disk space usage
Andrewgdewar Jan 23, 2025
f7d56ec
update
Andrewgdewar Jan 23, 2025
357d6c1
Add install command to buildspec
Andrewgdewar Jan 23, 2025
169c259
try yum
Andrewgdewar Jan 23, 2025
1d0e652
is this an alpine image
Andrewgdewar Jan 23, 2025
f009bc6
try defining and linking docker
Andrewgdewar Jan 23, 2025
5c6b391
run as root?
Andrewgdewar Jan 23, 2025
94e6c99
Update docker version
Andrewgdewar Jan 23, 2025
fd8c138
remove docker reference
Andrewgdewar Jan 23, 2025
3bf9c92
Add & :|
Andrewgdewar Jan 23, 2025
24506a4
Trying different syntax
Andrewgdewar Jan 23, 2025
9fc6de6
Updating the startup script
Andrewgdewar Jan 23, 2025
616f743
Update that actual action
Andrewgdewar Jan 23, 2025
a3eca36
Re-add install playwright
Andrewgdewar Jan 23, 2025
99ee127
Enforce browser install
Andrewgdewar Jan 23, 2025
ab620a7
Add deps.. le sigh
Andrewgdewar Jan 23, 2025
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
Binary file added .DS_Store
Binary file not shown.
428 changes: 263 additions & 165 deletions .github/workflows/content-sources-actions.yml

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions .github/workflows/playwright-tests.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Run playwright API test
on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
playwright-api-test:
runs-on:
- codebuild-content-services-backend-repo-${{ github.run_id }}-${{ github.run_attempt }}
- instance-size:small
- buildspec-override:true

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run get_go_version.sh script
id: get-go-version
run: |
chmod +x ./scripts/get_go_version.sh
GO_VERSION=$(./scripts/get_go_version.sh ./go.mod)
echo "::set-output name=go-version::$GO_VERSION"

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "${{ steps.get-go-version.outputs.go-version }}"

- name: Set up Make
run: |
yum update -y
yum install -y make

- name: Copy the example config
run: |
cp ./configs/config.yaml.example ./configs/config.yaml

- name: Create .env file
working-directory: _playwright-tests
run: |
echo "BASE_URL=http://127.0.0.1:8000 >> .env
echo "TOKEN=apple" >> .env
echo "CI=true" >> .env

- name: Make compose-up
working-directory: _playwright-tests
run: make compose-up

- name: Start-up the backend
working-directory: _playwright-tests
run: go run cmd/content-sources/main.go api consumer &

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version-file: "_playwright-tests/.nvmrc"

- name: Install playwright and dependencies
working-directory: _playwright-tests
run: PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 yarn install

# - name: Install Playwright Browsers
# working-directory: _playwright-tests
# run: yarn playwright install

- name: Run Playwright tests
working-directory: _playwright-tests
run: yarn playwright test

- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: "./_playwright-tests/playwright-ctrf/playwright-ctrf.json"
if: always()

# pull-request-report: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: npx github-actions-ctrf playwright-ctrf/playwright-ctrf.json

- name: Store report
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: ./_playwright-tests/playwright-report
retention-days: 10
2 changes: 1 addition & 1 deletion .github/workflows/title.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PR Validation
on:
pull_request:
types: [opened, edited, synchronize, reopened]
types: [opened, edited, reopened]

jobs:
title-validate:
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ compose_files/pulp/pulp-oci-images

# Bridge to Kubernetes
KubernetesLocalProcessConfig.yaml

#playwright ignores
_playwright-tests/node_modules/
_playwright-tests/test-results/
_playwright-tests/playwright-report/
_playwright-tests/playwright-ctrf/
_playwright-tests/blob-report/
_playwright-tests/playwright/.cache/
_playwright-tests/.env
_playwright-tests/.auth
_playwright-tests/bin
16 changes: 0 additions & 16 deletions KubernetesLocalProcessConfig.example.yaml

This file was deleted.

Binary file added _playwright-tests/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions _playwright-tests/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.17.0
8 changes: 8 additions & 0 deletions _playwright-tests/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#skus required for most common actions on content-sources
# MCT4022,MCT3718,MCT3695,ES0113909
# Copy the below, adding appropriate username/password

IDENTITY_HEADER=""
BASE_URL="http://127.0.0.1:8000"
TOKEN=""
CI=""
19 changes: 19 additions & 0 deletions _playwright-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "content-sources-playwright-api-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.2"
},
"dependencies": {
"dotenv": "^16.4.7",
"github-actions-ctrf": "^0.0.58",
"playwright-ctrf-json-reporter": "^0.0.18"
}
}
82 changes: 82 additions & 0 deletions _playwright-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { defineConfig, devices } from '@playwright/test';
import path from 'path';

import { config } from 'dotenv'

config({ path: path.join(__dirname, './.env') })


/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: false,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: false,
/* Retry on CI only */
retries: 1,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: !!process.env.CI ? [
["list"],
[
"playwright-ctrf-json-reporter",
{ useDetails: true, outputDir: "playwright-ctrf", outputFile: "playwright-ctrf.json" },
],
['html', { outputFolder: 'playwright-report' }]
] : "list",
// This may need to be increased for different environments and applications.
expect: { timeout: 15000 },
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
launchOptions: {
args: ['--use-fake-device-for-media-stream'],
},
...process.env.IDENTITY_HEADER ? {
extraHTTPHeaders: {
"x-rh-identity": process.env.IDENTITY_HEADER
}
} : {},
/* Base URL to use in actions like `await page.goto('/')`. */
// This is used for both the API and the UI navigation
// This can be overridden in tests for external api's should that be needed.
baseURL: process.env.BASE_URL,
//We need to make sure the TOKEN exists before setting the extraHTTPHeader for the API
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
ignoreHTTPSErrors: true,
},
/* Configure projects for major browsers */
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/, expect: { timeout: 20000 } },
{
name: 'Google Chrome',
// testIgnore: /.*UploadRepo.spec.ts/,
use: {
...devices['Desktop Chrome'],
},
dependencies: ['setup'],
},
// {
// // We need to use firefox for upload tests
// name: 'Firefox',
// // testMatch: [/.*UploadRepo.spec.ts/],
// use: {
// ...devices['Desktop Firefox'], // Use prepared auth state.
// storageState: path.join(__dirname, './.auth/user.json'),
// },
// dependencies: ['setup'],
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

15 changes: 15 additions & 0 deletions _playwright-tests/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Install NPM packages

npm ci

# Install Playwright browsers and dependencies

npx playwright install --with-deps

# Run your tests:

npx playwright test

# Run a single test:

npx playwright test UI/CreateCustomRepo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, expect } from '@playwright/test';

test('Content > getFeatures API', async ({ request }) => {
const result = await request.get('/api/content-sources/v1/repositories/');
expect(result.status()).toBe(200);
});
14 changes: 14 additions & 0 deletions _playwright-tests/tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test as setup } from '@playwright/test';
import { setAuthorizationHeader, throwIfMissingEnvVariables } from './helpers/loginHelpers';
import { describe } from 'node:test';


describe("Setup", async () => {
setup('Ensure needed ENV variables exist', async () => {
expect(() => throwIfMissingEnvVariables()).not.toThrow()
})

setup('Authenticate', async ({ page }) => {
await setAuthorizationHeader("BananaMan", 99999)
})
})
41 changes: 41 additions & 0 deletions _playwright-tests/tests/helpers/loginHelpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from "path";
import { exec } from "child_process";

export const setAuthorizationHeader = async (userName: string, org: number) => {
process.env.IDENTITY_HEADER = decodeURI(
await new Promise((resolve, reject) => {
exec(
`"${path.join(
__dirname,
"../../../scripts/header.sh"
)}" ${org} ${userName}`,
(error, stdout, stderr) => {
if (error) {
reject(`Error: ${error.message}`);
} else if (stderr) {
reject(`Stderr: ${stderr}`);
} else {
resolve(stdout);
}
}
);
})
)
.replace("x-rh-identity: ", "")
.trim();
};

export const throwIfMissingEnvVariables = () => {
const ManditoryEnvVariables = ["BASE_URL"];

const missing: string[] = [];
ManditoryEnvVariables.forEach((envVar) => {
if (!process.env[envVar]) {
missing.push(envVar);
}
});

if (missing.length > 0) {
throw new Error("Missing env variables:" + missing.join(","));
}
};
12 changes: 12 additions & 0 deletions _playwright-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es2021",
"jsx": "react",
"strict": true,
"module": "commonjs",
"esModuleInterop": true,
"resolveJsonModule": true, // Include modules imported with ".json" extension
"noImplicitAny": true // Raise error on expressions and declarations with an implied 'any' type
},
"include": ["tests"]
}
Loading
Loading