forked from microsoft/playwright-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_device_descriptors.py
More file actions
37 lines (29 loc) · 1.34 KB
/
test_device_descriptors.py
File metadata and controls
37 lines (29 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pytest
@pytest.mark.only_browser("chromium")
async def test_should_work(playwright, launch_arguments) -> None:
device_descriptor = playwright.devices["Pixel 2"]
device_type = device_descriptor["default_browser_type"]
browser = await playwright[device_type].launch(**launch_arguments)
context = await browser.new_context(
**device_descriptor,
)
page = await context.new_page()
assert device_descriptor["default_browser_type"] == "chromium"
assert browser.browser_type.name == "chromium"
assert "Pixel 2" in device_descriptor["user_agent"]
assert "Pixel 2" in await page.evaluate("navigator.userAgent")
assert device_descriptor["device_scale_factor"] > 2
assert await page.evaluate("window.devicePixelRatio") > 2
assert device_descriptor["viewport"]["height"] > 700
assert device_descriptor["viewport"]["height"] < 800
inner_height = await page.evaluate("window.screen.availHeight")
assert inner_height > 700
assert inner_height < 800
assert device_descriptor["viewport"]["width"] > 400
assert device_descriptor["viewport"]["width"] < 500
inner_width = await page.evaluate("window.screen.availWidth")
assert inner_width > 400
assert inner_width < 500
assert device_descriptor["has_touch"]
assert device_descriptor["is_mobile"]
await browser.close()