File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -81,4 +81,5 @@ def parse_device_descriptor(dict: Dict) -> Dict:
81
81
"device_scale_factor" : dict ["deviceScaleFactor" ],
82
82
"is_mobile" : dict ["isMobile" ],
83
83
"has_touch" : dict ["hasTouch" ],
84
+ "default_browser_type" : dict ["defaultBrowserType" ],
84
85
}
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+
4
+ @pytest .mark .only_browser ("chromium" )
5
+ async def test_should_work (playwright ) -> None :
6
+ device_descriptor = playwright .devices ["Pixel 2" ]
7
+ device_type = device_descriptor ["default_browser_type" ]
8
+ browser = await playwright [device_type ].launch ()
9
+ context = await browser .new_context (
10
+ ** device_descriptor ,
11
+ )
12
+ page = await context .new_page ()
13
+ assert device_descriptor ["default_browser_type" ] == "chromium"
14
+ assert browser .browser_type .name == "chromium"
15
+
16
+ assert "Pixel 2" in device_descriptor ["user_agent" ]
17
+ assert "Pixel 2" in await page .evaluate ("navigator.userAgent" )
18
+
19
+ assert device_descriptor ["device_scale_factor" ] > 2
20
+ assert await page .evaluate ("window.devicePixelRatio" ) > 2
21
+
22
+ assert device_descriptor ["viewport" ]["height" ] > 700
23
+ assert device_descriptor ["viewport" ]["height" ] < 800
24
+ inner_height = await page .evaluate ("window.innerHeight" )
25
+ inner_height > 700
26
+ inner_height < 800
27
+
28
+ assert device_descriptor ["viewport" ]["width" ] > 400
29
+ assert device_descriptor ["viewport" ]["width" ] < 500
30
+ inner_width = await page .evaluate ("window.innerWidth" )
31
+ inner_width > 400
32
+ inner_width < 500
33
+
34
+ assert device_descriptor ["has_touch" ]
35
+ assert device_descriptor ["is_mobile" ]
36
+
37
+ await browser .close ()
You can’t perform that action at this time.
0 commit comments