diff --git a/.env.sample b/.env.sample index 2e3ba82e..acc9cb6f 100644 --- a/.env.sample +++ b/.env.sample @@ -1,9 +1,11 @@ BROWSERSTACK_USERNAME="" BROWSERSTACK_ACCESS_KEY="" -A_EMAIL="" -A_PASSWORD="" -B_EMAIL="" -B_PASSWORD="" +ARCHIVE_EMAIL="" +ARCHIVE_PASSWORD="" +PATRON_EMAIL="" +PATRON_PASSWORD="" -CATEGORY="all" \ No newline at end of file +CATEGORY="all" + +WHATHOST="false" diff --git a/.gitignore b/.gitignore index f6a317df..e10884cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ node_modules/ /playwright-report /playwright/.cache /playwright/.auth +/playwright-summary .env *.err -*.log \ No newline at end of file +*.log diff --git a/README.md b/README.md index 819214dd..37216fc2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -82,7 +71,6 @@ - run: `npm run show:report` - ## Reference guide for writing tests - https://playwright.dev/docs/pom diff --git a/executeTest.js b/executeTest.js new file mode 100644 index 00000000..806e27a6 --- /dev/null +++ b/executeTest.js @@ -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); diff --git a/package-lock.json b/package-lock.json index 48caf170..24bf6b8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,14 +9,13 @@ "version": "1.0.0", "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" } }, @@ -154,12 +153,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.41.2.tgz", - "integrity": "sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.1.tgz", + "integrity": "sha512-1hZ4TNvD5z9VuhNJ/walIjvMVvYkZKf71axoF/uiAqpntQJXpG64dlXhoDXE3OczPuTuvjf/M5KWFg5VAVUS3Q==", "dev": true, "dependencies": { - "playwright": "1.41.2" + "playwright": "1.44.1" }, "bin": { "playwright": "cli.js" @@ -1070,12 +1069,12 @@ } }, "node_modules/playwright": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", - "integrity": "sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.1.tgz", + "integrity": "sha512-qr/0UJ5CFAtloI3avF95Y0L1xQo6r3LQArLIg/z/PoGJ6xa+EwzrwO5lpNr/09STxdHuUoP2mvuELJS+hLdtgg==", "dev": true, "dependencies": { - "playwright-core": "1.41.2" + "playwright-core": "1.44.1" }, "bin": { "playwright": "cli.js" @@ -1087,10 +1086,10 @@ "fsevents": "2.3.2" } }, - "node_modules/playwright/node_modules/playwright-core": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.41.2.tgz", - "integrity": "sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA==", + "node_modules/playwright-core": { + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.1.tgz", + "integrity": "sha512-wh0JWtYTrhv1+OSsLPgFzGzt67Y7BE/ZS3jEqgGBlp2ppp1ZDj8c+9IARNW4dwf1poq5MgHreEM2KV/GuR4cFA==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -1491,12 +1490,12 @@ } }, "@playwright/test": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.41.2.tgz", - "integrity": "sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.1.tgz", + "integrity": "sha512-1hZ4TNvD5z9VuhNJ/walIjvMVvYkZKf71axoF/uiAqpntQJXpG64dlXhoDXE3OczPuTuvjf/M5KWFg5VAVUS3Q==", "dev": true, "requires": { - "playwright": "1.41.2" + "playwright": "1.44.1" } }, "@types/node": { @@ -1518,8 +1517,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "agent-base": { "version": "6.0.2", @@ -1733,8 +1731,7 @@ "version": "8.8.0", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz", "integrity": "sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA==", - "dev": true, - "requires": {} + "dev": true }, "eslint-scope": { "version": "7.2.0", @@ -2182,23 +2179,21 @@ } }, "playwright": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", - "integrity": "sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.1.tgz", + "integrity": "sha512-qr/0UJ5CFAtloI3avF95Y0L1xQo6r3LQArLIg/z/PoGJ6xa+EwzrwO5lpNr/09STxdHuUoP2mvuELJS+hLdtgg==", "dev": true, "requires": { "fsevents": "2.3.2", - "playwright-core": "1.41.2" - }, - "dependencies": { - "playwright-core": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.41.2.tgz", - "integrity": "sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA==", - "dev": true - } + "playwright-core": "1.44.1" } }, + "playwright-core": { + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.1.tgz", + "integrity": "sha512-wh0JWtYTrhv1+OSsLPgFzGzt67Y7BE/ZS3jEqgGBlp2ppp1ZDj8c+9IARNW4dwf1poq5MgHreEM2KV/GuR4cFA==", + "dev": true + }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index e7ab4a72..4b82fa39 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { @@ -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" diff --git a/playwright.config.ts b/playwright.config.ts index 0a17bfda..2fc4b438 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -16,18 +16,38 @@ const formattedDateTime = () => { }; const reportName = () => `${process.env.CATEGORY}/${formattedDateTime()}`; +const summaryName = () => `${process.env.CATEGORY}-summary.json`; /** * See https://playwright.dev/docs/test-configuration. - * + * Read more about Playwright timeouts in: https://testerops.com/playwright-timeouts/ + * * Timeouts were set by `ms` */ export default defineConfig({ - workers: 2, - // Timeout for each test - timeout: 2 * 60 * 1000, - // Maximum time the whole test suite can run - globalTimeout: 20 * 60 * 1000, + // To use + // trace: 'on-first-retry' + // below to set retries: (to at least) 1 + retries: 1, + + // uncomment to run tests in parallel + // fullyParallel: true, + // AND uncomment line below + // OR reverse to run tests sequentially + workers: 1, + + // Set timeout for each test (currently 2 minutes) + timeout: 2 * 60 * 1000, + + // Set maximum time the whole test suite can run (currently 40 minutes) + globalTimeout: 40 * 60 * 1000, + + expect: { + // Maximum time expect() should wait for the condition to be met + // For example in `await expect(locator).toHaveText();` + // (currently 2 minutes) + timeout: 2 * 60 * 1000, + }, testDir: './tests', reporter: [ [ @@ -37,11 +57,22 @@ export default defineConfig({ open: 'never', }, ], + [ + 'json', + { + outputFile: `playwright-summary/${summaryName()}`, + open: 'never', + } + ] ], use: { /* Base URL to use in actions like `await page.goto('/')`. */ // This is set in config/index.ts baseURL: config.baseURL, + // Implied and comes into picture during the navigation from one page to another + navigationTimeout: 1 * 60 * 1000, + // If the test fails, it will retry once and create trace file if that fails + trace: 'on-first-retry', }, /* Configure projects for major browsers */ @@ -61,4 +92,4 @@ export default defineConfig({ use: { ...devices['Desktop Safari'] }, }, ], -}); +}); \ No newline at end of file diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index ba528509..00000000 --- a/run-tests.sh +++ /dev/null @@ -1,11 +0,0 @@ -TIMEFORMAT='It took %0R seconds.' -time { - npm run test:books - npm run test:collection - npm run test:details - npm run test:home - npm run test:login - npm run test:music - npm run test:search - npm run test:profile -} diff --git a/tests/av/tv.spec.js b/tests/av/tv.spec.js index 54651de6..8b7bff6e 100644 --- a/tests/av/tv.spec.js +++ b/tests/av/tv.spec.js @@ -1,7 +1,7 @@ import { expect, test } from '@playwright/test'; test('TV has borrow button', async ({ page }) => { - await page.goto('https://archive.org/details/CSPAN_20160425_022500_2011_White_House_Correspondents_Dinner') + await page.goto('/details/CSPAN_20160425_022500_2011_White_House_Correspondents_Dinner') const e = page.locator('.action-buttons-section') await expect(e).toHaveText(/Borrow Program/) diff --git a/tests/details/details-page.spec.ts b/tests/details/details-page.spec.ts index e1074821..0eac61c3 100644 --- a/tests/details/details-page.spec.ts +++ b/tests/details/details-page.spec.ts @@ -92,7 +92,9 @@ test(`Load theater: radio as regular patron user`, async ({ }); }); -test(`Load theater: radio as guest/not logged in user`, async ({ detailsPage }) => { +test(`Load theater: radio as guest/not logged in user`, async ({ + detailsPage, +}) => { await test.step(`Go to radio details page and verify priv'd user borrow program`, async () => { await detailsPage.gotoPage('WGBH_89_7_FM_20210918_040000'); await detailsPage.radioPlayerTheaterDisplay(); @@ -100,10 +102,7 @@ test(`Load theater: radio as guest/not logged in user`, async ({ detailsPage }) }); }); -test(`Load theater: tv as priv'd user`, async ({ - loginPage, - detailsPage, -}) => { +test(`Load theater: tv as priv'd user`, async ({ loginPage, detailsPage }) => { await test.step(`Do login as priv'd user`, async () => { await loginPage.loginAs('privs'); }); @@ -116,10 +115,7 @@ test(`Load theater: tv as priv'd user`, async ({ }); }); -test(`Load theater: tv as patron user`, async ({ - loginPage, - detailsPage, -}) => { +test(`Load theater: tv as patron user`, async ({ loginPage, detailsPage }) => { await test.step(`Do login as patron user`, async () => { await loginPage.loginAs('patron'); }); @@ -132,7 +128,9 @@ test(`Load theater: tv as patron user`, async ({ }); }); -test(`Load theater: tv as guest/not logged in user`, async ({ detailsPage }) => { +test(`Load theater: tv as guest/not logged in user`, async ({ + detailsPage, +}) => { await test.step(`Go to tv details page and verify priv'd user borrow program`, async () => { await detailsPage.gotoPage( 'CSPAN3_20170413_154200_Discussion_Focuses_on_Sesame_Street_and_Autism', diff --git a/tests/details/lending-bar.spec.ts b/tests/details/lending-bar.spec.ts index 4b3d14df..95511225 100644 --- a/tests/details/lending-bar.spec.ts +++ b/tests/details/lending-bar.spec.ts @@ -1,6 +1,9 @@ import { test } from '../fixtures'; -test(`Load theater: bookreader with lending bar`, async ({ detailsPage, loginPage }) => { +test(`Load theater: bookreader with lending bar`, async ({ + detailsPage, + loginPage, +}) => { await test.step('loan book with basic components', async () => { await detailsPage.gotoPage('coleridgesublime0000char'); await detailsPage.lendingBar.verifyDefaultTexts(); diff --git a/tests/donation/iframe-banner-source.spec.ts b/tests/donation/iframe-banner-source.spec.ts index fdbc44f8..f5591001 100644 --- a/tests/donation/iframe-banner-source.spec.ts +++ b/tests/donation/iframe-banner-source.spec.ts @@ -4,7 +4,9 @@ const permanentVariant1 = 'IADefault1'; const permanentVariant2 = 'IADefault2'; test(`Wayback navbar.php with ${permanentVariant1}`, async ({ page }) => { - await page.goto(`/web/navbar.php?platform=wb&transpiled=1&reCache=1&variant=${permanentVariant1}`); + await page.goto( + `/web/navbar.php?platform=wb&transpiled=1&reCache=1&variant=${permanentVariant1}`, + ); await expect(page).toHaveTitle(/Internet Archive Wayback Machine/); await expect(page.locator('header#donate_banner')).toBeVisible(); @@ -12,14 +14,22 @@ test(`Wayback navbar.php with ${permanentVariant1}`, async ({ page }) => { await expect(page.locator('ia-topnav')).toBeVisible(); - const constinueToDonationButton = page.locator('button#continue-button:has-text("Continue")'); + const constinueToDonationButton = page.locator( + 'button#continue-button:has-text("Continue")', + ); await expect(constinueToDonationButton).toBeVisible(); }); -test(`Test click to donate page - Wayback navbar.php with ${permanentVariant1}`, async ({ page }) => { - await page.goto(`/web/navbar.php?platform=wb&transpiled=1&reCache=1&variant=${permanentVariant1}`); +test(`Test click to donate page - Wayback navbar.php with ${permanentVariant1}`, async ({ + page, +}) => { + await page.goto( + `/web/navbar.php?platform=wb&transpiled=1&reCache=1&variant=${permanentVariant1}`, + ); - const constinueToDonationButton = page.locator('button#continue-button:has-text("Continue")'); + const constinueToDonationButton = page.locator( + 'button#continue-button:has-text("Continue")', + ); await expect(constinueToDonationButton).toBeVisible(); await constinueToDonationButton.click(); @@ -27,4 +37,3 @@ test(`Test click to donate page - Wayback navbar.php with ${permanentVariant1}`, await page.waitForLoadState('domcontentloaded'); await expect(page.locator('donation-form-controller')).toBeVisible(); }); - diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 8da6e7f3..47499975 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -191,8 +191,12 @@ export const test = base.extend({ }); test.beforeEach(async ({ request }) => { - const whathost = await request.get('/services/whathost.php'); - console.log('whathost: ', await whathost.text()); + // add config to check what_host node the test is connecting at + // update the .env file to enable/disable it + if (process.env.WHAT_HOST === 'true') { + const whathost = await request.get('/services/whathost.php'); + console.log('whathost: ', await whathost.text()); + } }); export { expect } from '@playwright/test'; diff --git a/tests/page-objects/lending-bar.ts b/tests/page-objects/lending-bar.ts index 71f1fb8d..ab7645a4 100644 --- a/tests/page-objects/lending-bar.ts +++ b/tests/page-objects/lending-bar.ts @@ -12,11 +12,15 @@ export class LendingBar { } async verifyDefaultTexts() { - const textGroup = await this.iaBookActions.locator('text-group > .variable-texts'); + const textGroup = await this.iaBookActions.locator( + 'text-group > .variable-texts', + ); const textGroupTexts = await textGroup.textContent(); await expect(textGroup).toBeVisible(); - await expect(textGroupTexts).toContain('Renewable every hour, pending availability.'); + await expect(textGroupTexts).toContain( + 'Renewable every hour, pending availability.', + ); } async verifyInfoIcon() { @@ -24,13 +28,17 @@ export class LendingBar { const infoIconUrl = await infoIcon.locator('a').getAttribute('href'); await expect(infoIcon).toBeVisible(); - await expect(infoIconUrl).toContain('https://help.archive.org/help/borrowing-from-the-lending-library'); + await expect(infoIconUrl).toContain( + 'https://help.archive.org/help/borrowing-from-the-lending-library', + ); } async verifyLendingBarBasicNonLoggedIn() { await expect(this.iaBookActions).toBeVisible(); - const actionGroup = await this.iaBookActions.locator('collapsible-action-group'); + const actionGroup = await this.iaBookActions.locator( + 'collapsible-action-group', + ); const primaryAction = await actionGroup.locator('button.initial').first(); const primaryActionText = await primaryAction.textContent(); @@ -49,7 +57,9 @@ export class LendingBar { } async verifyLendingBarLoggedIn() { - const actionGroup = await this.iaBookActions.locator('collapsible-action-group'); + const actionGroup = await this.iaBookActions.locator( + 'collapsible-action-group', + ); const borrowButton = await actionGroup.locator('button.initial').first(); const borrowButtonText = await borrowButton.textContent(); @@ -62,13 +72,15 @@ export class LendingBar { // click on this primaryAction button should send you on login page await borrowButton.click(); - + // wait for navigation to complete - await this.page.waitForLoadState('load'); + await this.page.waitForLoadState('load'); } else { // case after user has borrowed book const iaBookActions = await this.page.locator('ia-book-actions'); - const returnNowButton = await iaBookActions.locator('button.ia-button').first(); + const returnNowButton = await iaBookActions + .locator('button.ia-button') + .first(); const returnNowButtonText = await returnNowButton.textContent(); await expect(returnNowButton).toBeVisible(); @@ -76,7 +88,7 @@ export class LendingBar { // click on this primaryAction button should send you on login page await returnNowButton.click(); - + // wait for navigation to complete await this.page.waitForLoadState('load'); }