|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from typing import Any, Dict, List |
| 16 | + |
| 17 | +from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands |
| 18 | + |
| 19 | +from ..mobilecommand import MobileCommand as Command |
| 20 | + |
| 21 | + |
| 22 | +class Logs(CanExecuteCommands): |
| 23 | + @property |
| 24 | + def log_types(self) -> List[str]: |
| 25 | + """Gets a list of the available log types. This only works with w3c |
| 26 | + compliant browsers. |
| 27 | +
|
| 28 | + Example: |
| 29 | + -------- |
| 30 | + >>> driver.log_types |
| 31 | + """ |
| 32 | + return self.execute(Command.GET_AVAILABLE_LOG_TYPES)['value'] |
| 33 | + |
| 34 | + def get_log(self, log_type: str) -> List[Dict[str, Any]]: |
| 35 | + """Gets the log for a given log type. |
| 36 | +
|
| 37 | + Parameters: |
| 38 | + ---------- |
| 39 | + log_type : str |
| 40 | + - Type of log that which will be returned |
| 41 | +
|
| 42 | + Example: |
| 43 | + -------- |
| 44 | + >>> driver.get_log('browser') |
| 45 | + >>> driver.get_log('driver') |
| 46 | + >>> driver.get_log('client') |
| 47 | + >>> driver.get_log('server') |
| 48 | + """ |
| 49 | + return self.execute(Command.GET_LOG, {'type': log_type})['value'] |
| 50 | + |
| 51 | + def _add_commands(self) -> None: |
| 52 | + self.command_executor.add_command(Command.GET_LOG, 'POST', '/session/$sessionId/se/log') |
| 53 | + self.command_executor.add_command(Command.GET_AVAILABLE_LOG_TYPES, 'GET', '/session/$sessionId/se/log/types') |
0 commit comments