def testPlayVideo(self): """ Summary:testRecordVideoAndDelete: Record a video, then play and delete the video. Steps:1. Open Camera app 2. Record a video 3. Touch thumbnail to view the video 4. Tocuh screen center to play the video 5. Exit Camera app """ #step1,2 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Shutter button').wait.exists(), 'Camera launch failed' d(description = 'Camera, video, or panorama selector').click.wait() d(description = 'Switch to video').click.wait() assert d(description = 'Shutter button').wait.exists(), 'Video Camera launch failed' #step3 d.swipe(startX, startY, endX, endY, steps = 10) time.sleep(2) d.click(274,482) d.press('menu') assert d(text = 'Delete').wait.exists() #step4 d.press('back') d.click(274,482) time.sleep(10) d.click(274,482) # assert playing progress bar exist assert d(index = 2, className = 'android.view.View').wait.exists(), 'Video play failed'
def testDeleteVideo(self): """ Summary:testRecordVideoAndDelete: Record a video, then play and delete the video. Steps:1. Open Camera app 2. Record a video 3. Touch thumbnail to view the video 4. Touch Delete button to delete the video 5. Exit Camera app """ BEFORE_DELETE=commands.getoutput(QUERY_VIDEO_COUNT_COMMANDS) #step1,2 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Shutter button').wait.exists(), 'Camera launch failed' d(description = 'Camera, video, or panorama selector').click.wait() d(description = 'Switch to video').click.wait() assert d(description = 'Shutter button').wait.exists(), 'Video Camera launch failed' #step3 d.swipe(startX, startY, endX, endY, steps = 10) time.sleep(2) d.click(274,482) #step4 d.press('menu') assert d(text = 'Delete').wait.exists() d(text = 'Delete').click.wait() d(text = 'OK').click.wait(timeout = 2000) AFTER_DELETE = commands.getoutput(QUERY_VIDEO_COUNT_COMMANDS) assert int(AFTER_DELETE) == int(BEFORE_DELETE) - 1, 'Video record failed'
def testDeletePicture(self): """ Summary:testCapturePictureAndDelete: Take a picture, then view and delete the picture. Steps:1. Open Camera app 2. Touch thumbnail to view the picture 3. Touch setting menu 4. Touch Delete button to delete the picture 5. Exit Camera app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Shutter button').wait.exists(), 'Camera launch failed' BEFORE_DELETE = commands.getoutput(QUERY_PICTURE_COUNT_COMMANDS) #step2 d.swipe(startX, startY, endX, endY, steps = 10) time.sleep(2) d.click(274,482) #step3 d.press('menu') assert d(text = 'Delete').wait.exists() #step4 d(text = 'Delete').click.wait() d(text = 'OK').click.wait(timeout = 2000) AFTER_DELETE = commands.getoutput(QUERY_PICTURE_COUNT_COMMANDS) assert int(AFTER_DELETE) == int(BEFORE_DELETE) - 1, 'Picture delete failed'
def _setCameraMode(self, mode, setting, option): d(description='Camera settings').click.wait() print dict_for_settings.get(mode).index(setting) if dict_for_settings.get(mode).index(setting) < MAX_SETTINGS_IN_A_SCREEN: print 'if' d(resourceId="com.intel.camera22:id/hori_list_button")[dict_for_settings.get(mode).index(setting)].click.wait() print len(dict_for_settings.get(mode)) print dict_for_options.get(mode).get(setting).index(option) if len(dict_for_settings.get(mode)) > MAX_SETTINGS_IN_A_SCREEN: d(resourceId="com.intel.camera22:id/hori_list_button")[MAX_SETTINGS_IN_A_SCREEN + dict_for_options.get(mode).get(setting).index(option)].click.wait() else: d(resourceId="com.intel.camera22:id/hori_list_button")[len(dict_for_settings.get(mode)) + dict_for_options.get(mode).get(setting).index(option)].click.wait() else: print 'else' # d(resourceId="com.intel.camera22:id/hori_list_button")[6].drag.to(resourceId="com.intel.camera22:id/hori_list_button")[0] d.swipe(640,180,100,180,steps=10) print dict_for_settings.get(mode).index(setting) print len(dict_for_settings.get(mode)) d(resourceId="com.intel.camera22:id/hori_list_button")[dict_for_settings.get(mode).index(setting) - (len(dict_for_settings.get(mode)) - MAX_SETTINGS_IN_A_SCREEN)].click.wait() d(resourceId="com.intel.camera22:id/hori_list_button")[MAX_SETTINGS_IN_A_SCREEN + dict_for_options.get(mode).get(setting).index(option)].click.wait() print dict_for_settings_keys.get(setting) if setting == 'Geo': result = commands.getoutput('adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0.xml | grep ' + dict_for_settings_keys.get(setting)) else: result = commands.getoutput('adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0_0.xml | grep ' + dict_for_settings_keys.get(setting)) print result return result
def testCallFromPhoneBook(self): """ Summary:testCallFromPhoneBook: Make a call from phonebook. Steps:1. Launch phone app 2. Touch Contacts tab 3. Touch the first contact 4. Touch call button to make a call 5. End the call 6. Exit Phone app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Favorites and all contacts').wait.exists(), 'Phone launch failed' #step2 d(description = 'Favorites and all contacts').click.wait() #step3,4 for i in range (random.randint(1,5)): d.swipe(196,700,196,180,steps = 10) for i in range (random.randint(1,5)): d.swipe(196,180,196,700,steps = 10) d.click(random.randint(130,370),random.randint(217,871)) assert d(text = 'Dialing').wait.exists(timeout = 15000), 'Not start to call' assert d(textContains = '0:').wait.exists(timeout = 15000), 'Call is not connected' #step5 d(description = 'End').click.wait() assert d(description = 'Favorites and all contacts').wait.exists(), 'Call end failed'
def test(): launch_tb_activity() Facial_x = 338 Facial_y = 270 # apply_one(Facial_x,Facial_y) Cloth_x = 551 Cloth_y = 270 #apply_one(Cloth_x,Cloth_y) Tech_x = 820 Tech_y = 270 #apply_one(Tech_x,Tech_y) time.sleep(5) d.swipe(900, 270, 10, 270) time.sleep(8) Eletronic_x = 108 Eletronic_y = 270 apply_one(Eletronic_x, Eletronic_y) House_x = 270 House_y = 270 apply_one(House_x, House_y) time.sleep(2) d.press("home") print("Done")
def testAlarmDelete(self): """ Summary:testAlarmDelete: Delete an alarm. Steps: 1.Launch alarm and check launch successfully 2.Verify alarm is exist or not 3.If no alarm, then add one 4.Delete an alarm """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Alarms').wait.exists(), 'Clock launch failed' d(description = 'Alarms').click.wait() assert d(text = 'Alarms').wait.exists(), 'Alarm launch failed' #step2,3 ALARM_COUNT = commands.getoutput(QUERY_ALARM_COUNT_COMMANDS) if int(ALARM_COUNT) == 0: d(description = 'Add alarm').click.wait() d(text = 'Cancel').click.wait() #step4 d.swipe(startX, startY, endX, endY, steps = 10) assert d(text = 'Alarm deleted.'), 'Alarm delete failed'
def test_launcher_widgets(self): print("Test Widgets") d.press.back() time.sleep(2) d.press.home() time.sleep(2) d.press.menu() if d(text="Widgets",className="android.widget.TextView", resourceId="com.android.launcher3:id/widget_button").exists: print("Found Widgets") d(text="Widgets",className="android.widget.TextView", resourceId="com.android.launcher3:id/widget_button").click() time.sleep(2) while not d(text="Email",className="android.widget.TextView", resourceId="com.android.launcher3:id/widget_name").exists: d.swipe(400, 500, 50, 500, steps=50); if d(className="android.widget.LinearLayout").child(text="Email",className="android.widget.TextView", resourceId="com.android.launcher3:id/widget_name").exists: print("swipe email widget to launcher") d.drag(360, 200, 480, 200, steps=100) time.sleep(2) if d(text="Choose folder",className="android.widget.TextView", resourceId="android:id/action_bar_title").exists: print("choose inbox folder for email") d(text="Inbox",className="android.widget.TextView", resourceId="com.android.email:id/name").click() time.sleep(2) else: print("drap email widget to launcher fail") else: print("No found email widget") d.press.back() time.sleep(2) else: print("No found widgets button") d.press.back() time.sleep(2)
def wifi(self): device.screen.on() device.press.menu() device(text ="Settings").click() device(text ="Wireless & networks").down(className="android.widget.TextView").click() device.screenshot("home.png") device.swipe(591,191,688,245) device.press.home()
def house(): d.swipe(900, 270, 10, 270) time.sleep(2) launch_tb_activity() print("house") x = 270 y = 270 apply_one(x, y) exit_tb()
def electron(): launch_tb_activity() print("electron") x = 108 y = 270 d.swipe(900, 270, 10, 270) time.sleep(2) apply_one(x, y) exit_tb()
def others(): d.swipe(900, 270, 10, 270) time.sleep(2) launch_tb_activity() print("others") x = 820 y = 270 apply_one(x, y) exit_tb()
def main(): #base_info() #base_info() #op_test() print("Go") #t=Device('0331416080186') print("Start") #print(t.info) #d.press.home() #d.swipe(200,500,700,500) #d.press.home() #click_test() #scroll_test() ''' d.press.home() d.swipe(200,500,700,500) #d.press.home() click_test() ''' #liuliang() #d(text=u'数码科技').click() #if d(text=u'腾讯体育').exists: #print("Existed") #d.dump("hierarchy.xml") #d.swipe(500,1570,500,400) delta_each = 400 time.sleep(3) for dragtime in range(20): print('dragtime') for i in range(3): d.click(919, 420 + i * delta_each) print('click') time.sleep(8) #each_dianpu() each_dianpu() time.sleep(8) d.swipe(919, 420 + delta_each * 3, 919, 400) time.sleep(5)
def testOpenPicture(self): """ Summary:testCapturePictureAndDelete: Take a picture, then view and delete the picture. Steps:1. Open Camera app 2. Touch thumbnail to view the picture 3. Exit Camera app """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Shutter button').wait.exists(), 'Camera launch failed' #Step2 d.swipe(startX, startY, endX, endY, steps = 10) time.sleep(2) d.click(274,482) d.press('menu') assert d(text = 'Delete').wait.exists()
def testOpenMusicPlayer(self): """ Summary:testOpenMusicPlayer: Open music player. Steps: 1. Open music app 2. Touch All tab 3. Play a music file 4. Back to home screen, run music on background """ #step1 commands.getoutput('adb shell am start ' + self.runComponent) assert d(text = 'Listen Now').wait.exists(), 'Music player launch failed' #step2 d.swipe(0,400,400,400,steps=10) assert d(text = 'Playlists').wait.exists(), 'Option bar launch failed' d(text = 'Playlists').click.wait() assert d(text = 'Last added').wait.exists(), 'Playlists launch failed' #step3 d(text = 'Last added').click.wait() d.click(120,400) assert d(description = 'Pause').wait.exists(), 'Music play failed'
def launch_tb(): # cling position method d.screen.on() time.sleep(1) os.system("adb shell am force-stop com.taobao.taobao") time.sleep(1) d.press("home") d.swipe(120, 1110, 900, 1110) d(text="shopping").click() time.sleep(1) # launch TB d.click(225, 1300) time.sleep(8) #click Trial d.click(950, 900) time.sleep(8) #click Te She Dao Gou d.click(300, 300) time.sleep(8) #click Free to try d.click(930, 1105) time.sleep(10)
def testAlarmAdd(self): ''' Summary:testAlarmAdd: Add an alarm. Steps: 1.Launch alarm and check launch successfully 2.Get alarm number 3.Verify alarm is exist or not 4.If exist, delete it 5.Add alarm ''' #step1 #os.system('adb shell am start ' + self.runComponent) commands.getoutput('adb shell am start ' + self.runComponent) assert d(description = 'Alarms').wait.exists(), 'Clock launch failed' d(description = 'Alarms').click.wait() assert d(text = 'Alarms').wait.exists(), 'Alarm launch failed' #step2 #BEFORE_DELETE = os.popen(QUERY_ALARM_COUNT_COMMANDS) BEFORE_DELETE = commands.getoutput(QUERY_ALARM_COUNT_COMMANDS) #step3,4 for i in range(0, int(BEFORE_DELETE)): d.swipe(startX, startY, endX, endY, steps = 10) assert d(text = 'Alarm deleted.'), 'Alarm delete failed' #AFTER_DELETE = os.popen(QUERY_ALARM_COUNT_COMMANDS) AFTER_DELETE = commands.getoutput(QUERY_ALARM_COUNT_COMMANDS) assert int(AFTER_DELETE) == 0, 'Still exist alarm' #step5 d(description = 'Add alarm').click.wait() d(text = 'Cancel').click.wait() assert d(text = ':00').wait.exists(), 'Alarm create failed'
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 d.watcher("Vellamo out of memory").when(text="Vellamo Out of Memory").click(text="ok") for i in range(1, loop+1): print "第 %d 次循环" %i d.screen.on() d.press.home() removeRecentList(d, "Benchmarking Application") d(description="Apps").click() d(text="Vellamo").click() time.sleep(2) if d(text="Accept").exists: d(text="Accept").click() if d(text="Welcome").exists: d.swipe(500,240,100,240) d.swipe(500,240,100,240) d.swipe(500,240,100,240) d(className="android.support.v4.view.ViewPager", \ resourceId="com.quicinc.vellamo:id/act_main_pager_portrait")\ .child(className="android.view.View")[0].click() #d(className="android.view.View")[2].click() if d(text="Yes").exists: d(text="Yes").click() while not d(text="Your device's score!").exists: time.sleep(2) else: d.screenshot("%s/screenshot/%d_vellamo_%s.png"\ %(sys.path[0], i, now.strftime(ISOFORMAT))) d.press.home() i += 1 print "***** test end ********"
def swipeDown(): print('start swipeDown...') d.swipe(200, 180, 200, 550) time.sleep(1) print('end swipeDown...')
def swipeRight(): d.swipe(1020, 100, 100, 100)
def swipeLeft(): d.swipe(100, 100, 1020, 100)
def swipeBottomRight(): lc.fileLog().info('start swipeBottomRight...') d.swipe(130, 530, 890, 530) # 滑动范围写死 time.sleep(2) lc.fileLog().info('end swipeBottomRight...')
d(className="android.widget.ImageView", description="Clock").click() string = d(className="android.widget.TextView", resourceId="com.android.deskclock:id/digital_clock" ).info["contentDescription"] print string.encode("utf-8") d.press.back() d.press.home() # ================== 點擊進入 所有應用程式 ======================== d(resourceId="com.android.launcher3:id/all_apps_handle").click() time.sleep(2) # ================== 設備操作 - 往上Swipe ============================ print "Swipe to All Apps" d.swipe(240, 680, 240, 200, steps=40) time.sleep(2) # ==================== 滑動到 Settings =========================== print "Scroll to Settings and click" d(className="android.support.v7.widget.RecyclerView", resourceId="com.android.launcher3:id/apps_list_view") \ .child_by_text( "Settings", allow_scroll_search=True, className="android.widget.TextView" ).click() time.sleep(2) # ==================== 滑動到 System ====================== print "Scroll to System and then click" d(className="android.support.v7.widget.RecyclerView", resourceId="com.android.settings:id/dashboard_container") \
from uiautomator import device as d import time import random # 点亮屏幕 d.screen.on() info = d.info print(info) # 1920 * 1080 screen_height = info.get('displayHeight') screen_width = info.get('displayWidth') def print_click(sx, sy, ex, ey, second): print( str(round(second, 2)) + '秒后拖拽(' + str(round(sx, 2)) + ', ' + str(round(sy, 2)) + '), 到(' + str(round(ex, 2)) + ',' + str(round(ey, 2)) + ')') while 1: sx = random.uniform(20, screen_width / 3 * 2) sy = random.uniform(screen_height / 2, screen_height - 150) ex = random.uniform(20, screen_width / 3 * 2) ey = random.uniform(50, screen_height / 2) second = random.uniform(20, 40) print_click(sx, sy, ex, ey, second) time.sleep(second) steps = random.uniform(10, 30) d.swipe(sx, sy, ex, ey, steps)
def swipe(): d.screenshot(file1) t = time.time() d.screenshot(file2) screen1Delay = time.time() - t t = time.time() d.screenshot(file3) screen2Delay = time.time() - t t = time.time() bx, by, rx1, ry1, rx2, ry2, rx3, ry3 = getInfo(file1, file2, file3) vx1 = (rx2 - rx1) / screen1Delay vy1 = (ry2 - ry1) / screen1Delay vx2 = (rx3 - rx2) / screen2Delay vy2 = (ry3 - ry2) / screen2Delay # account for direction changing changedDir = vx2 != 0 and abs(vx1) / abs(vx2) > changeDirThreshold if changedDir: projrx3 = rx2 + vx1 * screen2Delay changedDir = projrx3 < minX or projrx3 > maxX if changedDir: print("Changed direction: vx1: {:f}, vx2: {:f}, vy1: {:f}, vy2: {:f}".format(vx1, vx2, vy1, vy2)) vx = -vx1 if changedDir else vx2 vy = -vy1 if changedDir else vy2 procDelay = time.time() - t t = time.time() rx = rx3 + vx * (procDelay + projActDelay) ry = ry3 + vy * (procDelay + projActDelay) # account for screen limits usedT = 0 if rx > maxX: usedT = (maxX - rx3) / vx rx = maxX - vx * (procDelay + projActDelay - usedT) elif rx < minX: usedT = (minX - rx3) / vx rx = minX - vx * (procDelay + projActDelay - usedT) if ry > maxY: usedT = (maxY - ry3) / vy ry = maxY - vy * (procDelay + projActDelay - usedT) elif ry < minY: usedT = (minY - ry3) / vy ry = minY - vy * (procDelay + projActDelay - usedT) if usedT != 0: print("Out of bounds: usedT: {:f}, rx: {:f}, ry: {:f}".format(usedT, rx, ry)) d.swipe(bx, by, rx, ry, swipeSpeed) actDelay = time.time() - t if vx != 0: print("Ball: ({}, {})\nRing: ({}, {}) -> ({}, {}) -> ({}, {})\nTarget: ({}, {})".format(bx, by, rx1, ry1, rx2, ry2, rx3, ry3, rx, ry)) print("Delays: ({:f}, {:f}, {:f}, {:f})".format(screen1Delay, screen2Delay, procDelay, actDelay))
def swipe_right(): sx = android_device.info[u'displaySizeDpX'] / 2 sy = android_device.info[u'displaySizeDpY'] / 2 ex = sx - 100 ey = sy - 100 android_device.swipe(sx, sy, ex, ey, steps=5)
def unlockScreen(self): d.wakeup() if d(resourceId='com.android.systemui:id/clock_view').wait.exists( timeout=2000): d.swipe(D_C_X, D_HEIGHT - 1, D_C_X, 0, 5)
def miniSwipe(): d.swipe(100, 1000, 100, 600, steps=50)
def swipeUpLeftItems(): lc.fileLog().info('start swipeUpLeftItems...') d.swipe(100, 560, 100, 100) # 滑动范围写死 time.sleep(1) lc.fileLog().info('end swipeUpLeftItems...')
def auto_swipe(): d.screen.on() # 点亮屏幕 d.swipe(500, 500, 0, 500) # 模拟器坐标位置
import sys sys.setrecursionlimit(10000) from uiautomator import device as d #d = u2.connect('192.168.199.163') print(d.info) i = 0 while i < 10000: import random import time x1 = random.randint(250, 300) x2 = random.randint(800, 900) y1 = random.randint(500, 600) y2 = random.randint(600, 800) steps = random.randint(20, 22) d.swipe(x1, y1, x2, y2, steps)
def swipeRightInAppMenuPage(): lc.fileLog().info('start swipeRightInAppMenuPage...') d.swipe(50, 275, 950, 275) # 滑动范围写死 time.sleep(2) lc.fileLog().info('end swipeRightInAppMenuPage...')
def swipeUp(): print('start swipeUp...') d.swipe(200, 550, 200, 180) # 滑动范围写死 time.sleep(1) print('end swipeUp...')
def autoSwipe(): d.swipe(1000, 500, 200, 500) time.sleep(30)
def view_history_message(): while continue_drag(): d.swipe(150, 410, 150, 110, steps=20) back() back()
def test_idlescreen_swipe(self): print("Swipe on idlescreen") d.swipe(300, 480, 480, 20, steps=10) time.sleep(2) d.swipe(300, 480, 480, 20, steps=10) time.sleep(2)
def fullPageSwipe(): d.swipe(100, 1400, 100, 150, steps=50)
from uiautomator import device as d d.swipe(1000, 500, 1000, 200) # down to up
def swipeDown(): lc.fileLog().info('start swipeDown...') d.swipe(200, 180, 200, 550) time.sleep(1) lc.fileLog().info('end swipeDown...')
from uiautomator import device as d #App1 x1, y1 = 100, 310 #App2 x2, y2 = 245, 310 #App3 x3, y3 = 380, 310 d.press.home() d.click(x1, y1) #d.wait.update() d.press.home() d.click(x2, y2) #d.wait.update() d.press.home() d.click(x3, y3) #d.wait.update() d.press.home() d.press("recent") #d.wait.update() sx, sy, ex, ey = 240, 90, 240, 700 d.swipe(ex, ey, sx, sy, steps=10) d.swipe(sx, sy, ex, ey, steps=10) #d.wait.update() d.click(380, 110) d.server.stop()
def swipeLeftInAppMenuPage(): lc.fileLog().info('start swipeLeftInAppMenuPage...') d.swipe(950, 275, 50, 275) time.sleep(2) lc.fileLog().info('end swipeLeftInAppMenuPage...')
def swipeListViewOfToneDown(): lc.fileLog().info('start swipeListViewOfToneDown...') d.swipe(500, 160, 500, 420) # 滑动范围写死 lc.fileLog().info('stop swipeListViewOfToneDown...')
def swipeDownRightItems(): lc.fileLog().info('start swipeDownRightItems...') d.swipe(900, 100, 900, 560) # 滑动范围写死 time.sleep(1) lc.fileLog().info('end swipeDownRightItems...')
def swipeDownLeftItems(): lc.fileLog().info('start swipeDownLeftItems...') d.swipe(100, 100, 100, 560) time.sleep(1) lc.fileLog().info('end swipeDownLeftItems...')