diff --git a/__test__/BasePage.test.ts b/__test__/BasePage.test.ts new file mode 100644 index 0000000..ffcc4a4 --- /dev/null +++ b/__test__/BasePage.test.ts @@ -0,0 +1,16 @@ +import { describe, test, expect } from 'vitest' +import { resolveElementName } from '../src/pages/BasePage' + +describe('resolveElementName', () => { + const cases = [ + { explicit: 'myName', caller: 'getter', fallback: '#sel', expected: 'myName' }, + { explicit: undefined, caller: 'getter', fallback: '#sel', expected: 'getter' }, + { explicit: undefined, caller: null, fallback: '#sel', expected: '#sel' }, + ] + + cases.forEach(({ explicit, caller, fallback, expected }) => { + test(`resolves to "${expected}" when explicit=${explicit}, caller=${caller}`, () => { + expect(resolveElementName(explicit, caller, fallback)).toBe(expected) + }) + }) +}) diff --git a/cypress/e2e/basepage/basepage.cy.ts b/cypress/e2e/basepage/basepage.cy.ts new file mode 100644 index 0000000..d82d681 --- /dev/null +++ b/cypress/e2e/basepage/basepage.cy.ts @@ -0,0 +1,35 @@ +import { BasePage } from '../../../src/pages/BasePage' + +class TestPage extends BasePage { + get heading() { + return this.el('h1') + } + + get link() { + return this.elContains('Impressum') + } + + getExplicitName() { + return this.el('h1', 'explicitHeading') + } +} + +describe('BasePage', () => { + const page = new TestPage() + + beforeEach(() => { + cy.visit('/') + }) + + it('logs getter name for el()', () => { + page.heading.should('exist') + }) + + it('logs getter name for elContains()', () => { + page.link.should('exist') + }) + + it('uses explicit name when provided', () => { + page.getExplicitName().should('exist') + }) +}) diff --git a/dist/index.d.ts b/dist/index.d.ts index d1599b1..36e95a7 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -7,7 +7,6 @@ interface DomainMappingConfig { minLinksRequired?: number } -// eslint-disable-next-line @typescript-eslint/no-unused-vars declare namespace Cypress { interface Chainable { ttAccessibility(context?: any, options?: any): Chainable @@ -43,4 +42,13 @@ declare namespace Cypress { } } -export {} +export abstract class BasePage { + protected el( + selector: string, + name?: string + ): Cypress.Chainable> + protected elContains( + text: string, + name?: string + ): Cypress.Chainable> +} diff --git a/dist/index.js b/dist/index.js index 9978eb8..26ce575 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,3 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.BasePage = void 0; require("./commands"); +var BasePage_1 = require("./pages/BasePage"); +Object.defineProperty(exports, "BasePage", { enumerable: true, get: function () { return BasePage_1.BasePage; } }); diff --git a/dist/pages/BasePage.d.ts b/dist/pages/BasePage.d.ts new file mode 100644 index 0000000..cdc6e28 --- /dev/null +++ b/dist/pages/BasePage.d.ts @@ -0,0 +1,6 @@ +export declare function resolveElementName(explicit: string | undefined, caller: string | null, fallback: string): string; +export declare abstract class BasePage { + protected el(selector: string, name?: string): Cypress.Chainable>; + protected elContains(text: string, name?: string): Cypress.Chainable; + private extractCallerName; +} diff --git a/dist/pages/BasePage.js b/dist/pages/BasePage.js new file mode 100644 index 0000000..3e92d3c --- /dev/null +++ b/dist/pages/BasePage.js @@ -0,0 +1,26 @@ +"use strict"; +/// +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BasePage = void 0; +exports.resolveElementName = resolveElementName; +function resolveElementName(explicit, caller, fallback) { + return explicit || caller || fallback; +} +class BasePage { + el(selector, name) { + cy.log(`🔹 ${resolveElementName(name, this.extractCallerName(), selector)}`); + return cy.get(selector); + } + elContains(text, name) { + cy.log(`🔹 ${resolveElementName(name, this.extractCallerName(), text)}`); + return cy.contains(text); + } + extractCallerName() { + var _a, _b; + const stack = new Error().stack; + if (!stack) + return null; + return ((_b = (_a = stack.split('\n')[3]) === null || _a === void 0 ? void 0 : _a.match(/get (\w+)/)) === null || _b === void 0 ? void 0 : _b[1]) || null; + } +} +exports.BasePage = BasePage; diff --git a/eleventy-page/output/NCA/index.html b/eleventy-page/output/NCA/index.html index 814f811..4f40e58 100644 --- a/eleventy-page/output/NCA/index.html +++ b/eleventy-page/output/NCA/index.html @@ -1,38 +1,42 @@ - - - - NCA - TESTIFY - - - +
+

