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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion appium/webdriver/extensions/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ def toggle_location_services(self: T) -> T:
return self

def set_location(
self: T, latitude: Union[float, str], longitude: Union[float, str], altitude: Union[float, str] = None
self: T,
latitude: Union[float, str],
longitude: Union[float, str],
altitude: Union[float, str] = None,
speed: Union[float, str] = None,
) -> T:
"""Set the location of the device

Args:
latitude: String or numeric value between -90.0 and 90.00
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)

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

Expand Down
21 changes: 18 additions & 3 deletions test/unit/webdriver/device/location_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,50 @@ 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), WebDriver)
assert isinstance(driver.set_location(11.1, 22.2, 33.3, 23.2), 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

@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'), WebDriver)
assert isinstance(driver.set_location('11.1', '22.2', '33.3', '23.2'), 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'

@httpretty.activate
def test_set_location_without_altitude(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
assert isinstance(driver.set_location(11.1, 22.2), WebDriver)
assert isinstance(driver.set_location(11.1, 22.2, speed=23.2), 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']['speed'] - 23.2) <= FLT_EPSILON
assert d['location'].get('altitude') is None

@httpretty.activate
def test_set_location_without_speed(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), 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 d['location'].get('speed') is None

@httpretty.activate
def test_location(self):
driver = android_w3c_driver()
Expand Down