def judge(self,dic,retry_time):
timer = 0
global xml_path
xml_path = self.get_xml()
if xml_path is None:
print "Error : can not generate window dump file."
panel = None
return panel
else:
self.native_unlock_screen()
if retry_time is not None:
while 1:
if timer < int(retry_time):
if self.parse_window_dump(paras_dictory) is None:
print "Warnning : there is no view or many views match your require, retry again!"
self.little_swipe()
time.sleep(1)
timer+=1
self.judge(paras_dictory,retry_time)
else:
op = self.get_instance()
panel = Panel(op)
return panel
break
else:
panel = None
return panel
else:
if self.parse_window_dump(paras_dictory) is None:
print "Warnning : there is no view or many views match your require, start to search hooks library...!"
self.hooks.get_generators(self.get_all_nodes())
status = self.hooks.parse()
# if status is True, it means find corresponding frame and click next button to skip this frame
if status:
time.sleep(1)
self.judge(paras_dictory,retry_time).click()
else:
panel = None
return panel
else:
op = self.get_instance()
panel = Panel(op)
return panel
if len(p_counter) == 0:
print "Error : invalid input, there is no useful parameter given!!!"
sys.exit(-1)
for factor in self.get_all_nodes():
id_collector = factor.attrib['resource-id']
text_collector = factor.attrib['text']
index_collector = factor.attrib['index']
desc_collector = factor.attrib['content-desc']
pack_collector = factor.attrib['package']
enabled_collector = factor.attrib['enabled']
for your_input in p_counter:
id_strs = re.findall(r1,id_collector.strip('\n'))
id_string = id_strs
if not id_strs == []:
id_string=id_strs[0]
else:
id_string = id_collector.strip('\n\r')
if your_input == id_string:
bound_id = factor.get("bounds")
counter_id +=1
if your_input == text_collector.strip('\n'):
bound_text = factor.get("bounds")
counter_text +=1
if your_input == index_collector.strip('\n'):
bound_index = factor.get("bounds")
counter_index +=1
if your_input == desc_collector.strip('\n'):
bound_desc = factor.get("bounds")
counter_desc +=1
if your_input == pack_collector.strip('\n'):
bound_pack = factor.get("bounds")
counter_pack +=1
if your_input == enabled_collector.strip('\n'):
bound_enabled = factor.get("bounds")
counter_enabled +=1
if counter_id == 0:
false_flag += 1
if counter_index == 0:
false_flag += 1
if counter_pack == 0:
false_flag += 1
if counter_desc == 0:
false_flag += 1
if counter_text == 0:
false_flag += 1
if counter_enabled == 0:
false_flag += 1
if counter_id == 1:
bound_list.append(bound_id)
if counter_text == 1:
bound_list.append(bound_text)
if counter_desc == 1:
bound_list.append(bound_desc)
if counter_pack == 1:
bound_list.append(bound_pack)
if counter_index == 1:
bound_list.append(bound_index)
if counter_enabled == 1:
bound_list.append(bound_enabled)
if false_flag <= 6 - len(p_counter):
if len(bound_list) == 0:
bound = None
elif len(bound_list) == 1:
bound = bound_list[0]
elif len(bound_list) == 2:
temp_bound = bound_list[0]
if bound_list[1] == temp_bound:
bound = temp_bound
else:
bound = None
elif len(bound_list) > 2:
temp_bound = bound_list[0]
for bo in range(1,len(bound_list)):
if bound_list[bo] != temp_bound:
bound = None
break
else:
bound = temp_bound
else:
bound = None
return bound
def native_power_on(self):
if not self.native_check_screen_on():
power_on_command = self.adb_shell() + 'input keyevent 26'
self.execute_command(power_on_command).wait()
def native_unlock_screen(self):
self.native_power_on()
if self.native_is_screen_lock():
self.native_push_up()
def native_check_screen_on(self):
is_screen_on = False
for line in self.get_dumpsys_display():
if 'mScreenState' in line and 'ON' in line:
is_screen_on = True
return is_screen_on 作者: yaboandroid 时间: 2017-1-13 10:04
def get_max_resolution(self):
max_resolution = []
for line in self.get_dumpsys_display():
if 'mDisplayWidth' in line:
max_resolution.append(line.strip('\r').split('=')[-1])
if 'mDisplayHeight' in line:
max_resolution.append(line.strip('\r').split('=')[-1])
return max_resolution
def shift_left(self,counter=1):
press_left_command = self.executor.adb_shell() + 'input keyevent 21'
for j in range(int(counter)):
self.executor.execute_command(press_left_command).wait()
time.sleep(1)
def volume_up(self,counter=1):
volume_up_command = self.executor.adb_shell() + 'input keyevent 24'
for j in range(int(counter)):
self.executor.execute_command(volume_up_command).wait()
time.sleep(0.5)
def volume_down(self,counter=1):
volume_down_command = self.executor.adb_shell() + 'input keyevent 25'
for j in range(int(counter)):
self.executor.execute_command(volume_down_command).wait()
time.sleep(0.5)
def shift_right(self,counter=1):
press_right_command = self.executor.adb_shell() + 'input keyevent 22'
for k in range(int(counter)):
self.executor.execute_command(press_right_command).wait()
time.sleep(1)
def power_on(self):
if not self.check_screen_on():
power_on_command = self.executor.adb_shell() + 'input keyevent 26'
self.executor.execute_command(power_on_command).wait()
def press_back(self,counter=1):
press_back_command = self.executor.adb_shell() + 'input keyevent 4'
for i in range(int(counter)):
self.executor.execute_command(press_back_command).wait()
time.sleep(1)
def check_screen_on(self):
is_screen_on = False
for line in self.executor.get_dumpsys_display():
if 'mScreenState' in line and 'ON' in line:
is_screen_on = True
return is_screen_on
def launch_app_with_intent(self,app="Native_HomePage",**kwargs):
intent_dictory = self.executor.get_intents_dictory()
if app in intent_dictory.keys():
app_intent = intent_dictory[app]['intent']
launch_app_command = self.executor.adb_shell() + 'am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n ' + app_intent
self.executor.execute_command(launch_app_command).wait()
else:
print "[Error] there is no intent match your given application, please double check or contact author to add!!!"
sys.exit(-1) 作者: yaboandroid 时间: 2017-1-13 10:08
class Panel(object):
def __init__(self,panel):
self.panel = panel