Skip to content

Commit

Permalink
initial changes in code, config and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dualcnhq committed Jun 4, 2024
1 parent d422ee3 commit c18e144
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 163 deletions.
12 changes: 7 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BROWSERSTACK_USERNAME="<retrieve_from_browserstack_account>"
BROWSERSTACK_ACCESS_KEY="<retrieve_from_browserstack_account>"

A_EMAIL="<priv_email>"
A_PASSWORD="<priv_password>"
B_EMAIL="<reg_email>"
B_PASSWORD="<reg_password>"
ARCHIVE_EMAIL="<priv_email>"
ARCHIVE_PASSWORD="<priv_password>"
PATRON_EMAIL="<patron_email>"
PATRON_PASSWORD="<patron_password>"

CATEGORY="all"
CATEGORY="all"

WHATHOST="false"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ node_modules/
/playwright-report
/playwright/.cache
/playwright/.auth
/playwright-summary

.env
*.err
*.log
*.log
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):

- 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):

- 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`

- 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
49 changes: 49 additions & 0 deletions executeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { execSync } = require('child_process');

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

function runTest(category = 'all', headed = false, browser = 'chromium') {
// Construct the npm run test command based on parameters
let command = `CATEGORY=${category} npx playwright test`;

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' });
console.log(output.toString());
} catch (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') {
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 executeTest.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

0 comments on commit c18e144

Please sign in to comment.