feat(emulation): emulate a mouse pointer in headless chrome (#3922)

This commit is contained in:
Joel Einbinder 2020-09-21 08:20:05 -07:00 committed by GitHub
parent c2d9af8618
commit 75edc61531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -120,7 +120,8 @@ export class Chromium extends BrowserType {
chromeArguments.push(
'--headless',
'--hide-scrollbars',
'--mute-audio'
'--mute-audio',
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4',
);
}
if (options.chromiumSandbox === false)

View file

@ -130,4 +130,31 @@ describe('mobile viewport', (suite, parameters) => {
expect(await page.evaluate(() => window.innerWidth)).toBe(320);
await context.close();
});
it('should emulate the hover media feature', (test, parameters) => {
test.fail(options.WEBKIT(parameters));
}, async ({playwright, browser}) => {
const iPhone = playwright.devices['iPhone 6'];
const mobilepage = await browser.newPage({ ...iPhone });
expect(await mobilepage.evaluate(() => matchMedia('(hover: hover)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(hover: none)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(any-hover: hover)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(any-hover: none)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(pointer: coarse)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(pointer: fine)').matches)).toBe(false);
expect(await mobilepage.evaluate(() => matchMedia('(any-pointer: coarse)').matches)).toBe(true);
expect(await mobilepage.evaluate(() => matchMedia('(any-pointer: fine)').matches)).toBe(false);
await mobilepage.close();
const desktopPage = await browser.newPage();
expect(await desktopPage.evaluate(() => matchMedia('(hover: none)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(hover: hover)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(any-hover: none)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(any-hover: hover)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(pointer: coarse)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(pointer: fine)').matches)).toBe(true);
expect(await desktopPage.evaluate(() => matchMedia('(any-pointer: coarse)').matches)).toBe(false);
expect(await desktopPage.evaluate(() => matchMedia('(any-pointer: fine)').matches)).toBe(true);
await desktopPage.close();
});
});