diff --git a/Pipfile b/Pipfile index af7d5418..613f3dea 100644 --- a/Pipfile +++ b/Pipfile @@ -15,5 +15,5 @@ tox = "~=4.25" types-python-dateutil = "~=2.9" [packages] -selenium = "==4.31.0" +selenium = "==4.32.0" typing-extensions = "~=4.13.2" diff --git a/appium/webdriver/extensions/logs.py b/appium/webdriver/extensions/logs.py new file mode 100644 index 00000000..5f87e109 --- /dev/null +++ b/appium/webdriver/extensions/logs.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Any, Dict, List + +from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands + +from ..mobilecommand import MobileCommand as Command + + +class Logs(CanExecuteCommands): + @property + def log_types(self) -> List[str]: + """Gets a list of the available log types. This only works with w3c + compliant browsers. + + Example: + -------- + >>> driver.log_types + """ + return self.execute(Command.GET_AVAILABLE_LOG_TYPES)['value'] + + def get_log(self, log_type: str) -> List[Dict[str, Any]]: + """Gets the log for a given log type. + + Parameters: + ---------- + log_type : str + - Type of log that which will be returned + + Example: + -------- + >>> driver.get_log('browser') + >>> driver.get_log('driver') + >>> driver.get_log('client') + >>> driver.get_log('server') + """ + return self.execute(Command.GET_LOG, {'type': log_type})['value'] + + def _add_commands(self) -> None: + self.command_executor.add_command(Command.GET_LOG, 'POST', '/session/$sessionId/se/log') + self.command_executor.add_command(Command.GET_AVAILABLE_LOG_TYPES, 'GET', '/session/$sessionId/se/log/types') diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 9886c197..bc9c9a0a 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -54,6 +54,7 @@ from .extensions.keyboard import Keyboard from .extensions.location import Location from .extensions.log_event import LogEvent +from .extensions.logs import Logs from .extensions.remote_fs import RemoteFS from .extensions.screen_record import ScreenRecord from .extensions.session import Session @@ -213,6 +214,7 @@ class WebDriver( Keyboard, Location, LogEvent, + Logs, Network, Performance, Power, @@ -467,9 +469,3 @@ def _add_commands(self) -> None: self.command_executor.add_command(Command.GET_SCREEN_ORIENTATION, 'GET', '/session/$sessionId/orientation') self.command_executor.add_command(Command.SET_SCREEN_ORIENTATION, 'POST', '/session/$sessionId/orientation') - - # override for Appium 1.x - # Appium 2.0 and Appium 1.22 work with `/se/log` and `/se/log/types` - # FIXME: remove after a while - self.command_executor.add_command(Command.GET_LOG, 'POST', '/session/$sessionId/log') - self.command_executor.add_command(Command.GET_AVAILABLE_LOG_TYPES, 'GET', '/session/$sessionId/log/types') diff --git a/test/unit/webdriver/log_test.py b/test/unit/webdriver/log_test.py index 6d0984a9..f3b76d35 100644 --- a/test/unit/webdriver/log_test.py +++ b/test/unit/webdriver/log_test.py @@ -24,7 +24,7 @@ def test_get_log_types(): driver = ios_w3c_driver() httpretty.register_uri( httpretty.GET, - appium_command('/session/1234567890/log/types'), + appium_command('/session/1234567890/se/log/types'), body=json.dumps({'value': ['syslog']}), ) log_types = driver.log_types @@ -36,7 +36,7 @@ def test_get_log(): driver = ios_w3c_driver() httpretty.register_uri( httpretty.POST, - appium_command('/session/1234567890/log'), + appium_command('/session/1234567890/se/log'), body=json.dumps({'value': ['logs as array']}), ) log_types = driver.get_log('syslog')