|
| 1 | +from seleniumbase import BaseCase |
| 2 | +BaseCase.main(__name__, __file__) |
| 3 | + |
| 4 | + |
| 5 | +class TestGeolocation(BaseCase): |
| 6 | + def tearDown(self): |
| 7 | + self.save_teardown_screenshot() # If test fails, or if "--screenshot" |
| 8 | + if self.is_chromium() and not self._multithreaded: |
| 9 | + # Reset Permissions and GeolocationOverride |
| 10 | + self.execute_cdp_cmd("Browser.resetPermissions", {}) |
| 11 | + self.execute_cdp_cmd("Emulation.setGeolocationOverride", {}) |
| 12 | + super().tearDown() |
| 13 | + |
| 14 | + def test_geolocation(self): |
| 15 | + self.open("about:blank") |
| 16 | + if self._multithreaded: |
| 17 | + self.skip("Skipping test in multi-threaded mode.") |
| 18 | + if not self.is_chromium(): |
| 19 | + print("\n* execute_cdp_cmd() is only for Chromium browsers") |
| 20 | + self.skip("execute_cdp_cmd() is only for Chromium browsers") |
| 21 | + self.execute_cdp_cmd( |
| 22 | + "Browser.grantPermissions", |
| 23 | + { |
| 24 | + "origin": "https://www.openstreetmap.org/", |
| 25 | + "permissions": ["geolocation"], |
| 26 | + }, |
| 27 | + ) |
| 28 | + self.execute_cdp_cmd( |
| 29 | + "Emulation.setGeolocationOverride", |
| 30 | + { |
| 31 | + "latitude": 48.87645, |
| 32 | + "longitude": 2.26340, |
| 33 | + "accuracy": 100, |
| 34 | + }, |
| 35 | + ) |
| 36 | + self.open("https://www.openstreetmap.org/") |
| 37 | + self.click("span.geolocate") |
| 38 | + self.assert_url_contains("48.87645/2.26340") |
| 39 | + if not (self.headless or self.headless2 or self.xvfb): |
| 40 | + self.sleep(2.5) |
0 commit comments