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> <title>Textarea test</title>
</head> </head>
<body> <body>
<textarea></textarea> <textarea rows="5" cols="20"></textarea>
<script src='mouse-helper.js'></script> <script src='mouse-helper.js'></script>
<script> <script>
globalThis.result = ''; globalThis.result = '';

View File

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