Skip to content

Conversation

@Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Jun 26, 2025

Description

Fixes #237

Implements a new retry logic into page Utils to address flakiness issues with Playwright operations like page.goto, page.waitForFunction, page.waitForLoadState, and locator.click.

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

What was tested

npm run test:smoke

How to test

npm run test:smoke

Technical description

Problem Addressed

E2E tests were experiencing flakiness due to unreliable network conditions, slow page loads, and timing issues with element interactions. Common failures included:

  • Navigation timeouts with page.goto()
  • Element interaction failures with locator.click()
  • Race conditions with page.waitForLoadState()

Solution

This PR introduces a comprehensive retry mechanism that automatically retries flaky operations with configurable options, improving test reliability without requiring manual intervention.

How to Use

Basic Usage

// Wrap any flaky operation with retry logic
await withRetry(async () => {
    await this.page.goto('/admin');
    await this.page.locator('#submit').click();
}, {
    maxAttempts: 3,
    delay: 2000
});

Documentation

This pull request introduces a retry utility to improve the reliability of Playwright tests and integrates it into various test steps and utility methods. The most important changes include adding the retry-helper.ts module, refactoring test steps to use the retry logic, and updating utility methods for better error handling and retries.

Retry Utility Implementation:

  • utils/retry-helper.ts: Added a new module retry-helper.ts that provides a withRetry function for executing operations with retry logic, including configurable options like maximum attempts, delay, exponential backoff, and custom retry conditions. Also introduced common retry conditions such as networkErrors and elementErrors.

Integration of Retry Logic in Test Steps:

  • src/support/steps/general.ts: Refactored several test steps (plugin is activated, I go to {string}, I visit {string}, and I click on {string}) to use the withRetry utility for handling flaky operations. Added retry configurations with appropriate conditions and delays for each step. [1] [2]

Updates to Utility Methods:

  • utils/page-utils.ts: Updated the visitPage and saveSettings methods to include retry logic using the withRetry utility. Enhanced error handling for network and element-related issues, ensuring operations are retried as needed. [1] [2]

Dependency Updates:

  • src/support/steps/general.ts and utils/page-utils.ts: Imported withRetry and RetryConditions from the new retry-helper.ts module to enable retry functionality in test steps and utility methods. [1] [2]

New dependencies

None

Risks

None

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Copilot AI review requested due to automatic review settings June 26, 2025 03:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a retry utility to improve the reliability of flaky Playwright operations by automatically retrying navigation and interaction steps. Key changes include:

  • Adding the new retry-helper module with the withRetry function and predefined RetryConditions.
  • Refactoring page navigation and settings methods in utils/page-utils.ts to incorporate retry logic.
  • Updating test steps in src/support/steps/general.ts to use the retry logic for plugin activation, page visits, and element clicks.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
utils/retry-helper.ts Added a new retry utility module with withRetry and common retry conditions.
utils/page-utils.ts Updated visitPage and saveSettings methods to use the new retry logic.
src/support/steps/general.ts Refactored test step implementations to include retry logic in flaky operations.
Comments suppressed due to low confidence (2)

utils/retry-helper.ts:8

  • [nitpick] Consider renaming the property 'backoff' to 'useExponentialBackoff' to improve clarity regarding its purpose.
  backoff?: boolean; // Exponential backoff

src/support/steps/general.ts:228

  • [nitpick] It would be beneficial to add a brief comment explaining the fixed wait time after the click action to clarify its purpose for future maintainability.
        await this.page.waitForTimeout(500);

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.

random "And plugin is activated" failing

2 participants