@jahia/cypress 8.2.1 → 8.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,158 +0,0 @@
1
- # Browser Helpers
2
-
3
- ## Overview
4
-
5
- The Browser Helpers module provides exported helper functions for debugging and managing browser storage (`cookies`, `localStorage`, `sessionStorage`) in Cypress tests.
6
-
7
- Warning: These helpers log full storage/cookie values by design. Use carefully in automated runs to avoid leaking tokens, credentials, or session identifiers in logs.
8
-
9
- ## Import and Usage Model
10
-
11
- ```typescript
12
- import {BrowserHelper} from '@jahia/cypress';
13
-
14
- it('inspects browser state', () => {
15
- cy.login();
16
- BrowserHelper.logCookies();
17
- BrowserHelper.logLocalStorage();
18
- });
19
- ```
20
-
21
- ## Available Helpers
22
-
23
- ### `BrowserHelper.logCookies()`
24
-
25
- Logs all available cookies with metadata and values.
26
-
27
- - Returns: `Cypress.Chainable<void>`
28
- - Typical use: inspect authentication and security cookie attributes during debugging
29
-
30
- ### `BrowserHelper.logCookie(cookieName)`
31
-
32
- Logs one cookie by name in a detailed format.
33
-
34
- - Parameters: `cookieName: string`
35
- - Returns: `Cypress.Chainable<void>`
36
-
37
- ### `BrowserHelper.clearSessionCookies()`
38
-
39
- Clears only session cookies.
40
-
41
- - Returns: `Cypress.Chainable<void>`
42
-
43
- ### `BrowserHelper.clearPersistentCookies()`
44
-
45
- Clears only persistent cookies.
46
-
47
- - Returns: `Cypress.Chainable<void>`
48
-
49
- ### `BrowserHelper.simulateClose()`
50
-
51
- Simulates a browser close by clearing `sessionStorage` and session cookies only.
52
-
53
- - Returns: `void`
54
- - Clears: session cookies + all `sessionStorage`
55
- - Keeps: persistent cookies + `localStorage`
56
-
57
- ### `BrowserHelper.resetState()`
58
-
59
- Resets browser client-side state by clearing all cookies and all storages.
60
-
61
- - Returns: `void`
62
- - Clears: all cookies + all `localStorage` + all `sessionStorage`
63
-
64
- ### `BrowserHelper.logSessionStorage()`
65
-
66
- Logs all `sessionStorage` entries grouped by origin.
67
-
68
- - Returns: `Cypress.Chainable<void>`
69
-
70
- ### `BrowserHelper.logLocalStorage()`
71
-
72
- Logs all `localStorage` entries grouped by origin.
73
-
74
- - Returns: `Cypress.Chainable<void>`
75
-
76
- ## Integration Examples
77
-
78
- ### Authentication Debugging
79
-
80
- ```typescript
81
- import {BrowserHelper} from '@jahia/cypress';
82
-
83
- describe('Authentication Flow', () => {
84
- it('keeps session after reload', () => {
85
- cy.step('Login', () => {
86
- cy.login('testuser@example.com', 'password');
87
- BrowserHelper.logCookie('JSESSIONID');
88
- cy.get('[data-testid="dashboard"]').should('be.visible');
89
- });
90
-
91
- cy.step('Reload page', () => {
92
- cy.reload();
93
- BrowserHelper.logCookie('JSESSIONID');
94
- cy.get('[data-testid="dashboard"]').should('be.visible');
95
- });
96
- });
97
- });
98
- ```
99
-
100
- ### Simulate Browser Close
101
-
102
- ```typescript
103
- import {BrowserHelper} from '@jahia/cypress';
104
-
105
- it('validates behavior after browser close', () => {
106
- cy.login();
107
- BrowserHelper.logCookies();
108
-
109
- // Simulate browser close (clears session cookies and session storage)
110
- BrowserHelper.simulateClose();
111
-
112
- // Visit the app again to see the effect of reset
113
- cy.visit(url);
114
-
115
- BrowserHelper.logCookies();
116
- BrowserHelper.logSessionStorage();
117
- });
118
- ```
119
-
120
- ### Simulate Browser Reset (clear all cookies and storages)
121
-
122
- ```typescript
123
- import {BrowserHelper} from '@jahia/cypress';
124
-
125
- it('validates behavior after full browser reset', () => {
126
- cy.login();
127
- BrowserHelper.logCookies();
128
-
129
- // Reset all browser state
130
- BrowserHelper.resetState();
131
-
132
- // Visit the app again to see the effect of reset
133
- cy.visit(url);
134
-
135
- BrowserHelper.logCookies();
136
- BrowserHelper.logSessionStorage();
137
- });
138
- ```
139
-
140
- ## Best Practices
141
-
142
- 1. Use these helpers for interactive debugging, not as regular test assertions.
143
- 2. Avoid running full storage/cookie logging in CI unless required.
144
- 3. Prefer targeted checks (`logCookie`) over full dumps (`logCookies`) for sensitive environments.
145
- 4. Use `resetState()` for hard test isolation, and `simulateClose()` for realistic session lifecycle checks.
146
-
147
- ## API Reference
148
-
149
- | Helper | Parameters | Returns | Description |
150
- |--------|------------|---------|-------------|
151
- | `BrowserHelper.logCookies()` | - | `Cypress.Chainable<void>` | Logs all cookies with full metadata |
152
- | `BrowserHelper.logCookie(cookieName)` | `string` | `Cypress.Chainable<void>` | Logs one cookie by name |
153
- | `BrowserHelper.clearSessionCookies()` | - | `Cypress.Chainable<void>` | Clears session cookies only |
154
- | `BrowserHelper.clearPersistentCookies()` | - | `Cypress.Chainable<void>` | Clears persistent cookies only |
155
- | `BrowserHelper.simulateClose()` | - | `void` | Clears session storage and session cookies |
156
- | `BrowserHelper.resetState()` | - | `void` | Clears all storages and all cookies |
157
- | `BrowserHelper.logSessionStorage()` | - | `Cypress.Chainable<void>` | Logs all session storage data |
158
- | `BrowserHelper.logLocalStorage()` | - | `Cypress.Chainable<void>` | Logs all local storage data |
@@ -1,104 +0,0 @@
1
- # Context Reporter: Test Tags and Integration with TestRail
2
-
3
- ## Overview
4
-
5
- Test tags are user-defined labels that can be attached to test suites and individual tests to provide metadata about test characteristics, scope, and purpose. Tags are collected during test execution and included in the mochawesome test report.
6
-
7
- ## Integration with TestRail and jahia-reporter
8
-
9
- Tags defined in Cypress tests are **automatically synchronized to TestRail test cases** by the `jahia-reporter` tool during the test reporting phase. This enables:
10
-
11
- - **Test categorization** in TestRail for better organization
12
- - **Dashboard filtering** based on test characteristics
13
- - **Reporting dashboards** that slice data by tag combinations (e.g., smoke tests, regression, performance, critical path)
14
- - **Traceability** linking test runs to business requirements or feature areas
15
-
16
- ## Usage
17
-
18
- ### Basic Syntax
19
-
20
- Use the `tag()` function to attach one or more tags:
21
-
22
- ```typescript
23
- import {context} from '@jahia/cypress';
24
-
25
- describe('Authentication', () => {
26
- context.tag('smoke', 'critical');
27
-
28
- it('should login successfully', () => {
29
- context.tag('p1'); // Add P1 severity
30
- cy.login();
31
- cy.url().should('include', '/home');
32
- });
33
-
34
- it('should logout successfully', () => {
35
- cy.logout();
36
- });
37
- });
38
- ```
39
-
40
- ### Where to Call
41
-
42
- - **In `describe()`**: Tags apply to **all nested tests** in the suite (inherited by child suites and tests)
43
- - **In `it()`**: Tags apply to **only that specific test**
44
- - **Both**: Combine suite-level and test-level tags (both are collected)
45
-
46
- ### Example: Multi-Level Tagging
47
-
48
- ```typescript
49
- import {context} from '@jahia/cypress';
50
-
51
- describe('Content Management', () => {
52
- context.tag('regression', 'content'); // Suite-level tags
53
-
54
- describe('Publishing Workflow', () => {
55
- context.tag('critical'); // Additional suite-level tag
56
-
57
- it('should publish page', () => {
58
- context.tag('p0', 'smoke'); // Test-level tags
59
- // effective tags: ['regression', 'content', 'critical', 'p0', 'smoke']
60
- });
61
-
62
- it('should unpublish page', () => {
63
- // effective tags: ['regression', 'content', 'critical']
64
- });
65
- });
66
- });
67
- ```
68
-
69
- ## Implementation Details
70
- - Tags are collected during test execution via Mocha hooks and then added to the test's `context`.
71
- - Suite tags are inherited by nested describe blocks and tests.
72
- - All unique tags are deduplicated.
73
-
74
- Tags are stored as an object (`{title: <title>, value: <value>}`) in order to be properly parsed by mocha html-reporter.
75
- Example:
76
- ```json
77
- {title: 'tags', value: ['tag1', 'tag2', 'tag3']}
78
- ```
79
-
80
- Finally, the `context` field in Cypress report will contain a stringified JSON array of tags meta-info along with other context information added by the user.
81
-
82
- Example of `context` field in the report (note - array contains both tags meta-info and user-added context info like video path; array is stringified by `mochawesome` reporter):
83
- ```json
84
- "context": "[\n {\n \"title\": \"tags\",\n \"value\": [\n \"graphql-api-upa\",\n \"upa\",\n \"custom-factor\",\n \"P1\",\n \"authentication\"\n ]\n },\n \"videos/graphQL.mfa.customFactor.cy.ts.mp4\"\n]",
85
- ```
86
- This `context` field will be parsed by `jahia-reporter` afterward to extract the tags and sync them to `TestRail`. If the `context` field doesn't contain tags in expected format, it will be ignored by `jahia-reporter` and labels in `TestRail` won't be updated.
87
-
88
-
89
- ## Best Practices
90
-
91
- 1. **Use consistent tag names** across your test suite
92
- 2. **Keep tag values simple** (lowercase, no spaces, use hyphens for multi-word tags)
93
- 3. **Avoid overtagging** — use a reasonable number of tags (3-5 per test)
94
- 4. **Combine categories** — mix priority, type, and feature tags for flexibility
95
- 5. **Use suite-level tags** for common characteristics (saves repetition)
96
- 6. **Add test-level tags** for exceptions or special cases
97
-
98
- ## Troubleshooting
99
-
100
- ### Tags not appearing in TestRail
101
- - Ensure `context.tag()` is called at the right scope (in `describe()` or `it()`)
102
- - Check that jahia-reporter is configured to sync tags to TestRail
103
- - Verify the test report is being generated and contains `context` attribute with tags
104
-
@@ -1,403 +0,0 @@
1
- # Cypress Logger Module
2
-
3
- ## Overview
4
-
5
- The Logger module is a helper utility designed to enhance Cypress test logging capabilities by providing structured log levels and decorating log messages with appropriate severity indicators. It enables developers to create more organized and filterable test output by categorizing log messages into different levels.
6
-
7
- This documentation also covers the testStep custom action, which provides structured test organization through foldable log groups.
8
-
9
- ## Features
10
-
11
- - **Multiple Log Levels**: Support for DEBUG and INFO logging levels, can easily be extended if required.
12
- - **Level-based Filtering**: Configure minimum log level to control output verbosity
13
- - **JSON Object Logging**: Specialized method for logging JSON objects
14
- - **Cypress Integration**: Seamless integration with Cypress logging system
15
- - **Chainable Interface**: Returns Cypress chainable objects for fluent test writing
16
- - **Environment Variable Control**: Persistent log level configuration across test runs
17
- - **Test Step Organization**: Foldable test steps for better test structure and readability.
18
-
19
- ## Log Levels and Test Steps
20
-
21
- The module supports two distinct logging levels with hierarchical filtering:
22
-
23
- ### Log.debug()
24
- - **Purpose**: Detailed diagnostic information for debugging and development
25
- - **Visibility**: Only shown when log level is set to DEBUG
26
- - **Use Case**: Verbose logging for troubleshooting complex test scenarios
27
-
28
- ### Log.info()
29
- - **Purpose**: General informational messages about test execution
30
- - **Visibility**: Shown when log level is set to INFO or DEBUG
31
- - **Use Case**: Standard test progress and status information
32
-
33
- ### cy.step()
34
- - **Purpose**: Group related test actions under foldable and self-descriptive step names
35
- - **Visibility**: Shown always
36
- - **Use Case**: Organize complex test scenarios and have self-documenting code
37
-
38
- ## Configuration
39
-
40
- ### Setting Log Level
41
-
42
- ```typescript
43
- import { Log } from '@jahia/cypress';
44
-
45
- // Set visibility to DEBUG level for verbose output
46
- Log.setLevel(Log.LEVEL.DEBUG);
47
-
48
- // Set visibility to INFO level for standard output (default configuration)
49
- Log.setLevel(Log.LEVEL.INFO);
50
- ```
51
-
52
- ## Usage
53
-
54
- ### Basic Logging
55
-
56
- ```typescript
57
- import { Log } from '@jahia/cypress';
58
-
59
- describe('Test Suite', () => {
60
- it('should demonstrate logging capabilities', () => {
61
- // Info level logging (always visible)
62
- Log.info('Starting test execution');
63
-
64
- // Debug level logging (only visible when DEBUG level is set)
65
- Log.debug('Detailed diagnostic information');
66
-
67
- // Chainable usage
68
- Log.info('Processing user data')
69
- .then(() => {
70
- // Continue with test logic
71
- cy.visit('/login');
72
- });
73
- });
74
- });
75
- ```
76
-
77
- ### JSON Object Logging
78
-
79
- ```typescript
80
- import { Log } from '@jahia/cypress';
81
-
82
- describe('API Tests', () => {
83
- it('should log API responses', () => {
84
- cy.request('/api/users').then((response) => {
85
- // Log response data at DEBUG level
86
- Log.json(Log.LEVEL.DEBUG, response.body);
87
-
88
- // Log summary at INFO level
89
- const summary = { status: response.status, count: response.body.length };
90
- Log.json(Log.LEVEL.INFO, summary);
91
- });
92
- });
93
- });
94
- ```
95
-
96
- ### Test Step Organization
97
-
98
- The test step action creates foldable, hierarchical log groups to organize complex test scenarios:
99
-
100
- ```typescript
101
- describe('User Registration Flow', () => {
102
- it('should register a new user successfully', () => {
103
- cy.step('Navigate to registration page', () => {
104
- cy.visit('/register');
105
- cy.url().should('include', '/register');
106
- });
107
-
108
- cy.step('Fill out registration form', () => {
109
- cy.get('[data-testid="first-name"]').type('John');
110
- cy.get('[data-testid="last-name"]').type('Doe');
111
- cy.get('[data-testid="email"]').type('john.doe@example.com');
112
- cy.get('[data-testid="password"]').type('SecurePassword123!');
113
- cy.get('[data-testid="confirm-password"]').type('SecurePassword123!');
114
- });
115
-
116
- cy.step('Submit registration and verify success', () => {
117
- cy.get('[data-testid="register-button"]').click();
118
- cy.get('[data-testid="success-message"]').should('be.visible');
119
- cy.url().should('include', '/welcome');
120
- });
121
- });
122
- });
123
- ```
124
-
125
- #### Test Step Features
126
-
127
- - **Hierarchical Organization**: Group related test actions under descriptive step names
128
- - **Foldable Interface**: Steps can be collapsed/expanded in Cypress Test Runner
129
- - **Clean Log Output**: Reduces clutter by organizing actions into logical groups
130
- - **Better Debugging**: Easier to identify which step failed during test execution
131
- - **Documentation**: Steps serve as living documentation of test flow
132
-
133
- ## Output Format
134
-
135
- ### Console Display
136
-
137
- The logger decorates messages with level indicators in the Cypress runner:
138
-
139
- ```
140
- [ INFO ] Starting test execution
141
- [ DEBUG ] Detailed diagnostic information
142
- [ INFO ] {
143
- "status": 200,
144
- "data": {
145
- "users": 5
146
- }
147
- }
148
- ```
149
-
150
- ### Level Filtering Behavior
151
-
152
- | Set Level | INFO Messages | DEBUG Messages |
153
- |-----------|---------------|----------------|
154
- | INFO | ✅ Visible | ❌ Hidden |
155
- | DEBUG | ✅ Visible | ✅ Visible |
156
-
157
- ## Best Practices
158
-
159
- ### Development Environment
160
- - Use `DEBUG` level during active development for maximum visibility
161
- - Log detailed state information and intermediate values
162
- - Include context-rich debug messages for complex operations
163
-
164
- ```typescript
165
- // Good: Detailed development logging
166
- Log.debug('User authentication state: authenticated=true, role=admin');
167
- Log.debug('Form validation results', validationResults);
168
- ```
169
-
170
- ### CI/CD Environment
171
- - Use `INFO` level for cleaner output in automated environments
172
- - Focus on test milestones and important status updates
173
- - Avoid excessive logging that could impact performance
174
-
175
- ```typescript
176
- // Good: Concise CI/CD logging
177
- Log.info('Test suite: User Management - Started');
178
- Log.info('Authentication tests completed successfully');
179
- ```
180
-
181
- ### Test Organization with Steps
182
- - Use meaningful step descriptions that explain the intent
183
- - Group related actions within logical steps
184
- - Keep steps focused on a single responsibility
185
- - Combine with logging for comprehensive test documentation
186
-
187
- ```typescript
188
- // Good: Well-organized test with steps and logging
189
- describe('E-commerce Checkout', () => {
190
- it('should complete purchase flow', () => {
191
- cy.step('Add products to cart', () => {
192
- Log.info('Starting product selection');
193
- cy.visit('/products');
194
- cy.get('[data-testid="product-1"]').click();
195
- cy.get('[data-testid="add-to-cart"]').click();
196
- Log.debug('Product added to cart successfully');
197
- });
198
-
199
- cy.step('Proceed to checkout', () => {
200
- Log.info('Initiating checkout process');
201
- cy.get('[data-testid="cart-icon"]').click();
202
- cy.get('[data-testid="checkout-button"]').click();
203
- Log.debug('Navigated to checkout page');
204
- });
205
-
206
- cy.step('Complete payment', () => {
207
- Log.info('Processing payment information');
208
- // Payment form interactions
209
- Log.info('Payment completed successfully');
210
- });
211
- });
212
- });
213
- ```
214
-
215
- ## Integration Examples
216
-
217
- ### Page Object Pattern
218
-
219
- ```typescript
220
- class LoginPage {
221
- visit() {
222
- Log.info('Navigating to login page');
223
- return cy.visit('/login');
224
- }
225
-
226
- login(username: string, password: string) {
227
- Log.debug(`Attempting login for user: ${username}`);
228
- cy.get('[data-testid="username"]').type(username);
229
- cy.get('[data-testid="password"]').type(password);
230
- cy.get('[data-testid="login-button"]').click();
231
- Log.info('Login form submitted');
232
- }
233
- }
234
- ```
235
-
236
- ### Complex Workflows with Nested Steps
237
-
238
- ```typescript
239
- describe('Multi-step Workflow', () => {
240
- it('should handle complex user journey', () => {
241
- cy.step('User Authentication', () => {
242
- cy.step('Navigate to login', () => {
243
- cy.visit('/login');
244
- Log.debug('Login page loaded');
245
- });
246
-
247
- cy.step('Enter credentials', () => {
248
- cy.get('[data-testid="username"]').type('testuser');
249
- cy.get('[data-testid="password"]').type('password');
250
- Log.debug('Credentials entered');
251
- });
252
-
253
- cy.step('Submit login form', () => {
254
- cy.get('[data-testid="login-button"]').click();
255
- Log.info('User logged in successfully');
256
- });
257
- });
258
-
259
- cy.step('Product Selection', () => {
260
- // Product selection steps
261
- Log.info('Product selection completed');
262
- });
263
-
264
- cy.step('Checkout Process', () => {
265
- // Checkout steps
266
- Log.info('Checkout process completed');
267
- });
268
- });
269
- });
270
- ```
271
-
272
- ### Test Hooks
273
-
274
- ```typescript
275
- describe('Feature Tests', () => {
276
- beforeEach(() => {
277
- cy.step('Test Environment Setup', () => {
278
- Log.debug('Setting up test environment');
279
- // Setup code
280
- });
281
- });
282
-
283
- afterEach(() => {
284
- cy.step('Test Environment Cleanup', () => {
285
- Log.debug('Cleaning up test environment');
286
- // Cleanup code
287
- });
288
- });
289
- });
290
- ```
291
-
292
- ## Performance Considerations
293
-
294
- ### Log Level Impact
295
-
296
- - **DEBUG Level**: Higher overhead due to increased log volume
297
- - **INFO Level**: Minimal overhead with essential information only
298
- - **JSON Logging**: Additional serialization overhead for large objects
299
-
300
- ### Optimization Tips
301
-
302
- 1. Use appropriate log levels for different environments
303
- 2. Avoid logging large objects in production environments
304
- 3. Consider conditional logging for performance-critical tests
305
- 4. Use test steps judiciously - too many nested steps can impact readability
306
-
307
- ## API Reference
308
-
309
- ### Logger Methods
310
-
311
- | Method | Parameters | Return Type | Description |
312
- |--------|------------|-------------|-------------|
313
- | `info(message)` | `string` | `Cypress.Chainable` | Logs INFO level message |
314
- | `debug(message)` | `string` | `Cypress.Chainable` | Logs DEBUG level message |
315
- | `json(level, object)` | `LEVEL`, `string` | `Cypress.Chainable` | Logs formatted JSON object |
316
- | `setVerbosity(level)` | `LEVEL` | `void` | Sets minimum visible log level |
317
-
318
- ### Test Step Methods
319
-
320
- | Method | Parameters | Return Type | Description |
321
- |--------|------------|-------------|-------------|
322
- | `cy.step(message, func)` | `string`, `() => void` | `void` | Creates foldable test step group |
323
-
324
- ### Enums
325
-
326
- | Enum | Values | Description |
327
- |------|--------|-------------|
328
- | `LEVEL` | `DEBUG (0)`, `INFO (1)` | Available logging levels |
329
-
330
- ### TypeScript Declarations
331
-
332
- The testStep module extends the global Cypress interface:
333
-
334
- ```typescript
335
- declare global {
336
- namespace Cypress {
337
- interface Chainable<Subject> {
338
- step(message: string, func: () => void): void;
339
- }
340
- }
341
- }
342
- ```
343
-
344
- ## Migration Guide
345
-
346
- ### From Console Logging
347
-
348
- **Before:**
349
- ```typescript
350
- console.log('Test started');
351
- console.debug('Detailed information');
352
- ```
353
-
354
- **After:**
355
- ```typescript
356
- Log.info('Test started');
357
- Log.debug('Detailed information');
358
- ```
359
-
360
- ### From Cypress.log()
361
-
362
- **Before:**
363
- ```typescript
364
- Cypress.log({ message: 'Custom message' });
365
- ```
366
-
367
- **After:**
368
- ```typescript
369
- Log.info('Custom message');
370
- ```
371
-
372
- ### From Unstructured Tests to Steps
373
-
374
- **Before:**
375
- ```typescript
376
- it('should complete user flow', () => {
377
- cy.visit('/login');
378
- cy.get('[data-testid="username"]').type('user');
379
- cy.get('[data-testid="password"]').type('pass');
380
- cy.get('[data-testid="login-button"]').click();
381
- cy.visit('/products');
382
- cy.get('[data-testid="product-1"]').click();
383
- cy.get('[data-testid="add-to-cart"]').click();
384
- });
385
- ```
386
-
387
- **After:**
388
- ```typescript
389
- it('should complete user flow', () => {
390
- cy.step('Login to application', () => {
391
- cy.visit('/login');
392
- cy.get('[data-testid="username"]').type('user');
393
- cy.get('[data-testid="password"]').type('pass');
394
- cy.get('[data-testid="login-button"]').click();
395
- });
396
-
397
- cy.step('Add product to cart', () => {
398
- cy.visit('/products');
399
- cy.get('[data-testid="product-1"]').click();
400
- cy.get('[data-testid="add-to-cart"]').click();
401
- });
402
- });
403
- ```