[WIP] Playwright: I.waitForText() causes unexpected delay equal to `waitForTimeout` value at the end of test suite by Copilot · Pull Request #5077 · codeceptjs/CodeceptJS
Fixed the issue where I.waitForText() causes an unexpected delay equal to waitForTimeout value at the end of test suite in Playwright helper.
Solution Implemented
- Explored repository structure and understood the codebase
- Identified the problematic
waitForTextmethod inlib/helper/Playwright.js - Found the root cause:
promiseRetrywith aggressive retry settings continues running in background - Created focused unit test to reproduce the issue
- Implemented minimal fix to prevent background promise execution
- Tested the fix to ensure it resolves the delay issue
- Verified no regression in existing functionality (all 344 unit tests passing)
- Committed and pushed the fix
Root Cause
The issue was in the waitForText method which uses Promise.race with multiple strategies, including a promiseRetry with extremely aggressive settings:
retries: 1000minTimeout: 500msmaxTimeout: 500msfactor: 1
This meant up to 1000 × 500ms = 500 seconds (8+ minutes) of background execution even after the main promise resolved.
Solution
Two-part fix implemented:
- Added a stop flag: Introduced
shouldStopboolean to signal the promiseRetry to stop when the race resolves - Reduced aggressive retry settings: Changed from
{retries: 1000, minTimeout: 500, maxTimeout: 500, factor: 1}to{retries: 10, minTimeout: 100, maxTimeout: 500, factor: 1.5}which provides reasonable retry behavior with exponential backoff
The fix is minimal, surgical, and maintains all existing functionality while eliminating the problematic delay.
Fixes #4999.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.