From 0270666fc81ca1b4734186a7025cd2df0dc3785c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 19 Jul 2021 00:20:07 -0700 Subject: [PATCH 1/2] feat: add satellites in set_location --- appium/webdriver/extensions/location.py | 4 ++++ test/unit/webdriver/device/location_test.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index 780db790a..e5ee062c4 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -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 @@ -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 since Appium 1.22.0 Returns: Union['WebDriver', 'Location']: Self instance @@ -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 diff --git a/test/unit/webdriver/device/location_test.py b/test/unit/webdriver/device/location_test.py index afbef3329..79e3f36b3 100644 --- a/test/unit/webdriver/device/location_test.py +++ b/test/unit/webdriver/device/location_test.py @@ -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, 0), 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']) <= 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', '0'), 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'] == '0' @httpretty.activate def test_set_location_without_altitude(self): From 0d95768703774ea350e99c9c910a01a11ecf494b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 21 Jul 2021 01:47:54 -0700 Subject: [PATCH 2/2] fix review --- appium/webdriver/extensions/location.py | 2 +- test/unit/webdriver/device/location_test.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index e5ee062c4..68d451a61 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -52,7 +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 since Appium 1.22.0 + satellites: String or numeric value of active GPS satellites in range 1..12. (Android emulators only) Returns: Union['WebDriver', 'Location']: Self instance diff --git a/test/unit/webdriver/device/location_test.py b/test/unit/webdriver/device/location_test.py index 79e3f36b3..c351c2f4f 100644 --- a/test/unit/webdriver/device/location_test.py +++ b/test/unit/webdriver/device/location_test.py @@ -33,27 +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, 0), 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']) <= 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', '0'), 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'] == '0' + assert d['location']['satellites'] == '12' @httpretty.activate def test_set_location_without_altitude(self):