Skip to content

test(e2e): Centralize cookie banner handling in global setup and cleanup test code#5333

Closed
zoobestik wants to merge 24 commits intomasterfrom
e2e-arts
Closed

test(e2e): Centralize cookie banner handling in global setup and cleanup test code#5333
zoobestik wants to merge 24 commits intomasterfrom
e2e-arts

Conversation

@zoobestik
Copy link
Collaborator

@zoobestik zoobestik commented Jan 26, 2026

The main changes include a new global setup for managing cookie consent on production, a refactor of banner dismissal logic, updates to Playwright configuration and dependencies, and cleanup of test code to remove redundant cookie banner interactions.

Test Infrastructure Improvements

  • Added a new global-setup.ts script for Playwright that automatically handles cookie banner acceptance and storage state creation for production environments. This ensures tests run without manual banner interaction and maintains consistent state across test runs.
  • Added playwright-teamcity-reporter as a dependency in package.json to support enhanced reporting in CI environments.
🖼️ Teamcity Test Report Screenshot 2026-01-26 at 21 00 53

Cookie Banner Handling Refactor

  • Refactored the external banner closing logic: replaced the old closeCookiesConsentBanner function with a new closeExternalBanners that only dismisses development overlays, and moved cookie banner handling for production to global setup. Updated all test files to use the new approach and removed redundant cookie banner interactions from production tests.
  • Added a dedicated test for cookie banner functionality in production, ensuring the banner is visible, closeable, and sets cookies correctly.

Test Logic Enhancements

  • Improved URL matching logic in server-side use case tests for robustness against redirects.
  • Updated test setup functions to remove unused parameters and streamline initialization.
  • Added logic to skip certain tests on production environments to avoid false positives.

@zoobestik zoobestik force-pushed the e2e-arts branch 2 times, most recently from 29b4bbb to c5ba157 Compare January 26, 2026 21:57
@zoobestik zoobestik requested a review from a team as a code owner January 26, 2026 22:20
@zoobestik zoobestik marked this pull request as draft January 26, 2026 22:43
@zoobestik zoobestik force-pushed the e2e-arts branch 4 times, most recently from ba5acba to dac5cbe Compare January 27, 2026 00:42
@zoobestik zoobestik marked this pull request as ready for review January 27, 2026 14:27
/reports*
/data/page_views_map.json
test-results
test/storage-state.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is created each time the tests run, see shared account in all tests

