forked from appium/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_mobile_command.py
More file actions
61 lines (50 loc) · 2.18 KB
/
Copy pathexecute_mobile_command.py
File metadata and controls
61 lines (50 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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 selenium import webdriver
class ExecuteMobileCommand(webdriver.Remote):
def press_button(self, button_name):
"""Sends a physical button name to the device to simulate the user pressing.
iOS only.
Possible button names can be found in
https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Categories/XCUIDevice%2BFBHelpers.h
Args:
button_name (str): the button name to be sent to the device
Returns:
`appium.webdriver.webdriver.WebDriver`
"""
data = {
'name': button_name
}
self.execute_script('mobile: pressButton', data)
return self
@property
def battery_info(self):
"""Retrieves battery information for the device under test.
Returns:
`dict`: containing the following entries
level: Battery level in range [0.0, 1.0], where 1.0 means 100% charge.
Any value lower than 0 means the level cannot be retrieved
state: Platform-dependent battery state value.
On iOS (XCUITest):
1: Unplugged
2: Charging
3: Full
Any other value means the state cannot be retrieved
On Android (UIAutomator2):
2: Charging
3: Discharging
4: Not charging
5: Full
Any other value means the state cannot be retrieved
"""
return self.execute_script('mobile: batteryInfo')