playwright-fluent
Version:
Fluent API around playwright
49 lines (48 loc) • 2.19 kB
JavaScript
;
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 headless with simulated device', async () => {
// Given
const browser = 'chromium';
const options = {
headless: true,
};
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 };
// eslint-disable-next-line no-console
console.log('viewport', viewport);
// eslint-disable-next-line no-console
console.log('windowState', windowState);
if (windowState.outerHeight > 0) {
expect(Math.abs(viewport.height - windowState.outerHeight)).toBeLessThanOrEqual(132);
}
if (windowState.outerWidth > 0) {
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);
});
});