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

WEBDEV-6884 update scripts execution #50

Merged
merged 13 commits into from
Jul 31, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/call-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: npx playwright install --with-deps

- name: Run Playwright tests
run: ./run-tests.sh
run: npm run test

- uses: actions/upload-artifact@v3
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/donation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
run: npx playwright install --with-deps

- name: Run Donation Tests
run: npm run test:donation
run: npm run test donation
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules/
/playwright-report
/playwright/.cache
/playwright/.auth
/playwright-summary

.env
*.err
Expand Down
60 changes: 24 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,51 @@

# End to end tests for Archive.org using [Playwright](https://playwright.dev/)


## (Optional) BrowserStack Local Setup

- login to BrowserStack and retrieve the account username and access key, see documentation [here](https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs/test-runner)
- Login to BrowserStack and retrieve the account username and access key, see documentation [here](https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs/test-runner)


## Running tests locally
## Local Setup

- install dependencies:
- Install dependencies:

`npm i`

- install Playwright browser libs:
- Install Playwright browser libs:

`npx playwright install`

- run all the tests in headless mode and generate 1 whole test report:

`npm run test`
- Create a `.env` file by copying the contents from `.env.sample` and add the respective values you want to use for testing

- run all the tests in headless mode by each category and generate test report by category:
- this is required to run tests with loggedIn flows

`./run-tests.sh`

- run all the tests in headed mode (this will load multiple browsers):
## Running tests

`npm run test:headed`
- Run all tests: `npm run test`

- create a `.env` file by copying the contents from `.env.sample` and add the respective values you want to use for testing
- Run test by category (sample):
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved

- This will run a custom script that can take different shell arguments/parameters for the following (arguments arrangement can be jumbled or not in proper order):
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved

- test category (by folder structure):
- `about, av, books, collection, details, donation, etc...`
- default value: `all`

## Running individual tests by category (headless mode)
- test execution mode:
- `headless/headed`
- default value: `headless`

- run about tests: `npm run test:about`
- run av tests: `npm run test:av`
- run books tests: `npm run test:books`
- run collection tests: `npm run test:collection`
- run details tests: `npm run test:details`
- run home tests: `npm run test:home`
- run login tests: `npm run test:login`
- run music tests: `npm run test:music`
- run search tests: `npm run test:search`
- run profile tests: `npm run test:profile`
- browser:
- `chromium, firefox, webkit`
- default value: `chromium`
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved

- Sample:

## Running individual tests by category (headed mode)

- run about tests: `npm run test:about:headed`
- run av tests: `npm run test:av:headed`
- run books tests: `npm run test:books:headed`
- run collection tests: `npm run test:collection:headed`
- run details tests: `npm run test:details:headed`
- run home tests: `npm run test:home:headed`
- run login tests: `npm run test:login:headed`
- run music tests: `npm run test:music:headed`
- run search tests: `npm run test:search:headed`
- run profile tests: `npm run test:profile:headed`
- run all "books" tests in headless mode: `npm run test books`
- run all "about" tests in headed mode webkit browser: `npm run test about headed webkit`


## Running tests using VSCode Playwright plugin
Expand All @@ -82,7 +71,6 @@

- run: `npm run show:report`


## Reference guide for writing tests

- https://playwright.dev/docs/pom
Expand Down
52 changes: 52 additions & 0 deletions executeTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { execSync } = require('child_process');

const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);

function runTest(category = 'all', headed = false, browser = 'chromium') {
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved
// Construct the npm run test command based on parameters
let command = `CATEGORY=${category} npx playwright test`;
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved

if (category !== 'all') {
command += ` tests/${category}`;
}

if (headed) {
command += ` --headed`;
}

if (browser !== 'chromium') {
command += ` --project='Desktop - ${capitalizeFirstLetter(browser)}'`;
}

// Execute the command
try {
console.log(`Executing command: ${command}`);
const output = execSync(command, { stdio: 'inherit' });
if (output !== null) {
console.log(output.toString());
}
} catch (error) {
console.log('error: ', error);
console.error(error.stderr ? error.stderr.toString() : error.toString());
process.exit(1);
}
}

