def write_email(self, to_address, subject, content): ''' write an email ,only text @type to_address: string @param to_address: destination address. @type subject: string @param subject: email subject. @type content: string @param content: email content. ''' ime = IME() #input to_address clear_edittext_by_id("to", 1, 0) ime.IME_input(1, to_address, input_type="b") #input subject click_textview_by_id("subject") ime.IME_input(1, subject) #input content ime.IME_input(1, content) #entertext_edittext_by_id("body_text",content) click_imageview_by_id("send")
def __init__(self): ''' init function. ''' self.mode_name = "mms" self.ime = IME() Base.__init__(self, self.mode_name) self.debug_print('Mms init:%f' % (time.time()))
def __init__(self): ''' init function. ''' self.mode_name = "playstore" Base.__init__(self, self.mode_name) self.ime = IME() self.debug_print('PlayStore init:%f' % (time.time()))
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 __init__(self): ''' init method. ''' self.mode_name = "settings" Base.__init__(self, self.mode_name) self.ime = IME() self.email = Email() self.debug_print('Settings init:%f' % (time.time()))
def test_case_main(self, case_results): """ main function ,entry add feature @return: none """ self.ime = IME() click_imageview_by_index(0) click_imageview_by_index(2) click_imageview_by_index(1) # 1 -delete all #self.del_contact_all() # 2 -add some contact for i in range(1, 3): click_imageview_by_id('menu_add_contact') self.IsfirstAddContact() if i % 2: self.add_contact_to_phone(i) else: self.add_contact_to_SIM_Card(i) #click btn done #click_imageview_by_index(0) click_imageview_by_id('icon') sleep(1) # add favorite #click_textview_by_id('menu_star') #for ux click_textview_by_id('star') sleep(1) # goback click_imageview_by_index(0) sleep(3) if not can_continue(): break
class Mms(Base): ''' Mms is a class for operating Mms application. @see: L{Base <Base>} ''' TAG = "Mms" '''@var TAG: tag of Mms''' def __init__(self): ''' init function. ''' self.mode_name = "mms" self.ime = IME() Base.__init__(self, self.mode_name) self.debug_print('Mms init:%f' % (time.time())) 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 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 delete_all_threads(self): #c_caijie ''' delete all threads. ''' click_textview_by_id('from', clickType=LONG_CLICK) sleep(2) click_button_by_id('selection_menu') sleep(5) click_textview_by_text('Select all') sleep(5) click_textview_by_id('delete') sleep(5) click_button_by_index(1) sleep(60) def send_sms(self, number, content): #c_caijie if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', number) sleep(5) send_key(KEY_ENTER) sleep(5) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', content) sleep(5) click_imageview_by_id('send_button_sms') sleep(3) 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 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 number(self, thread=''): tag = 'number(%s)' % thread drag_by_param(50, 30, 50, 80, 20) if '' == thread: head = get_view_text_by_id(VIEW_TEXT_VIEW, 'from', isScrollable=0).decode('utf-8') else: drag_by_param(50, 20, 50, 80, 10) thread = str(thread) left = '.*' + thread[0:3] + '\s?' + thread[3:7] + '\s?' + thread[ 7:11] + '.*' head = get_text(left, isScrollable=1, searchFlag=TEXT_MATCHES_REGEX) if head is '': log_test_framework(tag, 'cannot find thread = ' + thread) n = 0 return (n, thread, left) # left should be 'NULL'?? import re if re.search(u'\xa0', head): [left, right] = head.split(u'\xa0') n = re.search('\d+', right).group() n = int(n) else: left = head # thread = s n = 1 # n = '1' thread = left.replace(u' ', u'') # remove all space thread = thread.replace(u'+86', u'') log_test_framework(tag, 'thread = ' + thread) log_test_framework(tag, 'n = ' + str(n)) # n = int(n) log_test_framework(tag, 'end') return (n, thread, left) #added by c_yazli 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_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 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_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 add_picture(self): #c_caijie ''' add picture from storage @author: min.sheng ''' click_imageview_by_desc('Attach') sleep(3) click_textview_by_text("Capture Picture") if wait_for_fun(lambda: search_view_by_id("permission_allow_button"), True, 8): click_button_by_id('permission_allow_button') if wait_for_fun(lambda: search_text("OK"), True, 5): click_textview_by_text("OK") if wait_for_fun(lambda: search_view_by_id('shutter_button'), True, 10): click_button_by_id('shutter_button') sleep(3) if wait_for_fun(lambda: search_view_by_desc("Review done"), True, 10): click_imageview_by_desc("Review done") elif wait_for_fun(lambda: search_view_by_id('btn_done'), True, 10): click_imageview_by_id("btn_done") #click_textview_by_id("menu_list") #sleep(3) #click_textview_by_text("temp.jpg", searchFlag=TEXT_CONTAINS) #sleep(2) def add_subject(self, subjectString): send_key(KEY_MENU) sleep(1) click_textview_by_text("Add subject") sleep(1) click_textview_by_text("Subject") sleep(1) self.ime.IME_input(1, subjectString) sleep(1) def add_content(self): click_textview_by_text("Type message") entertext_edittext_on_focused("DEVCI test") #self.ime.IME_input_english(1, "DEVCI test") sleep(1) def add_recipient(self, recipientname): #c_caijie click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_on_focused(recipientname) sleep(5) send_key(KEY_ENTER) sleep(3) ''' @attention: add by min.sheng check the mms app ''' 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 save_draft(self): #c_caijie ''' use slot1 or slot2 to send a sms to a specific phone number,then check whether send success. @type send_slot_number: number @param send_slot_number: send slot,1-slot1,2-slot2, 3-default @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. ''' if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', '18721465130') sleep(8) send_key(KEY_ENTER) sleep(5) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', 'nosend187') sleep(5) send_key(KEY_BACK) sleep(5) send_key(KEY_BACK) sleep(5) def search_sms(self, content): #c_caijie click_textview_by_id("search") sleep(3) entertext_edittext_by_id('search_view', content) sleep(8) #click_textview_by_desc('Search') #sleep(8) def sms_signature(self, signature): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Text (SMS) messages settings") sleep(3) click_textview_by_text("SMS signature disabled") sleep(3) click_textview_by_text('Edit SMS signature') sleep(3) entertext_edittext_by_id("edit", signature) sleep(5) click_button_by_id('button1') sleep(3) send_key(KEY_BACK) sleep(3) send_key(KEY_BACK) sleep(3) def delivery_report(self): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Text (SMS) messages settings") sleep(3) click_textview_by_text('Delivery reports') sleep(3) send_key(KEY_BACK) sleep(2) send_key(KEY_BACK) sleep(2) def preferred_storage(self, storage): #c_caijie click_imageview_by_desc('More options') if wait_for_fun(lambda: search_text("Settings"), True, 5): click_textview_by_text('Settings') if wait_for_fun(lambda: search_text("Text (SMS) messages settings"), True, 8): click_textview_by_text("Text (SMS) messages settings") if wait_for_fun(lambda: search_text("Preferred storage"), True, 5): click_textview_by_text('Preferred storage') sleep(3) click_textview_by_text(storage) sleep(5) send_key(KEY_BACK) sleep(3) send_key(KEY_BACK) sleep(3) def set_text_message_limit(self, number): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text('Text message limit') sleep(5) entertext_edittext_by_id("numberpicker_input", number) sleep(5) click_button_by_id('button1') sleep(3) send_key(KEY_BACK) sleep(3) # def send_text_message_limit(self):#c_caijie # self.send_sms("18721465135", "one") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "two") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "three") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "four") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "five") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "six") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "seven") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "eight") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "nine") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "ten") # send_key(KEY_BACK) # sleep(3) # send_key(KEY_BACK) # sleep(3) # self.send_sms("18721465135", "eleven") def send_text_message_limit(self): #c_caijie if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', "13636583073") sleep(5) send_key(KEY_ENTER) sleep(5) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "one") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "two") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "three") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "four") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "five") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "six") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "seven") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "eight") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "nine") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "ten") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', "eleven") sleep(5) click_imageview_by_id('send_button_sms') sleep(3) def restore_default_settings(self): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Restore default settings') sleep(8) def manage_SIM1_card_message(self): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Text (SMS) messages settings") sleep(3) click_textview_by_text('Manage SIM card messages') sleep(3) def send_import_template(self, number): #c_caijie if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', number) send_key(KEY_ENTER) sleep(5) click_button_by_id("add_attachment_first") sleep(3) click_imageview_by_id("pager_indicator_second") sleep(3) if search_text("Import Template", isVerticalList=0, searchFlag=TEXT_CONTAINS): click_textview_by_text("Import Template") sleep(2) click_textview_by_text('Please call me later') sleep(5) click_imageview_by_id('send_button_sms') sleep(3) def send_add_subject(self, number): #c_caijie if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', number) sleep(8) send_key(KEY_ENTER) sleep(5) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', 'subject') sleep(5) click_button_by_id("add_attachment_first") sleep(3) click_textview_by_text('Subject') sleep(5) click_textview_by_text('Subject') sleep(3) entertext_edittext_on_focused('subject') sleep(10) send_key(KEY_ENTER) sleep(5) click_imageview_by_id('send_button_sms') sleep(3) def discard_sms(self, number, content): #c_caijie if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(5) click_textview_by_id("recipients_editor") sleep(3) entertext_edittext_by_id('recipients_editor', number) sleep(8) send_key(KEY_ENTER) sleep(5) click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', content) sleep(8) click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Discard') sleep(8) def delivery_report_mms(self): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Multimedia (MMS) messages settings") sleep(3) click_textview_by_text("Delivery reports", searchFlag=TEXT_MATCHES) sleep(5) send_key(KEY_BACK) sleep(2) send_key(KEY_BACK) sleep(2) def add_audio(self, filename): #c_caijie click_imageview_by_desc('Attach') sleep(3) click_textview_by_text("Audio") sleep(2) click_textview_by_text("External audio") sleep(3) click_textview_by_text(filename, searchFlag=TEXT_CONTAINS) sleep(2) click_button_by_text("OK") sleep(3) def auto_retrieve_mms(self): click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Multimedia (MMS) messages settings") sleep(3) click_textview_by_text('Auto-retrieve') sleep(3) send_key(KEY_BACK) sleep(2) send_key(KEY_BACK) sleep(2) def forward_sms_saved_in_sim_card(self, phonenumber): #c_caijie click_imageview_by_desc('More options') sleep(3) click_textview_by_text('Settings') sleep(3) click_textview_by_text("Text (SMS) messages settings") sleep(3) click_textview_by_text('Manage SIM card messages') if wait_for_fun(lambda: search_text("From: 10086"), True, 60): #click_textview_by_id("sim_message_address", clickType=LONG_CLICK) click_textview_by_text("From: 10086", clickType=LONG_CLICK) sleep(3) click_textview_by_id("forward") sleep(5) entertext_edittext_by_id("recipients_editor", phonenumber) sleep(3) send_key(KEY_ENTER) sleep(2) click_imageview_by_id('send_button_sms') sleep(2) def send_sms_to_multi_recipient(self, content): if search_view_by_id('create'): click_button_by_id('create') sleep(5) if search_view_by_id('action_compose_new'): click_button_by_id('action_compose_new') sleep(3) click_button_by_id("recipients_picker") if wait_for_fun(lambda: search_view_by_id("selection_menu"), True, 5): click_button_by_id("selection_menu") if wait_for_fun(lambda: search_text("Select all"), True, 5): click_textview_by_text("Select all") if wait_for_fun(lambda: search_text("Ok"), True, 5): click_textview_by_id("btn_ok") if wait_for_fun( lambda: search_view_by_id("embedded_text_editor"), True, 10): click_textview_by_id('embedded_text_editor') sleep(3) entertext_edittext_by_id('embedded_text_editor', content) sleep(5) send_key(KEY_ENTER) sleep(2) click_imageview_by_id('send_button_sms') sleep(2)
# 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() LOG_TAG = 'qrd_share_case' #create a instance def createInstance(class_name, *args, **kwargs): (module_name, class_name) = class_name.rsplit('.', 1)
def __init__(self): self.mode_name = "weibo" Base.__init__(self, self.mode_name) self.ime = IME() self.debug_print('Base init:%f' % (time.time()))
class Weibo(Base): ''' Weibo will provide common weibo related functions for all cases ,such as login to weibo, share with weibo and so on. ''' def __init__(self): self.mode_name = "weibo" Base.__init__(self, self.mode_name) self.ime = IME() self.debug_print('Base init:%f' % (time.time())) #input: be sure the weibo app have started, but not sure where it is or whether it have logined ? #output: return true or false . def is_login(self): ''' judge current whether it has logined. if the current activity is not in the switch user activity, we will think it has logined. @return: True, if it has logined,otherwise , False ''' activityName = get_activity_name() if activityName == 'com.sina.weibo.SwitchUser': return False return True #input: the page is in the login page #output: just enter the email and password and press the login button,and try to wait for 5 seconds. # if the activity page switched to another page in the 5 seconds, we assume success def login(self): ''' enter the account information and login to the main interface @return: True, if it login successfully,otherwise , False ''' #focus on the login input box click_textview_by_id('etLoginUsername', 1, 0) self.ime.IME_input(1, SC.PRIVATE_WEIBO_ACCOUNT_SEQUENCE) drag_by_param(90, 10, 95, 15, 1) #focus in the password input box click_textview_by_id('etPwd', 1, 0) sleep(1) self.ime.IME_input(1, SC.PRIVATE_WEIBO_PASSWORD_SEQUENCE) click_button_by_id('bnLogin') loginActivity = "com.sina.weibo.SwitchUser" #wait the login activity disapper waitActivity = lambda: get_activity_name() == loginActivity return wait_for_fun(waitActivity, False, 15) #input: make sure the weibo app is running. #output: if the surrent page is in Navigater, it will drag to enter the home page .otherwise, will do nothing. def skip_navigator(self): ''' skip the navigator. ''' activityName = get_activity_name() if activityName == 'com.sina.weibo.NavigateViewPageActivity': drag_by_param(90, 50, 10, 50, 10) drag_by_param(90, 50, 10, 50, 10) drag_by_param(90, 50, 10, 50, 10) if search_view_by_id('iv_skip_btn'): click_imageview_by_id('iv_skip_btn') #cancel to share to friends if search_view_by_id('ivNavigater_selection'): click_imageview_by_id('ivNavigater_selection') #begin weibo if search_view_by_id('ivNavigater_clickable'): click_imageview_by_id('ivNavigater_clickable') sleep(4) #input: viewing a picture #output:back to the camera app def share_with_weibo(self, message): ''' share with weibo. @note: Be sure it is in the viewing picture interface @type message:string @param message:the message want to share with weibo ''' shareWithWeibo = self.get_value('share_to_weibo') if search_view_by_desc(self.get_value('default_share_to_weibo')): click_view_by_container_id('default_activity_button', 'android.widget.ImageView', 0) else: click_imageview_by_desc(self.get_value('share_object')) #click the text sell all if wait_for_fun( lambda: search_text(self.get_value('see_all'), searchFlag=TEXT_CONTAINS), True, 3): click_textview_by_text(self.get_value('see_all')) if search_text(shareWithWeibo): click_textview_by_text(shareWithWeibo) else: log_test_case(self.mode_name, 'Can not find the weibo') return False sleep(1) waitActivity = lambda: get_activity_name().startswith("com.sina.weibo") if not wait_for_fun(waitActivity, True, 20): return False if not self.is_login(): self.login() sleep(2) return self.share_with_weibo_inner(message) #input: in the post page #output:cose the post page def share_with_weibo_inner(self, message): ''' share with weibo. @note: Be sure it is in the write message interface @type message:string @param message:the message want to share with weibo ''' waitBlog = lambda: search_view_by_id("et_mblog") if not wait_for_fun(waitBlog, True, 10): start_activity("com.sina.weibo", ".EditActivity") #enter the message click_textview_by_id('et_mblog', 1, 0) sleep(1) self.ime.IME_input(1, message, 'c') sleep(1) #click the delete position button(textView) #click_textview_by_text(self.get_value('send')) click_textview_by_id("titleSave") waitActivity = lambda: get_activity_name( ) == "com.sina.weibo.EditActivity" if not wait_for_fun(waitActivity, False, 20): # if the editActivity is still alive , close it loopTimes = 0 while loopTimes < 5: if search_text(self.get_value('same_draf_tip'), 1, 0): click_button_by_text(self.get_value('cancel')) break else: goback() loopTimes = loopTimes + 1 log_test_case(self.mode_name, 'Cancel post the weibo status') return False return True
class PlayStore(Base): ''' PlayStore is a class for operating google play store application. @see: L{Base <Base>} ''' TAG = "PlayStore" '''@var TAG: tag of PlayStore''' def __init__(self): ''' init function. ''' self.mode_name = "playstore" Base.__init__(self, self.mode_name) self.ime = IME() self.debug_print('PlayStore init:%f' % (time.time())) 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
class Settings(Base): ''' Settings is a class for operating Settings application. @see: L{Base <Base>} ''' global TAG, count '''@var count: count login,init value is 0 @var TAG: "tag of Settings" @attention: modify by min.sheng,change TAG to global ''' count = 0 TAG = "Settings" def __init__(self): ''' init method. ''' self.mode_name = "settings" Base.__init__(self, self.mode_name) self.ime = IME() self.email = Email() self.debug_print('Settings init:%f' % (time.time())) def close_lockscreen(self): #c_caijie ''' set screen lock as None. set screen sleep as Never. ''' # drag_by_param(0, 50, 90, 50, 10) # sleep(2) # click_textview_by_text("Display") # sleep(2) # click_textview_by_text("Sleep") # sleep(2) # click_textview_by_text("30 minutes") # sleep(2) # drag_by_param(0, 50, 90, 50, 10) # sleep(2) # if search_text("Security"): # click_textview_by_text("Security") # sleep(2) # click_textview_by_text("Screen lock") # time.sleep(2) # click_textview_by_text("None") # time.sleep(2) # send_key(KEY_BACK) ''' @attention: min.sheng @see: send_key(KEY_BACK) ''' time.sleep(1) scroll_up() time.sleep(3) click_textview_by_text(self.get_value("security")) time.sleep(1) click_textview_by_text(self.get_value("screen_lock")) time.sleep(1) click_textview_by_text(self.get_value("none")) time.sleep(1) ''' @attention: min.sheng @see: send_key(KEY_BACK) ''' send_key(KEY_BACK) #click_imageview_by_index(0) time.sleep(1) scroll_up() #click_textview_by_text(self.get_value("display")) click_textview_by_text(self.get_value("display")) #if is_checkbox_checked_by_index(0): # click_checkbox_by_index(0) click_textview_by_text(self.get_value("sleep")) time.sleep(1) ''' @attention: no select "never" for M, so change to 30 minutes @author: min.sheng ''' click_textview_by_text(self.get_value("30 minutes")) #click_textview_by_text(self.get_value("never")) time.sleep(1) click_imageview_by_index(0) #c_wwan send_key(KEY_BACK) if wait_for_fun( lambda: search_text("Data usage", searchFlag=TEXT_CONTAINS), True, 5): click_textview_by_text("Data usage") time.sleep(1) if wait_for_fun( lambda: search_text('OFF', searchFlag=TEXT_MATCHES), True, 5): click_button_by_id("switch_widget") time.sleep(1) else: pass send_key(KEY_BACK) send_key(KEY_HOME) time.sleep(1) def select_language(self, lan): ''' set system language. @type lan:string @param lan:: language name ''' click_textview_by_index(19) click_textview_by_index(1) sleep(1) click_textview_by_text(lan) sleep(2) click_imageview_by_index(0) 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 ''' if search_text('Wi‑Fi', searchFlag=TEXT_CONTAINS): click_textview_by_text('Wi‑Fi') else: click_textview_by_text('WLAN') #To see available networks 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) ''' @attention: add a log message by min.sheng ''' log_test_framework(TAG, "not find the wifiname:%s" % wifi_name) return False click_textview_by_text(wifi_name) flag_wifi = 0 if not wifi_pwd == "": if search_view_by_id("password"): click_checkbox_by_id('show_password') # entertext_edittext_by_index(0, wifi_pwd) click_textview_by_id("password") ''' @attention: modify by min.sheng @see: entertext_edittext_by_id('password', wifi_pwd) ''' entertext_edittext_by_id('password', wifi_pwd) #self.ime.IME_input(1, wifi_pwd) # self.ime.IME_input(wifi_pwd) # IME.IME_input(1, wifi_pwd) click_textview_by_text('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")): ''' @attention: modify by min.sheng, forget the passward and reconnect ''' click_button_by_text(self.get_value("forget")) click_textview_by_text(wifi_name) click_checkbox_by_id('show_password') click_textview_by_id("password") entertext_edittext_by_id('password', wifi_pwd) click_button_by_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 disable_wifi(self): ''' disable wifi. ''' click_textview_by_text(self.get_value("wifi")) if not search_text(self.get_value("see_available_networks"), searchFlag=TEXT_CONTAINS): click_button_by_index(0) click_imageview_by_index(0) def disable_wlan(self): ''' disable wlan ''' if search_text("see available networks", searchFlag=TEXT_CONTAINS): return True click_textview_by_id("switch_widget") 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 re_sign_in(self): ''' if could not sign in,sign in continuous for 3 times @return: whether sign in success ''' flag = True global count while (flag): if not search_text(self.get_value("signing_in"), searchFlag=TEXT_CONTAINS): flag = False if search_text(self.get_value("could_not_sign_in"), searchFlag=TEXT_CONTAINS): click_button_by_id("next_button") click_textview_by_text(self.get_value("next")) count += 1 if count == 3: count = 0 return False self.re_sign_in() else: count = 0 return True def whether_open_gps(self, open): ''' open or close gps. @type open: boolean @param open: true-open gps,false-close gps ''' click_textview_by_text(self.get_value("location_access")) if open: if not is_compoundbutton_checked_by_index(0): click_button_by_index(0) fun = lambda: search_view_by_id("button2") if wait_for_fun(fun, True, 2): click_button_by_id("button2") else: if not is_checkbox_checked_by_index(0): click_checkbox_by_index(0) else: if is_compoundbutton_checked_by_index(0): if is_checkbox_checked_by_index(0): click_checkbox_by_index(0) click_imageview_by_index(0) def whether_open_mobile_data(self, open): ''' open or close mobile data. @type open: boolean @param open: true-open mobile data,false-close mobile data ''' if open: if not is_compoundbutton_checked_by_index(1): click_button_by_index(1) else: if is_compoundbutton_checked_by_index(1): click_button_by_index(1) 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) # click_imageview_by_index(0) #click_imageview_by_desc("Navigate up") 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 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 is_wifi_connected(self, wifi_name): ''' get wifi status whether wifi is connected. @type wifi_name: string @param wifi_name: wifi name @return: true-if wifi_name have connected, false-if wifi_name haven't connected ''' click_textview_by_text(self.get_value("wifi")) if search_text(self.get_value("see_available_networks"), searchFlag=TEXT_CONTAINS): return False click_textview_by_text(wifi_name) if not search_text(self.get_value("connected")): return False return True def access_to_my_location(self, access): ''' whether access to my location in Location access @type access: boolean @param access: true- on,false-off ''' click_textview_by_text(self.get_value("location_access")) if access: if not is_compoundbutton_checked_by_index(0): click_button_by_index(0) for i in range(0, 2): fun = lambda: search_view_by_id("button1") if wait_for_fun(fun, True, 2): click_button_by_id("button1") else: click_button_by_index(0) click_button_by_index(0) for i in range(0, 2): fun = lambda: search_view_by_id("button1") if wait_for_fun(fun, True, 2): click_button_by_id("button1") else: if is_compoundbutton_checked_by_index(0): click_button_by_index(0) click_imageview_by_index(0) def bluetooth(self, switch='on'): ''' Trun on or turn off the bluetooth. author:[email protected] @type switch: string @param switch: wifi name ''' click_textview_by_text(self.get_value('bluetooth')) if (switch == 'on' or switch == 'enable'): if get_view_text_by_id(VIEW_TEXT_VIEW, 'switch_text', isScrollable=0) == 'Off': click_textview_by_text('Off') sleep(5) elif (switch == 'off' or switch == 'disable'): if get_view_text_by_id(VIEW_TEXT_VIEW, 'switch_text', isScrollable=0) == 'On': click_textview_by_text('On', isScrollable=0) else: raise ValueError( r"switch should be 'on','off' or 'enable','disable'") 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 check_carrier_sim(self, slotId): ''' check the carrier of sim @author: min.sheng @type param: slotId: string @param slotId: SIM1:sim1; SIM2:sim2 ''' start_activity('com.android.settings', '.Settings') click_textview_by_text("SIM cards") sleep(2) click_textview_by_text(slotId) sleep(2) carrier_result = get_view_text_by_id(VIEW_TEXT_VIEW, "carrier") return carrier_result def modify_sim_name(self, slotId, operation, name): ''' get the name of simcard @author: min.sheng @type param: slotId: string @param slotId: SIM1:sim1; SIM2:sim2 @type operation: string @param operation: get:get the name set:set the name @type name:string @param name: the name you want set ''' start_activity('com.android.settings', '.Settings') click_textview_by_text("SIM cards") sleep(2) click_textview_by_text(slotId) sleep(2) if operation == "get": sim_name = get_view_text_by_id(VIEW_EDIT_TEXT, "sim_name") return sim_name elif operation == "set": entertext_edittext_by_id("sim_name", name) #click ok click_button_by_id("button1") 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") sleep(2) if search_text("Your recent screens appear here", isScrollable=0): 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 check_after_resetphone(self): ''' check some feature after reset the phone @author: min.sheng ''' if search_text("Close"): click_button_by_text("Close") sleep(1) if search_text("OK"): click_button_by_text("OK") sleep(1) send_key(KEY_HOME) sleep(1) # click_textview_by_desc(self.get_value('Apps list')) # if search_text("OK"): # click_button_by_text("OK") # send_key(KEY_HOME) def airplane_mode(self): #c_caijie start_activity('com.android.settings', 'com.android.settings.Settings') sleep(5) click_textview_by_text('More') sleep(3) click_textview_by_text('Airplane mode') sleep(5) if search_text("OK", searchFlag=TEXT_CONTAINS): click_button_by_id('button1') sleep(3) def cellular_networks(self): #c_caijie start_activity('com.android.settings', 'com.android.settings.Settings') sleep(5) click_textview_by_text('More') sleep(3) click_textview_by_text('Cellular networks') sleep(3) click_textview_by_text('Data roaming') sleep(3) def set_language_to_simplified_chinese(self): #c_caijie click_textview_by_text("Languages & input") sleep(2) click_textview_by_text("English (United States)") sleep(2) if search_text("Add a language"): click_textview_by_text("Add a language") sleep(2) click_textview_by_text("简体中文(中国)") sleep(5) drag_by_param(50, 15, 0, 0, 10) sleep(2) def set_language_from_chinese_to_english_us(self): #c_caijie click_textview_by_text("语言和输入法") sleep(2) click_textview_by_text("中文 (简体)") sleep(2) click_textview_by_text("English (United States)") sleep(2) if search_text("确定"): click_button_by_text("确定") sleep(2) def change_font_size_to_large(self): click_textview_by_text("Display") sleep(2) click_textview_by_text("Font size") sleep(2) click_button_by_index(2) sleep(3) def change_font_size_to_default(self): click_textview_by_text("Display") sleep(2) click_textview_by_text("Font size") sleep(2) click_button_by_index(1) sleep(3) def set_wallpaper(self): click_textview_by_text("Display") sleep(2) click_textview_by_text("Wallpaper") sleep(2) click_textview_by_text("Snapdragon Gallery") sleep(2) click(290, 539) sleep(2) click(187, 392) sleep(2) if wait_for_fun(lambda: search_view_by_id("set_wallpaper_button"), True, 5): click_button_by_id("set_wallpaper_button") if wait_for_fun(lambda: search_text("Home screen"), True, 5): click_textview_by_text("Home screen") def SIM_status(self): click_textview_by_text("About phone") if wait_for_fun(lambda: search_text("Status"), True, 3): click_textview_by_text("Status") if wait_for_fun(lambda: search_text("SIM status"), True, 3): click_textview_by_text("SIM status") def data_usage(self): click_textview_by_text("Apps") if wait_for_fun(lambda: search_text("Settings"), True, 3): click_textview_by_text("Settings") if wait_for_fun(lambda: search_text("Data usage"), True, 3): click_textview_by_text("Data usage") def tethering_hotspot(self): click_textview_by_text("More") if wait_for_fun(lambda: search_text("Tethering & hotspot"), True, 3): click_textview_by_text("Tethering & hotspot") def check_APN(self): click_textview_by_text("More") if wait_for_fun(lambda: search_text("Cellular networks"), True, 3): click_textview_by_text("Cellular networks") if wait_for_fun(lambda: search_text("Access Point Names"), True, 3): click_textview_by_text("Access Point Names") def check_location(self): click_textview_by_text("Location") if wait_for_fun(lambda: search_view_by_desc("More options"), True, 3): click_imageview_by_desc("More options") if wait_for_fun(lambda: search_text("Scanning"), True, 3): click_textview_by_text("Scanning") def add_calendar_event(self): click_imageview_by_desc("More options") if wait_for_fun(lambda: search_text("New event"), True, 3): click_textview_by_text("New event") if wait_for_fun(lambda: search_text("Add account"), True, 5): click_button_by_text("Add account") if wait_for_fun(lambda: search_view_by_id("account_email"), True, 5): Email().add_eamil_account() sleep(5) start_activity('com.android.calendar', 'com.android.calendar.AllInOneActivity') if wait_for_fun( lambda: search_view_by_desc("More options"), True, 5): click_imageview_by_desc("More options") if wait_for_fun(lambda: search_text("New event"), True, 3): click_textview_by_text("New event") if wait_for_fun(lambda: search_view_by_id("title"), True, 3): entertext_edittext_by_id('title', 'event') sleep(5) click_textview_by_index(1) #click_textview_by_text("DONE") def enable_usb_debugging(self): click_textview_by_text("About phone") sleep(2) for i in range(6): click_textview_by_text("Build number") send_key(KEY_BACK) if wait_for_fun(lambda: search_text("Developer options"), True, 3): click_textview_by_text("Developer options") sleep(2) click_textview_by_text("USB debugging") def check_cellular_networks(self): click_textview_by_text("More") if wait_for_fun(lambda: search_text("Cellular networks"), True, 3): click_textview_by_text("Cellular networks") def check_cellular_data_limit(self): search_text("Data usage") click_textview_by_text("Data usage") if wait_for_fun(lambda: search_text("Cellular data usage"), True, 3): click_textview_by_text("Cellular data usage") if wait_for_fun(lambda: search_view_by_id("filter_settings"), True, 3): click_imageview_by_id("filter_settings") if wait_for_fun(lambda: search_text("Set data limit"), True, 3): click_textview_by_text("Set data limit") if wait_for_fun(lambda: search_text("OK"), True, 3): click_button_by_text("OK") def set_APN_protocol(self): click_textview_by_text("More") if wait_for_fun(lambda: search_text("Cellular networks"), True, 3): click_textview_by_text("Cellular networks") if wait_for_fun(lambda: search_text("Access Point Names"), True, 3): click_textview_by_text("Access Point Names") if wait_for_fun(lambda: search_text("CMNET"), True, 3): click_textview_by_text("CMNET") if wait_for_fun(lambda: search_text("APN protocol"), True, 3): click_textview_by_text("APN protocol") if wait_for_fun(lambda: search_text("IPv4"), True, 3): click_textview_by_text("IPv4") def enable_disable_screen_pinning(self): click_textview_by_text("Security") if wait_for_fun(lambda: search_text("Screen pinning"), True, 5): click_textview_by_text("Screen pinning") if wait_for_fun(lambda: search_text("Off"), True, 5): click_imageview_by_id("switch_widget") if wait_for_fun(lambda: search_text("On"), True, 5): #click_imageview_by_id("switch_widget") click_button_by_text("On")
def add_email_account(self, user_name, user_pwd): ''' add an email account @type user_name: string @param user_name: email user name. @type user_pwd: string @param user_pwd: email user password. @return: True: login successful; False: no. ''' #Add Email Account ime = IME() start_activity('com.android.settings', '.Settings') scroll_to_bottom() click_textview_by_text(self.get_value("add_account_label"), 1, 0) click_textview_by_text(self.get_value("app_email"), 1, 0) #input account click_textview_by_id("account_email", 1, 0) ime.IME_input(1, user_name) #input password ime.IME_input(1, user_pwd) #entertext_edittext_by_id("account_password",SC.PRIVATE_EMAIL_EMAIL_PASSWORD,1,0) sleep(1) click_button_by_id("next", 1, 0) click_button_by_id("pop", 1, 0) scroll_to_bottom() click_button_by_id("next", 1, 0) if not search_text(self.get_value("account_duplicate_dlg_title"), 1, 0): time = 0 while (search_text( self.get_value( "account_setup_check_settings_check_incoming_msg"), 1, 0) or search_text(self.get_value("could_not_open_connection"), 1, 0)) and time < 3: sleep(2) if search_text(self.get_value("could_not_open_connection"), 1, 0): goback() time = time + 1 click_button_by_id("next", 1, 0) if time == 3: return False else: click_imageview_by_id("account_security_type", 1, 0) click_textview_by_text(self.get_value("ssl_tls"), 1, 0) scroll_to_bottom() click_button_by_id("next", 1, 0) time = 0 while (search_text( self.get_value( "account_setup_check_settings_check_outgoing_msg"), 1, 0) or search_text( self.get_value("could_not_open_connection"), 1, 0)) and time < 3: sleep(3) if search_text(self.get_value("could_not_open_connection"), 1, 0): goback() time = time + 1 click_button_by_id("next", 1, 0) if time == 3: return False fun = lambda: search_view_by_id("next") wait_for_fun(fun, True, 10) click_button_by_id("next", 1, 0) sleep(3) click_textview_by_id("account_name", 1, 0) clear_edittext_by_id("account_name", 1, 0) sleep(1) ime.IME_input_english(1, "autotest") #entertext_edittext_by_id("account_name",SC.PRIVATE_EMAIL_ACCOUNT_NAME,1,0) click_button_by_id("next", 1, 0) sleep(1) goback() goback() return True else: goback() goback() goback() goback() goback() return False
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
def access_browser(self, url_address, check_value, 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. ''' search_result = False ime = IME() if is_checked == True: #clear the browser cache self.clear_cache() #click_imageview_by_id('tab_switcher') #addressing config web address #entertext_edittext_by_id('url', url_address) sleep(1) click_textview_by_id('url', clickType=LONG_CLICK) #this can #send_key(KEY_DEL) #modified by c_yazli sleep(1) click_button_by_id('clear', isVerticalList=0, isScrollable=1) #entertext_edittext_by_index(0, url_address) entertext_edittext_on_focused(url_address) send_key(KEY_ENTER) '''click_textview_by_id("url") send_key(KEY_DEL) #input address url ime.IME_input(1,url_address)''' #make sure whether access successful if is_checked == True: scroll_down() wait_fun = lambda: search_view_by_id("favicon") wait_result = wait_for_fun(wait_fun, True, wait_time) if wait_result == True: start_time = int(time.time()) while int(time.time()) - start_time < int(wait_time): click_button_by_id("favicon") if search_text(unicode(check_value), searchFlag=TEXT_CONTAINS): search_result = True break elif search_text(self.get_value("webpage_not_available")): search_result = False break else: sleep(1) goback() else: search_result = False else: if search_text(url_address): search_result = True else: search_result = False return search_result
def test_case_main(self, case_results): """ main function ,entry search and show contact record @return: none """ log_test_case(self.name, 'drag up and down') drag_by_param(95, 50, 95, 85, 1) drag_by_param(95, 85, 95, 50, 1) sleep(1) drag_by_param(95, 50, 95, 85, 1) drag_by_param(95, 85, 95, 50, 1) sleep(1) self.ime = IME() click_imageview_by_id('menu_search') #entertext_edittext_on_focused('Mi') #clear_edittext_by_index(0) ''' PRIVATE_del = ['del'] self.ime.IME_input(1, PRIVATE_del) self.ime.IME_input(1, PRIVATE_del) self.ime.IME_input(1, PRIVATE_del) ''' self.ime.IME_input_english(1, 'tes') sleep(2) if search_text(SC.PRIVATE_CONTACT_NAME): log_test_case(self.name, 'search name ok...') click_textview_by_text(SC.PRIVATE_CONTACT_NAME) #click_in_list_by_index(1) else: log_test_case(self.name, 'search failed...') return self.call_from_contact() #send sms to mike click_textview_by_id('secondary_action_button') self.ime.IME_input_english(1, 'send') #click_imageview_by_desc("send") click_button_by_id('send_button_sms') sleep(3) goback() #click_textview_by_text('binz') # show a moment sleep(1) #send EMAIL if search_text('*****@*****.**'): click_textview_by_text('*****@*****.**') # if search_text('Complete action using'): click_textview_by_text('Email') click_button_by_id('button_always') entertext_edittext_on_focused('email title') click_imageview_by_id("send") else: goback() # go address map scroll_to_bottom() if search_text('ADDRESS'): click_textview_by_text('pudong,shanghai,china') else: goback()
class Renren(Base): ''' Renren will provide common renren related functions for all cases ,such as login to renren, share with renren and so on. ''' welcome_activity = 'com.renren.mobile.android.loginfree.WelcomeActivity' ''' The class name of the welcome activity ''' login_activity = 'com.renren.mobile.android.ui.Login' ''' The class name of the login activity ''' welcome_screen = 'com.renren.mobile.android.ui.WelcomeScreen' ''' The class name of the welcome screen ''' def __init__(self): self.mode_name = "renren" Base.__init__(self, self.mode_name) self.ime = IME() self.debug_print('Base init:%f' % (time.time())) #input: be sure the weibo app have started, but not sure where it is or whether it have logined ? #output: return true or false . def is_login(self): ''' judge current whether it has logined. if the current activity is not in the welcome activity , login activity or welcome screen, we will think it has logined. @return: True, if it has logined,otherwise , False ''' activityName = get_activity_name() if activityName == self.welcome_activity or activityName == self.login_activity or activityName == self.welcome_screen: return False return True #input: the page is in the login page #output: just enter the email and password and press the login button,and try to wait for 5 seconds. # if the activity page switched to another page in the 5 seconds, we assume success def login(self): ''' enter the account information and login to the main interface @return: True, if it login successfully,otherwise , False ''' activityName = get_activity_name() if activityName == self.welcome_activity: click_imageview_by_id('welcome_login') if activityName == self.welcome_screen: click_imageview_by_id('welcome_login') #clear the account clear_edittext_by_id('account_layout') #focus on the login input box click_textview_by_id('account_layout', 1, 0) sleep(1) self.ime.IME_input(1, SC.PRIVATE_RENREN_ACCOUNT_SEQUENCE) #focus in the password input box #click_textview_by_id('password_edit', 1, 0) self.ime.IME_input(1, SC.PRIVATE_RENREN_PASSWORD_SEQUENCE) click_button_by_id('login_button') #wait the login activity disappear waitActivity = lambda: get_activity_name() == self.login_activity return wait_for_fun(waitActivity, False, 25) #input: make sure the weibo app is running. #output: if the surrent page is in Navigater, it will drag to enter the home page .otherwise, will do nothing. def skip_navigator(self): ''' skip the navigator. ''' activityName = get_activity_name() if activityName == 'com.renren.mobile.android.newfeatures.NewFeatureActivity': click_imageview_by_id('new_feature_btn_go') #input: viewing a picture #output:back to the camera app def share_with_renren(self, message): ''' share with renren. @note: Be sure it is in the viewing picture interface @type message:string @param message:the message want to share with renren ''' shareWithRenren = self.get_value('share_to_renren') if search_view_by_desc(self.get_value('default_share_to_renren')): click_view_by_container_id('default_activity_button', 'android.widget.ImageView', 0) else: click_imageview_by_desc(self.get_value('share_object')) #click the text sell all if wait_for_fun( lambda: search_text(self.get_value('see_all'), searchFlag=TEXT_CONTAINS), True, 3): click_textview_by_text(self.get_value('see_all')) if search_text(shareWithRenren): click_textview_by_text(shareWithRenren) else: log_test_case(self.mode_name, 'Can not find the renren') return False sleep(1) waitActivity = lambda: get_activity_name().startswith( "com.renren.mobile.android") if not wait_for_fun(waitActivity, True, 5): return False if not self.is_login(): self.login() sleep(2) click_button_by_id('edit_photo_done') sleep(2) click_button_by_id('edit_photo_done') sleep(3) return self.share_with_renren_inner(message) #input: the ui is in the post page #output:close the post page def share_with_renren_inner(self, message): ''' share with renren. @note: Be sure it is in the write message interface @type message:string @param message:the message want to share with renren ''' #enter the message click_textview_by_id('input_editor', 1, 0) sleep(1) self.ime.IME_input(1, message, 'c', 'b') sleep(1) #click the delete position button(textView) click_button_by_id('flipper_head_action') waitActivity = lambda: get_activity_name( ) == "com.renren.mobile.android.publisher.InputPublisherActivity" if not wait_for_fun(waitActivity, False, 25): # if the editActivity is still alive , close it loopTimes = 0 while loopTimes < 5: if search_text(self.get_value('cancel_post_tip'), 1, 0): click_button_by_text(self.get_value('ok')) break else: goback() loopTimes = loopTimes + 1 log_test_case(self.mode_name, 'Cancel post the renren status') return False return True def exit_reren(self): ''' exit the renren application . ''' goback() goback() loopCount = 0 while loopCount < 5: if search_text(self.get_value("sure_exit"), 1, 0): click_button_by_text(self.get_value('ok')) return loopCount = loopCount + 1 goback()