Unverified 提交 9b4d81a3 authored 作者: wwwillchen-bot's avatar wwwillchen-bot 提交者: GitHub

Improve SecurityReview E2E test wait logic (#2696)

## Summary - Fixed flaky SecurityReview E2E test by waiting for the "Running Security Review..." button state to appear and disappear, rather than just waiting for the original button to hide - Added documentation to `rules/e2e-testing.md` with a pattern for handling button state transitions in E2E tests ## Test plan - Run the SecurityReview E2E test multiple times to verify it's no longer flaky - `npm run e2e -- e2e-tests/security-review.spec.ts --repeat-each=10` 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2696" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> --------- Co-authored-by: 's avatarWill Chen <willchen90@gmail.com> Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
上级 6d85c7f8
......@@ -18,7 +18,13 @@ export class SecurityReview {
.getByRole("button", { name: "Run Security Review" })
.first();
await runSecurityReviewButton.click();
await runSecurityReviewButton.waitFor({ state: "hidden" });
// Wait for the "Running Security Review..." button to appear and then disappear
// This indicates the security review has completed
const runningButton = this.page.getByRole("button", {
name: "Running Security Review...",
});
await runningButton.waitFor({ state: "visible" });
await runningButton.waitFor({ state: "hidden" });
await this.chatActions.waitForChatCompletion();
}
......
......@@ -104,6 +104,32 @@ When adding new test server URLs, update **both** the test fixtures (`e2e-tests/
- **Navigation to tabs**: Use `await expect(link).toBeVisible({ timeout: Timeout.EXTRA_LONG })` before clicking tab links (especially in `goToAppsTab()`). Electron sidebar links can take time to render during app initialization.
- **Confirming flakiness**: Use `PLAYWRIGHT_RETRIES=0 PLAYWRIGHT_HTML_OPEN=never npm run e2e -- e2e-tests/<spec> --repeat-each=10` to reproduce flaky tests. `PLAYWRIGHT_RETRIES=0` is critical — CI defaults to 2 retries, hiding flakiness.
## Waiting for button state transitions
When clicking a button that triggers an async operation and changes its text/state (e.g., "Run Security Review" → "Running Security Review..."), wait for the loading state to appear and disappear rather than just waiting for the original button to be hidden:
```ts
// Wrong: waiting for original button to be hidden may race
const button = page.getByRole("button", { name: "Run Security Review" });
await button.click();
await button.waitFor({ state: "hidden" }); // Unreliable
// Correct: wait for loading state to appear then disappear
const button = page.getByRole("button", { name: "Run Security Review" });
await button.click();
const loadingButton = page.getByRole("button", {
name: "Running Security Review...",
});
await loadingButton.waitFor({ state: "visible" });
await loadingButton.waitFor({ state: "hidden" });
```
This pattern provides a more reliable signal that the async operation has completed, because:
1. It confirms the operation actually started (loading state appeared)
2. It confirms the operation finished (loading state disappeared)
3. It avoids race conditions where the button might briefly be in the DOM but not yet updated
## E2E test fixtures with .dyad directories
When adding E2E test fixtures that need a `.dyad` directory for testing:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论