Skip to content

Commit 23278d9

Browse files
authored
refactor: remove legacy fallback logic for android extensions (#1220)
Removed fallback logic in `open_notifications` and `current_package` in `appium/webdriver/extensions/android/common.py`. These methods now exclusively use `mobile:` script extensions. Also removed unused `OPEN_NOTIFICATIONS` and `GET_CURRENT_PACKAGE` constants from `MobileCommand` and updated unit tests accordingly.
1 parent 0f549c3 commit 23278d9

3 files changed

Lines changed: 4 additions & 31 deletions

File tree

appium/webdriver/extensions/android/common.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from selenium.common.exceptions import UnknownMethodException
1615
from typing_extensions import Self
1716

1817
from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
1918
from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts
2019
from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence
21-
from appium.webdriver.mobilecommand import MobileCommand as Command
2220

2321

2422
class Common(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence):
@@ -28,32 +26,13 @@ def open_notifications(self) -> Self:
2826
Returns:
2927
Union['WebDriver', 'Common']: Self instance
3028
"""
31-
ext_name = 'mobile: openNotifications'
32-
try:
33-
self.assert_extension_exists(ext_name).execute_script(ext_name)
34-
except UnknownMethodException:
35-
# TODO: Remove the fallback
36-
self.mark_extension_absence(ext_name).execute(Command.OPEN_NOTIFICATIONS, {})
29+
self.execute_script('mobile: openNotifications')
3730
return self
3831

3932
@property
4033
def current_package(self) -> str:
4134
"""Retrieves the current package running on the device."""
42-
ext_name = 'mobile: getCurrentPackage'
43-
try:
44-
return self.assert_extension_exists(ext_name).execute_script(ext_name)
45-
except UnknownMethodException:
46-
# TODO: Remove the fallback
47-
return self.mark_extension_absence(ext_name).execute(Command.GET_CURRENT_PACKAGE)['value']
35+
return self.execute_script('mobile: getCurrentPackage')
4836

4937
def _add_commands(self) -> None:
50-
self.command_executor.add_command(
51-
Command.GET_CURRENT_PACKAGE,
52-
'GET',
53-
'/session/$sessionId/appium/device/current_package',
54-
)
55-
self.command_executor.add_command(
56-
Command.OPEN_NOTIFICATIONS,
57-
'POST',
58-
'/session/$sessionId/appium/device/open_notifications',
59-
)
38+
pass

appium/webdriver/mobilecommand.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ class MobileCommand:
7878
GET_AVAILABLE_LOG_TYPES = 'getAvailableLogTypes'
7979

8080
# Android
81-
OPEN_NOTIFICATIONS = 'openNotifications'
8281
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
83-
GET_CURRENT_PACKAGE = 'getCurrentPackage'
8482
GET_SYSTEM_BARS = 'getSystemBars'
8583
GET_DISPLAY_DENSITY = 'getDisplayDensity'
8684
TOGGLE_WIFI = 'toggleWiFi'

test/unit/webdriver/device/common_test.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ def test_open_notifications(self):
2929
@httpretty.activate
3030
def test_current_package(self):
3131
driver = android_w3c_driver()
32-
httpretty.register_uri(
33-
httpretty.GET,
34-
appium_command('/session/1234567890/appium/device/current_package'),
35-
body='{"value": ".ExamplePackage"}',
36-
)
3732
httpretty.register_uri(
3833
httpretty.POST,
3934
appium_command('/session/1234567890/execute/sync'),
4035
body='{"value": ".ExamplePackage"}',
4136
)
4237
assert driver.current_package == '.ExamplePackage'
38+
assert {'args': [], 'script': 'mobile: getCurrentPackage'} == get_httpretty_request_body(httpretty.last_request())

0 commit comments

Comments
 (0)