NCA - TESTIFY

+ +

Beispieltext für diese Seite.

+ +
+ + diff --git a/eleventy-page/output/alle/index.html b/eleventy-page/output/alle/index.html index 91c1eb4..d516203 100644 --- a/eleventy-page/output/alle/index.html +++ b/eleventy-page/output/alle/index.html @@ -1,36 +1,40 @@ - - - - Blog Post 1 - - - +
+

Alle akzeptieren

+ +
+ + diff --git a/eleventy-page/output/alles/index.html b/eleventy-page/output/alles/index.html index 2ad6f1c..c5590d2 100644 --- a/eleventy-page/output/alles/index.html +++ b/eleventy-page/output/alles/index.html @@ -1,36 +1,40 @@ - - - - Blog Post 1 - - - +
+

Alles akzeptieren

+ +
+ + diff --git a/eleventy-page/output/blog/post1/index.html b/eleventy-page/output/blog/post1/index.html index 42f70fe..107118d 100644 --- a/eleventy-page/output/blog/post1/index.html +++ b/eleventy-page/output/blog/post1/index.html @@ -1,39 +1,40 @@ - - - - Blog Post 1 - - - +
+

Dies ist der Inhalt von Blog Post 1. Hier erfahren Sie mehr über interessante Themen und Neuigkeiten.

+ +
+ + diff --git a/eleventy-page/output/blog/post2/index.html b/eleventy-page/output/blog/post2/index.html index d54bd7e..45be78f 100644 --- a/eleventy-page/output/blog/post2/index.html +++ b/eleventy-page/output/blog/post2/index.html @@ -1,39 +1,40 @@ - - - - Blog Post 2 - - - +
+

Dies ist der Inhalt von Blog Post 2. Bleiben Sie auf dem Laufenden und entdecken Sie weitere spannende Themen.

+ +
+ + diff --git a/eleventy-page/output/console-errors/index.html b/eleventy-page/output/console-errors/index.html index f20cab8..a7be0c9 100644 --- a/eleventy-page/output/console-errors/index.html +++ b/eleventy-page/output/console-errors/index.html @@ -1,40 +1,44 @@ - - - - Performance - - - +
+

Console Log Seite

+

console.('Error Seite');

+ + +
+ + diff --git a/eleventy-page/output/css-file-not-loading/index.html b/eleventy-page/output/css-file-not-loading/index.html index 82782e2..a8e6a31 100644 --- a/eleventy-page/output/css-file-not-loading/index.html +++ b/eleventy-page/output/css-file-not-loading/index.html @@ -1,38 +1,42 @@ - - - - Performance - - - +
+ + +

2 CSS files 404

+ +
+ + diff --git a/eleventy-page/output/impressum/index.html b/eleventy-page/output/impressum/index.html index 564758f..378f53b 100644 --- a/eleventy-page/output/impressum/index.html +++ b/eleventy-page/output/impressum/index.html @@ -1,37 +1,41 @@ - - - - Impressum - - - +
+

Impressum

+

Beispieltext für das Impressum.

+ +
+ + diff --git a/eleventy-page/output/index.html b/eleventy-page/output/index.html index 3f4243b..2e6faed 100644 --- a/eleventy-page/output/index.html +++ b/eleventy-page/output/index.html @@ -1,43 +1,42 @@ - - - - Startseite - - - +
+

Willkommen auf der Startseite

+

Hier finden Sie Informationen über unser Unternehmen und unseren Blog.

+Kill Bugs Fakebild mit Roland Golla im Kill Bill Look + +
+ + diff --git a/eleventy-page/output/performance/index.html b/eleventy-page/output/performance/index.html index 98ace34..8cd6bba 100644 --- a/eleventy-page/output/performance/index.html +++ b/eleventy-page/output/performance/index.html @@ -1,41 +1,45 @@ - - - - Performance - - - +
+

Performance Seite

+

Hier sind viel zu große Bilder

+ + + + + +
+ + diff --git a/eleventy-page/output/ueber-uns/index.html b/eleventy-page/output/ueber-uns/index.html index 3119f6e..9e826e4 100644 --- a/eleventy-page/output/ueber-uns/index.html +++ b/eleventy-page/output/ueber-uns/index.html @@ -1,40 +1,41 @@ - - - - Über uns - - - +
+

