|
| 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 selenium import webdriver |
| 16 | +from ..mobilecommand import MobileCommand as Command |
| 17 | + |
| 18 | + |
| 19 | +class Performance(webdriver.Remote): |
| 20 | + |
| 21 | + def get_performance_data(self, package_name, data_type, data_read_timeout=None): |
| 22 | + """Returns the information of the system state |
| 23 | + which is supported to read as like cpu, memory, network traffic, and battery. |
| 24 | + Android only. |
| 25 | +
|
| 26 | + :Args: |
| 27 | + - package_name: The package name of the application |
| 28 | + - data_type: The type of system state which wants to read. |
| 29 | + It should be one of the supported performance data types. |
| 30 | + Check :func:`.get_performance_data_types` for supported types |
| 31 | + - data_read_timeout: (optional) The number of attempts to read |
| 32 | +
|
| 33 | + :Usage: |
| 34 | + self.driver.get_performance_data('my.app.package', 'cpuinfo', 5) |
| 35 | + """ |
| 36 | + data = {'packageName': package_name, 'dataType': data_type} |
| 37 | + if data_read_timeout is not None: |
| 38 | + data['dataReadTimeout'] = data_read_timeout |
| 39 | + return self.execute(Command.GET_PERFORMANCE_DATA, data)['value'] |
| 40 | + |
| 41 | + def get_performance_data_types(self): |
| 42 | + """Returns the information types of the system state |
| 43 | + which is supported to read as like cpu, memory, network traffic, and battery. |
| 44 | + Android only. |
| 45 | +
|
| 46 | + :Usage: |
| 47 | + self.driver.get_performance_data_types() |
| 48 | + """ |
| 49 | + return self.execute(Command.GET_PERFORMANCE_DATA_TYPES)['value'] |
| 50 | + |
| 51 | + # pylint: disable=protected-access |
| 52 | + |
| 53 | + def _addCommands(self): |
| 54 | + self.command_executor._commands[Command.GET_PERFORMANCE_DATA] = \ |
| 55 | + ('POST', '/session/$sessionId/appium/getPerformanceData') |
| 56 | + self.command_executor._commands[Command.GET_PERFORMANCE_DATA_TYPES] = \ |
| 57 | + ('POST', '/session/$sessionId/appium/performanceData/types') |
0 commit comments