2020-08-03 23:41:48 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
* Modifications 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.
|
|
|
|
*/
|
2020-09-03 07:43:38 +03:00
|
|
|
|
2021-04-29 21:11:32 +03:00
|
|
|
import { browserTest as it, expect } from './config/browserTest';
|
2021-04-03 07:07:45 +03:00
|
|
|
|
|
|
|
it.describe('device', () => {
|
2021-04-30 23:26:13 +03:00
|
|
|
it.skip(({ browserName }) => browserName === 'firefox');
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should work', async ({playwright, browser, server}) => {
|
|
|
|
const iPhone = playwright.devices['iPhone 6'];
|
|
|
|
const context = await browser.newContext({ ...iPhone });
|
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/mobile.html');
|
|
|
|
expect(await page.evaluate(() => window.innerWidth)).toBe(375);
|
|
|
|
expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone');
|
|
|
|
await context.close();
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should support clicking', async ({playwright, browser, server}) => {
|
|
|
|
const iPhone = playwright.devices['iPhone 6'];
|
|
|
|
const context = await browser.newContext({ ...iPhone });
|
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/input/button.html');
|
|
|
|
const button = await page.$('button');
|
|
|
|
await page.evaluate(button => button.style.marginTop = '200px', button);
|
|
|
|
await button.click();
|
|
|
|
expect(await page.evaluate('result')).toBe('Clicked');
|
|
|
|
await context.close();
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-02-19 00:29:56 +03:00
|
|
|
it('should scroll to click', async ({browser, server, contextOptions}) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
const context = await browser.newContext({
|
2021-02-19 00:29:56 +03:00
|
|
|
...contextOptions,
|
2020-08-28 23:53:47 +03:00
|
|
|
viewport: {
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
},
|
|
|
|
deviceScaleFactor: 1,
|
|
|
|
isMobile: true
|
|
|
|
});
|
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/input/scrollable.html');
|
|
|
|
const element = await page.$('#button-91');
|
|
|
|
await element.click();
|
|
|
|
expect(await element.textContent()).toBe('clicked');
|
|
|
|
await context.close();
|
2020-08-03 23:41:48 +03:00
|
|
|
});
|
2021-02-19 00:29:56 +03:00
|
|
|
|
2021-05-15 17:42:35 +03:00
|
|
|
it('should scroll twice when emulated', async ({server, contextFactory, playwright}) => {
|
2021-02-19 00:29:56 +03:00
|
|
|
const device = playwright.devices['iPhone 6'];
|
2021-05-15 17:42:35 +03:00
|
|
|
const context = await contextFactory(device);
|
2021-02-19 00:29:56 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.setContent(`
|
|
|
|
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
|
|
|
Lorem ipsum dolor sit amet consectetur adipiscing elit proin, integer curabitur imperdiet rhoncus cursus tincidunt bibendum, consequat sed magnis laoreet luctus mollis tellus. Nisl parturient mus accumsan feugiat sem laoreet magnis nisi, aptent per sollicitudin gravida orci ac blandit, viverra eros praesent auctor vivamus semper bibendum. Consequat sed habitasse luctus dictumst gravida platea semper phasellus, nascetur ridiculus purus est varius quisque et scelerisque, id vehicula eleifend montes sollicitudin dis velit. Pellentesque ridiculus per natoque et eleifend taciti nunc, laoreet auctor at condimentum imperdiet ante, conubia mi cubilia scelerisque sociosqu sem.</p> <p>Curabitur magna per felis primis mauris non dapibus luctus ultricies eros, quis et egestas condimentum lobortis eget semper montes litora purus, ridiculus elementum sollicitudin imperdiet dictum lacinia parturient cras eu. Risus cum varius rhoncus eros torquent pretium taciti id erat dis egestas, nibh tristique montes convallis metus lacus phasellus blandit ut auctor bibendum semper, facilisis mi integer eget ultrices lobortis odio viverra duis dui. Risus ullamcorper lacinia in venenatis sodales fusce tortor potenti volutpat quis, dictum vulputate suspendisse velit mollis torquent sociis aptent morbi, senectus nascetur justo maecenas conubia magnis viverra gravida fames. Phasellus sed nec gravida nibh class augue lectus, blandit quis turpis orci diam nam pellentesque, ultricies metus imperdiet hendrerit lacinia lacus.</p> <p>Inceptos facilisi montes cum hendrerit, pulvinar ut tellus eget velit, arcu nulla aenean. Phasellus augue urna nostra molestie interdum vehicula, posuere fames cum euismod massa curabitur donec, inceptos cubilia tellus facilisis fermentum. Lacus laoreet facilisis ultrices cursus quisque at ad porta vestibulum massa inceptos, curae class aliquet maecenas cum ullamcorper pulvinar erat mus vitae. Cum in aenean convallis dis quam tincidunt justo sed quisque, imperdiet faucibus hendrerit felis commodo scelerisque magnis vehicula etiam leo, eros varius platea lobortis maecenas condimentum nisi phasellus. Turpis vulputate mus himenaeos sociosqu facilisis dignissim leo quam, ultricies habitasse commodo molestie est tortor vitae et, porttitor risus erat cursus phasellus facilisi litora.</p> <p>Nostra habitasse egestas magnis velit pellentesque parturient cum lectus viverra, vestibulum sociosqu nunc vel urna consequat lacinia phasellus at sapien, aenean pretium dictum sed montes interdum imperdiet iaculis. Leo hac eros arcu senectus maecenas, tortor pulvinar venenatis lacinia volutpat, mattis platea ut facilisi. Aenean condimentum at et donec sociosqu fermentum luctus potenti semper vulputate, sapien justo non est auctor gravida ultricies fames per commodo, sed habitasse facilisi nulla quisque hendrerit aliquet viverra bibendum.</p> <p>Interdum nisl quam etiam montes porttitor laoreet nullam senectus velit, mauris proin tellus imperdiet litora venenatis fames massa quis, sollicitudin justo vivamus curae in sociis suscipit facilisi. Platea inceptos lacus elementum pellentesque quam euismod dictumst sociis tincidunt vulputate porttitor eros, turpis netus ut ad tempor sapien aliquet sodales molestie consequat nostra. Cum augue in quisque primis ut nunc sodales, sem orci tempus posuere cubilia suspendisse lacinia ligula, magna sed ridiculus at maecenas habitant.</p> <p>Natoque magna ac feugiat tellus bibendum diam, metus lobortis nisl ornare varius praesent, dictumst gravida lacus parturient semper. Pellentesque faucibus congue fusce posuere placerat dictum vitae, dui vestibulum eu sociis tempus aliquam ultricies malesuada, potenti laoreet lacus sem gravida nisi. Nostra platea sagittis hendrerit congue conubia senectus bibendum quis sapien pharetra, scelerisque nam imperdiet fermentum feugiat suspendisse viverra luctus at, semper ac consequat vitae mi gravida parturient mollis nascetur. Vel taciti justo consequat primis et blandit convallis sed, felis purus fusce a venenatis etiam aenean scelerisque, fringilla volutpat sagittis eges
|
|
|
|
<button>hi</button>
|
|
|
|
`);
|
|
|
|
await page.evaluate(() => window.scroll(0, 100));
|
|
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(100);
|
|
|
|
|
|
|
|
await page.evaluate(() => window.scroll(0, 200));
|
|
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(200);
|
|
|
|
|
|
|
|
await context.close();
|
|
|
|
});
|
|
|
|
|
2021-05-15 17:42:35 +03:00
|
|
|
it('should reset scroll top after a navigation', async ({server, contextFactory, playwright, browserName}) => {
|
2021-04-03 07:07:45 +03:00
|
|
|
it.skip(browserName === 'webkit');
|
|
|
|
|
2021-02-19 00:29:56 +03:00
|
|
|
const device = playwright.devices['iPhone 6'];
|
2021-05-15 17:42:35 +03:00
|
|
|
const context = await contextFactory(device);
|
2021-02-19 00:29:56 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/input/scrollable.html');
|
|
|
|
await page.evaluate(() => window.scroll(0, 100));
|
|
|
|
|
|
|
|
await page.goto(server.PREFIX + '/input/scrollable2.html');
|
|
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(0);
|
|
|
|
await context.close();
|
|
|
|
});
|
|
|
|
|
2021-05-15 17:42:35 +03:00
|
|
|
it('should scroll to a precise position with mobile scale', async ({server, contextFactory, playwright, browserName}) => {
|
2021-04-03 07:07:45 +03:00
|
|
|
it.skip(browserName === 'webkit');
|
|
|
|
|
2021-02-19 00:29:56 +03:00
|
|
|
const device = playwright.devices['iPhone 6'];
|
2021-05-15 17:42:35 +03:00
|
|
|
const context = await contextFactory(device);
|
2021-02-19 00:29:56 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/input/scrollable.html');
|
|
|
|
expect(await page.evaluate(() => document.body.scrollHeight)).toBeGreaterThan(1000);
|
|
|
|
await page.evaluate(() => window.scroll(0, 100));
|
|
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(100);
|
|
|
|
await context.close();
|
|
|
|
});
|
|
|
|
|
2021-05-15 17:42:35 +03:00
|
|
|
it('should emulate viewport and screen size', async ({server, contextFactory, playwright}) => {
|
2021-03-30 00:10:58 +03:00
|
|
|
const device = playwright.devices['iPhone 12'];
|
2021-05-15 17:42:35 +03:00
|
|
|
const context = await contextFactory(device);
|
2021-03-30 00:10:58 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.setContent(`<meta name="viewport" content="width=device-width, user-scalable=no" />`);
|
|
|
|
|
|
|
|
expect(await page.evaluate(() => ({
|
|
|
|
width: window.screen.width,
|
|
|
|
height: window.screen.height
|
|
|
|
}))).toEqual({ width: 390, height: 844 });
|
|
|
|
|
|
|
|
expect(await page.evaluate(() => ({
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight
|
|
|
|
}))).toEqual({ width: 390, height: 664 });
|
|
|
|
|
|
|
|
await context.close();
|
|
|
|
});
|
|
|
|
|
2021-05-15 17:42:35 +03:00
|
|
|
it('should emulate viewport without screen size', async ({server, contextFactory, playwright}) => {
|
2021-03-30 00:10:58 +03:00
|
|
|
const device = playwright.devices['iPhone 6'];
|
2021-05-15 17:42:35 +03:00
|
|
|
const context = await contextFactory(device);
|
2021-03-30 00:10:58 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.setContent(`<meta name="viewport" content="width=device-width, user-scalable=no" />`);
|
|
|
|
|
|
|
|
expect(await page.evaluate(() => ({
|
|
|
|
width: window.screen.width,
|
|
|
|
height: window.screen.height
|
|
|
|
}))).toEqual({ width: 375, height: 667 });
|
|
|
|
|
|
|
|
expect(await page.evaluate(() => ({
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight
|
|
|
|
}))).toEqual({ width: 375, height: 667 });
|
|
|
|
|
|
|
|
await context.close();
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
});
|