def firstdo(self): ''' app 进入输入手机号界面前的准备操作 :return: ''' #deviceinfo.startApp('com.coohuaclient/.ui.activity.SplashActivity') time.sleep(5) try: #向右滑动解锁 # d(resourceId='com.coohuaclient:id/tv_slide_horizontal_guide').drag.to(resourceId='com.coohuaclient:id/view_hand',steps=100) # textclick('点我左划试试') # d(resourceId='com.coohuaclient:id/tv_slide_horizontal_guide').drag.to(resourceId='com.coohuaclient:id/tv_left_cost',steps=100) # d(resourceId='com.coohuaclient:id/btn_click_me').click() # #上划 # d(resourceId='com.coohuaclient:id/wave_circle_up').drag.to(d.info['displaySizeDpX']/2,100,steps=50) #d(resourceId='com.coohuaclient:id/wave_circle_down').drag.to(d.info['displaySizeDpX']/2,d.info['displaySizeDpY'],steps=50) #跳过 d(resourceId='com.coohuaclient:id/tv_date').click() d(resourceId='com.coohuaclient:id/btn_register').click() except: print Exception try: textclick(u'注册') except: print Exception
def setselftimerstatus(self,status): commands.getoutput('adb shell input swipe 530 6 523 22') time.sleep(1) d(description=Setting_description).click.wait() commands.getoutput('adb shell input swipe 670 165 78 165') commands.getoutput('adb shell input tap 679 182') time.sleep(1) if status == '10': commands.getoutput('adb shell input tap 414 294') elif status == '5': commands.getoutput('adb shell input tap 295 294') elif status == '3': commands.getoutput('adb shell input tap 181 294') elif status == '0': commands.getoutput('adb shell input tap 54 294') time.sleep(3) state = commands.getoutput(SelfTimer_STATE) statevalue = state.find(status) assert statevalue != -1 def launchcamera(self): d(description='Apps').click.wait() while not d.exists(text='Camera'): d().swipe.right() time.sleep(3) d(text='Camera').click.wait() d(description="Shutter button").wait.exists(timeout=3000) time.sleep(5)
def setsencestatus(self,status): commands.getoutput('adb shell input swipe 530 6 523 22') time.sleep(1) d(description=Setting_description).click.wait() commands.getoutput('adb shell input tap 531 165') time.sleep(1) if status == 'auto': commands.getoutput('adb shell input swipe 660 285 66 285') commands.getoutput('adb shell input tap 657 294') elif status == 'sports': commands.getoutput('adb shell input swipe 660 285 66 285') commands.getoutput('adb shell input tap 534 290') elif status == 'night': commands.getoutput('adb shell input tap 643 290') elif status == 'landscape': commands.getoutput('adb shell input tap 512 290') elif status == 'portrait': commands.getoutput('adb shell input tap 385 290') elif status == 'night-portrait': commands.getoutput('adb shell input tap 285 290') elif status == 'barcode': commands.getoutput('adb shell input tap 177 290') elif status == 'fireworks': commands.getoutput('adb shell input tap 58 290') time.sleep(3) state = commands.getoutput(Scene_STATE) statevalue = state.find(status) assert statevalue != -1
def testOpenMmsWithImage(self): """ Summary:testOpenMmsWithVideo:open a mms with video #Init condition:Clear up all messagebox Precondition: 1.There is a 600kb audio file in sdcard Steps:1.Launch message app 2.Open a mms with audio 3.Delete message 4.Exit message app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(text = 'Messaging').wait.exists(), 'Message launch failed' self._clearMessage() commands.getoutput('adb shell am start -a android.intent.action.SEND -t image/* --es address ' + MESSAGE_RECEIVER_NUMBER + ' --es sms_body ' + SEND_MESSAGE_CONTENT + ' --eu android.intent.extra.STREAM file:///mnt/sdcard/001/300K/Picture.jpg -n com.android.mms/.ui.ComposeMessageActivity') time.sleep(2) d.press('back') #step2 d(textContains = 'subject').click.wait() assert d(description = 'Send MMS').wait.exists(), 'MMS open failed' #step3 d.press('back') d.press('back') self._clearMessage()
def runtest(serialno, loop, videoname): if serialno: from uiautomator import Device d = Device(serialno) else: from uiautomator import device as d print "总共 %d 次循环" %loop for i in range(1, loop+1): print "第 %d 次循环" %i d.screen.on() d.press.home() removeRecentList(d, "File Manager") d(description="Apps").click() d(text="File Manager").click() time.sleep(0.5) d(text="sdcard").click() d(text="Movies").click() d(text=videoname).click() for i in range(1,20): x = random.randint(100, 600) d.click(x, 80) time.sleep(3) d.press.back() d.press.home() i += 1 print "***** test end ********"
def testOpenSms(self): """ Summary:testOpenSMS:open a sms #Init condition:Clear up all messagebox Precondition: 1.Prepare a received sms. Steps:1.Launch Messages app 2.Open a sms 3.Delete message 4.Exit message app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(text = 'Messaging').wait.exists(), 'Message launch failed' self._clearMessage() commands.getoutput('adb shell am start -a android.intent.action.SEND --es address ' + MESSAGE_RECEIVER_NUMBER + ' --es sms_body ' + SEND_MESSAGE_CONTENT + ' -n com.android.mms/.ui.ComposeMessageActivity') time.sleep(2) d.press('back') #step2 d(textContains = 'test').click.wait() assert d(description = 'Send').wait.exists(), 'SMS open failed' #step3 d.press('back') d.press('back') self._clearMessage()
def testSendSMS(self): """ Summary:testSendSMS: Send a SMS. #Init condition:Clear up all messagebox Steps:1. Open Messages app 2. Touch Compose button 3. Input deliver number and content 4. Touch Send button 5. Delete all messages 6. Exit Messages app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(text = 'Messaging').wait.exists(), 'Message launch failed' self._clearMessage() #step2,3 commands.getoutput('adb shell am start -a android.intent.action.SEND --es address ' + MESSAGE_RECEIVER_NUMBER + ' --es sms_body ' + SEND_MESSAGE_CONTENT + ' -n com.android.mms/.ui.ComposeMessageActivity') time.sleep(2) #step4 d(description = 'Send').click.wait() assert d(textContains = ':', className = 'android.widget.TextView').wait.exists(timeout = 35000), 'Message send failed' #step5 d.press('back') self._clearMessage()
def drag_txt1_to_txt2(txt1,txt2): """Drag the ui object to another ui object (center). Example: | drag txt1 to txt2| txt1 | txt2 | #drag txt1 to txt2 | """ d(text=txt1).drag.to(text=txt2, steps=50)
def loop_sdn(): if d(text="Service Dialing Numbers").wait.exists(): d(text="Service Dialing Numbers").click() d.press("back") else: c.common.log("text=Service Dialing Numbers未找到,保存截图") c.common.save_fail_img()
def onClickSwitch(textName): if(d(className="android.widget.ListView", resourceId="com.android.settings:id/listviewApp").child_by_text(textName, className="android.widget.RelativeLayout").child(className="android.widget.Switch", text="OFF").exists): d(className="android.widget.ListView", resourceId="com.android.settings:id/listviewApp").child_by_text(textName, className="android.widget.RelativeLayout").child(className="android.widget.Switch").click() return True else: print(textName +"Already ONN") return False
def drag_txt_to_xy(txt,x,y,steps=100): """Drag the ui object to point (x, y). Example: | drag txt1 to xy| Music | 250 | 300 | """ d(text=txt).drag.to(x, y, steps)
def testSendMMSWithVideo(self): """ Summary:testSendMMSWithVideo: Send a mms with video attachment. #Init condition:Clear up all messagebox Steps:1. Open Messages app 2. Touch Compose button 3. Input deliver number and content 4. Touch Attach button 5. Select Gallery 6. Enter 001 folder, select a video 7. Touch Send button 8. Delete all messages 9. Exit Messages app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(text = 'Messaging').wait.exists(), 'Message launch failed' self._clearMessage() #step2,3,4,5,6 commands.getoutput('adb shell am start -a android.intent.action.SEND -t video/* --es address ' + MESSAGE_RECEIVER_NUMBER + ' --es sms_body ' + SEND_MESSAGE_CONTENT + ' --eu android.intent.extra.STREAM file:///mnt/sdcard/001/300K/Video.3gp -n com.android.mms/.ui.ComposeMessageActivity') assert d(text = 'View').wait.exists(), 'message create failed' #step7 d(description = 'Send MMS').click.wait() assert d(textContains = ':', className = 'android.widget.TextView').wait.exists(timeout = 60000), 'Message send failed' #step8 d.press('back') self._clearMessage()
def __pressback(self,c): for i in range(c): d.press.back() if d(text="退出").exists: d(text="确定",className="android.widget.Button").click() time.sleep(3) break
def operation_usage(): #d.press.home() result=d(textContains=u'设置').wait.exists(timeout=10000) #单位是毫秒, 如果timeout还没有找到,就返回false print("next") if result: print("You press setting") else: print("You don't touch any thing") ''' if d(text=u'设置').exists: d(text='WLAN').click() else: print("move") ''' # d(text=u'显示').click() #支持unicode d(scrollable=True).scroll(steps=3) time.sleep(3) #d.open.notification() d.wait.idle() print("waiting for idle")
def runtest(serialno, loop): print "liu: in runtest" if serialno: print "liu: in serialno" from uiautomator import Device d = Device(serialno) else: print "liu: in else" from uiautomator import device as d print "总共 %d 次循环" %loop for i in range(1, loop+1): print "第 %d 次循环" %i d.screen.on() d.press.home() d(description="Apps").click() d(text="Basemark ES2 Taiji Free").click() time.sleep(2) if d(text="Agree").exists: d(text="Agree").click() d(text="Run Benchmark").click() while not d(text="FRAMES PER SECOND").exists: time.sleep(2) else: d.screenshot("%s/screenshot/%d_taiji_%s.png"\ %(sys.path[0], i, now.strftime(ISOFORMAT))) d.press.home() i += 1 print "***** test end ********"
def inputCode(self): d(resourceId="com.android.systemui:id/key1").click() d(resourceId="com.android.systemui:id/key2").click() d(resourceId="com.android.systemui:id/key3").click() d(resourceId="com.android.systemui:id/key4").click() time.sleep(2) d(resourceId="com.android.systemui:id/key_enter").click()
def removeRecentList(d, app_desc): d.press.home() d.press.recent() time.sleep(1) if d(description=app_desc).exists: d(description=app_desc).long_click() d(text="Remove from list").click() d.press.home()
def wait_until_txt_gone(txt,TIMEOUT=15): """Wait until the ui object gone or the given timeout expires. Example: | wait until txt gone | Settings | 15000 | """ TIMEOUT=int(TIMEOUT) d(text=txt).wait.gone(timeout=TIMEOUT)
def test_run_calculator(self): print("Run Calculator") d.press.back() time.sleep(2) d.press.home() time.sleep(2) d(description="Apps",className="android.widget.TextView").click() time.sleep(2)
def swipe_up_className(className,timeout=50): """Swipe up on the given Resource Id or the given timeout expires. Example: | swipe up rscId| com.nokia.z:id/secondTopMostLayout | 15000 | """ if d(className=className).wait.exists(timeout=timeout): d(className=className).swipe.up()
def get_txt_by_index_rscId(index,rscId): """Get Text of editable field. Example: | input | com.android.settings:id/password | #get text by the given id field | """ if d(resourceId=rscId)[int(index)].exists: return d(resourceId=rscId)[int(index)].text
def swipe_down_rscId(rscId,timeout=50): """Swipe down on the given Resource Id or the given timeout expires. Example: | swipe down rscId| com.nokia.z:id/secondTopMostLayout | 15000 | """ if d(resourceId=rscId).wait.exists(timeout=timeout): d(resourceId=rscId).swipe.down()
def fillVerifycode(self,verifycode): ''' 填写手机验证码 :param verifycode: :return: ''' d(resourceId='com.coohuaclient:id/et_verify_code').set_text(verifycode) textclick(u'下一步')
def __launchApp(self): #find app self.__findApp() # launch app d(text="财经杂志",packageName="com.android.launcher").click() time.sleep(3) assert d(className="android.widget.ImageView", \ packageName="com.caijing")[0]
def input_txt(rscId,txt): """Set Text of editable field. Example: | input txt | com.android.settings:id/password | 88888888 | #Type in passwords "88888888" at the given id field | """ if d(resourceId=rscId).exists: d(resourceId=rscId).set_text(txt)
def test_edit_new_email(self): print("Test Add email account") d(className="android.view.View",resourceId="com.android.launcher3:id/layout").\ child(description="Apps",className="android.widget.TextView").click() while not d(text="Email",className="android.widget.TextView").exists: d.drag(600, 480, 50, 480, steps=100); print("Finding Email APP") d(text="Email",className="android.widget.TextView").click() time.sleep(2)
def sunning(): cmd = 'adb shell am start -n com.suning.mobile.ebuy/.base.host.InitialActivity' # os.system(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) print(p.stdout.read()) time.sleep(5) d(text=u'领云钻').click() time.sleep(8) d(text=u'打卡领云钻').wait.exists(timeout=10000) print("Done")
def requestVerfiyCode(phonenum): try: print "phonenum:" + phonenum d(resourceId='com.coohuaclient:id/et_phone_num').clear_text() d(resourceId='com.coohuaclient:id/et_phone_num').set_text(phonenum) textclick(u'获取验证码') time.sleep(2) except: print Exception
def press_recent(): d.press("recent") if d(description="Clear all").wait.exists(timeout=2000): d(description="Clear all").click.wait() if d(textContains="Your recent").wait.exists(timeout=2000): d.press("back") else: save_fail_img() d.press("home") return True
def test_settings_view(self): d.press.home() time.sleep(2) d.press.menu() time.sleep(2) d(text="Settings",className="android.widget.TextView", resourceId="com.android.launcher3:id/settings_button").click() time.sleep(2) arr =["Bluetooth","Data usage","Audio profiles","Display","Storage","Battery","Apps","Location","Security","Accessibility","Printing","About phone"] # "Language & input","Backup & reset","Add account","Date & time","Scheduled power on & off","Accessibility","Printing","About phone"] # for i in range(0, 12): if d(text=arr[i],className="android.widget.TextView").exists: print("View "+arr[i]) else: while not d(text=arr[i],className="android.widget.TextView").exists: # print() d.drag(100, 350, 100, 50, steps=100) d(text=arr[i],className="android.widget.TextView").click() if d(text="Unfortunately, Settings has stopped.").exists: print("When runing "+arr[i]+",Settings Crash") d(text="OK").click() return time.sleep(2) d.press.back() time.sleep(2)
def crack_k(self, count, ap, passwd): print "LOOP %d" % count d.press.home() d(text='Settings').click() d.press.down() time.sleep(1) d.press.center() time.sleep(2) #d(text='+').click() d.click(370, 1140) time.sleep(5) cmd = 'adb shell input text %s' % ap p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) cmd = 'adb shell input keyevent KEYCODE_ESCAPE' p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) time.sleep(1) d.press.enter() time.sleep(1) # d.press.enter() d.press.down() d.press.down() d.press.enter() cmd = 'adb shell input text %s' % passwd p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) cmd = 'adb shell input keyevent KEYCODE_ESCAPE' p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) time.sleep(1) return 1
def dialing0To9(num): numDict = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine' } lc.fileLog().info('start dialing0To9...') d(resourceId='com.android.contacts:id/' + numDict.get(num)).click() lc.fileLog().info('stop dialing0To9...') time.sleep(2)
def setUp(self): super(MaxBSPTest, self).setUp() self.backToDesktop() if d(text=u'确定').wait.exists(timeout=2000): self.firstLaunch() self.start_time = time.time() print "start: \t%s" % (time.strftime('%Y%m%d_%H%M%S', time.localtime(self.start_time))) print "case name: ",
def testLaunchAndCloseIreaderByBackKey(self): ''' Summary: Test launch and close ireader by back key Steps: 1. Launch ireader 2. Chech enter ireader successfully 3. Exit ireader by back key 4. Repeat steps 1-3 500 times ''' for i in range(1,2): #Step 1 d(text='掌阅iReader',className='android.widget.TextView').click.wait() time.sleep(3) #Step 2 assert d(text='书城',className='android.widget.TextView') #Step 3 d.press('back') d.press('back') d.press('back')
def gamePlay(self, cycle=1): for i in range(cycle): print "%s, " % (i + 1), os.popen( 'adb shell am start -n com.imangi.templerun2.bd/com.templerun2.SuperIdsSingleSplashActivity' ) time.sleep(5) d.click(D_C_X, 1800) # Tap to start time.sleep(2) for i in range(10): d.swipe(D_C_X, D_HEIGHT - 1, D_C_X, 0, 5) d.press('home') d.press('recent') while d(resourceId='com.android.systemui:id/dismiss_task' ).wait.exists(timeout=2000): d(resourceId='com.android.systemui:id/dismiss_task' ).click.wait() print "\n"
def find_ap(count, apName): if d(text=apName).exists: d.press.enter() time.sleep(2) d.press.enter() time.sleep(45) #check_connection(count) else: print "Failed ! Can't find the AP"
def taobao_cuizi(): d.screen.on() d.press.home() activity_name = 'com.taobao.taobao/com.taobao.tao.homepage.MainActivity3' launch_app(activity_name) if d(text=u'领金币').wait.exists(timeout=12 * 1000): #print "Dismiss update" d(text=u'领金币').click() #登录账号,刷新下即可 time.sleep(15) jb_x = 900 jb_y = 370 d.click(jb_x, jb_y) print "Click" time.sleep(6)
def backToDesktop(self): t = 0 while d(resourceId='com.android.launcher:id/hotseat').wait.gone( timeout=2000): self.pressBack() t = t + 1 if t > 10: print "what happened..." break
def swipe_to_right_tab(): address_bar_info = d(resourceId=CHROME_ADDRESS_BAR_RESID).info bounds = Bounds(address_bar_info) sx = bounds.right ex = bounds.left sy = (bounds.top + bounds.bottom) / 2 ey = sy d.swipe(sx, sy, ex, ey) time.sleep(2)
def open_continuous_discovery(self, package_name): ''' Open the Continuous discovery switch and enable it. Return if it's set to True. ''' self.launch_app(package_name) time.sleep(2) side_bar_btn = d(className='android.widget.Button', index=0) side_bar_btn.click() time.sleep(2) settings_btn = d(className='android.view.View', description='Settings') settings_btn.click() time.sleep(2) switch_btn = d(className='android.view.View', index=6) switch_btn.click()
def init_rgb_led_sensor(self): ''' Go to the detairgb_led page of the OCF resource. ''' self.rgb_led_item = d(className='android.view.View', descriptionContains='Path: /a/rgbled') self.rgb_led_item.click() time.sleep(1) self.details_btn = d(className='android.widget.Button') self.id_item = d(className='android.view.View', descriptionStartsWith='id') self.range_item = d(className='android.view.View', descriptionStartsWith='range') self.rgb_led_value_item = d(className='android.view.View', index=15).child( className='android.view.View', index=1) self.rgb_led_value = self.rgb_led_value_item.description
def call_end(): sleep(1) print("Test Case-7: Performing Phone Call End operation:") try: # Call Ending d(resourceId="com.android.incallui:id/endButton").click() sleep(2) print( "Test Case-7 Result: Phone Call End operation done successfully : (PASS) " ) print("==============================================") except: print( "Test Case-7 Result: Not able to perform Phone Call End operation : (FAILED) " ) d.press.home() print("Yeah! Came back to home menu")
def do_facebook(self, action, variables): contact = action["value"] d.screen.on() d.press.home() Adb.start("com.facebook.orca/.auth.StartScreenActivity") d(resourceId="com.facebook.orca:id/action_search").click() Adb.write(contact) d(className="android.widget.ListView").child(index=1).click() d(resourceId="com.facebook.orca:id/edit_text").click() Adb.write(self.get_var("$mensagem", variables)) d(description="Enviar").click()
def get_allscore_antion(self): thirdD = d(text="3D") self.thirdD_num = self.get_score_action("3D") time.sleep(1) thirdD.click() self.marooned_num = self.get_score_action("3D [Marooned]") time.sleep(1) self.garden_num = self.get_score_action("3D [Garden]") time.sleep(1) thirdD.click() UX = d(text="UX") self.UX_num = self.get_score_action("UX") time.sleep(1) UX.click() self.data_Secure = self.get_score_action("UX Data Secure") time.sleep(1) self.data_process = self.get_score_action("UX Data process") time.sleep(1) self.strategy_games = self.get_score_action("UX Strategy games") time.sleep(1) self.image_process = self.get_score_action("UX Image process") time.sleep(1) self.io_performance = self.get_score_action("UX I/O performance") time.sleep(1) UX.click() CPU = d(text="CPU") self.CPU_num = self.get_score_action("CPU") time.sleep(1) CPU.click() self.mathematics = self.get_score_action("CPU Mathematics") time.sleep(1) self.common_Use = self.get_score_action("CPU Common Use") time.sleep(1) self.multi_Core = self.get_score_action("CPU Multi-Core") time.sleep(1) CPU.click() self.RAM = d(text="RAM") self.RAM_num = self.get_score_action("RAM") time.sleep(1) return True
def description_click(self,description): if (d(description = description).exists): d(description = description).click() time.sleep(1) else: d(scrollable = True).scroll.to(description = description) d(description = description).click() time.sleep(3)
def turnOnWiFi(self): self.launchSettings() d(textContains='Fi').click.wait() assert d(resourceId=resource_widget).wait.exists(timeout=2000) if d(resourceId=resource_empty).wait.exists(timeout=2000): d(resourceId=resource_widget).click.wait() assert d(resourceId=resource_empty).wait.gone( timeout=5000), "What's wrong..."
def text_click(self,text): if (d(text = text).exists): d(text = text).click() time.sleep(1) else: d(scrollable = True).scroll.to(text = text) d(text = text).click() time.sleep(3)
def detail_to_history_message(): wait(5) """ 处理在详情界面的操作 1:没关注则关注 2:进入历史消息 :return: """ has_focus = not d(text="关注").exists if not has_focus: click_by_text("关注", 3000) back() can_view_history = d(text="查看历史消息").exists if can_view_history: click_by_text("查看历史消息", 10000) wait_sleep(3000) view_history_message()
def search_public_number(): """ resourceId = 公众号搜索界面的editText的id :return: """ d(className='android.widget.EditText').clear_text() # clear the text d(className='android.widget.EditText').set_text(wc_search_key) # set the text wait_update(1000) wait(2) # d.click(1005, 1710) # 键盘的搜索 d.click(663, 1132) wait_update(10000) wait(5) # 第一个公众号的位置 d.click(300, 330) wait_update(5000) detail_to_history_message()
def Remove_APN_Note4(self): time.sleep(2) if d(className="android.widget.ImageButton", description="More options").exists: d(className="android.widget.ImageButton", description="More options").click() time.sleep(1) if d(text="Reset to default").exists: d(text="Reset to default").click() time.sleep(1) d(text="OK").click() time.sleep(2)
def check_time_indicator_bar(given_time, offset_hour=0, offset_minutes=0): """ given_time is in strptime.time() format """ d.open.notification() try: if d(resourceId='com.android.systemui:id/datetime').wait(2000): time_str = d( resourceId='com.android.systemui:id/clock').info['text'] time_str = datetime.datetime.strptime(time_str, "%H:%M") else: raise Exception("Did not reach the Notification panel") except UnboundLocalError: exit(0) d(resourceId="com.android.systemui:id/notification_icon_area").click() if compare_time(given_time, time_str, offset_hour, offset_minutes): return True else: return False
def wifiStatus(): time.sleep(8) print "Checking status" if d(text="Wi-Fi password not valid").exists: print "password not valid" d.screenshot("password_not_valid.png") #os.popen('adb kill-server') sys.exit() elif d(text="Hide password").exists: print "Enter password" d.screenshot("Enter_password_.png") #os.popen('adb kill-server') sys.exit() elif d(text="Couldn't connect to").exists: print "Coundn't connect ..." d.press.back() d.press.back() else: print "Connected to AP"
def test_purchaseFlow(): """ Part 1 - Purchase flow with 1 item in the cart """ kp.closeKabum() kp.cleanCache() basicFluxCartWithLogin(kd.product1) finishPurchase('credito') sleep(2) assert d(resourceId=kp.resId + 'confirmacao_toolbar').exists == True
def get_date_format(): date_format = '' if d(text="Choose date format").exists: d(text="Choose date format").click() if d(resourceId="android:id/text1", index=0).info['checked'] == 'True': date_format = 'Regional' + regional_format elif d(resourceId="android:id/text1", index=1).click() == 'True': date_format = second_format elif d(resourceId="android:id/text1", index=2).click() == 'True': date_format = third_format elif d(resourceId="android:id/text1", index=3).click() == 'True': date_format = fourth_format else: date_format = 'Could not establish the date format used' d(text="Cancel").click() return date_format
def go_to_apps_beginning(): UiAutomatorUtils.clear_popups() d.screen.on() d.press.home() d(description=APPS_BUTTON_DESC).click() if d(scrollable=True).wait.exists(timeout=3000): d(scrollable=True).scroll.horiz.backward() d(scrollable=True).scroll.horiz.toBeginning( max_swipes=MAX_SWIPES_TO_LIMIT)
def gdyd_samsung(): d.screen.on() d.press.home() #解锁,没有密码的情况下 sx = 560 sy = 1700 ex = 560 ey = 900 #d.swipe(sx,sy,ex,ey,steps=2) #d(scrollable=True).fling.horiz.forward() home_swipe_sx = 627 home_swipe_sy = 900 home_swipe_ex = 120 home_swipe_ey = 900 while not d(text=u"广东移动").exists: d.swipe(home_swipe_sx, home_swipe_sy, home_swipe_ex, home_swipe_ey, steps=2) time.sleep(3) d(text=u'广东移动').click() if d(text=u'版本更新').wait.exists(timeout=12 * 1000): print "Dismiss update" d(text=u'取消').click() #登录账号,刷新下即可 s_x = 544 s_y = 367 e_x = 544 e_y = 1438 time.sleep(8) d.swipe(s_x, s_y, e_x, e_y, steps=4) while not d(text=u"签到赢话费").exists: d.swipe(home_swipe_sx, home_swipe_sy, home_swipe_ex, home_swipe_ey, steps=2) time.sleep(3) d(text=u'签到赢话费').click() time.sleep(10) yd_x = 540 yd_y = 1100 d.click(yd_x, yd_y) print "GDYD done"
def jd_cuizi(): d.screen.on() d.press.home() activity_name = 'com.jingdong.app.mall/.main.MainActivity' launch_app(activity_name) if not d(text=u'领京豆').wait.exists(timeout=20 * 1000): print "Failed to get the page" return d(text=u'领京豆').click() dou_x = 853 dou_y = 400 #glaxy_x=yun_x*gallery*full/cuizi_full time.sleep(15) d.click(dou_x, dou_y) print "Click" time.sleep(2) d.click(dou_x, dou_y) print "Click" #点击使用功能 d.press.back() time.sleep(4) d.swipe(1000, 770, 100, 770) time.sleep(8) d.click(990, 846) ''' if d(text=u'全部').wait.exists(timeout=2000): d(text=u'全部').click() ''' time.sleep(4) d(text=u'领流量').click() time.sleep(5) #这个签到好像找不到 #d(text=u'签到').click() d.click(271, 813) time.sleep(5) d.click(271, 813) time.sleep(5) print "get liu liang" print "JD done"
def testlogin(self, data): d(resourceId='com.aixuetang.teacher:id/et_username').set_text( data['username']) d(resourceId='com.aixuetang.teacher:id/et_password').set_text( data['password']) d(resourceId='com.aixuetang.teacher:id/tv_login').click() assert_m = assert_i(cm=d( resourceId='com.aixuetang.teacher:id/tv_login')) self.assertTrue(assert_m)
def get_date(): settings_format = "%B %d, %Y" date_str = d(text="Set date").sibling( resourceId="android:id/summary").info['text'] try: date_val = datetime.datetime.strptime(date_str, settings_format).date() except ValueError: raise SyntaxError("Unexpected format for date in Settings: %s." % date_str) return date_val
def get_time_absolute(): try: if d(text="Set time").sibling(resourceId="android:id/summary").exists: time_str = d(text="Set time").sibling( resourceId="android:id/summary").info time_elem = datetime.datetime.strptime(time_str['text'], "%H:%M %p").time() else: raise Exception, 'Could not find the time field at the suggested locations. Please revise the xml' \ ' structure against the code written here' except ValueError: if d(text="Set time").sibling(resourceId="android:id/summary").exists: time_str = d(text="Set time").sibling( resourceId="android:id/summary").info time_elem = datetime.datetime.strptime(time_str['text'], "%H:%M").time() else: raise Exception, 'Could not find the time field at the suggested locations. Please revise the xml' \ ' structure against the code written here' return time_elem