def __init__(self, local_socket_name, port): """ Initialize the SocketUtil Instance by passing local socket name. For Windows and Linux-PC , it will connect localhost:6100 since this port will forward to remote socket myuiautomator on device. For running on Linux-Phone , it will connect to socket myuiautomator directly. @type local_socket_name:string @param local_socket_name: name of socket. @port port:port of socket. """ osInfo = get_platform_info() try: if osInfo == "Windows" or osInfo == "Linux-PC": self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect(("127.0.0.1", port)) self.fd = self.sock.makefile("rw", 0) elif osInfo == "Linux-Phone": self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.connect(local_socket_name) self.fd = self.sock.makefile("rw", 0) except socket.error, msg: log_test_framework("io_wrapper", "socket error: " + msg.strerror) self.sock = None self.fd = None raise IOError, "msg"
def attach_record_audio(self, audiotime): #c_caijie click_imageview_by_desc('attach') click_textview_by_text('Record audio') sleep(1) click_button_by_id('recordButton') sleep(1) if search_view_by_id('permission_allow_button'): click_button_by_id('permission_allow_button') sleep(5) if search_view_by_id('permission_allow_button'): click_button_by_id('permission_allow_button') sleep(5) click_button_by_id('stopButton') sleep(3) click_button_by_id('acceptButton') sleep(3) if search_view_by_id('permission_allow_button'): click_button_by_id('permission_allow_button') sleep(5) if search_view_by_id('permission_allow_button'): click_button_by_id('permission_allow_button') sleep(5) if search_view_by_id('button1'): click_button_by_id('button1') sleep(2) log_test_framework(self.TAG, "attach record_audio successfully") return True else: log_test_framework(self.TAG, "Fail to attach record_audio ") return False
def enableSIM2(clickType='Enable'): text2 = get_view_text_by_index(VIEW_BUTTON, 1) log_test_framework("current button is ", text2) if clickType == 'Enable': if text2 == 'OFF': click_button_by_index(1) sleep(15) if search_view_by_id('android:id/button3'): click_button_by_id('android:id/button3') sleep(5) return True elif clickType == 'Disable': if text2 == 'ON': click_button_by_index(1) sleep(2) if search_text('Deactivating the SIM', isScrollable=0): click_button_by_id('android:id/button1') sleep(20) if search_view_by_id('android:id/button3'): click_button_by_id('android:id/button3') sleep(5) return True else: take_screenshot() log_test_framework('type error', '')
def test_case_main(self, case_results): global case_flag , TAG ,p case_flag = False TAG = 'download file: Browser ' log_test_case(self.case_config_map[fs_wrapper.CASE_NAME_ATTR], self.name +' : case Start') log_test_framework(TAG, self.name + " -Start") recordName=''.join(__name__.split('_')[-2:]) #start_activity("com.android.browser", "org.chromium.chrome.browser.ChromeTabbedActivity") p=subprocess.Popen('adb shell screenrecord /sdcard/%s.mp4'%recordName,shell=True) # if wait_for_fun(lambda:search_view_by_id('permission_allow_button'), True, 15): # phone.permission_allow() # if wait_for_fun(lambda:search_view_by_id('terms_accept'), True, 15): # click_button_by_id('terms_accept') # if wait_for_fun(lambda:search_view_by_id('next_button'), True, 5): # click_button_by_id('next_button') # if wait_for_fun(lambda:search_view_by_id('next_button'), True, 5): # click_button_by_id('next_button') # if wait_for_fun(lambda:search_view_by_id('next_button'), True, 5): # click_button_by_id('next_button') browser.browser_downloadQQ(True) openNotification() sleep(4) if search_text('Download complete',isScrollable=0): log_test_framework(self.name,'download successful') click_textview_by_text('Download complete') sleep(2) if not search_text('has stopped',isScrollable=0,searchFlag=TEXT_CONTAINS): log_test_framework("system_sanity_browser_case2:", "download file open pass") take_screenshot() case_flag=True else: take_screenshot() else: take_screenshot() case_flag=False log_test_framework(self.name, 'download file fail') send_key(KEY_BACK) sleep(1) send_key(KEY_BACK) sleep(1) send_key(KEY_HOME) sleep(1) if search_text('has stopped',isScrollable=0,searchFlag=TEXT_CONTAINS): log_test_framework("system_sanity_browser_case2:", "Popup has stopped") take_screenshot() sleep(2) send_key(KEY_BACK) case_flag=False if case_flag: qsst_log_case_status(STATUS_SUCCESS, "" , SEVERITY_HIGH) else: qsst_log_case_status(STATUS_FAILED, "", SEVERITY_HIGH) case_results.append((self.case_config_map[fs_wrapper.CASE_NAME_ATTR], case_flag))
def set_default_voice(self, card_id): ''' set default voice. @type card_id: string @param card_id: default voice card id, 1-slot1, 2-slot2, 0-always ask ''' if search_text("SIM cards"): click_textview_by_text("SIM cards") sleep(2) if search_text("Calls"): click_textview_by_text("Calls") sleep(1) if card_id == 0: sleep(1) click_in_list_by_index(0) elif card_id == 1: sleep(1) click_in_list_by_index(1) elif card_id == 2: sleep(1) click_in_list_by_index(2) else: log_test_framework(self.TAG, "card_id:" + card_id + "is error.") sleep(3)
def test_suit_init(self, suit_results): ''' init the test suit . such as: save the current suit name; init the report logging; launcher this application; set the L{current_case_continue_flag<current_case_continue_flag>} to True; ''' set_cur_suit_name(self.name) log_test_framework(self.name, "suit init...") qsst_log_suit_init() set_can_continue() suit_config_map = fs_wrapper.get_test_suit_config(self.name) global suit_description suit_description = suit_config_map.get(fs_wrapper.SUIT_DESCRIPTION) if suit_description == None: suit_description = '' import settings.common as SC #if auto insert case waypoint. if SC.PRIVATE_TRACKING_AUTO_INSERT_CASE_WAYPOINT: if int(SC.PUBLIC_RUNNING_REPEAT_NUMBER) == 1: insert_waypoint(START_RUN + self.name, suit_description) else: insert_waypoint( START_RUN + '(' + str(TestCaseBase.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ') ' + self.name, suit_description) return True
def get_all_suit_config(config_filename): ''' used by old version, DO NOT uset it any more. ''' all_suit_config_map = {} try: config_file = open(config_filename, 'r') except IOError: log_test_framework( TAG, "Config file: '" + config_filename + "' doesn't exist or can't be opened!") return all_suit_config_map lines = config_file.readlines() for line in lines: line = line.strip(SYMBOL_LINE_BREAK) if len(line) != 0: items = line.split(SUIT_CONFIG_SYMBOL1) suit_name = items[0] attrs = items[1].split(SUIT_CONFIG_SYMBOL2) all_suit_config_map[suit_name] = [] all_suit_config_map[suit_name].append(attrs[0]) all_suit_config_map[suit_name].append(attrs[1]) all_suit_config_map[suit_name].append(attrs[2]) if len(attrs) == 5: all_suit_config_map[suit_name].append(attrs[3]) all_suit_config_map[suit_name].append(attrs[4]) return all_suit_config_map
def bluetooth_pair(self): ''' pair a bluetooth device. author:[email protected] @return: True-success False-fail ''' tag = r'qrd_shared/Settings/bluetooth_pair()' flag = False # pair with another device if not search_text( 'Paired devices', isScrollable=0, searchFlag=TEXT_MATCHES): reciver = get_view_text_by_index(VIEW_TEXT_VIEW, 5) # reciver = get_view_text_by_index(VIEW_TEXT_VIEW, 6) click_textview_by_text(reciver) func = lambda: search_text( 'Bluetooth pairing request', isScrollable=0 ) # # also in slave:start #should open bt before if wait_for_fun(func, True, 5): click_button_by_text('Pair') # # also in slave:end func = lambda: search_text( 'Paired devices', isScrollable=0, searchFlag=TEXT_MATCHES) if wait_for_fun(func, True, 30): flag = True else: log_test_framework(tag, "cannot pair device") if search_text("Couldn't pair with", isScrollable=0): click_button_by_text('OK') else: # click_imageview_by_id('icon',isScrollable=0) flag = True return flag
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 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("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("keep_me_up"), searchFlag=TEXT_CONTAINS): click_button_by_id("button1") if search_text(self.get_value("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("entertainment"), searchFlag=TEXT_CONTAINS): click_button_by_id("skip_button") click_button_by_id("done_button") return True
def go_home(self): for i in range(10): flag1 = is_view_enabled_by_text(VIEW_TEXT_VIEW, 'Messaging', isScrollable=0, searchFlag=TEXT_MATCHES) ''' @attention: modify by min.sheng , change content of flag2 ''' #flag2 = search_view_by_id("list") #flag3 = search_view_by_id("empty") #flag2 = is_view_enabled_by_id(VIEW_BUTTON, 'floating_action_button', isScrollable=0) flag2 = is_view_enabled_by_id(VIEW_BUTTON, 'action_compose_new', isScrollable=0) '''try:scroll_to_bottom() except:pass''' if flag1 & flag2: return True else: log_test_framework(self.TAG, "not find message home flag") goback() sleep(1) return False
def get_test_case_config(case_name, suit_name): ''' get a case's configuration from its xml file(eg:test_case_contacts.xml), and return it as map. @type case_name: string @param case_name: case name. @type suit_name: string @param suit_name: suite name contains this case. @return: map contains the configuration of this case. ''' result_map = {} xml_file_name = suit_name + PATH_SEPARATOR + case_name + XML_SUFFIX if run_init_settings: xml_file_name = PRECONDITION_SETTINGS_PATH + PATH_SEPARATOR + case_name + XML_SUFFIX if path.exists(xml_file_name): if path.isfile(xml_file_name): try: xml_file = open(xml_file_name) except IOError: log_test_framework(TAG, "Open file " + xml_file_name + " error") return result_map xml_dom = parse(xml_file) root = xml_dom.documentElement all_attrs = root.attributes.keys() for attr in all_attrs: result_map[attr] = root.getAttribute(attr) for requiredAtrr in CASE_REQUIRED_ATTRS: #check the required key , if no the key in the map , return empty if not result_map.has_key(requiredAtrr): raise AttributeException('Need '+requiredAtrr+" attribute in "+case_name) return result_map
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 get_all_suit_config(config_filename): ''' used by old version, DO NOT uset it any more. ''' all_suit_config_map = {} try: config_file = open(config_filename, 'r') except IOError: log_test_framework(TAG,"Config file: '" + config_filename + "' doesn't exist or can't be opened!") return all_suit_config_map lines = config_file.readlines() for line in lines: line = line.strip(SYMBOL_LINE_BREAK) if len(line) != 0: items = line.split(SUIT_CONFIG_SYMBOL1) suit_name = items[0] attrs = items[1].split(SUIT_CONFIG_SYMBOL2) all_suit_config_map[suit_name] = [] all_suit_config_map[suit_name].append(attrs[0]) all_suit_config_map[suit_name].append(attrs[1]) all_suit_config_map[suit_name].append(attrs[2]) if len(attrs) == 5: all_suit_config_map[suit_name].append(attrs[3]) all_suit_config_map[suit_name].append(attrs[4]) return all_suit_config_map
def set_default_data(self, card_id): ''' set default data. @type card_id: string @param card_id: default data card id, 1-slot1, 2-slot2, 0-always ask ''' if search_text("SIM cards"): click_textview_by_text("SIM cards") else: return () sleep(1) if search_text("Mobile data"): click_textview_by_text("Mobile data") if search_text("Cellular data"): click_textview_by_text("Cellular data") if card_id == 0: return () elif card_id == 1: click_in_list_by_index(0) elif card_id == 2: click_in_list_by_index(1) else: log_test_framework(self.TAG, "card_id:" + card_id + "is error.") #click_imageview_by_index(0) sleep(5)
def test_suit_init(self, suit_results): ''' init the test suit . such as: save the current suit name; init the report logging; launcher this application; set the L{current_case_continue_flag<current_case_continue_flag>} to True; ''' set_cur_suit_name(self.name) log_test_framework(self.name, "suit init...") qsst_log_suit_init() set_can_continue() return True
def check_default_mms_app(self): if search_view_by_id("banner_sms_promo_title"): log_test_framework(self.TAG, "need to choose mms app") send_key(KEY_MENU) click_textview_by_text("Settings") sleep(1) click_textview_by_text("SMS Disabled") click_button_by_text("Yes") else: pass
def exist(self, msgType=''): tag = 'exist(%s)' % msgType if search_text('No conversations', isScrollable=0): log_test_framework(tag, 'no conversations') return False elif msgType is '':return True elif msgType is 'mms': pass return True
def 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 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 enable_wifi(self, wifi_name, wifi_pwd): ''' enable wifi. @type wifi_name: string @param wifi_name: wifi name @type wifi_pwd: tuple @param wifi_pwd: wifi password @return: whether enable wifi success ''' click_textview_by_text(self.get_value("wifi")) if search_text(self.get_value("see_available_networks"), searchFlag=TEXT_CONTAINS): click_button_by_index(0) sleep(10) sleep(5) #scroll_down() if not search_text(wifi_name): click_imageview_by_index(0) return False click_textview_by_text(wifi_name) flag_wifi = 0 if not wifi_pwd == "": if search_view_by_id("password"): #entertext_edittext_by_index(0, wifi_pwd) click_textview_by_id("password") self.ime.IME_input(1, wifi_pwd) click_button_by_text(self.get_value("connect")) elif search_text(self.get_value("connected")): flag_wifi = 1 goback() elif search_text(self.get_value("forget")) and search_text(self.get_value("connect")): click_button_by_text(self.get_value("connect")) else: log_test_framework(self.TAG, "something wrong after click wifi name.") goback() click_imageview_by_index(0) return False else: if search_text(self.get_value("forget")): goback() if flag_wifi == 1: click_imageview_by_index(0) return True sleep(10) click_textview_by_text(wifi_name) if search_text(self.get_value("connected")): goback() click_imageview_by_index(0) return True else: goback() click_imageview_by_index(0) return False
def loadBgTestSuit(self,base_path): suit_name = "test_suit_background" test_suit = BgTestSuitBase(suit_name, "This is a background suit.") log_test_framework(TAG, "suit_name:"+suit_name) log_test_framework(TAG, "base_path:"+base_path) case_list = self.getCaseList(base_path) for case in case_list: log_test_framework(TAG, "add background case:"+case[1]) case_suit_name = case[0][:case[0].index('.')] case_config_map = fs_wrapper.get_test_case_config(case[1], case_suit_name, True) self.addTestCase(test_suit, case_config_map, case[0] + fs_wrapper.DOT_TAG + case[1], case_suit_name, case[1]) return test_suit
def addTestCase(self, bg_test_suit, caseConfigMap, className, suitName, caseName): ''' add the case to the suit @type bg_test_suit: L{BgTestSuitBase<BgTestSuitBase>} @param bg_test_suit: suit you want to operation @type caseConfigMap: array @param caseConfigMap: the configuration map of the case which is adding to the suit ''' test_case = BgTestCaseBase.createInstance(className, caseName, suitName) test_case.case_config_map = caseConfigMap log_test_framework(test_case.name, "background case added") bg_test_suit.addCase(test_case)
def set_property(self, prop_key, prop_value): ''' set the property value. @type prop_key:string @param prop_key:property key. @type prop_value:string @param prop_value:property value. ''' try: os.system('setprop ' + prop_key + ' ' + prop_value) except IOError, msg: log_test_framework(LOG_TAG, "IO error: " + msg.strerror)
def addTestCase(self, test_suit, caseConfigMap, className, suitName, caseName, appName): ''' add the case to the suit @type test_suit: L{TestSuitBase<TestSuitBase>} @param test_suit: suit you want to operation @type caseConfigMap: array @param caseConfigMap: the configuration map of the case which is adding to the suit ''' test_case = TestCaseBase.createInstance(className, caseName, suitName, appName) test_case.case_config_map = caseConfigMap log_test_framework(test_case.name, "case added") test_suit.addCase(test_case)
def loadTestSuit(self, base_path): ''' load the test suits from the path @type base_path: string @param base_path: the path of the suit @return: return all the suits which can found under this path ''' # load enabled suit as a list suit_names = fs_wrapper.get_suit_name_list(base_path) suit_list = [] status = 0 if case_utility.is_in_reboot_status(): status = 1 for suit_name in suit_names: log_test_framework(TAG, "loadTestSuit suit_name:"+suit_name) if status == 1 and not case_utility.is_suit_in_reboot_status(suit_name): log_test_framework(TAG, "loadTestSuit in not reboot status") continue elif status == 1 and case_utility.is_suit_in_reboot_status(suit_name): log_test_framework(TAG, "loadTestSuit in reboot status") status = 2 suit_py_module_name = fs_wrapper.get_suit_py_module_name(suit_name) if len(suit_py_module_name) == 0: continue # load test suit one by one test_suit = self.loadTestSuitFromName(suit_py_module_name, suit_name) if test_suit != None: log_test_framework(test_suit.name, "suit added") suit_list.append(test_suit) return suit_list
def switchData(switch='ON'): sleep(2) text2 = get_view_text_by_id(VIEW_BUTTON, 'android:id/toggle', isScrollable=0) log_test_framework("current button is ", text2) if switch == 'ON': if text2 == 'OFF': click_textview_by_id('android:id/toggle') sleep(2) text3 = get_view_text_by_id(VIEW_BUTTON, 'android:id/toggle', isScrollable=0) if text3 == 'OFF': take_screenshot() log_test_framework("click data switch still ", text3) return False return True elif switch == 'OFF': if text2 == 'ON': click_textview_by_id('android:id/toggle') sleep(2) text4 = get_view_text_by_id(VIEW_BUTTON, 'android:id/toggle', isScrollable=0) if text4 == 'ON': take_screenshot() log_test_framework("click data switch still ", text3) return False return True else: take_screenshot() log_test_framework('type error', '')
def get_response_line(self, result): """ get response from server through socket,parase new line tag as end tag. @type result:list @param result: result get from the server side. @return: True if success, False if exception occurs. """ if not self.sock: return False try: result[0] = self.fd.readline().strip(NEW_LINE_TAG) except IOError, msg: log_test_framework("io_wrapper", "socket recv error: " + msg.strerror) return False
def test_suit_run(self, suit_results): ''' the entry of the suit.through this method to control the suit life cycle. @type suit_results: array @param suit_results: the case result array. ''' if self.test_suit_init(suit_results): self.test_suit_main(suit_results) self.test_suit_end(suit_results) return True else: log_test_framework(self.name, "suit init fail") self.test_suit_end(suit_results) return False
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 send_msg_line(self, msg): """ send message to server through socket,end with new line tag. To support multi language, It will set encoding to 'utf-8',so plesae make sure your message is encoded in 'utf-8'. @type msg:string @param msg:message to be sent, encoded in 'utf-8' @return: True on success, False on exceptions. """ if not self.sock: return False try: self.sock.sendall(msg + NEW_LINE_TAG) except socket.error, msg: log_test_framework("io_wrapper", "socket send error: " + msg.strerror) return False
def download(self, name, description): ''' download a application according to the application name and description. @type name: string @param name: application's name @type description: string @param description: applicaiton's description that is company name in most situations. @return: true-if the application download success,false-if the application download failed. ''' click_button_by_id("search_button") #entertext_edittext_on_focused(name) click_textview_by_id("search_src_text") self.ime.IME_input_english(1, name) send_key(KEY_ENTER) sleep(20) click_textview_by_text(description) sleep(20) if search_text(self.get_value("uninstall")): log_test_framework( self.TAG, "find uninstall button," + name + " has been installed.") return True if search_text(self.get_value("install")): click_button_by_id("buy_button") click_button_by_id("acquire_button") click_imageview_by_id("home") pre_time = time.time() running = True while running: if search_text(self.get_value("uninstall")): running = False log_test_framework(self.TAG, "download " + name + " successed.") return True if time.time() - pre_time > 10 * 60: running = False log_test_framework(self.TAG, "download " + name + " time out.") click_button_by_id(self.TAG, "cancel_download") log_test_framework(self.TAG, "cancel download " + name) return False else: log_test_framework( self.TAG, "error in find install button interface, download " + name + " error.") return False
def test_suit_end(self, suit_results): ''' end the test suit . save some loggoing ''' import settings.common as SC #if auto insert case waypoint. if SC.PRIVATE_TRACKING_AUTO_INSERT_CASE_WAYPOINT: if int(SC.PUBLIC_RUNNING_REPEAT_NUMBER) == 1: insert_waypoint(END + self.name, suit_description) else: insert_waypoint( END + '(' + str(TestCaseBase.cycle_index) + '/' + str(SC.PUBLIC_RUNNING_REPEAT_NUMBER) + ') ' + self.name, suit_description) log_test_framework(self.name, "suit end") qsst_log_suit_end()
def test_case_main(self, case_results): ''' main entry. @type case_results: tuple @param case_results: record some case result information ''' success = 0 count = 1000 for i in range(0, count): if call("test_suit_scenario1", "test_suit_scenario1_case2"): success += 1 log_test_framework(self.TAG, "total:" + success + "/" + count) if success < count: set_cannot_continue() sleep(1) case_results.append( (self.case_config_map[fs_wrapper.CASE_NAME_ATTR], can_continue()))
def kill_allpid(self): ''' kill current all pid @author: min.sheng ''' send_key(KEY_HOME) sleep(2) start_activity("com.android.systemui", "com.android.systemui.recents.RecentsActivity") if search_text("Your recent screens appear here"): return while not search_view_by_desc("Apps"): if is_view_enabled_by_id(VIEW_IMAGE_VIEW, "dismiss_task"): log_test_framework(TAG, "found the dismiss_task") click_imageview_by_id("dismiss_task",1,0) sleep(3) else: log_test_framework(TAG, "clear pid finished") return
def set_default_sms(self, card_id): ''' set default sms. @type card_id: string @param card_id: default sms card id, 1-slot1, 2-slot2, 0-always ask ''' click_textview_by_text(self.get_value("dual_sim_settings")) click_textview_by_text(self.get_value("sms")) if card_id == 0: click_in_list_by_index(2) elif card_id == 1: click_in_list_by_index(0) elif card_id == 2: click_in_list_by_index(1) else: log_test_framework(self.TAG, "card_id:" + card_id + "is error.") click_imageview_by_index(0)
def get_test_suit_config(suit_name, is_bg_suit=False): ''' get a suit's configuration from its xml file(eg:test_suit_contacts.xml), and return it as map. @type suit_name: string @param suit_name: suit name. @type is_bg_case: boolean @param is_bg_case: whether is background suit. @return: map contains the configuration of this suit. ''' result_map = {} if (is_bg_suit == True): from background_case_pool.bg_test_loader import BACKGROUND_CASE_POOL xml_file_name = BACKGROUND_CASE_POOL + PATH_SEPARATOR + suit_name + PATH_SEPARATOR + suit_name + XML_SUFFIX else: xml_file_name = suit_name + PATH_SEPARATOR + suit_name + XML_SUFFIX if run_init_settings: xml_file_name = PRECONDITION_SETTINGS_PATH + PATH_SEPARATOR + suit_name + XML_SUFFIX if path.exists(xml_file_name): if path.isfile(xml_file_name): try: xml_file = open(xml_file_name) except IOError: log_test_framework(TAG, "Open file " + xml_file_name + " error") return result_map xml_dom = parse(xml_file) root = xml_dom.documentElement all_attrs = root.attributes.keys() for attr in all_attrs: result_map[attr] = root.getAttribute(attr) if (is_bg_suit == True): REQUIRED_ATTRS = BG_SUIT_REQUIRED_ATTRS else: REQUIRED_ATTRS = SUIT_REQUIRED_ATTRS for requiredAtrr in REQUIRED_ATTRS: #check the required key , if no the key in the map , return empty if not result_map.has_key(requiredAtrr): raise AttributeException('Need ' + requiredAtrr + " attribute in " + suit_name) return result_map
def set_default_data(self, card_id): ''' set default data. @type card_id: string @param card_id: default data card id, 1-slot1, 2-slot2, 0-always ask ''' click_textview_by_text(self.get_value("multi_sim_settings")) click_textview_by_text(self.get_value("data_call")) if card_id == 0: click_in_list_by_index(2) elif card_id == 1: click_in_list_by_index(0) elif card_id == 2: click_in_list_by_index(1) else: log_test_framework(self.TAG, "card_id:" + card_id + "is error.") fun = lambda:search_text(self.get_value("set_dds_success")) wait_for_fun(fun,False,20)
def download(self, name, description): ''' download a application according to the application name and description. @type name: string @param name: application's name @type description: string @param description: applicaiton's description that is company name in most situations. @return: true-if the application download success,false-if the application download failed. ''' click_button_by_id("search_button") #entertext_edittext_on_focused(name) click_textview_by_id("search_src_text") self.ime.IME_input_english(1, name) send_key(KEY_ENTER) sleep(20) click_textview_by_text(description) sleep(20) if search_text(self.get_value("uninstall")): log_test_framework(self.TAG, "find uninstall button," + name + " has been installed.") return True if search_text(self.get_value("install")): click_button_by_id("buy_button") click_button_by_id("acquire_button") click_imageview_by_id("home") pre_time = time.time() running = True while running: if search_text(self.get_value("uninstall")): running = False log_test_framework(self.TAG, "download " + name + " successed.") return True if time.time() - pre_time > 10*60: running = False log_test_framework(self.TAG, "download " + name + " time out.") click_button_by_id(self.TAG, "cancel_download") log_test_framework(self.TAG, "cancel download " + name) return False else: log_test_framework(self.TAG, "error in find install button interface, download " + name + " error.") return False
def test_suit_run(self, suit_results): ''' the entry of the suit.through this method to control the suit life cycle. @type suit_results: array @param suit_results: the case result array. ''' if self.test_suit_init(suit_results): #t1=threading.Thread(target=record_screen,args=('haha',)) #t2=threading.Thread(target=self.test_suit_main,args=suit_results,) #t1.start() #t1.join() #t2.start() #t2.join() self.test_suit_main(suit_results) self.test_suit_end(suit_results) return True else: log_test_framework(self.name, "suit init fail") self.test_suit_end(suit_results) return False
def clear(self, clearType): tag = 'clear(%s)' % clearType if clearType is 'draft': while is_view_enabled_by_text(VIEW_TEXT_VIEW, 'Draft', searchFlag=TEXT_CONTAINS): log_test_framework(tag, 'have draft.clearing...') click_textview_by_text('Draft', searchFlag=TEXT_CONTAINS) # click_menuitem_by_text('Discard',isScrollable=0) try:click_menuitem_by_text('Discard', isScrollable=0) except: goback() try:clear_edittext_by_id('embedded_text_editor', isScrollable=0) except:pass try:click_button_by_id('remove_image_button', isScrollable=0, waitForView=1) except:pass try:click_button_by_id('remove_slideshow_button', isScrollable=0) except:pass try:clear_edittext_by_id('subject', isScrollable=0) except:pass try:click_textview_by_id('recipients_editor', isScrollable=0) except:pass elif clearType is 'error': while is_view_enabled_by_id(VIEW_IMAGE_VIEW, 'error', isScrollable=1): log_test_framework(tag, 'have error.clearing...') click_imageview_by_id('error', isScrollable=0) click_menuitem_by_text('Discard', isScrollable=0) goback() else: log_test_framework(tag, 'cannot clear...clearType is wrong') pass
def attach_capture_video(self, videotime, size_flag=0): click_imageview_by_desc('Attach') sleep(3) click_textview_by_text('Capture video') sleep(5) 'add if ' if search_text("JUST ONCE"): click_textview_by_text("JUST ONCE") sleep(2) drag_by_param(538, 57, 538, 1457, 200) sleep(2) click_imageview_by_desc('Shutter') sleep(videotime) func_shutter = lambda: search_view_by_id('shutter_button') if wait_for_fun(func_shutter, True, 10): click_imageview_by_id('shutter_button') sleep(2) #if search_view_by_id('btn_done'): if search_view_by_id('btn_done'): click_imageview_by_id('btn_done') sleep(1) log_test_framework(self.TAG, "attach captured video successfully") return True elif search_view_by_id('done_button'): click_imageview_by_id('done_button') sleep(1) log_test_framework(self.TAG, "attach captured video successfully") return True else: log_test_framework(self.TAG, "Fail to attach captured video ") return False
def attach_audio(self, audioname): click_imageview_by_desc('attach') click_textview_by_text('Audio') click_textview_by_text('System audio') #if search_view_by_desc('Media Storage'): if search_text('Media Storage'): click_textview_by_text('Media Storage') if search_text('JUST ONCE'): sleep(2) click_textview_by_text('JUST ONCE') sleep(1) click_textview_by_text(audioname) sleep(1) if search_text("OK"): click_textview_by_text("OK") sleep(1) log_test_framework(self.TAG, "attach audio successfully") return True else: log_test_framework(self.TAG, "Fail to attach system audio ") return False
def attach_capture_video_oversize(self, videotime=20, size_flag=0): click_imageview_by_desc('Attach') sleep(3) click_textview_by_text('Capture video') sleep(5) 'add if ' if search_text("JUST ONCE"): click_textview_by_text("JUST ONCE") sleep(2) drag_by_param(538, 57, 538, 1457, 200) sleep(2) for i in range(0, 10): click_imageview_by_desc('Shutter') sleep(videotime) if not (search_view_by_id('btn_done') or search_view_by_id('done_button')): log_test_framework(self.TAG, "File does not exceed the size") click_imageview_by_desc('Shutter') sleep(2) if search_view_by_id('btn_done'): click_imageview_by_id('btn_done') sleep(2) elif search_view_by_id('done_button'): click_imageview_by_id('done_button') sleep(2) click_imageview_by_desc('Attach') sleep(3) click_textview_by_text('Capture video') sleep(5) if search_text("JUST ONCE"): click_textview_by_text("JUST ONCE") sleep(2) drag_by_param(538, 57, 538, 1457, 200) sleep(2) continue else: log_test_framework(self.TAG, "File is exceed the size ") return True
def set_default_sms(self, card_id): #c_caijie ''' set default sms. @type card_id: string @param card_id: default sms card id, 1-slot1, 2-slot2, 0-always ask ''' if search_text("SIM cards"): click_textview_by_text("SIM cards") sleep(2) if search_text("SMS messages", searchFlag=TEXT_CONTAINS): click_textview_by_text("SMS messages") sleep(2) if card_id == 0: click_in_list_by_index(0) elif card_id == 1: click_in_list_by_index(1) elif card_id == 2: click_in_list_by_index(2) else: log_test_framework(self.TAG, "card_id:" + card_id + "is error.") #click_imageview_by_index(0) sleep(5)
def test_case_main(self, case_results): ''' main entry. @type case_results: tuple @param case_results: record some case result information ''' success = 0 launcher.launch_from_launcher("system_settings") count = 0 flag = True while (flag): if not settings.enable_wifi(SC.PUBLIC_WIFI_NAME, SC.PUBLIC_WIFI_PASSWORD_SEQUENCE): count += 1 if count == 3: flag = False else: success += 1 flag = False if not settings.add_google_account( SC.PRIVATE_GMAIL_GMAIL_ACCOUNT_SEQUENCE, SC.PRIVATE_GMAIL_GMAIL_PASSWORD_SEQUENCE): log_test_framework(self.TAG, "add google account fail.") set_cannot_continue() else: success += 1 if call("test_suit_playstore", "test_suit_playstore_case2"): success += 1 if success < 3: set_cannot_continue() sleep(1) case_results.append( (self.case_config_map[fs_wrapper.CASE_NAME_ATTR], can_continue()))
def test_suit_end(self, suit_results): ''' end the test suit . save some loggoing ''' log_test_framework(self.name, "suit end") qsst_log_suit_end()
#import settings.common as SC import settings.common as SC # load all test suits and cases global test_loader test_loader = TestLoader() global_number = SC.PUBLIC_RUNNING_REPEAT_NUMBER #init the status , include to know whether is it in reboot status init_status() last_current_time = get_last_current_time() for current_number in range(int(last_current_time),int(global_number)): TestCaseBase.cycle_index = current_number + 1 #init the env each report time init_env(current_number,global_number) log_test_framework("test_main","Current report "+str(current_number)+"/"+str(global_number)) try: if SC.PUBLIC_RANDOM_ORDER: # random #get the all case list case_list = test_loader.getCaseList('./') random.shuffle(case_list) for case in case_list: try: import qrd_shared.case qrd_shared.case.call(case[0], case[1]) except Exception as e: log_test_framework('test_main',"Error :" + str(e)) log_test_framework('test_main',"Traceback :" + traceback.format_exc()) else: suit_list = test_loader.loadTestSuit('./')
def __init__(self): log_test_framework(LOG_TAG, "init: ")
def loadTestSuitFromName(self, suit_module_name, suit_name): ''' load test suit from name @type suit_module_name: string @param suit_module_name: suit module name @type suit_name: string @param suit_name: suit name @return: return the suit instance ''' suit_config_map = fs_wrapper.get_test_suit_config(suit_name) if suit_config_map.get(fs_wrapper.SUIT_ENABLE_ATTR) != '1': return None suit_info = None # create test suit instance test_suit = TestSuitBase.createInstance(suit_module_name + fs_wrapper.DOT_TAG + suit_name, suit_name, suit_info) if suit_config_map.get(fs_wrapper.SUIT_RUNNER_ATTR) != None: test_suit.runner = suit_config_map.get(fs_wrapper.SUIT_RUNNER_ATTR) if suit_config_map.get(fs_wrapper.SUIT_APP_NAME) != None: app_name = suit_config_map.get(fs_wrapper.SUIT_APP_NAME) # load test cases for test suit. # It will aggregate all the relative suit info for this test suit, too. cases = fs_wrapper.get_all_cases_py_module_name(test_suit.name) #relative_suits = [] status = 0 if is_suit_in_reboot_status(suit_name) and is_in_reboot_status(): status = 1 log_test_framework(TAG, "suit_name:"+suit_name) for case in cases: log_test_framework(TAG, "check case:"+case[1]) if status == 1 and not is_case_in_reboot_status(case[1]): log_test_framework(TAG, "status == 1 and not is_case_in_reboot_status") continue elif status == 1 and is_case_in_reboot_status(case[1]): log_test_framework(TAG, "status == 1 and is_case_in_reboot_status") status = 2 if get_reboot_reason() == REBOOT_CRASH: log_test_framework(TAG, "get_reboot_reason() == REBOOT_CRASH") qsst_log_restore_reboot() continue qsst_log_restore_reboot() log_test_framework(TAG, "add case:"+case[1]) case_config_map = fs_wrapper.get_test_case_config(case[1], test_suit.name) if case_config_map.get(fs_wrapper.CASE_ENABLE_ATTR) == '1': case_app_name = case_config_map.get(fs_wrapper.CASE_APP_NAME) if case_app_name == None or case_app_name == "": case_app_name = app_name else: log_test_framework(TAG,'case_app_name null') reference = case_config_map.get(fs_wrapper.CASE_REFERENCE); if reference != None and reference!= "": (suit_name, case_name) = reference.rsplit('.', 1) class_name = reference + fs_wrapper.DOT_TAG + case_name self.addTestCase(test_suit,case_config_map,class_name, suit_name,case_name, case_app_name) else: self.addTestCase(test_suit,case_config_map,case[0] + fs_wrapper.DOT_TAG + case[1], suit_name,case[1], case_app_name) return test_suit
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')