Skip to content

Commit 4979ba9

Browse files
committed
initial commit
0 parents  commit 4979ba9

File tree

12 files changed

+1859
-0
lines changed

12 files changed

+1859
-0
lines changed

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
type-check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 'lts/iron' # '20.x'
16+
cache: 'yarn'
17+
- run: yarn install --frozen-lockfile
18+
- run: yarn type-check
19+
20+
lint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: 'lts/iron' # '20.x'
27+
cache: 'yarn'
28+
- run: yarn install --frozen-lockfile
29+
- run: yarn lint

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/
6+
/playwright/.auth/
7+
.vscode
8+
.env

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint

CONTRIBUTING.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## Code style
2+
This project uses the recommended rules from [typescript-eslint](https://typescript-eslint.io/) and [Stylistic](https://eslint.style/) to enforce a consistent code style.
3+
4+
Together with lint-staged and husky, the code style is enforced on every commit.
5+
To check the code style manually, you can run:
6+
7+
```bash
8+
yarn lint # or yarn lint:fix to automatically fix some issues
9+
```
10+
11+
If you are using VSCode, you can install the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) to see the errors in the editor. Also here's a configuration for the editor to automatically fix some issues on save:
12+
13+
<details>
14+
<summary>VSCode config</summary>
15+
You can save this configuration on `.vscode/settings.json` file
16+
17+
```jsonc
18+
{
19+
// Disable the default formatter, use eslint instead
20+
"prettier.enable": false,
21+
"editor.formatOnSave": false,
22+
23+
// Auto fix
24+
"editor.codeActionsOnSave": {
25+
"source.fixAll.eslint": "explicit",
26+
"source.organizeImports": "never"
27+
},
28+
29+
// Silent the stylistic rules in you IDE, but still auto fix them
30+
"eslint.rules.customizations": [
31+
{ "rule": "style/*", "severity": "off", "fixable": true },
32+
{ "rule": "format/*", "severity": "off", "fixable": true },
33+
{ "rule": "*-indent", "severity": "off", "fixable": true },
34+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
35+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
36+
{ "rule": "*-order", "severity": "off", "fixable": true },
37+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
38+
{ "rule": "*-newline", "severity": "off", "fixable": true },
39+
{ "rule": "*quotes", "severity": "off", "fixable": true },
40+
{ "rule": "*semi", "severity": "off", "fixable": true },
41+
{ "rule": "*-lines", "severity": "off", "fixable": true },
42+
],
43+
44+
// Enable eslint for all supported languages
45+
"eslint.validate": [
46+
"javascript",
47+
"javascriptreact",
48+
"typescript",
49+
"typescriptreact",
50+
"vue",
51+
"html",
52+
"markdown",
53+
"json",
54+
"jsonc",
55+
"yaml",
56+
"toml",
57+
"xml",
58+
"gql",
59+
"graphql",
60+
"astro",
61+
"css",
62+
"less",
63+
"scss",
64+
"pcss",
65+
"postcss"
66+
],
67+
"files.exclude": {
68+
"**/.git": true,
69+
"**/.svn": true,
70+
"**/.hg": true,
71+
"**/CVS": true,
72+
"**/.DS_Store": true,
73+
"**/Thumbs.db": true,
74+
"**/node_modules": true
75+
}
76+
}
77+
```
78+
79+
</details>
80+
81+
## Writing tests
82+
83+
Follow the Playwright [best practices](https://playwright.dev/docs/best-practices) when writting tests. Use the UI mode for faster development leveraing the [locator picker](https://playwright.dev/docs/test-ui-mode#pick-locator) to easily find elements on the page.
84+
85+
86+
### Page Object Model
87+
88+
To improve test readability and maintainability, we use the [Page Object Model](https://playwright.dev/docs/pom) pattern. This pattern allows us to encapsulate the logic of the pages in classes, making the tests more readable and easier to maintain.
89+
90+
Page objects are located in the `/pages` directory. Each page object should have a class that represents the page and its methods. The page object should not contain assertions, only methods that interact with the page.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Red Hat, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# End-to-end Playwright tests for OSIM
2+
This repository contains end-to-end tests for [OSIM](https://github.com/RedHatProductSecurity/osim) using [Playwright](https://playwright.dev/).
3+
4+
## Required environment variables
5+
6+
- `OSIM_URL`: URL of the OSIM instance to test
7+
- `OSIDB_URL`: URL of the OSIDB instance to test
8+
- `JIRA_USERNAME`: Username of the authenticated user in JIRA
9+
- `JIRA_API_KEY`: API key for jira
10+
- `BUGZILLA_API_KEY`: API key for bugzilla
11+
12+
The project uses [dotenv](https://www.npmjs.com/package/dotenv) to load the environment variables from a `.env` file.
13+
14+
## Installation
15+
16+
Clone the repository and install the dependencies:
17+
18+
```bash
19+
git clone [email protected]:RedHatProductSecurity/osim-ui-tests.git
20+
cd osim-ui-tests
21+
yarn install
22+
```
23+
24+
This should download the browser binaries for Playwright, if having problems, you can do it manually by running:
25+
26+
```bash
27+
yarn playwright install
28+
```
29+
30+
## Running the tests
31+
32+
You can run Playwright in [UI mode](https://playwright.dev/docs/test-ui-mode) by running:
33+
34+
```bash
35+
yarn dev
36+
```
37+
This mode allows you to run the tests in a browser and see the results in the Playwright UI. Perfect for development and debugging.
38+
39+
To run the tests in headless mode, you can run:
40+
41+
```bash
42+
yarn test
43+
```
44+
45+
or specify the browser to use:
46+
47+
```bash
48+
yarn test:firefox # see package.json for more options
49+
```
50+
51+
## License
52+
53+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
54+
55+
### See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information on how to contribute to this project.

environment.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare global {
2+
namespace NodeJS {
3+
interface ProcessEnv {
4+
JIRA_API_KEY: string;
5+
BUGZILLA_API_KEY: string;
6+
JIRA_USERNAME: string;
7+
OSIDB_URL: string;
8+
OSIM_URL: string;
9+
}
10+
}
11+
}
12+
13+
export {};

eslint.config.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
import stylistic from '@stylistic/eslint-plugin'
4+
5+
export default tseslint.config(
6+
eslint.configs.recommended,
7+
...tseslint.configs.strictTypeChecked,
8+
...tseslint.configs.stylisticTypeChecked,
9+
stylistic.configs.customize({
10+
braceStyle:'1tbs',
11+
commaDangle:'always-multiline',
12+
indent: 2,
13+
quotes: 'single',
14+
semi: true,
15+
}),
16+
{
17+
rules: {
18+
'@typescript-eslint/restrict-template-expressions': ['error',{ allow: [{ name: 'undefined', from: 'lib' }] }],
19+
}
20+
},
21+
{
22+
languageOptions: {
23+
parserOptions: {
24+
projectService: true,
25+
tsconfigRootDir: import.meta.dirname
26+
}
27+
}
28+
},
29+
{
30+
ignores: [
31+
'eslint.config.mjs',
32+
'playwright.config.ts',
33+
'tests-results/**/*',
34+
'playwright-report/**/*'
35+
]
36+
}
37+
);

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "osim-integration-tests",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"private": true,
7+
"devDependencies": {
8+
"@faker-js/faker": "^9.2.0",
9+
"@playwright/browser-chromium": "^1.48.2",
10+
"@playwright/browser-firefox": "^1.48.2",
11+
"@playwright/test": "^1.48.2",
12+
"@stylistic/eslint-plugin": "^2.10.1",
13+
"@types/eslint__js": "^8.42.3",
14+
"@types/kerberos": "^1.1.5",
15+
"@types/node": "^22.9.0",
16+
"@typescript-eslint/eslint-plugin": "^8.14.1-alpha.8",
17+
"@typescript-eslint/parser": "^8.14.1-alpha.8",
18+
"dayjs": "^1.11.13",
19+
"dotenv": "^16.4.5",
20+
"eslint": "^9.14",
21+
"husky": "^9.1.6",
22+
"kerberos": "^2.2.0",
23+
"lint-staged": "^15.2.10",
24+
"typescript": "^5.6.3",
25+
"typescript-eslint": "^8.14.1-alpha.8",
26+
"undici": "^6.21.0"
27+
},
28+
"scripts": {
29+
"test": "playwright test --reporter=list",
30+
"test:chrome": "playwright test --reporter=list --project=chrome",
31+
"test:firefox": "playwright test --reporter=list --project=firefox",
32+
"dev": "playwright test --ui",
33+
"lint": "eslint . ",
34+
"lint:fix": "eslint . --fix",
35+
"type-check": "tsc --noEmit",
36+
"postinstall": "husky"
37+
},
38+
"engines": {
39+
"node": ">=20.0.0"
40+
},
41+
"lint-staged": {
42+
"*.ts": "eslint"
43+
},
44+
"dependencies": {}
45+
}

playwright.config.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { defineConfig, devices, type Project } from '@playwright/test';
2+
import dotenv from 'dotenv';
3+
import path from 'path';
4+
5+
dotenv.config({ path: path.resolve(__dirname, '.env') });
6+
7+
const browsers: Project[] = [
8+
{
9+
name: 'firefox',
10+
use: {
11+
...devices['Desktop Firefox'],
12+
launchOptions: {
13+
firefoxUserPrefs: {
14+
'network.negotiate-auth.trusted-uris': '.redhat.com',
15+
},
16+
},
17+
},
18+
},
19+
{
20+
name: 'chromium',
21+
use: {
22+
...devices['Desktop Chrome'],
23+
launchOptions: {
24+
args: ['--auth-server-whitelist="*.redhat.com"'],
25+
},
26+
},
27+
},
28+
];
29+
30+
/**
31+
* See https://playwright.dev/docs/test-configuration.
32+
*/
33+
export default defineConfig({
34+
testDir: './tests',
35+
fullyParallel: true,
36+
forbidOnly: !!process.env.CI,
37+
retries: process.env.CI ? 2 : 0,
38+
workers: process.env.CI ? 1 : undefined,
39+
reporter: 'html',
40+
use: {
41+
storageState: 'playwright/.auth/user.json',
42+
ignoreHTTPSErrors: true,
43+
trace: 'on-first-retry',
44+
baseURL: `https://${process.env.OSIM_URL}`,
45+
},
46+
timeout: 60000,
47+
expect: {
48+
timeout: 20000,
49+
},
50+
projects: [
51+
{
52+
name: 'setup',
53+
testMatch: /.*\.setup\.ts/,
54+
},
55+
...browsers.map(browser => ({
56+
name: browser.name,
57+
use: {
58+
...browser.use,
59+
},
60+
dependencies: ['setup'],
61+
})),
62+
],
63+
});

0 commit comments

Comments
 (0)