15
15
16
16
class Adb (object ):
17
17
@staticmethod
18
- def __run_adb_command (command , device_id = None , wait = True , timeout = 60 , fail_safe = False , log_level = logging .DEBUG ):
18
+ def run_adb_command (command , device_id = None , wait = True , timeout = 60 , fail_safe = False , log_level = logging .DEBUG ):
19
19
if device_id is None :
20
20
command = '{0} {1}' .format (ADB_PATH , command )
21
21
else :
@@ -28,7 +28,7 @@ def __get_ids(include_emulator=False):
28
28
Get IDs of available android devices.
29
29
"""
30
30
devices = []
31
- output = Adb .__run_adb_command ('devices -l' ).output
31
+ output = Adb .run_adb_command ('devices -l' ).output
32
32
# Example output:
33
33
# emulator-5554 device product:sdk_x86 model:Android_SDK_built_for_x86 device:generic_x86
34
34
# HT46BWM02644 device usb:336592896X product:m8_google model:HTC_One_M8 device:htc_m8
@@ -42,9 +42,9 @@ def __get_ids(include_emulator=False):
42
42
@staticmethod
43
43
def restart ():
44
44
Log .info ("Restart adb." )
45
- Adb .__run_adb_command ('kill-server' )
45
+ Adb .run_adb_command ('kill-server' )
46
46
Process .kill (proc_name = 'adb' )
47
- Adb .__run_adb_command ('start-server' )
47
+ Adb .run_adb_command ('start-server' )
48
48
49
49
@staticmethod
50
50
def get_devices (include_emulators = False ):
@@ -63,7 +63,7 @@ def is_running(device_id):
63
63
command = "shell dumpsys window windows | findstr mCurrentFocus"
64
64
else :
65
65
command = "shell dumpsys window windows | grep -E 'mCurrentFocus'"
66
- result = Adb .__run_adb_command (command = command , device_id = device_id , timeout = 10 , fail_safe = True )
66
+ result = Adb .run_adb_command (command = command , device_id = device_id , timeout = 10 , fail_safe = True )
67
67
return bool ('Window' in result .output )
68
68
69
69
@staticmethod
@@ -87,7 +87,7 @@ def wait_until_boot(device_id, timeout=180, check_interval=3):
87
87
88
88
@staticmethod
89
89
def reboot (device_id ):
90
- Adb .__run_adb_command (command = 'reboot' , device_id = device_id )
90
+ Adb .run_adb_command (command = 'reboot' , device_id = device_id )
91
91
Adb .wait_until_boot (device_id = device_id )
92
92
93
93
@staticmethod
@@ -96,18 +96,18 @@ def prevent_screen_lock(device_id):
96
96
Disable screen lock after time of inactivity.
97
97
:param device_id: Device identifier.
98
98
"""
99
- Adb .__run_adb_command (command = 'shell settings put system screen_off_timeout -1' , device_id = device_id )
99
+ Adb .run_adb_command (command = 'shell settings put system screen_off_timeout -1' , device_id = device_id )
100
100
101
101
@staticmethod
102
102
def pull (device_id , source , target ):
103
- return Adb .__run_adb_command (command = 'pull {0} {1}' .format (source , target ), device_id = device_id )
103
+ return Adb .run_adb_command (command = 'pull {0} {1}' .format (source , target ), device_id = device_id )
104
104
105
105
@staticmethod
106
106
def get_page_source (device_id ):
107
107
temp_file = os .path .join (Settings .TEST_OUT_HOME , 'window_dump.xml' )
108
108
File .delete (temp_file )
109
- Adb .__run_adb_command (command = 'shell rm /sdcard/window_dump.xml' , device_id = device_id )
110
- result = Adb .__run_adb_command (command = 'shell uiautomator dump' , device_id = device_id )
109
+ Adb .run_adb_command (command = 'shell rm /sdcard/window_dump.xml' , device_id = device_id )
110
+ result = Adb .run_adb_command (command = 'shell uiautomator dump' , device_id = device_id )
111
111
if 'UI hierchary dumped to' in result .output :
112
112
time .sleep (1 )
113
113
Adb .pull (device_id = device_id , source = '/sdcard/window_dump.xml' , target = temp_file )
@@ -145,20 +145,20 @@ def is_text_visible(device_id, text, case_sensitive=False):
145
145
def get_screen (device_id , file_path ):
146
146
File .delete (path = file_path )
147
147
if Settings .HOST_OS == OSType .WINDOWS :
148
- Adb .__run_adb_command (command = 'exec-out screencap -p > ' + file_path ,
149
- device_id = device_id ,
150
- log_level = logging .DEBUG )
148
+ Adb .run_adb_command (command = 'exec-out screencap -p > ' + file_path ,
149
+ device_id = device_id ,
150
+ log_level = logging .DEBUG )
151
151
else :
152
- Adb .__run_adb_command (command = "shell screencap -p | perl -pe 's/\\ x0D\\ x0A/\\ x0A/g' > " + file_path ,
153
- device_id = device_id )
152
+ Adb .run_adb_command (command = "shell screencap -p | perl -pe 's/\\ x0D\\ x0A/\\ x0A/g' > " + file_path ,
153
+ device_id = device_id )
154
154
if File .exists (file_path ):
155
155
return
156
156
else :
157
157
raise Exception ('Failed to get screen of {0}.' .format (device_id ))
158
158
159
159
@staticmethod
160
160
def get_device_version (device_id ):
161
- result = Adb .__run_adb_command (command = 'shell getprop ro.build.version.release' , device_id = device_id )
161
+ result = Adb .run_adb_command (command = 'shell getprop ro.build.version.release' , device_id = device_id )
162
162
if result .exit_code == 0 :
163
163
return result .output
164
164
else :
@@ -167,7 +167,7 @@ def get_device_version(device_id):
167
167
@staticmethod
168
168
def open_home (device_id ):
169
169
cmd = 'shell am start -a android.intent.action.MAIN -c android.intent.category.HOME'
170
- Adb .__run_adb_command (command = cmd , device_id = device_id )
170
+ Adb .run_adb_command (command = cmd , device_id = device_id )
171
171
Log .info ('Open home screen of {0}.' .format (str (device_id )))
172
172
173
173
@staticmethod
@@ -177,6 +177,6 @@ def install(apk_path, device_id):
177
177
:param apk_path: File path to .apk.
178
178
:param device_id: Device id.
179
179
"""
180
- result = Adb .__run_adb_command (command = '-s {0} install -r {1}' .format (device_id , apk_path ), timeout = 60 )
180
+ result = Adb .run_adb_command (command = '-s {0} install -r {1}' .format (device_id , apk_path ), timeout = 60 )
181
181
assert 'Success' in result .output , 'Failed to install {0}. Output: {1}' .format (apk_path , result .output )
182
182
Log .info ('{0} installed successfully on {1}.' .format (apk_path , device_id ))
0 commit comments