const test = base.extend({
context: async function makeCleanContext({ browser }, use) {
const context = await browser.newContext({
storageState: undefined
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test, run without shared account for testing cookie banner on production.
For skipping tests on production, use snippet:
test.skip(({ baseURL }) => isProduction(baseURL), '...');

It works for any level: module, describe, test.

expect(await link1.textContent()).toBe('Free IntelliJ IDEA Ultimate license ↗');

const link2 = toolingSectionInfo.locator('a[href="https://play.kotlinlang.org/"]');
const link2 = toolingSectionInfo.locator('a[href^="https://play.kotlinlang.org/"]');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In production, concatenated extra args:
Image

@nikpachoo nikpachoo requested a review from solarday January 30, 2026 10:38
Copy link
Collaborator

@nikpachoo nikpachoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

expect(await link4.textContent()).toBe('Code With Me ↗');

const link5 = toolingSectionInfo.locator('a[href="https://hyperskill.org/tracks?category=4&utm_source=jbkotlin_hs&utm_medium=referral&utm_campaign=kotlinlang-education&utm_content=button_1&utm_term=22.03.23&"]');
const link5 = toolingSectionInfo.locator('a[href^="https://hyperskill.org/tracks?category=4&utm_source=jbkotlin_hs&utm_medium=referral&utm_campaign=kotlinlang-education&utm_content=button_1&utm_term=22.03.23"]');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT, maybe it's better to omit the UTM tags?

Suggested change
const link5 = toolingSectionInfo.locator('a[href^="https://hyperskill.org/tracks?category=4&utm_source=jbkotlin_hs&utm_medium=referral&utm_campaign=kotlinlang-education&utm_content=button_1&utm_term=22.03.23"]');
const link5 = toolingSectionInfo.locator('a[href^="https://hyperskill.org/tracks?category=4"]');

- Add global setup for Playwright tests with cookie banner functionality.
- Simplify `closeExternalBanners` utility for better production handling.
- Skip cookie banner tests in non-production environments.
- Update test configurations and remove unnecessary consent banner logic.
- Adjust case-study and navigation link verifications.
- Amend storage state usage in Playwright settings.
# Conflicts:
#	.gitignore
- Add `playwright-teamcity-reporter@1.0.5` to dependencies.
- Update Playwright configuration to use `playwright-teamcity-reporter` as the default reporter in CI mode.
- Replace obsolete dependencies in E2E tests with simplified `BuildSitePages`.
- Update artifact rules to consolidate output in `dist` directory.
- Simplify Dockerfile by removing unused `libs` and `_assets` copies.
- Upgrade Playwright to version 1.57 in Docker and dependencies.
- Replace custom Dockerfiles with official lightweight images.
- Simplify `docker-compose-e2e-statics.yml` by using shared volumes and updated networks.
- Refactor `global-setup.ts` to ensure consistent storage state initialization.
- Adjust `closeExternalBanners` logic to improve development checks.
- Fix test `beforeEach` hooks ordering in education-related specs for consistency.
- Add error handling for `waitForLoadState` to improve debugging of failed customer link loads.
- Remove unused `isProduction` import from test utilities.
…spec.ts

- Add `scrollIntoViewIfNeeded` to ensure visibility before hovering customer links.
- Add context-aware `test.step` usage to enhance customer link verification flow.
- Refactor `scrollIntoViewIfNeeded` and `click` logic within `isVisible` check for clarity.
- Update `waitForLoadState` with `domcontentloaded` and timeout for better performance.
- Add `try-catch` block to handle invalid URL parsing gracefully.
- Update development environment check to validate `baseURL` and exclude `localhost`.
- Replace absolute URLs with relative path checks across multiple test specs.
- Update `solutions-tab.spec.ts`, `main-page-buttons.spec.ts`, and `landings.spec.ts` to improve maintainability and alignment with production setup.
- across `solutions-tab.spec.ts`, `grammar.spec.ts`, and `landings.spec.ts`.
- Remove unused `baseURL` parameter from tests for improved clarity and maintenance.
- Correct `isDevelopment` utility function to properly identify `localhost` as a development environment.
- Correct `isDevelopment` utility function to properly identify `localhost` as a development environment.
- Add `data-test` attributes to various components in `education`, replacing CSS-based selectors for improved test reliability.
- Remove `closeExternalBanners` utility and its usage across tests as it is no longer needed.
- Update Playwright specs (`courses.spec.ts`, `education.spec.ts`) to use `data-test` attributes.
- Refactor relative path navigation in tests for `CoursesPage` and `TeachPage` initialization.
- Eliminate unnecessary `waitForTimeout` calls for improved test performance in `teach.spec.ts`.
- Refactor `playwright.config.ts` to enhance `isDevelopment` logic, ensuring proper handling of CI and local development environments.
- Replace outdated CSS file references with updated paths (`hide-sticky-banner.css` → `sticky-navigation.css`) across E2E tests.
- Improve `checkScreenshot` utility to handle lazy-loaded images by setting `loading` to `eager` and `decoding` to `sync`.
- Extend `checkScreenshot` to support additional `stylePath` options for more flexible screenshot styling.
- Refactor `global-setup.ts` to generalize banner handling (`closeConsentBanner` → `closeProductionElements`) and ensure DOM readiness.
- Consolidate `isDevelopment` logic in `playwright.config.ts` for streamlined configuration management.
- Remove obsolete `utils.ts` in `e2e` and move relevant utilities to the main `utils.ts` file for centralized management.
- Replace outdated `sticky-navigation.css` references with updated paths (`test/snapshots/assets/sticky-navigation.css`) across multiple specs.
- Add `skipProduction` and `skipNonProduction` utilities to replace inline `test.skip` calls, improving readability and consistency.
- Refactor `checkFullPageScreenshot` and `getElementScreenshotWithPadding` functionality for enhanced screenshot handling.
- Simplify logic in production-related tests (`cookie-banner.spec.ts`, `landings.spec.ts`) with new utilities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants