Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appium/webdriver/extensions/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def set_location(
longitude: Union[float, str],
altitude: Union[float, str] = None,
speed: Union[float, str] = None,
satellites: Union[float, str] = None,
) -> T:
"""Set the location of the device

Expand All @@ -51,6 +52,7 @@ def set_location(
longitude: String or numeric value between -180.0 and 180.0
altitude: String or numeric value (Android real device only)
speed: String or numeric value larger than 0.0 (Android real devices only)
satellites: String or numeric value of active GPS satellites in range 1..12. (Android emulators only)

Returns:
Union['WebDriver', 'Location']: Self instance
Expand All @@ -65,6 +67,8 @@ def set_location(
data['location']['altitude'] = altitude
if speed is not None:
data['location']['speed'] = speed
if satellites is not None:
data['location']['satellites'] = satellites
self.execute(Command.SET_LOCATION, data)
return self

Expand Down
6 changes: 4 additions & 2 deletions test/unit/webdriver/device/location_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ def test_toggle_location_services(self):
def test_set_location_float(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
assert isinstance(driver.set_location(11.1, 22.2, 33.3, 23.2), WebDriver)
assert isinstance(driver.set_location(11.1, 22.2, 33.3, 23.2, 12), WebDriver)

d = get_httpretty_request_body(httpretty.last_request())
assert abs(d['location']['latitude'] - 11.1) <= FLT_EPSILON
assert abs(d['location']['longitude'] - 22.2) <= FLT_EPSILON
assert abs(d['location']['altitude'] - 33.3) <= FLT_EPSILON
assert abs(d['location']['speed'] - 23.2) <= FLT_EPSILON
assert abs(d['location']['satellites'] - 12) <= FLT_EPSILON

@httpretty.activate
def test_set_location_str(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
assert isinstance(driver.set_location('11.1', '22.2', '33.3', '23.2'), WebDriver)
assert isinstance(driver.set_location('11.1', '22.2', '33.3', '23.2', '12'), WebDriver)

d = get_httpretty_request_body(httpretty.last_request())
assert d['location']['latitude'] == '11.1'
assert d['location']['longitude'] == '22.2'
assert d['location']['altitude'] == '33.3'
assert d['location']['speed'] == '23.2'
assert d['location']['satellites'] == '12'

@httpretty.activate
def test_set_location_without_altitude(self):
Expand Down