def wait_for_root_page(self, root_text="", decription_text=""): failed_time = 0 self.logout(self.my_func_name(), "Wait for %s root page" % self.app_name) #self.logout(self.my_func_name(),"Wait %s ------"%root_text) for i in range(600): if i % 5 == 0: kill_adb_uiautomator_block() if decription_text == "": if self.device(resourceIdMatches=".+/%s$" % root_text).exists: print break else: if self.device(description="%s" % decription_text).exists: print break i += 1 time.sleep(1) if not app_excetion_kill_case(self.app_package): if failed_time > 6: self.logout(self.my_func_name(), "%s test is failed..." % self.app_package) return False failed_time += 1 continue sys.stdout.write("\r>>>Please wait for %s root page. %s (s)" % (self.app_name, i)) sys.stdout.flush() failed_time = 0
def wait_for_complete_ex(self, complete_text, timeout=3600): i = 0 failed_time = 0 self.logout(self.my_func_name(), "%s test waiting..." % self.app_package) kill_adb_uiautomator_block() while i < timeout: if self.device(resourceId="%s" % complete_text).exists: print self.logout(self.my_func_name(), "%s test finshed..." % self.app_package) return True else: i += 5 kill_adb_uiautomator_block() time.sleep(5) if not app_excetion_kill_case(self.app_package): if failed_time > 2: self.logout(self.my_func_name(), "%s test is failed..." % self.app_package) return False failed_time += 1 continue sys.stdout.write("\r>>>Please wait for test complete. %s (s)" % i) sys.stdout.flush() failed_time = 0 else: self.logout(self.my_func_name(), "Timeout for %s test" % self.app_name) return False
def screen_on(self): time.sleep(5) kill_adb_uiautomator_block() if self.device.screen == "off": self.logout(self.my_func_name(), "unlock screen...") kill_adb_uiautomator_block() self.device.wakeup() #os.system("adb shell input keyevent 82") time.sleep(1) else: self.logout(self.my_func_name(), "Screen On.")
def run_test(self,timeout=50): #self.clear_data() self.mobile_test.launch_app() #time.sleep(30) self.mobile_test.wait_for_root_page("ok_button") kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_resourceIdMatches('ok_button') self.mobile_test.click_ui_button_by_resourceIdMatches('launch_button',timeout) while "Extracting content" in self.mobile_test.device.dump(): time.sleep(10) kill_adb_uiautomator_block() time.sleep(2) # time.sleep #time.sleep(60) if self.tr_name == "MobileXPRT_perf": self.mobile_test.click_ui_button_by_resourceIdMatches('cancel_button',timeout) # self.mobile_test.wait_for_root_page('button_media_tests') if not self.mobile_test.click_ui_button_by_resourceIdMatches('button_media_tests',120): return False if self.tr_name == "MobileXPRT_ux": self.mobile_test.click_ui_button_by_resourceIdMatches('ok_button',timeout) self.mobile_test.click_ui_button_by_resourceIdMatches('done_button',timeout) # self.mobile_test.wait_for_root_page('button_ux_tests') if not self.mobile_test.click_ui_button_by_resourceIdMatches('button_ux_tests',120): return False kill_adb_uiautomator_block() time.sleep(10) self.tr.start_watt() time.sleep(400) if self.mobile_test.wait_for_complete("group_score",timeout=500) == False: return False time.sleep(2) self.tr.kill_watt_runtime() kill_adb_uiautomator_block() if not app_excetion_kill_case(self.mobile_test.app_package): return False app_device = self.mobile_test.device(resourceIdMatches = ".+/group_name") if(app_device.exists): right_dev = app_device.right(resourceIdMatches = ".+/group_score") if right_dev.exists: self.data = str(right_dev.info['text']) kill_adb_uiautomator_block() # if self.data != ""and self.data.isdigit(): if self.data != "": self.mobile_test.logout(self.mobile_test.my_func_name(),"Test data is %s"%self.data) return self.data return False
def main(self): self.tr = TestResult(sys.argv) kill_adb_uiautomator_block() try: self.mobile_test.screen_on() time.sleep(1) adbcmds.turn_airplane('1') adbcmds.turn_bluetooth('0') adbcmds.turn_wifi('0') adbcmds.turn_gps('0') adbcmds.set_display_time() except Exception, e: self.mobile_test.logout(self.mobile_test.my_func_name(), "Error setup load......") return False
def get_score_info_data(self, key_code, info_code, timeout=10): icount = 0 score = "" kill_adb_uiautomator_block() while icount < timeout: # print 'icount = %s'%icount app_dev = self.device(resourceIdMatches=".+/%s$" % key_code) if app_dev.exists: info_dict = app_dev.info info_dict = _byteify(info_dict) # print 'info_code = %s'%info_code score = info_dict[info_code] # print 'score = %s'%score break time.sleep(1) icount += 1 kill_adb_uiautomator_block() return score
def click_ui_button_by_resourceIdMatches(self, key_code, timeout=10): icount = 0 kill_adb_uiautomator_block() while icount < timeout: if not app_excetion_kill_case(self.app_package): self.logout(self.my_func_name(), "%s test is failed..." % self.app_package) return False app_dev = self.device(resourceIdMatches=".+/%s$" % key_code) if app_dev.exists: app_dev.click() icount = 0 break time.sleep(1) icount += 1 kill_adb_uiautomator_block() if icount > 0: return False else: return True
def click_ui_button_by_text(self, key_code="", textcont="", timeout=10): icount = 0 kill_adb_uiautomator_block() while icount < timeout: if not app_excetion_kill_case(self.app_package): self.logout(self.my_func_name(), "%s test is failed..." % self.app_package) return False if "" == textcont: app_dev = self.device(text=key_code) else: app_dev = self.device(textContains=key_code) if app_dev.exists: app_dev.click() icount = 0 break time.sleep(1) icount += 1 kill_adb_uiautomator_block() if icount > 0: return False else: return True
def clear_recent(self): kill_adb_uiautomator_block() self.device.press.home() time.sleep(2) kill_adb_uiautomator_block() launcher_packsge = self.device.info['currentPackageName'] time.sleep(2) kill_adb_uiautomator_block() self.device.press.recent() time.sleep(2) kill_adb_uiautomator_block() cur_package = self.device.info['currentPackageName'] #while cur_package != "com.android.launcher": while cur_package != launcher_packsge: # self.device.swipe(100,640,600,640,steps=10) time.sleep(1) cur_package = self.device.info['currentPackageName']
def run_test(self, timeout=100): self.clear_data() self.chrome_test.skip_chrome_wizard() self.push_data() time.sleep(5) self.mobile_test.launch_app() time.sleep(5) if not self.mobile_test.click_ui_button_by_text("Accept"): return False # if self.mobile_test.device(text="Vellamo EULA").exists: # kill_adb_uiautomator_block() # self.mobile_test.device(text="ACCEPT").click.wait() time.sleep(5) self.mobile_test.wait_for_root_page("main_root_vslider") if self.mobile_test.device(text="LET'S ROLL").exists: self.mobile_test.device(text="LET'S ROLL").click() # self.mobile_test.wait_for_root_page("button1") # kill_adb_uiautomator_block() # self.mobile_test.click_ui_button_by_resourceIdMatches('android:id/button1') if self.tr_name == "Vellamo_chrome_browser": kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_text_to_right_resourceIdMatches( "Browser", "card_launcher_run_button") time.sleep(2) score_text = "Chrome Browser" if self.tr_name == "Vellamo_webview_browser": kill_adb_uiautomator_block() # self.mobile_test.device(resourceId='com.quicinc.vellamo:id/card_browser_button').click() self.mobile_test.click_ui_button_by_resourceIdMatches( 'card_browser_button') time.sleep(2) kill_adb_uiautomator_block() self.mobile_test.device( resourceId='com.quicinc.vellamo:id/card_browser_button').right( resourceId='com.quicinc.vellamo:id/card_browser_button' ).click() time.sleep(2) kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_text_to_right_resourceIdMatches( "Browser", "card_launcher_run_button") score_text = "Android WebView Browser" if self.tr_name == "Vellamo_Metal": kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_text_to_right_resourceIdMatches( "Metal", "card_launcher_run_button") score_text = "Metal" if self.tr_name == "Vellamo_Multicore": kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_text_to_right_resourceIdMatches( "Multicore", "card_launcher_run_button") score_text = "Multicore" self.mobile_test.click_ui_button_by_text("Got it") time.sleep(5) self.tr.start_watt() time.sleep(5) self.mobile_test.logout(self.mobile_test.my_func_name(), "Begin testing......") time.sleep(2) if self.tr_name == "Vellamo_chrome_browser" or self.tr_name == "Vellamo_webview_browser": time.sleep(140) elif self.tr_name == "Vellamo_Multicore": time.sleep(70) else: time.sleep(30) self.mobile_test.wait_for_complete("card_score_score") time.sleep(2) self.tr.kill_watt_runtime() if not self.mobile_test.click_ui_button_by_text("No"): return False # self.mobile_test.device(text='NO').click() time.sleep(2) self.mobile_test.click_ui_button_by_text('Compare Scores') # if self.mobile_test.device(text='Compare Scores').exists: # kill_adb_uiautomator_block() # self.mobile_test.device(text="Compare Scores").click() if self.mobile_test.device(className="android.widget.ImageView", instance=0).exists: kill_adb_uiautomator_block() self.mobile_test.click_ui_button_by_resourceIdMatches( 'score_pane_topbar_button') # self.mobile_test.device(resourceId='com.quicinc.vellamo:id/score_pane_topbar_button').click.wait() if not app_excetion_kill_case(self.mobile_test.app_package): return False # app_device = self.mobile_test.device(text = score_text) # if(app_device.exists): # right_dev = app_device.right(resourceIdMatches = ".+/card_score_score$") # if right_dev.exists: # self.data = str(right_dev.info['text']) self.data = self.mobile_test.get_score_info_data( 'card_score_score', 'text') kill_adb_uiautomator_block() if self.data != "" and self.data.isdigit(): self.mobile_test.logout(self.mobile_test.my_func_name(), "Test data is %s" % self.data) return self.data return False