2020-08-19 05:13:40 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-10-23 19:31:30 +03:00
|
|
|
import type { Page, Frame, ElementHandle } from '@playwright/test';
|
2022-03-26 02:05:50 +03:00
|
|
|
import { contextTest as it, expect } from '../config/browserTest';
|
|
|
|
import { attachFrame } from '../config/utils';
|
2023-10-23 19:31:30 +03:00
|
|
|
import type { TestServer } from '../config/testserver';
|
2020-08-19 05:13:40 +03:00
|
|
|
|
2023-10-23 19:31:30 +03:00
|
|
|
async function checkSlowMo(toImpl: (api: any) => any, page: Page, task: () => Promise<unknown>) {
|
2020-08-19 05:13:40 +03:00
|
|
|
let didSlowMo = false;
|
2022-11-22 22:06:45 +03:00
|
|
|
const contextDebugger = toImpl(page.context()).debugger();
|
|
|
|
contextDebugger._slowMo = 100;
|
|
|
|
const orig = contextDebugger._doSlowMo;
|
|
|
|
contextDebugger._doSlowMo = async () => {
|
2020-08-19 05:13:40 +03:00
|
|
|
if (didSlowMo)
|
|
|
|
throw new Error('already did slowmo');
|
|
|
|
await new Promise(x => setTimeout(x, 100));
|
|
|
|
didSlowMo = true;
|
2022-11-22 22:06:45 +03:00
|
|
|
return orig.call(contextDebugger);
|
2020-08-28 14:20:29 +03:00
|
|
|
};
|
2020-08-19 05:13:40 +03:00
|
|
|
await task();
|
|
|
|
expect(!!didSlowMo).toBe(true);
|
|
|
|
}
|
|
|
|
|
2023-10-23 19:31:30 +03:00
|
|
|
async function checkPageSlowMo(toImpl: (api: any) => any, page: Page, task: () => Promise<unknown>) {
|
2020-08-19 05:13:40 +03:00
|
|
|
await page.setContent(`
|
|
|
|
<button>a</button>
|
|
|
|
<input type="checkbox" class="check">
|
|
|
|
<input type="checkbox" checked=true class="uncheck">
|
|
|
|
<input class="fill">
|
|
|
|
<select>
|
|
|
|
<option>foo</option>
|
|
|
|
</select>
|
|
|
|
<input type="file" class="file">
|
2020-08-28 14:20:29 +03:00
|
|
|
`);
|
2020-08-19 05:13:40 +03:00
|
|
|
await checkSlowMo(toImpl, page, task);
|
|
|
|
}
|
2021-04-05 05:32:14 +03:00
|
|
|
|
|
|
|
it.describe('slowMo', () => {
|
2021-04-30 23:26:13 +03:00
|
|
|
it.skip(({ mode }) => mode !== 'default');
|
2021-04-05 05:32:14 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo check', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.check('.check'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo click', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.click('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo dblclick', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.dblclick('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo dispatchEvent', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.dispatchEvent('button', 'click'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo fill', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.fill('.fill', 'foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo focus', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.focus('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo goto', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.goto('about:blank'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo hover', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.hover('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo press', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.press('button', 'Enter'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo reload', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.reload());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo selectOption', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.selectOption('select', 'foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo setInputFiles', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.setInputFiles('.file', []));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo type', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.type('.fill', 'a'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Page SlowMo uncheck', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkPageSlowMo(toImpl, page, () => page.uncheck('.uncheck'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo check', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.check('.check'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo click', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.click('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo dblclick', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.dblclick('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo dispatchEvent', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.dispatchEvent('button', 'click'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo fill', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.fill('.fill', 'foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo focus', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.focus('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo goto', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.goto('about:blank'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo hover', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.hover('button'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo press', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.press('button', 'Enter'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo selectOption', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.selectOption('select', 'foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo setInputFiles', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.setInputFiles('.file', []));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo type', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.type('.fill', 'a'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('Frame SlowMo uncheck', async ({ page, server, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkFrameSlowMo(toImpl, page, server, frame => frame.uncheck('.uncheck'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo check', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, '.check', element => element.check());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo click', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.click());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo dblclick', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.dblclick());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo dispatchEvent', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.dispatchEvent('click'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo fill', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, '.fill', element => element.fill('foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo focus', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.focus());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo hover', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.hover());
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo press', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'button', element => element.press('Enter'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo selectOption', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, 'select', element => element.selectOption('foo'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo setInputFiles', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, '.file', element => element.setInputFiles([]));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo type', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, '.fill', element => element.type('a'));
|
|
|
|
});
|
2021-09-27 19:58:08 +03:00
|
|
|
it('ElementHandle SlowMo uncheck', async ({ page, toImpl }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
await checkElementSlowMo(toImpl, page, '.uncheck', element => element.uncheck());
|
|
|
|
});
|
2020-08-19 05:13:40 +03:00
|
|
|
});
|
|
|
|
|
2023-10-23 19:31:30 +03:00
|
|
|
async function checkFrameSlowMo(toImpl: (api: any) => any, page: Page, server: TestServer, task: (frame: Frame) => Promise<unknown>) {
|
2020-08-19 05:13:40 +03:00
|
|
|
const frame = await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
|
|
|
await frame.setContent(`
|
|
|
|
<button>a</button>
|
|
|
|
<input type="checkbox" class="check">
|
|
|
|
<input type="checkbox" checked=true class="uncheck">
|
|
|
|
<input class="fill">
|
|
|
|
<select>
|
|
|
|
<option>foo</option>
|
|
|
|
</select>
|
|
|
|
<input type="file" class="file">
|
2020-08-28 14:20:29 +03:00
|
|
|
`);
|
2020-08-19 05:13:40 +03:00
|
|
|
await checkSlowMo(toImpl, page, task.bind(null, frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-23 19:31:30 +03:00
|
|
|
async function checkElementSlowMo(toImpl: (api: any) => any, page: Page, selector: string, task: (element: ElementHandle<HTMLElement>) => Promise<unknown>) {
|
2020-08-19 05:13:40 +03:00
|
|
|
await page.setContent(`
|
|
|
|
<button>a</button>
|
|
|
|
<input type="checkbox" class="check">
|
|
|
|
<input type="checkbox" checked=true class="uncheck">
|
|
|
|
<input class="fill">
|
|
|
|
<select>
|
|
|
|
<option>foo</option>
|
|
|
|
</select>
|
|
|
|
<input type="file" class="file">
|
2020-08-28 14:20:29 +03:00
|
|
|
`);
|
2023-10-23 19:31:30 +03:00
|
|
|
const element = (await page.$(selector)) as ElementHandle<HTMLElement>;
|
2020-08-19 05:13:40 +03:00
|
|
|
await checkSlowMo(toImpl, page, task.bind(null, element));
|
|
|
|
}
|