def end_test(): ''' Run test cases. Random or repeat test cases. First, lead test suit list. Second,repeat case 1~x x is be defined on Settings config.Third, random test case if you choose on Settings config. ''' import logging_wrapper #end track and export track as KML end_current_track_and_export_kml(get_log_root()) #move the crash to the current log dir move_crash() clear_status() #back to auto test after end set_can_continue() launcher = Launcher() launcher.launch_from_launcher('auto_test') end_test_runners_accessibility() log_root = logging_wrapper.log_root if os.path.exists(log_root): log_status = log_root + os.sep + "log_status.qsst" logging_wrapper.__write_log(SERVICE_END_TIME + DIVIDE + get_file_timestring(), log_status) enableTouchPanel() if SC.PRIVATE_HOSTLOGGING_ENABLE_FEATURE: quit_qxdm()
def __init__(self): ''' init function. ''' self.mode_name = "cmcc_mtbf" self.ime = IME() self.launcher = Launcher() Base.__init__(self, self.mode_name) self.debug_print('cmcc_mtbf init:%f' % (time.time()))
def end_test(): ''' Run test cases. Random or repeat test cases. First, lead test suit list. Second,repeat case 1~x x is be defined on Settings config.Third, random test case if you choose on Settings config. ''' #move the crash to the current log dir move_crash() clear_status() #back to auto test after end set_can_continue() launcher = Launcher() launcher.launch_from_launcher('auto_test') end_test_runners_accessibility()
def __init__(self, name, suit_name, app_name, enabled=True, run_Reason=CASE_RUN_SELF): self.name = name self.suit_name = suit_name self.app_name = app_name self.enabled = enabled self.launcher = Launcher() self.runReason = run_Reason
class TestCaseBase(object): """Base class for test case""" global launcher '''cycle index of repeat case''' cycle_index = 1 '''record server side adb pid''' global adb_main_log_pid adb_main_log_pid = -1 global adb_radio_log_pid adb_radio_log_pid = -1 global adb_events_log_pid adb_events_log_pid = -1 global capture_log capture_log = False def __init__(self, name, suit_name, app_name, enabled=True, run_Reason=CASE_RUN_SELF): self.name = name self.suit_name = suit_name self.app_name = app_name self.enabled = enabled self.launcher = Launcher() self.runReason = run_Reason def test_case_init(self): ''' init the test case . such as: set the L{current_case_continue_flag<current_case_continue_flag>} to True; save the current case name; init the logging; launcher this application ''' case_config_map = fs_wrapper.get_test_case_config( self.name, self.suit_name) global case_des case_des = case_config_map.get(fs_wrapper.CASE_DESCRIPTION) if case_des == None: case_des = '' #if auto insert case waypoint. if SC.PRIVATE_TRACKING_AUTO_INSERT_CASE_WAYPOINT: if int(SC.PUBLIC_RUNNING_REPEAT_NUMBER) == 1: case_utility.insert_waypoint( case_utility.START_RUN + self.name, case_des) else: case_utility.insert_waypoint( case_utility.START_RUN + '(' + str(self.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ') ' + self.name, case_des) if getprop_suspend(): log_test_case('TestCaseBase', 'enable touch panel') enableTouchPanel() log_test_case('TestCaseBase', 'end enable touch panel') if getprop_suspend(): signal.signal(signal.SIGUSR1, OnshakeSignal_handler) log_test_case( 'suspend', 'suspended, wait for shake-signal from java resume --- 3') signal.pause() log_test_case( 'Finally!!!', 'good luck, already gotten signal and resumed.... --- 4') log_test_framework(self.name, 'case init...') set_can_continue() if (self.runReason == CASE_BE_REFERED): (ori_suit_name, ori_case_name) = self.original_ClassName.rsplit('.', 1) set_cur_case_name(ori_case_name) elif (self.runReason == CASE_RUN_SELF): set_cur_case_name(self.name) qsst_log_case_init() clear_logcat() #deal with watcher ANR and FC global enable_watcher_anr_fc enable_watcher_anr_fc = case_config_map.get( fs_wrapper.CASE_ENABLE_WATCHER_ANR_AND_FC) if (enable_watcher_anr_fc == '0'): case_utility.disable_watcher_anr_fc() def test_case_end(self): ''' end the test case . call L{exit_app<exit_app>} to exit the application ''' #if auto insert case waypoint. if SC.PRIVATE_TRACKING_AUTO_INSERT_CASE_WAYPOINT: if int(SC.PUBLIC_RUNNING_REPEAT_NUMBER) == 1: case_utility.insert_waypoint(case_utility.END + self.name, case_des) else: case_utility.insert_waypoint( case_utility.END + '(' + str(self.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ') ' + self.name, case_des) #deal with watcher ANR and FC global enable_watcher_anr_fc if (enable_watcher_anr_fc == '0'): case_utility.enable_watcher_anr_fc() self.exit_app() log_test_framework(self.name, 'case end') self.stop_capture_adb_qxdm_log() def test_case_notification(self): ''' send notification to tell user that the current case is starting ''' import settings.common as SC if fs_wrapper.run_init_settings: case_utility.update_notificationbar('presettings is running...') else: set_can_continue() if (self.runReason == CASE_BE_REFERED): (ori_suit_name, ori_case_name) = self.original_ClassName.rsplit('.', 1) elif (self.runReason == CASE_RUN_SELF): ori_suit_name = self.suit_name ori_case_name = self.name else: return case_description = self.case_config_map.get( fs_wrapper.CASE_DESCRIPTION) if (case_description == None or case_description == ""): note_case_info = ori_case_name else: note_case_info = case_description suit_config_map = fs_wrapper.get_test_suit_config(ori_suit_name) suit_description = suit_config_map.get(fs_wrapper.SUIT_DESCRIPTION) if (suit_description == None or suit_description == ""): note_suit_info = ori_suit_name else: note_suit_info = suit_description #case_utility.update_notificationbar('(' + str(self.cycle_index) +'/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ')' + self.suit_name + '.' + self.name) log_test_framework( 'notify', '(' + str(self.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ')' + note_suit_info + '.' + note_case_info) case_utility.update_notificationbar( '(' + str(self.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ')' + note_suit_info + '.' + note_case_info) def test_case_run(self, case_results): ''' the entry of the case.through this method to control the case life cycle. @type case_results: array @param case_results: the case result array. ''' try: self.test_case_notification() '''init the case''' self.test_case_init() check_capacity_result = self.check_capacity() if check_capacity_result != "": qsst_log_case_status( logging_wrapper.UNSUPPORTED_CASE, "Unsupported case, need capacity:" + check_capacity_result, logging_wrapper.SEVERITY_HIGH) self.test_case_end() return False self.start_capture_adb_qxdm_log() except Exception as e: '''if an exception occurs,we will set the status of this case to STATUS_FAILED''' self.dealwith_exception(e) qsst_log_case_status(logging_wrapper.STATUS_FAILED, str(e), logging_wrapper.SEVERITY_HIGH) self.test_case_end() return False try: # lanch this app from launcher self.launcher.launch_from_launcher(self.app_name) success = self.test_case_main(case_results) except Exception as e: '''if an exception occurs,we will set the status of this case to STATUS_FAILED''' str_context = get_context_info() if str_context == None: str_exception = "CONTEXT:" + str_context + " " + logging_wrapper.DIVIDE + str( e) else: str_exception = str(e) qsst_log_case_status(logging_wrapper.STATUS_FAILED, str_exception, logging_wrapper.SEVERITY_HIGH) self.dealwith_exception(e) self.test_case_end() return False self.test_case_end() if success == None: return True return success def test_case_main(self, case_results): ''' the subclass need to override this function to do itself things @type case_results: array @param case_results: the case result array. ''' case_results.append((self.name, False)) def __str__(self): return '[Case][Name: %s, SuitName: %s, enabled: %d]' % ( self.name, self.suit_name, self.enabled) @staticmethod def createInstance(class_name, *args, **kwargs): ''' give the class name and the args to create a test instance @type class_name: string @param class_name: class name of this case @type args: reference @param args: arguments the case needs ''' (module_name, class_name) = class_name.rsplit('.', 1) module_meta = __import__(module_name, globals(), locals(), [class_name]) class_meta = getattr(module_meta, class_name) o = class_meta(*args, **kwargs) return o # exit the app , the default behavior is to click the back key # if your app is not fit , please override this method def exit_app(self): ''' exit this application. the subclass can override to complete itself steps to exit it own application ''' try: self.launcher.back_to_launcher() return True except Exception as e: self.dealwith_exception(e) return False def dealwith_exception(self, e): ''' deal with the exception.such as: save the exception stack or exception message ''' save_fail_log() log_test_framework('TestCaseBase', 'Exception is :' + str(e)) log_test_framework('TestCaseBase', 'Traceback :' + traceback.format_exc()) def check_capacity(self): case_capacity = self.case_config_map.get( fs_wrapper.CASE_DEPEND_CAPACITY) if case_capacity == None: return "" capacities = case_capacity.split(",") for capacity in capacities: if not capacity in CC.capacity_list: return capacity return "" def start_capture_adb_qxdm_log(self): #start capture adb log and qxdm log on server side global adb_main_log_pid global adb_radio_log_pid global adb_events_log_pid global capture_log disable_hostlogging = self.case_config_map.get( fs_wrapper.CASE_DISABLE_HOSTLOGGING) if (not fs_wrapper.run_init_settings) and ( not disable_hostlogging == "true") and SC.PRIVATE_HOSTLOGGING_ENABLE_FEATURE: l = len(SC.PUBLIC_LOG_PATH) log_path = get_log_path_on_server_side() init_qxdm_success = get_init_qxdm_success() adb_log_path = log_path + "\\" + self.suit_name + "\\" + self.name + "\\adblog" qxdm_log_path = log_path + "\\" + self.suit_name + "\\" + self.name + "\\qxdmlog" case_utility.mkdir_on_server_side(adb_log_path) case_utility.mkdir_on_server_side(qxdm_log_path) adb_main_log_pid = case_utility.start_capture_adblog( "adb logcat -v time >> " + adb_log_path + "\\main.log") adb_radio_log_pid = case_utility.start_capture_adblog( "adb logcat -v time -b radio >> " + adb_log_path + "\\radio.log") adb_events_log_pid = case_utility.start_capture_adblog( "adb logcat -v time -b events >> " + adb_log_path + "\\events.log") capture_log = True def stop_capture_adb_qxdm_log(self): #stop capture adb log and qxdm log on server side disable_hostlogging = self.case_config_map.get( fs_wrapper.CASE_DISABLE_HOSTLOGGING) if capture_log and (not fs_wrapper.run_init_settings) and ( not disable_hostlogging == "true") and SC.PRIVATE_HOSTLOGGING_ENABLE_FEATURE: case_utility.stop_capture_adblog(adb_main_log_pid) case_utility.stop_capture_adblog(adb_radio_log_pid) case_utility.stop_capture_adblog(adb_events_log_pid) case_utility.clear_adb_log() l = len(SC.PUBLIC_LOG_PATH) log_path = get_log_path_on_server_side() init_qxdm_success = get_init_qxdm_success() path = log_path + "\\" + self.suit_name + "\\" + self.name + "\\qxdmlog\\" if init_qxdm_success: if not case_utility.save_item_store(path.replace("\\\\", "\\")): log_test_framework( self.name, "Save item failed [" + path.replace("\\\\", "\\") + "].") if not case_utility.clear_view_items(): log_test_framework(self.name, "clear view failed.")
def __init__(self, name, suit_name, app_name, enabled=True): self.name = name self.suit_name = suit_name self.app_name = app_name self.enabled = enabled self.launcher = Launcher()
class TestCaseBase(object): """Base class for test case""" global launcher '''cycle index of repeat case''' cycle_index = 1 def __init__(self, name, suit_name, app_name, enabled=True): self.name = name self.suit_name = suit_name self.app_name = app_name self.enabled = enabled self.launcher = Launcher() def test_case_init(self): ''' init the test case . such as: set the L{current_case_continue_flag<current_case_continue_flag>} to True; save the current case name; init the logging; launcher this application ''' if getprop_suspend() : signal.signal(signal.SIGUSR1, OnshakeSignal_handler) log_test_case('suspend', 'suspended, wait for shake-signal from java resume --- 3') signal.pause() log_test_case('Finally!!!', 'good luck, already gotten signal and resumed.... --- 4') log_test_framework(self.name, 'case init...') set_can_continue() set_cur_case_name(self.name) qsst_log_case_init() self.launcher.launch_from_launcher(self.app_name) clear_logcat() def test_case_end(self): ''' end the test case . call L{exit_app<exit_app>} to exit the application ''' self.exit_app() log_test_framework(self.name, 'case end') def test_case_run(self, case_results): ''' the entry of the case.through this method to control the case life cycle. @type case_results: array @param case_results: the case result array. ''' try: import settings.common as SC if fs_wrapper.run_init_settings: case_utility.update_notificationbar('presettings is running...') else: case_utility.update_notificationbar('(' + str(self.cycle_index) +'/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ')' + self.suit_name + '.' + self.name) self.test_case_init() '''init the case''' except Exception as e: '''if an exception occurs,we will set the status of this case to STATUS_FAILED''' self.dealwith_exception(e) qsst_log_case_status(logging_wrapper.STATUS_FAILED, str(e), logging_wrapper.SEVERITY_HIGH) self.test_case_end() return False try: success = self.test_case_main(case_results) except Exception as e: '''if an exception occurs,we will set the status of this case to STATUS_FAILED''' str_context = get_context_info() if str_context == None: str_exception = "CONTEXT:"+str_context+" "+logging_wrapper.DIVIDE+str(e) else: str_exception = str(e) qsst_log_case_status(logging_wrapper.STATUS_FAILED, str_exception, logging_wrapper.SEVERITY_HIGH) self.dealwith_exception(e) self.test_case_end() return False self.test_case_end() if success == None: return True return success def test_case_main(self, case_results): ''' the subclass need to override this function to do itself things @type case_results: array @param case_results: the case result array. ''' case_results.append((self.name, False)) def __str__(self): return '[Case][Name: %s, SuitName: %s, enabled: %d]' % (self.name, self.suit_name, self.enabled) @staticmethod def createInstance(class_name, *args, **kwargs): ''' give the class name and the args to create a test instance @type class_name: string @param class_name: class name of this case @type args: reference @param args: arguments the case needs ''' (module_name, class_name) = class_name.rsplit('.', 1) module_meta = __import__(module_name, globals(), locals(), [class_name]) class_meta = getattr(module_meta, class_name) o = class_meta(*args, **kwargs) return o # exit the app , the default behavior is to click the back key # if your app is not fit , please override this method def exit_app(self): ''' exit this application. the subclass can override to complete itself steps to exit it own application ''' try: self.launcher.back_to_launcher() return True except Exception as e: self.dealwith_exception(e) return False def dealwith_exception(self, e): ''' deal with the exception.such as: save the exception stack or exception message ''' save_fail_log() log_test_framework('TestCaseBase','Exception is :' + str(e)) log_test_framework('TestCaseBase','Traceback :' + traceback.format_exc())
#author: # [email protected] #function: # the qrd share lib. #doc: # juts need you to add : import your_model as alias ############################################ # init a instance of the mode notificationBar = NotificationBar() camera = Camera() weibo = Weibo() renren = Renren() settings = Settings() playstore = PlayStore() launcher = Launcher() phone = Phone() browser = Browser() email = Email() doubanfm = Doubanfm() mms = Mms() gmail = Gmail() ime = IME() contact = Contact() gallery = Gallery() cmccMTBF = CmccMTBF() sample = Sample() incommon = InCommon() if is_serial_enabled(): shieldbox = ShieldBox()
class CmccMTBF(Base): ''' CmccMTBF is a class for cmcc mtbf. @see: L{Base <Base>} ''' TAG = "CmccMTBF" '''@var TAG: tag of CmccMTBF''' FOLDER_NAME = "cmcc_mtbf" IMAGE_NAME = "image" AUDIO_NAME = "audio" VIDEO_NAME = "video" def __init__(self): ''' init function. ''' self.mode_name = "cmcc_mtbf" self.ime = IME() self.launcher = Launcher() Base.__init__(self, self.mode_name) self.debug_print('cmcc_mtbf init:%f' % (time.time())) def launch_app_by_name(self, name): self.launcher.launch_from_launcher(name) def messaging_delete_all_threads(self): ''' delete all threads. ''' send_key(KEY_MENU) delete_all_threads = self.get_value("messaging_delete_all_threads") if search_text(delete_all_threads): click_textview_by_text(delete_all_threads) click_button_by_index(1) wait_for_fun(lambda:search_text(self.get_value("messaging_no_conversations")), True, 5) else: goback() def messaging_click_home_icon(self): ''' click home icon. @return: true-if click success.false-if click failed. ''' if wait_for_fun(lambda:search_view_by_id("home"), True, 10): click_imageview_by_id("home") return True log_test_framework(self.TAG, "Can't search view 'home'.") return False def messaging_send_sms(self, send_slot_number, recive_phone_number, content): ''' use slot1 or slot2 to send a sms to a specific phone number,then check whether send success. @type send_slot_number: string @param send_slot_number: send slot,1-slot1,2-slot2 @type recive_phone_number: number @param recive_phone_number: the phone nunber that recive the message. @type content: string @param content: text message. @return: true-if send success,false-if send failed. ''' num = recive_phone_number mms_text = content click_imageview_by_id('action_compose_new') click_textview_by_id("recipients_editor") #self.ime.IME_input_number(1, num, "c") entertext_edittext_by_id('recipients_editor', num) click_textview_by_text(self.get_value("messaging_type_message")) #self.ime.IME_input_english(1, mms_text) entertext_edittext_by_id('embedded_text_editor', mms_text) click_imageview_by_id('send_button_sms') #click_button_by_index(send_slot_number - 1) return self.messaging_check_send_success() def messaging_check_draft_function(self, recive_phone_number, content): ''' use slot1 or slot2 to send a sms to a specific phone number,then check whether send success. @type recive_phone_number: string @param recive_phone_number: the phone nunber that recive the message. @type content: string @param content: text message. @return: true-if send success,false-if send failed. ''' num = recive_phone_number mms_text = content click_imageview_by_id('action_compose_new') click_textview_by_id("recipients_editor") #self.ime.IME_input_number(1, num, "c") entertext_edittext_by_id('recipients_editor', num) click_textview_by_text(self.get_value("messaging_type_message")) #self.ime.IME_input_english(1, mms_text, input_type='t') entertext_edittext_by_id('embedded_text_editor', mms_text) self.messaging_click_home_icon() click_textview_by_text(self.get_value("messaging_draft"), searchFlag = TEXT_CONTAINS) phone_number = self.messaging_format_phone_number(recive_phone_number) b_number = search_text(phone_number) b_msg = search_text(content) self.messaging_click_home_icon() return (b_number and b_msg) def messaging_check_draft_function_with_attch(self, recive_phone_number, content, type): ''' use slot1 or slot2 to send a sms to a specific phone number,then check whether send success. @type recive_phone_number: string @param recive_phone_number: the phone nunber that recive the message. @type content: string @param content: text message. @type content: string @param content: attach type. @return: true-if send success,false-if send failed. ''' num = recive_phone_number click_textview_by_text(self.get_value("messaging_draft"), searchFlag = TEXT_CONTAINS) phone_number = self.messaging_format_phone_number(recive_phone_number) b_number = search_text(phone_number) b_msg = search_text(content) if type == self.IMAGE_NAME: click_button_by_text(self.get_value("messaging_view")) b_attach = search_text(self.get_value("messaging_gallery")) goback() elif type == self.AUDIO_NAME: b_attach = search_text(self.get_value("messaging_play")) elif type == self.VIDEO_NAME: click_button_by_text(self.get_value("messaging_view")) b_attach = search_text(self.get_value("messaging_video")) goback() self.messaging_click_home_icon() return (b_number and b_msg and b_attach) def messaging_send_mms_with_attachment(self, recive_phone_number, content, attachment, send): ''' use slot1 or slot2 to send a sms to a specific phone number,then check whether send success. @type recive_phone_number: string @param recive_phone_number: the phone nunber that recive the message. @type content: string @param content: text message. @type content: boolean @param content: whether send this mms. @return: true-if send success,false-if send failed. ''' num = recive_phone_number mms_text = content click_imageview_by_id('action_compose_new') click_textview_by_id("recipients_editor") #self.ime.IME_input_number(1, num, "c") entertext_edittext_by_id('recipients_editor', num) click_textview_by_text(self.get_value("messaging_type_message")) #self.ime.IME_input_english(1, mms_text, input_type='t') entertext_edittext_by_id('embedded_text_editor', mms_text) if attachment == self.IMAGE_NAME: self.messaging_add_attach(self.IMAGE_NAME, self.get_value("messaging_gallery")) elif attachment == self.AUDIO_NAME: self.messaging_add_audio_attch() elif attachment == self.VIDEO_NAME: self.messaging_add_attach(self.VIDEO_NAME, self.get_value("messaging_video")) if send: click_textview_by_desc(self.get_value("messaging_send_mms")) return self.messaging_check_send_success() self.messaging_click_home_icon() return True def messaging_add_attach(self, name, open_app): click_textview_by_desc(self.get_value("messaging_attach")) if name == self.IMAGE_NAME: click_textview_by_text(self.get_value("messaging_pictures")) elif name == self.VIDEO_NAME: click_textview_by_text(self.get_value("messaging_videos")) click_textview_by_text(self.get_value("messaging_file_explorer")) click_textview_by_text(self.get_value("messaging_folder")) click_textview_by_text(self.get_value("messaging_phone_storage")) click_textview_by_text(self.FOLDER_NAME) click_textview_by_text(name) #if serach_text(open_app): # click_textview_by_text(open_app) def messaging_add_audio_attch(self): click_textview_by_desc(self.get_value("messaging_attach")) click_textview_by_text(self.get_value("messaging_audio")) click_textview_by_text(self.get_value("messaging_system_audio")) click_textview_by_text("Andromeda") click_textview_by_text("ok") def messaging_check_send_success(self): func = lambda:search_text(self.get_value("messaging_sent"), searchFlag = TEXT_CONTAINS) if wait_for_fun(func, True, 30): return self.messaging_click_home_icon() self.messaging_click_home_icon() return False def messaging_format_phone_number(self, num): ''' format phone number,for example:format "12345678901" to "123 4567 8901" @type num: string @param num: phone number that need format @return: a phone number which have formated ''' s = self.messaging_insert(num, ' ', 3) return self.messaging_insert(s, ' ', 8) def messaging_insert(self, original, new, pos): ''' insert a new string into a tuple. @type original: string @param original: original string @type new: string @param new: a string that need insert. @type pos: number @param pos: position that need insert. @return: a new string. ''' return original[:pos] + new + original[pos:] def browser_clear_browser_history_cookie(self): send_key(KEY_MENU) click_textview_by_text(self.get_value("browser_settings")) click_textview_by_text(self.get_value("browser_privacy")) if is_view_enabled_by_text(VIEW_TEXT_VIEW, self.get_value("browser_clear_cache")): click_textview_by_text(self.get_value("browser_clear_cache")) click_textview_by_text(self.get_value("browser_ok")) if is_view_enabled_by_text(VIEW_TEXT_VIEW, self.get_value("browser_clear_history")): click_textview_by_text(self.get_value("browser_clear_history")) click_textview_by_text(self.get_value("browser_ok")) if is_view_enabled_by_text(VIEW_TEXT_VIEW, self.get_value("browser_clear_all_cookie_data")): click_textview_by_text(self.get_value("browser_clear_all_cookie_data")) click_textview_by_text(self.get_value("browser_ok")) goback() goback() def browser_access_browser(self, url_address, check_value): scroll_down() time.sleep(1) click_textview_by_id("url") send_key(KEY_DEL) entertext_edittext_by_id("url", url_address) send_key(KEY_ENTER) start_time = int(time.time()) while int(time.time()) - start_time < 60: scroll_down() time.sleep(1) if search_view_by_id("favicon"): click_button_by_id("favicon") if search_text(self.get_value("browser_loading")): click_textview_by_text(self.get_value("browser_ok")) continue if search_text(unicode(check_value), searchFlag = TEXT_CONTAINS): click_textview_by_text(self.get_value("browser_ok")) return True if search_text("WWW。SINA。COM"): click_textview_by_text(self.get_value("browser_ok")) return True return False def browser_exit_browser(self): send_key(KEY_MENU) click_textview_by_text(self.get_value("browser_exit")) def _download_and_delete_files(self, url_address, wait_time): #addressing config web address click_textview_by_id("url") sleep(1) entertext_edittext_on_focused(url_address) #go send_key(KEY_ENTER) sleep(1) # download or play, select download wait_fun = lambda: search_view_by_id("alertTitle") wait_result = wait_for_fun(wait_fun, True, wait_time) if wait_result == True: #download button id is button1 click_button_by_id("button1") #rename download filename using current time. time_string = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) sleep(2) if search_view_by_id("download_filename_edit"): entertext_edittext_by_id("download_filename_edit", time_string) sleep(1) click_textview_by_id("download_start") for i in range(1000): sleep(5) download_status_text = get_view_text_by_id(VIEW_TEXT_VIEW, "status_text") in_find = download_status_text.find("progress") if -1 == in_find: break log_test_case(self.mode_name, 'The downloaded filename ' + time_string) #no progress bar, downloading is completed, play or open if -1 == in_find : #play or open the file sleep(1) if search_view_by_id("download_icon"): click_imageview_by_id("download_icon") sleep(5) activity_name = get_activity_name() if -1 == activity_name.find("Download"): goback() sleep(1) #delete select the download item if search_view_by_id("download_checkbox"): click_textview_by_id("download_checkbox") # should be menu item, but no find interface ,so replace imageview it. click_imageview_by_id("delete_download") log_test_case(self.mode_name, time_string + ' file was deleted!') #from download activity back to browser goback() def download_url_browser(self, url_address, wait_time, is_checked = True): ''' check whether access url successfully @type url_address: string @param url_address: url address. @type check_value: string @param check_value: when need check whether access successfully, this is the check value. @type wait_time: number @param wait_time: when check access , the wait time. @type is_checked: boolean @param is_checked: whether check to access successfully. @return: True: access successful; False: no. ''' if is_checked == True: #clear the browser cache #self.clear_cache() #self.clear_cache_history_cookie_data() self.browser_clear_browser_history_cookie() for i in range(5): log_test_case(self.mode_name, 'repeat ' + str(i)) self._download_and_delete_files(url_address, wait_time) #quit brower goback() #minimize or quit, quit id is == button1 if search_view_by_id("alertTitle"): click_button_by_id("button1") return True def file_explorer_check_file_exist(self): ''' check whether there is file in a directory @return: trur-if there is some files, false-if there is no file ''' send_key(KEY_MENU) click_textview_by_text(self.get_value('file_explorer_delete')) if not is_view_enabled_by_index(VIEW_CHECKBOX,0): goback() return False goback() return True def file_explorer_delete_file(self): ''' delete the first file in the list ''' send_key(KEY_MENU) click_textview_by_text(self.get_value('file_explorer_delete')) if is_view_enabled_by_index(VIEW_CHECKBOX,0): click_checkbox_by_index(0) click_button_by_text(self.get_value('file_explorer_ok')) click_button_by_text(self.get_value('file_explorer_confirm')) sleep(1) def calendar_add_google_account(self, user_name, user_pwd): ''' add google account. @type user_name: string @param user_name: google account name @type user_pwd: tuple @param user_pwd: google account password @return: whether add google account success ''' click_textview_by_text(self.get_value("setting_add_account")) click_textview_by_text("Google") click_button_by_id("next_button") #entertext_edittext_by_id("username_edit", user_name) click_textview_by_id("username_edit") self.ime.IME_input(1, user_name) #entertext_edittext_by_id("password_edit", user_pwd) click_textview_by_id("password_edit") self.ime.IME_input(1, user_pwd) if search_text(self.get_value("setting_keep_me_up"), searchFlag=TEXT_CONTAINS): click_button_by_id("button1") if search_text(self.get_value("setting_account_exsits"), searchFlag=TEXT_CONTAINS): log_test_framework(self.TAG, "Account already exists.") click_button_by_id("next_button") start_activity("com.android.settings", ".Settings") return True #click_button_by_id("next_button") if not self.re_sign_in(): log_test_framework(self.TAG, "Couldn't sign in.") return False if search_text(self.get_value("setting_entertainment"), searchFlag=TEXT_CONTAINS): click_button_by_id("skip_button") click_button_by_id("done_button") return True def calendar_delete_calendar_event(self): click_textview_by_id('top_button_date', 1, 0) click_textview_by_text(self.getValByCurRunTarget("calendar_agenda")) while search_view_by_id('agenda_item_color') == True: click_textview_by_id('agenda_item_color') click_textview_by_desc(self.getValByCurRunTarget("calendar_delete")) click_textview_by_text(self.getValByCurRunTarget("calendar_ok")) click_textview_by_id('top_button_date', 1, 0) click_textview_by_text(self.getValByCurRunTarget("calendar_day")) #MO by one slot #parameter: # phoneNumber: the whole call phone number # slot: 0--slot1, 1--slot2 2-- default slot can use for emergency call #Return: # True: get through. # False: no def phone_phone_call(self, phoneNumber): ''' MO by one slot @type phoneNumber: string @param phoneNumber: the whole call phone number. @type slot: number ''' #dial click_imageview_by_id("deleteButton",1,0,0,LONG_CLICK) for i in range(0, len(phoneNumber)): click_imageview_by_id(str(self.PREDEFINED_NUMBERS[phoneNumber[i]])) click_imageview_by_id("dialButton") sleep(1) if search_text(self.get_value("phone_network_not_available")): return False #whether get throught. phoneOn = False t = 0 while search_view_by_id("endButton") and t < 10: if search_text("0:",searchFlag=TEXT_CONTAINS): phoneOn = True break sleep(1) t = t+1 if phoneOn == False: return False else: return True #send an e-mail. def email_write_email(self, to_address, subject, body, attachment=False, sendFlag=True): ''' send an e-mail. @type to_address: string @param to_address: destination address. @type subject: string @param subject: email subject. @type body: string @param body: email body text. @type attachment: boolean @param attachment: whether send email with attachment. If true, the attachment will be a picture. @return: True: send successfully. False: send failed. ''' if (attachment): click_menuitem_by_text(self.get_value("email_add_attachment")) click_textview_by_text(self.get_value("email_file_explorer")) click_textview_by_text("Image") click_in_list_by_index(0, clickType=LONG_CLICK) sleep(1) click_textview_by_text(self.get_value("email_share")) click_textview_by_text(self.get_value("email_app")) click_textview_by_text(self.get_value("email_just_once")) sleep(1) click_textview_by_id("to") entertext_edittext_by_id("to",to_address) sleep(1) click_textview_by_id("subject") entertext_edittext_by_id("subject",subject) sleep(1) click_textview_by_id("body_text") entertext_edittext_by_id("body_text",body) sleep(1) if (sendFlag == True): click_imageview_by_id("send") if (attachment): goback() goback() goback() #check whether send successfully. sleep(2) click_imageview_by_id("show_all_mailboxes") click_textview_by_text(self.get_value("email_outbox")) click_imageview_by_id("refresh",1,0) outbox_loading_fun = lambda:search_text(self.get_value("email_no_messages"),1,1) fun_result = wait_for_fun(outbox_loading_fun,True,30) #When load long time, you can go back and enter again. if fun_result == False: goback() click_textview_by_text(self.get_value("email_outbox")) click_imageview_by_id("refresh",1,0) outbox_loading_fun = lambda:search_text(self.get_value("email_no_messages"),1,1) wait_for_fun(outbox_loading_fun,True,60) result = False count = get_view_text_by_id(VIEW_TEXT_VIEW,"spinner_count") if str(count) == "": result = True goback() return result