chore: deflake textarea test (#10983)

This commit is contained in:
jrandolf 2023-09-21 22:50:36 +02:00 committed by GitHub
parent 02a9917d16
commit 464386ecf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 15 deletions

View File

@ -4,7 +4,7 @@
<title>Textarea test</title>
</head>
<body>
<textarea></textarea>
<textarea rows="5" cols="20"></textarea>
<script src='mouse-helper.js'></script>
<script>
globalThis.result = '';

View File

@ -97,29 +97,30 @@ describe('Mouse', function () {
it('should select the text with mouse', async () => {
const {page, server} = await getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
const text =
"This is the text that we are going to try to select. Let's see how it goes.";
await page.goto(`${server.PREFIX}/input/textarea.html`);
await page.focus('textarea');
await page.keyboard.type(text);
// Firefox needs an extra frame here after typing or it will fail to set the scrollTop
await page.evaluate(() => {
return new Promise(requestAnimationFrame);
});
await page.evaluate(() => {
return (document.querySelector('textarea')!.scrollTop = 0);
});
using handle = await page
.locator('textarea')
.filterHandle(async element => {
return await element.evaluate((element, text) => {
return element.value === text;
}, text);
})
.waitHandle();
const {x, y} = await page.evaluate(dimensions);
await page.mouse.move(x + 2, y + 2);
await page.mouse.down();
await page.mouse.move(100, 100);
await page.mouse.up();
expect(
await page.evaluate(() => {
const textarea = document.querySelector('textarea')!;
return textarea.value.substring(
textarea.selectionStart,
textarea.selectionEnd
await handle.evaluate(element => {
return element.value.substring(
element.selectionStart,
element.selectionEnd
);
})
).toBe(text);