UNPKG

playwright-fluent

Version:
41 lines (40 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const playwright_fluent_1 = require("../../playwright-fluent"); const devices_1 = require("../../../devices"); describe('Playwright Fluent - emulateDevice', () => { let p; beforeEach(() => { p = new playwright_fluent_1.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should target chromium in headfull with simulated device', async () => { // Given const browser = 'chromium'; const options = { headless: false, }; const url = 'https://reactstrap.github.io'; const device = (0, devices_1.getDevice)('iPhone 6 landscape') || devices_1.defaultDevice; // When await p .withBrowser(browser) .withOptions(options) .emulateDevice('iPhone 6 landscape') .navigateTo(url); // Then const windowState = await p.getCurrentWindowState(); expect(Math.abs(windowState.innerWidth - device.viewport.width)).toBeLessThanOrEqual(10); expect(Math.abs(windowState.innerHeight - device.viewport.height)).toBeLessThanOrEqual(10); // Then default viewport should have (almost) the same size as the browser window const viewport = { width: windowState.innerWidth, height: windowState.innerHeight }; expect(Math.abs(viewport.height - windowState.outerHeight)).toBeLessThanOrEqual(132); expect(Math.abs(viewport.width - windowState.outerWidth)).toBeLessThanOrEqual(20); // Then default viewport should have (almost) the same size as the screen size const screen = windowState.screen; expect(Math.abs(viewport.height - screen.availHeight)).toBeLessThanOrEqual(132); expect(Math.abs(viewport.width - screen.availWidth)).toBeLessThanOrEqual(20); }); });