keep password editor clicks stable across native scrolling

This commit is contained in:
cieanyau committed 2026-11-07 02:44:57 +08:00
1 parent 27d240b41b
commit 836486cfd8
1 file changed
+6 -12
+6 -12
View File
@@ -141,21 +141,15 @@ for (const width of [320, 390]) {
await field.fill(password); await field.fill(password);
await field.press("End"); await field.press("End");
const point = await field.evaluate((input) => { const point = await field.evaluate((input) => {
const rect = input.getBoundingClientRect();
const style = getComputedStyle(input); const style = getComputedStyle(input);
// 长密码滚到末端;点击实际文字编辑区末端,而不是假设按钮应有多少padding。 // 读取相对输入框 padding box 的编辑区末端;locator 点击会等滚动/布局稳定,
// 不把测量后的绝对坐标误用于已自然滚动的页面。
return { return {
x: x:
style.direction === "rtl" style.direction === "rtl"
? rect.left + ? parseFloat(style.paddingLeft) + 1
parseFloat(style.borderLeftWidth) + : input.clientWidth - parseFloat(style.paddingRight) - 1,
parseFloat(style.paddingLeft) + y: input.clientHeight / 2,
1
: rect.right -
parseFloat(style.borderRightWidth) -
parseFloat(style.paddingRight) -
1,
y: rect.top + rect.height / 2,
overflowing: input.scrollWidth > input.clientWidth, overflowing: input.scrollWidth > input.clientWidth,
}; };
}); });
@@ -164,7 +158,7 @@ for (const width of [320, 390]) {
true, true,
"Exercise a scrolled long password", "Exercise a scrolled long password",
); );
await page.mouse.click(point.x, point.y); await field.click({ position: { x: point.x, y: point.y } });
assert.equal( assert.equal(
await field.getAttribute("type"), await field.getAttribute("type"),
"password", "password",