Skip to content

Commit ed9eaff

Browse files
authored
refactor: remove legacy fallback in toggle_location_services (#1224)
Removed the deprecated fallback logic in `toggle_location_services` that used the `TOGGLE_LOCATION_SERVICES` command. The method now exclusively uses the `mobile: toggleGps` script. Also removed the `TOGGLE_LOCATION_SERVICES` constant from `MobileCommand` and its registration in `Location._add_commands`, as it is no longer used. Updated `test/unit/webdriver/device/location_test.py` to verify the new behavior.
1 parent dc47ec4 commit ed9eaff

3 files changed

Lines changed: 4 additions & 13 deletions

File tree

appium/webdriver/extensions/location.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from typing import Dict, Union
1616

17-
from selenium.common.exceptions import UnknownMethodException
1817
from typing_extensions import Self
1918

2019
from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
@@ -33,11 +32,7 @@ def toggle_location_services(self) -> Self:
3332
Returns:
3433
Union['WebDriver', 'Location']: Self instance
3534
"""
36-
try:
37-
self.execute_script('mobile: toggleGps')
38-
except UnknownMethodException:
39-
# TODO: Remove the fallback
40-
self.execute(Command.TOGGLE_LOCATION_SERVICES)
35+
self.execute_script('mobile: toggleGps')
4136
return self
4237

4338
def set_location(
@@ -89,10 +84,5 @@ def location(self) -> Dict[str, float]:
8984

9085
def _add_commands(self) -> None:
9186
"""Add location endpoints. They are not int w3c spec."""
92-
self.command_executor.add_command(
93-
Command.TOGGLE_LOCATION_SERVICES,
94-
'POST',
95-
'/session/$sessionId/appium/device/toggle_location_services',
96-
)
9787
self.command_executor.add_command(Command.GET_LOCATION, 'GET', '/session/$sessionId/location')
9888
self.command_executor.add_command(Command.SET_LOCATION, 'POST', '/session/$sessionId/location')

appium/webdriver/mobilecommand.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class MobileCommand:
8181
GET_SYSTEM_BARS = 'getSystemBars'
8282
GET_DISPLAY_DENSITY = 'getDisplayDensity'
8383
TOGGLE_WIFI = 'toggleWiFi'
84-
TOGGLE_LOCATION_SERVICES = 'toggleLocationServices'
8584
GET_PERFORMANCE_DATA_TYPES = 'getPerformanceDataTypes'
8685
GET_PERFORMANCE_DATA = 'getPerformanceData'
8786
GET_NETWORK_CONNECTION = 'getNetworkConnection'

test/unit/webdriver/device/location_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class TestWebDriverLocation(object):
2424
@httpretty.activate
2525
def test_toggle_location_services(self):
2626
driver = android_w3c_driver()
27-
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/toggle_location_services'))
2827
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
2928
assert isinstance(driver.toggle_location_services(), WebDriver)
3029

30+
d = get_httpretty_request_body(httpretty.last_request())
31+
assert d['script'] == 'mobile: toggleGps'
32+
3133
@httpretty.activate
3234
def test_set_location_float(self):
3335
driver = android_w3c_driver()

0 commit comments

Comments
 (0)