Über uns

+

Wir sind ein Beispielunternehmen, das sich auf die Erstellung hochwertiger Inhalte spezialisiert hat.

+ +
+ + diff --git a/package.json b/package.json index 2509fea..63d1341 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cypress-ncatestify-plugin", - "version": "2.1.69", + "version": "2.1.70", "description": "NCA TESTIFY commands and tests", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/readme.md b/readme.md index 46b87e1..9056bc0 100644 --- a/readme.md +++ b/readme.md @@ -1,398 +1,356 @@ -# Cypress.IO plugin by NCA TESTIFY +# Cypress.IO Plugin by NCA TESTIFY -Basis tests for every website testing project. Now compatible with Cypress 14 and TypeScript 5.x! +Ready-to-use tests for any website. No testing experience required. -## Usage: +## What is this? -Add following line in your cypress/support/e2e.js|.ts file +This plugin gives you **pre-built tests** that check if your website works correctly: +- Are all links working? +- Do all images load? +- Is the site accessible? +- Is the SEO structure correct? -`import 'cypress-ncatestify-plugin'` +You don't need to write complex test code - just call our simple commands. -in your cypress.config.js|.ts file the key baseUrl must be set +## Quick Start (5 minutes) + +### 1. Install the plugin + +```bash +npm install cypress-ncatestify-plugin --save-dev +``` + +### 2. Import in your Cypress support file + +Add this line to `cypress/support/e2e.ts` (or `.js`): + +```ts +import 'cypress-ncatestify-plugin' +``` + +### 3. Set your website URL + +In `cypress.config.ts`: -### TypeScript (recommended) ```ts import { defineConfig } from 'cypress' export default defineConfig({ e2e: { - baseUrl: 'https://testify.team/de', - setupNodeEvents(on, config) { - return config - } + baseUrl: 'https://your-website.com' } }) ``` -### JavaScript -```js -const { defineConfig } = require('cypress') +### 4. Create your first test -module.exports = defineConfig({ - e2e: { - baseUrl: 'https://testify.team/de', - setupNodeEvents(on, config) { - return config - } - } -}) -``` +Create `cypress/e2e/my-first-test.cy.ts`: -Then in your Testfile - -```js -describe('Validate Testify Tests', () => { - it('Accessibility test', () => { +```ts +describe('My Website Tests', () => { + beforeEach(() => { cy.visit('/') - cy.ttAccessibility() }) - - it('Check internal links', () => { - cy.visit('/') - cy.ttEveryInternalLinkIsLoading() + + it('all links work', () => { + cy.ttEveryInternalLinkStatusOk() }) - - it('Validate images', () => { - cy.visit('/') + + it('all images load', () => { cy.ttValidateAllImagesResponseStatusOk() }) -}) -``` -## Run commands - -```bash -npm run typecheck -``` - -```bash -npm run build -``` - -```bash -npx cypress open --config-file config.cypress.ts/js -``` - -```bash -export CYPRESS_BASE_URL=https://nevercodealone.de && npx cypress open --config-file config.cypress.ts/js + it('site is accessible', () => { + cy.ttAccessibility() + }) +}) ``` -Run s specific file +### 5. Run your tests ```bash -export CYPRESS_BASE_URL=https://nevercodealone.de && npx cypress run --config-file cypress.config.ts --spec "cypress/e2e/validate.cy.ts" +npx cypress open ``` -### Static file CMS - -cd eleventy-page && npx eleventy --serve +That's it! You now have professional website tests. -### Build +--- -npx eleventy +## Page Object Model with BasePage -### Browser +For larger projects, organize your tests using the **Page Object Model**. This makes tests more readable and maintainable. -http://localhost:8080 +### Why use BasePage? -For contributing remove local `.js` files - -```bash -rm -rf **/*.js +Instead of seeing cryptic CSS selectors in your test logs: ``` - -Validate types with no generating - -```bash -npm run typecheck +cy.get('#ext-comp-1234') // What is this? ``` -Build js files - -```bash -npm run build +You see meaningful names: +``` +usernameInput // Much clearer! ``` -## Docker command for local host on port 8090 - -docker run -p 8090:80 -v $(pwd)/src:/app --entrypoint python3 python:3.9-alpine -m http.server --directory /app 80 - -## Testing and Code Quality - -### Running Tests +### How to use BasePage -To run the test suite, execute the following command: +**1. Create a Page class:** -```bash -npx jest --config jest.config.ts -``` +```ts +// cypress/pages/LoginPage.ts +import { BasePage } from 'cypress-ncatestify-plugin' -This will run all Jest tests located in the `__tests__` directory. +export class LoginPage extends BasePage { + // Define your page elements as getters + get usernameInput() { + return this.el('#username') // Logs: usernameInput + } -### Type Checking + get passwordInput() { + return this.el('#password') // Logs: passwordInput + } -To perform TypeScript type checking, run: + get submitButton() { + return this.elContains('Login') // Logs: submitButton + } -```bash -npm run typecheck + // Create reusable actions + login(user: string, pass: string) { + this.usernameInput.type(user) + this.passwordInput.type(pass) + this.submitButton.click() + } +} ``` -This ensures that the code adheres to the TypeScript configurations and catches potential type errors. +**2. Use in your tests:** -### Code Formatting +```ts +// cypress/e2e/login.cy.ts +import { LoginPage } from '../pages/LoginPage' -To auto-format the codebase, run: +const loginPage = new LoginPage() -```bash -npm run prettier +describe('Login', () => { + it('logs in successfully', () => { + cy.visit('/login') + loginPage.login('admin', 'secret') + cy.url().should('include', '/dashboard') + }) +}) ``` -This will format the code according to the rules specified in the `.prettierrc` file. +### BasePage Methods -### CI/CD Pipeline +| Method | Description | Example | +|--------|-------------|---------| +| `this.el(selector)` | Find element by CSS selector | `this.el('#email')` | +| `this.el(selector, name)` | Find element with custom log name | `this.el('#x1', 'email')` | +| `this.elContains(text)` | Find element containing text | `this.elContains('Submit')` | +| `this.elContains(text, name)` | Find by text with custom log name | `this.elContains('OK', 'confirm')` | -All of these checks are automatically run in our GitHub Actions CI/CD pipeline on every push and pull request to the `main` branch. This ensures that all merged code is properly tested, type-checked, and formatted. +--- -## Commands - -### Cookie Management - -#### Click accept all cookies -Automatically clicks cookie acceptance buttons for various cookie consent providers. - -```js -cy.ttCookieAllAcceptClick() -``` +## All Commands Reference ### Link Validation -#### Validate all internal links return OK status (200) -Checks that all internal links return a 200 status code. Supports HTTP Basic Authentication when baseUrl contains credentials. - -```js +```ts +// Check all internal links return 200 status cy.ttEveryInternalLinkStatusOk() -``` -#### Validate all internal links are loading -Visits each internal link to verify they load correctly. Automatically skips non-requestable links like anchors, fragments, javascript:, mailto:, tel:, and data: URLs. - -```js -cy.ttEveryInternalLinkIsLoading() // Validate up to 10 links (default) -cy.ttEveryInternalLinkIsLoading(20) // Validate up to 20 links -``` +// Visit each internal link to verify it loads +cy.ttEveryInternalLinkIsLoading() // Default: 10 links +cy.ttEveryInternalLinkIsLoading(20) // Check 20 links -**Note:** This command intelligently handles special link types: -- Anchor links (`href="#"`, `href="#section"`) are skipped -- JavaScript links (`href="javascript:void(0)"`) are skipped -- Email links (`href="mailto:..."`) are skipped -- Phone links (`href="tel:..."`) are skipped -- Data URLs (`href="data:..."`) are skipped -- External links are automatically filtered out -- PDF files are validated with a request instead of visiting - -#### Get all internal links as array -Returns an array of all internal links found on the page. - -```js +// Get all internal links as array cy.ttGetInternalLinks() -cy.ttGetInternalLinks('.content') // Optional: specify a container selector +cy.ttGetInternalLinks('.content') // From specific container ``` ### Image Validation -#### Validate all images return status code 200 -Verifies that all images (src and srcset) return a 200 status code. Supports HTTP Basic Authentication. - -```js +```ts +// Check all images load successfully cy.ttValidateAllImagesResponseStatusOk() ``` -### SEO & Meta Validation - -#### Validate imprint/legal page is clickable -Ensures legal/imprint links are present and clickable. - -```js -cy.ttValidateImprintClickable() -``` - -#### Validate no Google services are being loaded -Checks that no Google services (analytics, fonts, etc.) are loaded on the page. +### Accessibility -```js -cy.ttValidateNoGoogleServices() +```ts +// Run accessibility tests (uses axe-core) +cy.ttAccessibility() +cy.ttAccessibility('.main-content') // Test specific area ``` -#### Validate page has only one H1 headline -Ensures proper SEO structure with a single H1 tag. +### SEO Checks -```js +```ts +// Verify only one H1 tag exists cy.ttOnlyOneH1() -``` -#### Validate page has language tag -Verifies the HTML lang attribute matches the expected language. +// Check language tag +cy.ttValidateLanguageTag('de') // German +cy.ttValidateLanguageTag('en') // English -```js -cy.ttValidateLanguageTag('de') // For German -cy.ttValidateLanguageTag('en') // For English +// Check imprint/legal link exists +cy.ttValidateImprintClickable() ``` -### Security & Protocol Validation - -#### Detect HTTP links -Finds any non-HTTPS links on the page. +### Security -```js +```ts +// Find any non-HTTPS links cy.ttDetectHttp() + +// Check no Google services loaded +cy.ttValidateNoGoogleServices() ``` ### Error Handling -#### Setup console error listener -Monitors for JavaScript console errors during test execution. +```ts +// Verify 404 pages work correctly +cy.ttInvalidPath404() -```js +// Monitor console errors cy.ttSetupConsoleErrorListener() ``` -#### Validate invalid paths return 404 -Verifies that non-existent URLs properly return a 404 status. +### Cookie Management -```js -cy.ttInvalidPath404() +```ts +// Accept cookies (supports various providers) +cy.ttCookieAllAcceptClick() ``` -### Accessibility +### Performance -#### Check for accessibility issues -Runs automated accessibility tests using axe-core. +```ts +// Check page size threshold (MB) +cy.ttThreshold() // Default threshold +cy.ttThreshold(2) // 2MB limit -```js -cy.ttAccessibility() -cy.ttAccessibility('.main-content') // Optional: test specific context -cy.ttAccessibility(null, { runOnly: ['wcag2a', 'wcag2aa'] }) // Optional: axe options +// Verify page loaded completely +cy.ttPageLoaded() ``` -### Performance +### Utility Commands -#### Performance measurement with threshold -Measures total page load size against a threshold. +```ts +// Click element only if it exists +cy.ttClickIfElementExist('.cookie-banner') -```js -cy.ttThreshold() // Default threshold -cy.ttThreshold(2) // Set threshold to 2MB +// Check if element exists (returns boolean) +cy.ttElementExists('.modal').then(exists => { + if (exists) { + // do something + } +}) ``` -#### Page loaded verification -Verifies the page has fully loaded. +### Run All Tests -```js -cy.ttPageLoaded() +```ts +// Execute complete test suite +cy.ttRunTestifyBaseTests() ``` -### Content Validation +--- + +## HTTP Basic Authentication -#### Run all page content validation tests -Executes a suite of content validation tests. +For password-protected staging sites: -```js -cy.ttValidatePageContent() +```ts +// cypress.config.ts +export default defineConfig({ + e2e: { + baseUrl: 'https://user:password@staging.example.com' + } +}) ``` -#### Validate subpages and images -Validates multiple subpages and their images. +Or via environment variable: -```js -cy.ttValidateSubpagesAndImages() -cy.ttValidateSubpagesAndImages(5) // Test only first 5 pages -cy.ttValidateSubpagesAndImages(10, '.nav') // Test 10 pages from nav links +```bash +export CYPRESS_BASE_URL=https://user:password@staging.example.com +npx cypress run ``` -### Utility Commands +--- -#### Click element if it exists -Conditionally clicks an element only if it exists on the page. +## Common Issues -```js -cy.ttClickIfElementExist('.cookie-accept') -cy.ttClickIfElementExist('#modal-close') -``` +### "baseUrl must be set" -#### Check if element exists -Returns a boolean indicating whether an element exists. +Add `baseUrl` to your `cypress.config.ts`: -```js -cy.ttElementExists('.banner').then(exists => { - if (exists) { - // Element exists +```ts +export default defineConfig({ + e2e: { + baseUrl: 'https://your-site.com' } }) ``` -### Comprehensive Testing +### Tests timing out -#### Run all TESTIFY base tests -Executes the complete suite of TESTIFY validation tests. +Increase the timeout in your config: -```js -cy.ttRunTestifyBaseTests() +```ts +export default defineConfig({ + e2e: { + baseUrl: 'https://your-site.com', + defaultCommandTimeout: 10000 // 10 seconds + } +}) ``` -This runs: -- Internal link status validation -- Image response validation -- Google services check -- Imprint clickability -- Internal link loading -- Accessibility tests -- H1 validation -- 404 error handling -- Language tag validation (defaults to 'de') -- HTTP link detection +### Links failing that should pass -## HTTP Basic Authentication Support +Some links like `mailto:`, `tel:`, `javascript:` are automatically skipped. External links are also filtered out. -This plugin supports HTTP Basic Authentication for websites that require credentials. When your `baseUrl` contains authentication credentials, all link and image validation commands will automatically use these credentials. +--- -### Setup +## Development -Configure your Cypress baseUrl with credentials: +### Run tests -```js -// cypress.config.js -export default defineConfig({ - e2e: { - baseUrl: 'https://username:password@example.dev', - // ... other config - } -}) +```bash +npm test # Unit tests +npm run cy:run # Cypress tests +npm run typecheck # Type checking +npm run lint # ESLint ``` -Or set via environment variable: +### Build ```bash -export CYPRESS_BASE_URL=https://username:password@example.dev -npx cypress run +npm run build ``` -### Supported Commands - -The following commands automatically handle HTTP Basic Authentication: -- `ttEveryInternalLinkStatusOk()` - Validates internal link status codes -- `ttValidateAllImagesResponseStatusOk()` - Validates image response codes -- `ttInvalidPath404()` - Validates 404 error pages -- All other commands that use `cy.visit()` inherit authentication from the baseUrl +### Local test server -## Websites being tested with this plugin +```bash +cd eleventy-page && npx @11ty/eleventy --serve +# Open http://localhost:8080 +``` -https://www.auto-hortz.de -https://www.discounto.de -https://nevercodealone.de +--- ## Compatibility -This plugin is compatible with: -- Cypress 14.x +- Cypress 14.x / 15.x - TypeScript 5.x - Node.js 18+ + +## Sites using this plugin + +- https://www.auto-hortz.de +- https://www.discounto.de +- https://nevercodealone.de + +--- + +Made with care by [NCA TESTIFY](https://testify.team) diff --git a/src/index.d.ts b/src/index.d.ts index d1599b1..36e95a7 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -7,7 +7,6 @@ interface DomainMappingConfig { minLinksRequired?: number } -// eslint-disable-next-line @typescript-eslint/no-unused-vars declare namespace Cypress { interface Chainable { ttAccessibility(context?: any, options?: any): Chainable @@ -43,4 +42,13 @@ declare namespace Cypress { } } -export {} +export abstract class BasePage { + protected el( + selector: string, + name?: string + ): Cypress.Chainable> + protected elContains( + text: string, + name?: string + ): Cypress.Chainable> +} diff --git a/src/index.ts b/src/index.ts index 43c03b7..99d4e5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,3 @@ import './commands' + +export { BasePage } from './pages/BasePage' diff --git a/src/pages/BasePage.ts b/src/pages/BasePage.ts new file mode 100644 index 0000000..3a89a74 --- /dev/null +++ b/src/pages/BasePage.ts @@ -0,0 +1,27 @@ +/// + +export function resolveElementName( + explicit: string | undefined, + caller: string | null, + fallback: string +): string { + return explicit || caller || fallback +} + +export abstract class BasePage { + protected el(selector: string, name?: string) { + cy.log(`🔹 ${resolveElementName(name, this.extractCallerName(), selector)}`) + return cy.get(selector) + } + + protected elContains(text: string, name?: string) { + cy.log(`🔹 ${resolveElementName(name, this.extractCallerName(), text)}`) + return cy.contains(text) + } + + private extractCallerName(): string | null { + const stack = new Error().stack + if (!stack) return null + return stack.split('\n')[3]?.match(/get (\w+)/)?.[1] || null + } +} diff --git a/update.md b/update.md index 2cf13cc..33187f7 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,15 @@ # Update md file +2.1.70 + +- Add BasePage abstract class for Page Object Model with semantic logging +- Implement el(selector, name?) and elContains(text, name?) protected methods +- Auto-extract getter names from stack trace for readable Cypress logs +- Shows semantic names (e.g., usernameInput) instead of CSS selectors +- Export resolveElementName pure function for testability +- Add unit tests with table-driven test pattern +- Add integration tests for BasePage functionality + 2.1.69 - Restructure Cypress tests from monolithic validate.cy.ts to feature-based directories