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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions appium/webdriver/extensions/android/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from selenium.common.exceptions import UnknownMethodException
from typing_extensions import Self

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts
from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence
from appium.webdriver.mobilecommand import MobileCommand as Command


class Common(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence):
Expand All @@ -28,32 +26,13 @@ def open_notifications(self) -> Self:
Returns:
Union['WebDriver', 'Common']: Self instance
"""
ext_name = 'mobile: openNotifications'
try:
self.assert_extension_exists(ext_name).execute_script(ext_name)
except UnknownMethodException:
# TODO: Remove the fallback
self.mark_extension_absence(ext_name).execute(Command.OPEN_NOTIFICATIONS, {})
self.execute_script('mobile: openNotifications')
return self

@property
def current_package(self) -> str:
"""Retrieves the current package running on the device."""
ext_name = 'mobile: getCurrentPackage'
try:
return self.assert_extension_exists(ext_name).execute_script(ext_name)
except UnknownMethodException:
# TODO: Remove the fallback
return self.mark_extension_absence(ext_name).execute(Command.GET_CURRENT_PACKAGE)['value']
return self.execute_script('mobile: getCurrentPackage')

def _add_commands(self) -> None:
self.command_executor.add_command(
Command.GET_CURRENT_PACKAGE,
'GET',
'/session/$sessionId/appium/device/current_package',
)
self.command_executor.add_command(
Command.OPEN_NOTIFICATIONS,
'POST',
'/session/$sessionId/appium/device/open_notifications',
)
pass
2 changes: 0 additions & 2 deletions appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class MobileCommand:
GET_AVAILABLE_LOG_TYPES = 'getAvailableLogTypes'

# Android
OPEN_NOTIFICATIONS = 'openNotifications'
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
GET_CURRENT_PACKAGE = 'getCurrentPackage'
GET_SYSTEM_BARS = 'getSystemBars'
GET_DISPLAY_DENSITY = 'getDisplayDensity'
TOGGLE_WIFI = 'toggleWiFi'
Expand Down
6 changes: 1 addition & 5 deletions test/unit/webdriver/device/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ def test_open_notifications(self):
@httpretty.activate
def test_current_package(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/appium/device/current_package'),
body='{"value": ".ExamplePackage"}',
)
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/execute/sync'),
body='{"value": ".ExamplePackage"}',
)
assert driver.current_package == '.ExamplePackage'
assert {'args': [], 'script': 'mobile: getCurrentPackage'} == get_httpretty_request_body(httpretty.last_request())
Loading