From 4cfc91d4e188095efeb32a4c103f0ffb15c299c7 Mon Sep 17 00:00:00 2001 From: Bogdan Sala Date: Fri, 5 Mar 2021 23:41:54 +0200 Subject: [PATCH 1/3] feat: Added optional location speed attribute for android devices --- appium/webdriver/extensions/location.py | 6 +++++- test/unit/webdriver/device/location_test.py | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index b33693363..9c0082090 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -38,7 +38,8 @@ 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 @@ -46,6 +47,7 @@ def set_location( 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 then 0.0 (Android real devices only) Returns: Union['WebDriver', 'Location']: Self instance @@ -58,6 +60,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 diff --git a/test/unit/webdriver/device/location_test.py b/test/unit/webdriver/device/location_test.py index 37907aabb..afbef3329 100644 --- a/test/unit/webdriver/device/location_test.py +++ b/test/unit/webdriver/device/location_test.py @@ -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() From 299be364501a06b5c23a35213b8ca47bbeaeef3c Mon Sep 17 00:00:00 2001 From: Bogdan Sala Date: Sat, 6 Mar 2021 00:57:57 +0200 Subject: [PATCH 2/3] style: Code formating --- appium/webdriver/extensions/location.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index 9c0082090..e29519a9e 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -38,8 +38,11 @@ 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, speed: 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 From d2a3e1274d3da3618cff21aba1e657c5b4bf38b7 Mon Sep 17 00:00:00 2001 From: Bogdan Sala Date: Sat, 6 Mar 2021 15:57:45 +0200 Subject: [PATCH 3/3] docs: Corrected documentation. --- appium/webdriver/extensions/location.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index e29519a9e..780db790a 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -50,7 +50,7 @@ def set_location( 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 then 0.0 (Android real devices only) + speed: String or numeric value larger than 0.0 (Android real devices only) Returns: Union['WebDriver', 'Location']: Self instance