Skip to content

Commit ce78c0d

Browse files
authored
feat: Add optional location speed attribute for android devices (appium#594)
1 parent e49dc78 commit ce78c0d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

appium/webdriver/extensions/location.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ def toggle_location_services(self: T) -> T:
3838
return self
3939

4040
def set_location(
41-
self: T, latitude: Union[float, str], longitude: Union[float, str], altitude: Union[float, str] = None
41+
self: T,
42+
latitude: Union[float, str],
43+
longitude: Union[float, str],
44+
altitude: Union[float, str] = None,
45+
speed: Union[float, str] = None,
4246
) -> T:
4347
"""Set the location of the device
4448
4549
Args:
4650
latitude: String or numeric value between -90.0 and 90.00
4751
longitude: String or numeric value between -180.0 and 180.0
4852
altitude: String or numeric value (Android real device only)
53+
speed: String or numeric value larger than 0.0 (Android real devices only)
4954
5055
Returns:
5156
Union['WebDriver', 'Location']: Self instance
@@ -58,6 +63,8 @@ def set_location(
5863
}
5964
if altitude is not None:
6065
data['location']['altitude'] = altitude
66+
if speed is not None:
67+
data['location']['speed'] = speed
6168
self.execute(Command.SET_LOCATION, data)
6269
return self
6370

test/unit/webdriver/device/location_test.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,50 @@ def test_toggle_location_services(self):
3333
def test_set_location_float(self):
3434
driver = android_w3c_driver()
3535
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
36-
assert isinstance(driver.set_location(11.1, 22.2, 33.3), WebDriver)
36+
assert isinstance(driver.set_location(11.1, 22.2, 33.3, 23.2), WebDriver)
3737

3838
d = get_httpretty_request_body(httpretty.last_request())
3939
assert abs(d['location']['latitude'] - 11.1) <= FLT_EPSILON
4040
assert abs(d['location']['longitude'] - 22.2) <= FLT_EPSILON
4141
assert abs(d['location']['altitude'] - 33.3) <= FLT_EPSILON
42+
assert abs(d['location']['speed'] - 23.2) <= FLT_EPSILON
4243

4344
@httpretty.activate
4445
def test_set_location_str(self):
4546
driver = android_w3c_driver()
4647
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
47-
assert isinstance(driver.set_location('11.1', '22.2', '33.3'), WebDriver)
48+
assert isinstance(driver.set_location('11.1', '22.2', '33.3', '23.2'), WebDriver)
4849

4950
d = get_httpretty_request_body(httpretty.last_request())
5051
assert d['location']['latitude'] == '11.1'
5152
assert d['location']['longitude'] == '22.2'
5253
assert d['location']['altitude'] == '33.3'
54+
assert d['location']['speed'] == '23.2'
5355

5456
@httpretty.activate
5557
def test_set_location_without_altitude(self):
5658
driver = android_w3c_driver()
5759
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
58-
assert isinstance(driver.set_location(11.1, 22.2), WebDriver)
60+
assert isinstance(driver.set_location(11.1, 22.2, speed=23.2), WebDriver)
5961

6062
d = get_httpretty_request_body(httpretty.last_request())
6163
assert abs(d['location']['latitude'] - 11.1) <= FLT_EPSILON
6264
assert abs(d['location']['longitude'] - 22.2) <= FLT_EPSILON
65+
assert abs(d['location']['speed'] - 23.2) <= FLT_EPSILON
6366
assert d['location'].get('altitude') is None
6467

68+
@httpretty.activate
69+
def test_set_location_without_speed(self):
70+
driver = android_w3c_driver()
71+
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/location'))
72+
assert isinstance(driver.set_location(11.1, 22.2, 33.3), WebDriver)
73+
74+
d = get_httpretty_request_body(httpretty.last_request())
75+
assert abs(d['location']['latitude'] - 11.1) <= FLT_EPSILON
76+
assert abs(d['location']['longitude'] - 22.2) <= FLT_EPSILON
77+
assert abs(d['location']['altitude'] - 33.3) <= FLT_EPSILON
78+
assert d['location'].get('speed') is None
79+
6580
@httpretty.activate
6681
def test_location(self):
6782
driver = android_w3c_driver()

0 commit comments

Comments
 (0)