// Extract parameters from command line arguments
const args = process.argv.slice(2);
let category = 'all';
let headed = false;
let browser = 'chromium';

// Iterate through arguments to parse them
args.forEach(arg => {
if (arg === 'headed') {
headed = true;
} else if (arg === 'chromium' || arg === 'firefox' || arg === 'webkit') {
dualcnhq marked this conversation as resolved.
Show resolved Hide resolved
browser = arg;
} else {
category = arg;
}
});

runTest(category, headed, browser);
63 changes: 29 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 5 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,11 @@
"main": "index.js",
"scripts": {
"show:report": "npx http-server ./playwright-report",
"test": "CATEGORY=all npx playwright test",
"test": "node executeTests.js",
"test:codegen": "npx playwright codegen",
"test:chromium": "CATEGORY=allnpx playwright test --project=chromium",
"test:debug": "CATEGORY=all npx playwright test --debug",
"test:trace": "CATEGORY=all npx playwright test --config=./playwright.config.ts --trace on",
"test:ui": "CATEGORY=all npx playwright test --ui",
"test:headed": "CATEGORY=all npx playwright test --headed",
"test:about": "CATEGORY=about npx playwright test tests/about",
"test:av": "CATEGORY=av npx playwright test tests/av",
"test:books": "CATEGORY=books npx playwright test tests/books",
"test:collection": "CATEGORY=collection npx playwright test tests/collection",
"test:details": "CATEGORY=details npx playwright test tests/details",
"test:details-lending-bar": "CATEGORY=details npx playwright test tests/details/lending-bar",
"test:home": "CATEGORY=home npx playwright test tests/home",
"test:login": "CATEGORY=login npx playwright test tests/login",
"test:music": "CATEGORY=music npx playwright test tests/music",
"test:search": "CATEGORY=search npx playwright test tests/search",
"test:profile": "CATEGORY=profile npx playwright test tests/profile",
"test:about:headed": "CATEGORY=about npx playwright test tests/about --headed",
"test:av:headed": "CATEGORY=av npx playwright test tests/av --headed",
"test:books:headed": "CATEGORY=books npx playwright test tests/books --headed",
"test:collection:headed": "CATEGORY=collection npx playwright test tests/collection --headed",
"test:details:headed": "CATEGORY=details npx playwright test tests/details --headed",
"test:details-lending-bar:headed": "CATEGORY=details npx playwright test tests/details/lending-bar --headed",
"test:home:headed": "CATEGORY=home npx playwright test tests/home --headed",
"test:login:headed": "CATEGORY=login npx playwright test tests/login --headed",
"test:music:headed": "CATEGORY=music npx playwright test tests/music --headed",
"test:search:headed": "CATEGORY=search npx playwright test tests/search --headed",
"test:profile:headed": "CATEGORY=profile npx playwright test tests/profile --headed",
"test:donation:headed": "CATEGORY=donation npx playwright test tests/donation --headed",
"test:donation": "CATEGORY=donation npx playwright test tests/donation",
"format": "prettier --write \"tests/**/*.ts\"",
"lint": "prettier --check \"tests/**/*.ts\"",
"typecheck": "node node_modules/typescript/bin/tsc --noEmit",
Expand All @@ -45,14 +19,13 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.41.2",
"@playwright/test": "^1.44.1",
"@types/node": "^20.11.17",
"browserstack-local": "^1.4.8",
"dotenv": "^16.0.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"husky": "^8.0.3",
"playwright": "^1.41.2",
"prettier": "^3.0.0"
},
"eslintConfig": {
Expand All @@ -66,22 +39,14 @@
],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error"
],
"@typescript-eslint/no-unused-vars": 2,
"no-shadow": "off",
"@typescript-eslint/no-shadow": [
"error"
],
"@typescript-eslint/no-shadow": 2,
"class-methods-use-this": "off",
"import/no-unresolved": "off",
"import/extensions": [
"off",
"ignorePackages",
{
"js": "never",
"ts": "never"
}
"ignorePackages"
],
"no-unsafe-optional-chaining": "warn",
"default-param-last": "warn"
Expand Down
Loading