Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
53 changes: 53 additions & 0 deletions appium/webdriver/extensions/logs.py
Original file line number Diff line number Diff line change
@@ -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')
8 changes: 2 additions & 6 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -213,6 +214,7 @@ class WebDriver(
Keyboard,
Location,
LogEvent,
Logs,
Network,
Performance,
Power,
Expand Down Expand Up @@ -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')
4 changes: 2 additions & 2 deletions test/unit/webdriver/log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down