Skip to content

Commit 09c0958

Browse files
committed
fix(tests): wait for animation to complete
Otherwise we observe subtle differences in the captured image.
1 parent eeeecf6 commit 09c0958

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

weblate_web/tests_e2e/test_donation.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,49 @@ def assert_no_server_error(page: Page) -> None:
4040
assert not page.locator("text=Internal Server Error").is_visible()
4141

4242

43+
def wait_for_reward_animation(page: Page) -> None:
44+
"""Wait for donation reward card transitions to settle."""
45+
page.evaluate(
46+
"""
47+
() => new Promise((resolve) => {
48+
const rewards = document.querySelector(".rewards");
49+
if (!rewards) {
50+
resolve();
51+
return;
52+
}
53+
54+
let resolved = false;
55+
const finish = () => {
56+
if (resolved) {
57+
return;
58+
}
59+
resolved = true;
60+
requestAnimationFrame(() => requestAnimationFrame(resolve));
61+
};
62+
63+
requestAnimationFrame(() => {
64+
const animations = rewards
65+
.getAnimations({ subtree: true })
66+
.filter((animation) =>
67+
["pending", "running"].includes(animation.playState),
68+
);
69+
if (!animations.length) {
70+
finish();
71+
return;
72+
}
73+
Promise.allSettled(
74+
animations.map((animation) => animation.finished),
75+
).then(finish);
76+
window.setTimeout(finish, 1000);
77+
});
78+
})
79+
""",
80+
)
81+
82+
4383
def capture_step(page: Page, name: str) -> None:
4484
"""Capture a full-page screenshot for important donation flow steps."""
85+
wait_for_reward_animation(page)
4586
page.screenshot(path=f"test-results/donation-{name}.png", full_page=True)
4687

4788

0 commit comments

Comments
 (0)