Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: reset view scale after navigation (#26939)

Yury Semikhatskyfd28e8d80172
diff --git a/tests/library/browsercontext-viewport-mobile.spec.ts b/tests/library/browsercontext-viewport-mobile.spec.ts
index 20cc7c4b15..642eeaebdf 100644
--- a/tests/library/browsercontext-viewport-mobile.spec.ts
+++ b/tests/library/browsercontext-viewport-mobile.spec.ts
@@ -189,4 +189,44 @@ it.describe('mobile viewport', () => {
await page.waitForFunction('window.scrollY === 100');
await context.close();
});
+
+ it('view scale should reset after navigation', async ({ browser, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/26876' });
+ it.fixme(browserName === 'webkit');
+ const context = await browser.newContext({
+ viewport: { width: 390, height: 664 },
+ isMobile: true,
+ });
+ const page = await context.newPage();
+ await page.goto(`data:text/html,<meta name='viewport' content='device-width, initial-scale=1'><button>Mobile Viewport</button>`);
+ await page.route('**/button.html', route => {
+ void route.fulfill({
+ body: `<body>
+ <button>Click me</button>
+ <script>
+ window.clicks = [];
+ document.addEventListener('click', e => {
+ const dot = document.createElement('div');
+ dot.style.position = 'absolute';
+ dot.style.width = '10px';
+ dot.style.height = '10px';
+ dot.style.borderRadius = '5px';
+ dot.style.backgroundColor = 'red';
+ dot.style.left = e.pageX + 'px';
+ dot.style.top = e.pageY + 'px';
+ dot.textContent = 'x: ' + e.pageX + ' y: ' + e.pageY;
+ document.body.appendChild(dot);
+ window.clicks.push({ x: e.pageX, y: e.pageY });
+ });
+ </script>
+ </body>`,
+ contentType: 'text/html',
+ });
+ });
+ await page.goto('http://localhost/button.html');
+ await page.getByText('Click me').click({ force: true });
+ expect(await page.evaluate(() => (window as any).clicks)).toEqual(
+ browserName === 'chromium' ? [{ x: 41, y: 18 }] : [{ x: 37, y: 15 }]);
+ await context.close();
+ });
});