def testAddDelContact(self): #Launch phone app self._launchPhone() #Select Contacts d(text = '联系人').click.wait() assert d(text = '群组').wait.exists(timeout=5000),'Switch to phone book failed in 5s!' #Add new contact d(text = '添加').click.wait() assert d(text = '本地保存').wait.exists(timeout = 5000),'Pop-up reserve method failed in 5s!' d(text = '本地保存').click.wait() assert d(text = '新建 本地 联系人').wait.exists(timeout = 5000),'Switch to create contacts failed in 5s!' d(text="姓名").set_text("adele") # click the top of screen, prevent the duplication d.sleep(1) d.click(580,170) d(className = 'android.widget.EditText', text="电话").set_text('15050505050') d(text = '完成').click.wait() assert d(text = '联系人详情').wait.exists(timeout = 5000),'Switch to contacts detail failed in 5s!' assert d(text = 'adele').wait.exists(timeout = 5000), 'adele is not show on screen!' #Delete contact d(text = '删除此联系人').click.wait() assert d(textContains = '要删除联系人吗').wait.exists(timeout = 5000),'Delete confirm info does not pop-up in 5s!' d(text = '确认删除').click.wait() assert d(text = 'adele').wait.gone(timeout = 5000),'Delete contact failed in 5s!'
def _switchLauncherSettings(self,viewmode): # launch setting d.start_activity(component='com.android.settings/.Settings') assert d(text = '设置').wait.exists(timeout = 5000),'Launch settings failed in 5s!' # get into launcher settings if d(text = '单板块视图').wait.exists(timeout = 5000): pass else: u.selectOption('桌面设置项') assert d(text = '单板块视图').wait.exists(timeout = 5000),'Switch to Desktop Settings failed in 5s!' if viewmode == '36' or viewmode == '81': if d(text = '多板块视图').exists: d(text = VIEW_MODE[viewmode]).click.wait() if d(text = '设置桌面').wait.exists(timeout = 5000): d(text = '确定').click.wait() else: d(text = '九宫格').click.wait() d.sleep(3) if d(text = '设置桌面').wait.exists(timeout = 5000): d(text = '确定').click.wait() d.sleep(3) d.start_activity(component='com.android.settings/.Settings') assert d(text = '设置').wait.exists(timeout = 5000),'Launch settings failed in 5s!' d(text = VIEW_MODE[viewmode]).click.wait() if d(text = '设置桌面').wait.exists(timeout = 5000): d(text = '确定').click.wait() else: d(text = VIEW_MODE[viewmode]).click.wait() if d(text = '设置桌面').wait.exists(timeout = 5000): d(text = '确定').click.wait()
def testReadEmailWithAtt(self): #Launch Email self._launchEmail() #Get into star box d(resourceId = 'com.android.email:id/options_view').click.wait() #assert d(resourceId = 'com.android.email:id/bottom_dialog_title_text').wait.exists(timeout = 5000),'Pop-up menu list failed in 5s!' d(text = '已加旗标').click.wait() assert d(resourceId = 'com.android.email:id/title',text = '已加旗标').wait.exists(timeout = 5000),'Switch Star box failed in 5s!' # check inbox for i in range(30): d.sleep(1) if d(descriptionContains = ATT_SUBJECT).exists: break d(resourceId = 'com.android.email:id/refresh_view').click.wait() # check received mail assert d(descriptionContains = ATT_SUBJECT).exists,'Do not received mail!' d(descriptionContains = ATT_SUBJECT).click() assert d(resourceId = 'com.android.email:id/send_calendar_btn').wait.exists(timeout = 5000),'Switch to mail detail failed in 5s!' # check attachment if d(text = '加载').exists: d(text = '加载').click.wait() assert d(text = '打开').wait.exists(timeout = 15000),'Download attachment failed in 15s!' d(text = '打开').click.wait() assert d(text = '选择要使用的应用').wait.exists(timeout = 5000),"'选择要使用的应用' does not pop up in 5s!" d(text = '相册').click.wait() assert d(packageName = 'com.android.gallery3d').wait.exists(timeout = 5000),'Switch to gallery view failed in 5s!'
def testSwitchTheme(self): d.start_activity(component='com.android.settings/.Settings') assert d(text = '设置').wait.exists(timeout = 5000),'Launch settings failed in 5s!' u.selectOption('主题、壁纸、图标') assert d(resourceId = 'smartisanos:id/tv_title',text = '主题、壁纸、图标').wait.exists(timeout = 5000),'Switch to theme view failed in 5s!' u.selectOption('桌面主题') assert d(resourceId = 'com.smartisanos.launcher:id/tv_title',text = '桌面主题').wait.exists(timeout = 5000),'Switch to theme view failed in 5s!' for i in range(30): for theme in THEME_LIST: if i==0 and theme == '经典': continue d.start_activity(component='com.android.settings/.Settings') assert d(resourceId = 'com.smartisanos.launcher:id/tv_title',text = '桌面主题').wait.exists(timeout = 5000),'Switch to theme view failed in 5s!' if theme == '经典': d(resourceId = 'com.smartisanos.launcher:id/list_theme').swipe.down() d(resourceId = 'com.smartisanos.launcher:id/list_theme').swipe.down() d(resourceId = 'com.smartisanos.launcher:id/list_theme').swipe.down() d.sleep(1) u.selectOption(theme) assert d(resourceId = 'smartisanos:id/tv_title',text = theme).wait.exists(timeout = 5000),'Switch to theme thumbnail failed in 5s!' d(text = '设定').click.wait() assert d(text = '正在加载主题').wait.exists(timeout = 5000),'Loading theme view does not show up in 5s!' assert d(text = '正在加载主题').wait.gone(timeout = 10000),'Loading theme view does not disappeared in 10s!' assert d(resourceId = 'com.smartisanos.launcher:id/glview').wait.exists(timeout = 5000), 'Switch to launcher failed in 5s!' d.sleep(3) # exit theme setting d.start_activity(component='com.android.settings/.Settings') d.press('back')
def testSingleViewSwipe(self): # swipe home screen 1000 times totally for i in range(500): direction = random.choice(['left','right']) step = random.randint(5,50) self._swipeScreen(direction,step) d.sleep(1)
def testPlayStreamingVideo(self): #Start Browser d.start_activity(component='com.android.browser/.BrowserActivity') assert d(resourceId = 'com.android.browser:id/switch_btn').wait.exists(timeout = 5000),'Launch browser failed in 5s!' d(resourceId = 'com.android.browser:id/newtab_btn').click.wait() # input download audio url d(resourceId = 'com.android.browser:id/url', text = '输入网址').set_text('auto.smartisan.com/media/Auto_Test_Video.mp4') d.press('enter') # play without element on webpage # d.sleep(10) # #d.click('Streaming_Play.png') # d.click(540,960) # #d(description = '播放').click.wait() # assert d(description = '网页视图').wait.exists(timeout = 15000),'Loading streaming video failed in 15s!' # # play time # d.sleep(15) # #assert d(description = '媒体控件').wait.exists(timeout = 10000),'Switch to webview failed in 10s!' # if d.orientation != 'natural': # d.orientation = 'n' #play with element on webpage assert d(description = '播放').wait.exists(timeout = 20000),'Loading webpage failed in 20s!' d(description = '播放').click.wait() assert d(description = '视频').wait.exists(timeout = 10000),'Start playing streaming video failed in 10s!' d.sleep(10)
def testDownloadVideo(self): #Launch Browser self._launchBrowser() # input download audio url d(resourceId = 'com.android.browser:id/url', text = '输入网址').set_text('http://pan.baidu.com/s/1eQcRK3o') d.press('enter') d.sleep(5) d.swipe(540,1400,540,400,100) # click download d.click(800,1550) assert d(text = '是否下载该文件?').wait.exists(timeout = 10000), 'Not trigger download. ' d(text = '下载').click.wait() if d(textContains = '您正在通过移动数据下载').exists: d(text = '继续').click.wait() #Looping 60s to check if download is ok for i in range(60): if u.getFileCount('/sdcard/Download', 'mp4') > 0: return d.sleep(1) assert False, 'Can not download video in 60s. ' #Close all webpage windows and clear downloaded resource #self._closeWindows() self._clearData()
def testVisitWebPage4G(self): # turn off wifi self._setWifistatus('off') d.sleep(3) #Launch Browser self._launchBrowser() # visite webpage d(resourceId = 'com.android.browser:id/url', text = '输入网址').set_text(TOP5[3]) d.press('enter') d.expect(CHECK_POINT[3], timeout=15) # browse webpage d.swipe(1000,1300,1000,600,10) d.sleep(1) d.swipe(1000,1300,1000,600,10) d.sleep(1) d.swipe(1000,600,1000,1300,10) d.sleep(1) d.swipe(1000,600,1000,1300,10) d.sleep(1) # turn on wifi self._setWifistatus('on') d.start_activity(component='com.android.browser/.BrowserActivity') assert d(resourceId = 'com.android.browser:id/switch_btn').wait.exists(timeout = 5000),'Launch browser failed in 5s!'
def _clearCache(self): # close all webpage d(resourceId = 'com.android.browser:id/switch_btn').click.wait() d(resourceId = 'com.android.browser:id/clearall').click.wait() d(text = '关闭').click.wait() # clear cache d(resourceId = 'com.android.browser:id/menu_btn').click.wait() d.sleep(2) #select setting in option list d.click(590,1700) #d(resourceId = 'com.android.browser:id/option_list_item_text',text = '设置').click.wait() assert d(text = '设置').wait.exists(timeout = 3000),'Switch to setting view failed in 3s!' d(text = '隐私和安全').click.wait() assert d(resourceId = 'com.android.browser:id/action_new_event_text',text = '隐私和安全').wait.exists(timeout = 3000),'Switch to event view failed in 3s!' d(text = '清除缓存').click.wait() if d(resourceId = 'android:id/alertTitle',text = '清除缓存').exists: d(text = '确定').click.wait() d(text = '清除历史记录').click.wait() if d(resourceId = 'android:id/alertTitle',text = '清除历史记录').exists: d(text = '确定').click.wait() d(text = '清除所有 Cookie 数据').click.wait() if d(resourceId = 'android:id/alertTitle',text = '清除所有 Cookie 数据').exists: d(text = '确定').click.wait() d(text = '返回').click.wait() d(text = '完成').click.wait()
def testSaveNoteAsPic(self): # Launch Note d.start_activity(component='com.smartisanos.notes/.NotesActivity') if d(text = '列表').exists: d(text = '列表').click.wait() assert d(text = '便签').wait.exists(timeout = 5000),'Launch Note failed in 5s!' for i in range(500): d(resourceId = 'com.smartisanos.notes:id/add_button').click.wait() assert d(resourceId = 'com.smartisanos.notes:id/delete_insert_button').wait.exists(timeout = 5000),'Switch to note editer failed in 5s!' d(resourceId = 'com.smartisanos.notes:id/detail_note_editor').set_text('test content...') d(resourceId = 'com.smartisanos.notes:id/delete_insert_button').click.wait() d.sleep(1) d.click(900,1830) d.click('image.png') # select first pic d.click(150,370) d.click('done.png') assert d(resourceId = 'com.smartisanos.notes:id/detail_note_image').wait.exists(timeout = 5000),'Add pic to note failed in 5s!' d(resourceId = 'com.smartisanos.notes:id/send_finish_button').click.wait() d(resourceId = 'com.smartisanos.notes:id/send_finish_button').click.wait() assert d(text = '请选择操作').wait.exists(timeout = 5000),'Share selector does not pop-up in 5s!' d(text = '以图片形式分享').click.wait() assert d(text = '保存图片').wait.exists(timeout = 5000),'Switch to thumbs failed in 5s!' d(text = '取消').click.wait() d(text = '列表').click.wait()
def testShareNoteToWeibo(self): # Launch Note d.start_activity(component='com.smartisanos.notes/.NotesActivity') assert d(text = '便签').wait.exists(timeout = 5000),'Launch Note failed in 5s!' for i in range(500): d(resourceId = 'com.smartisanos.notes:id/add_button').click.wait() assert d(resourceId = 'com.smartisanos.notes:id/delete_insert_button').wait.exists(timeout = 5000),'Switch to note editer failed in 5s!' d(resourceId = 'com.smartisanos.notes:id/detail_note_editor').set_text('test content...') d(resourceId = 'com.smartisanos.notes:id/delete_insert_button').click.wait() d.sleep(1) d.click(900,1830) d.click('image.png') # select first pic d.click(150,370) d.click('done.png') assert d(resourceId = 'com.smartisanos.notes:id/detail_note_image').wait.exists(timeout = 5000),'Add pic to note failed in 5s!' d(resourceId = 'com.smartisanos.notes:id/send_finish_button').click.wait() d(resourceId = 'com.smartisanos.notes:id/send_finish_button').click.wait() assert d(text = '请选择操作').wait.exists(timeout = 5000),'Share selector does not pop-up in 5s!' d(text = '发送至新浪微博').click.wait() #d(text = '生成长微博').click.wait() #d(text = '保存到相册并继续').click.wait() assert d(resourceId = 'com.smartisanos.notes:id/weibo_body_view').wait.exists(timeout = 5000),'Switch to Weibo proview failed in 5s!' d(text = '下一步').click.wait() assert d(text = '发送').wait.exists(timeout = 5000),'Prepare to send weibo failed in 5s!' d(text = '取消').click.wait() d(text = '取消').click.wait() d(text = '列表').click.wait()
def testLaunchMultipleApp(self): # Launch an for app in MULTIPLE_APP_LIST: d.start_activity(component= app) assert d(resourceId = MULTIPLE_APP_LIST[app]).wait.exists(timeout = 5000),'Launch %s failed in 5s'%app d.sleep(5) d.press('home') d.sleep(1)
def testLaunchMultipleApp(self): # Launch an for app in MULTIPLE_APP_LIST: d.start_activity(component=app) assert d(packageName=MULTIPLE_APP_LIST[app]).wait.exists(timeout=5000), "Launch %s failed in 5s" % app d.sleep(5) d.press("home") d.sleep(1)
def _launchEmail(self): #Launch Email d.start_activity(component='com.android.email/.activity.Welcome') d.sleep(1) #Check if login account is needed. if d(text = '添加账户').exists: self._loginAccount() else: pass assert d(resourceId = 'com.android.email:id/subtitle',text = 'Exchange').wait.exists(timeout = 10000),'Launch email failed in 10s!'
def testLaunchAndExitMediaExplorer(self): for i in xrange(4): d.press('right') assert d(text="高清播放器").exists, 'Media Explorer icon not found!' d(text="高清播放器").click.wait() assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text='设备').wait.exists(timeout=5000), 'launch Media Explorer failed!' assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text="视频").wait.exists(timeout=5000), 'launch Media Explorer failed!' d.press('back') d.sleep(3) d.press('back') assert d(text="高清播放器").wait.exists(timeout=10000), 'exit from Media Explorer failed!'
def setUp(): # unlock screen # unlock() for i in xrange(2): d.press('back') d.press('home') d.sleep(1) # clear logcat commands.getoutput('adb shell logcat -c') d.sleep(1) registerSysWatchers()
def _sendMessage(self): #Send Message d(description = '发送').click.wait() if d(textContains = '卡 1 发送').exists: d(textContains = '卡 1 发送').click.wait() d(text = '准备发送…').wait.exists(timeout = 5000) d(text = '准备发送…').wait.gone(timeout = 10000) d.sleep(1) assert d(text="发送中…").wait.gone(timeout=60000), 'Send SMS failed in 60s' if d(textContains = '发送失败').exists: assert False,'Send SMS failed, please check single!'
def testSwitchView(self): if d(resourceId = 'com.android.browser:id/stop').exists: d(resourceId = 'com.android.browser:id/newtab_btn').click.wait() if d(resourceId = 'com.android.browser:id/frame0').exists: d(resourceId = 'com.android.browser:id/switch_btn').click.wait() for i in range(1000): d(resourceId = 'com.android.browser:id/menu_btn').click.wait() d.click('hiden_mode.png') d.sleep(1) d(resourceId = 'com.android.browser:id/menu_btn').click.wait() d.click('normal_mode.png')
def testLaunchAndExitFM(self): for i in xrange(8): d.press('right') assert d(text="网络电台").exists, 'FM app icon not found!' d(text="网络电台").click.wait() assert d(resourceId='com.xiaomi.mimusic:id/play_btn').child(className='android.widget.ImageView').wait.exists(timeout=10000), 'Open FM failed!' d.sleep(10) d.press('back') d.sleep(2) d.press('back') assert d(text="网络电台").wait.exists(timeout=10000), 'exit from FM failed!'
def selectOption(option): i = 1 while i: if d(text = option).exists: break d.swipe(540,1400,540,400,100) d.sleep(1) i+=1 if d(text = option).exists or i==10: break d.sleep(1) d(text = option).click.wait()
def tearDown(self): """ called after each test method end or exception occur. """ self.after_install = d.server.adb.cmd('shell pm list package -3').communicate()[0].split() del_apk = [i.split('=')[1] for i in self.after_install if i not in self.before_install] for apk in del_apk: d.server.adb.cmd('shell pm uninstall %s' % apk) d.sleep(3) for i in xrange(8): d.press('back') d.press('home') d.press('home')
def testMOCall(self): commands.getoutput('adb shell am start -n com.android.contacts/.activities.DialtactsActivity') d(resourceId = 'com.android.contacts:id/one_classic', description = '一').click.wait() d(resourceId = 'com.android.contacts:id/zero_classic', description = '零').click.wait() d(resourceId = 'com.android.contacts:id/zero_classic', description = '零').click.wait() d(resourceId = 'com.android.contacts:id/eight_classic', description = '八').click.wait() d(resourceId = 'com.android.contacts:id/six_classic', description = '六').click.wait() d(resourceId = 'com.android.contacts:id/call_classic').click.wait() assert d(text='结束').wait.exists(timeout=15000),'Calling failed!' d(text='结束').click.wait() d.sleep(3) d.expect('10086.png')
def testVisitTop5(self): #Launch Browser self._launchBrowser() #Visite TOP5 webpage for i in range(5): d(resourceId = 'com.android.browser:id/url', text = '输入网址').set_text(TOP5[i]) d.sleep(2) d.press('enter') if d(textContains = '需要了解您的位置信息').wait.exists(): d(text = '拒绝').click.wait() d.expect(CHECK_POINT[i],timeout=10, msg = 'Loading webpage %s failed in 10s!'%TOP5[i]) d(resourceId = 'com.android.browser:id/newtab_btn').click.wait()
def testTurnOnOffNFC(self): #Launch Setting d.start_activity(component='com.android.settings/.Settings') assert d(text = '设置').wait.exists(timeout = 5000),'Launch settings failed in 5s!' self._selectOption('NFC') assert d(resourceId = 'smartisanos:id/tv_title',text = 'NFC').wait.exists(timeout = 5000),'Switch to NFC failed in 5s!' d(className="android.widget.RelativeLayout", resourceId="com.android.settings:id/item_id_nfc").child(className="smartisanos.widget.SwitchEx").swipe.right(steps = 5) d.sleep(3) assert d(className="android.widget.RelativeLayout", resourceId="com.android.settings:id/item_id_android_beam").child(className="smartisanos.widget.SwitchEx").info['enabled'],'Turn NFC failed in 3s!' #d(text="NFC").right(className="smartisanos.widget.SwitchEx").click() d(className="android.widget.RelativeLayout", resourceId="com.android.settings:id/item_id_nfc").child(className="smartisanos.widget.SwitchEx").swipe.left(steps = 5) assert not d(className="android.widget.RelativeLayout", resourceId="com.android.settings:id/item_id_android_beam").child(className="smartisanos.widget.SwitchEx").info['enabled'],'Turn NFC failed in 3s!'
def testLaunchAndExitFM(self): for i in xrange(8): d.press('right') assert d(text="网络电台").exists, 'FM app icon not found!' d(text="网络电台").click.wait() assert d(resourceId='com.xiaomi.mimusic:id/play_btn').child( className='android.widget.ImageView').wait.exists( timeout=10000), 'Open FM failed!' d.sleep(10) d.press('back') d.sleep(2) d.press('back') assert d(text="网络电台").wait.exists( timeout=10000), 'exit from FM failed!'
def testSwitchSong(self): """ launch app store and exit """ for i in xrange(8): d.press('right') assert d(text="网络电台").exists, 'FM app icon not found!' d(text="网络电台").click.wait() assert d(resourceId='com.xiaomi.mimusic:id/play_btn').wait.exists(timeout=10000), 'Open FM failed!' d.sleep(10) assert d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").exists, 'song play screen not found!' first_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").info['text'] d.press('right') d.sleep(15) assert d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").exists, 'song play screen not found!' second_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").info['text'] assert not second_song_name == first_song_name, 'switch song failed!' d.press('right') d.sleep(15) assert d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").exists, 'song play screen not found!' third_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child(className="android.widget.TextView").info['text'] assert not third_song_name == second_song_name, 'switch song failed!' d.press('back') d.sleep(2) d.press('back')
def testSwitch64View(self): self._switchLauncherSettings('16') d.press('back') d.press('back') d.press('home') d.press('menu') for i in range(500): direction = random.choice(['left','right']) step = random.randint(5,50) self._swipeScreen(direction,step) for i in range(2): d.press('menu') d.sleep(1)
def testSendMMSWithPics(self): #Launch message app and enter new message screen self._launchAndEnterNewMsg() #Input receiver and text content self._editTestContent(MMS_RECEIVER,MMS_PICS_CONT) #Add pics as attachment d(resourceId = 'com.android.mms:id/switch_button').click.wait() # (120,1830) is the positon of '照片和视频' d.click(120,1830) #assert d(text = '请选择操作').wait.exists(timeout = 5000),"Trigger '照片和视频' failed in 5s!" #d(text = '选取照片').click.wait() assert d(packageName = 'com.android.gallery3d').wait.exists(timeout = 5000),'Switch to gallery view failed in 5s!' d.sleep(1) # (800,1825) is the position of '所有相册' d.click(800,1825) # select '根目录' d.click('MMS_Into_RootDir.png') d.sleep(1) d.click('MMS_Pics.png') d.sleep(1) # (1000,150) is the position of Done button d.click(1000,150) d.sleep(1) #Send MMS self._sendMessage()
def testDownloadPics(self): #Launch Browser self._launchBrowser() #Input download pics url d(resourceId = 'com.android.browser:id/url', text = '输入网址').set_text('auto.smartisan.com/media/Auto_Test_Image.jpg') d.sleep(1) d.press('enter') d.sleep(5) # swipe up to show '普通下载' d.long_click(500, 670) d.sleep(1) assert d(text = '保存图片').wait.exists(timeout = 5000),'Save download window does not pop-up in 5s!' d(text = '保存图片').click() if d(textContains = '您正在通过移动数据下载').wait.exists(timeout=1000): d(text = '继续').click.wait() #Looping 60s to check if download is ok for i in range(60): if u.getFileCount('/sdcard/Download', 'jpg') > 0: return d.sleep(1) assert False, 'Can not download pics in 60s. ' #Close all webpage windows and clear downloaded resource #self._closeWindows() self._clearData()
def testWeibo(self): # launch weibo d.start_activity(component='com.sina.weibo/.SplashActivity') assert d(packageName = 'com.sina.weibo').wait.exists(timeout = 5000),'Launch Weibo failed in 5s!' if d(text = '特别提示').wait.exists(timeout = 5000): d(text = '确定').click.wait() if d(text = '给我们评分').wait.exists(timeout = 5000): d(text = '不了,谢谢').click.wait() #Refresh weibo d(description = '首页').click.wait() d.sleep(3) if d(text = '赞').exists: d(text = '赞').click.wait()
def testWifiOpenAndClose(self): d.start_activity('--activity-clear-task', component='com.android.settings/.Settings') d(text="无线和网络").wait.exists(timeout=2000) #d(className="android.widget.ListView", resourceId="android:id/list").child(text='WLAN').click.wait() #d(text="WLAN").click.wait() d.press('enter') d(resourceId='android:id/action_bar').child(text='WLAN').wait.exists(timeout=3000) if d(className='android.widget.Switch', text='打开').exists: d.press('right') d.sleep(2) d.press('up') d.sleep(2) for i in xrange(10): d.press('enter') assert d(resourceId='android:id/action_bar').child(text='关闭').wait.exists(timeout=3000), 'wifi close failed!' d.press('enter') assert d(resourceId='android:id/action_bar').child(text='打开').wait.exists(timeout=3000), 'wifi open failed!' assert d(resourceId='android:id/list').child(text='已连接').wait.exists(timeout=20000), 'wifi connect failed!' elif d(className='android.widget.Switch', text='关闭').exists: d.press('right') d.sleep(2) d.press('up') d.sleep(2) for i in xrange(10): d.press('enter') assert d(resourceId='android:id/action_bar').child(text='打开').wait.exists(timeout=3000), 'wifi close failed!' assert d(resourceId='android:id/list').child(text='已连接').wait.exists(timeout=20000), 'wifi connect failed!' d.press('enter') assert d(resourceId='android:id/action_bar').child(text='打开').wait.exists(timeout=3000), 'wifi open failed!'
def testSwitchSong(self): """ launch app store and exit """ for i in xrange(8): d.press('right') assert d(text="网络电台").exists, 'FM app icon not found!' d(text="网络电台").click.wait() assert d(resourceId='com.xiaomi.mimusic:id/play_btn').wait.exists( timeout=20000), 'Open FM failed!' d.sleep(10) assert d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView" ).exists, 'song play screen not found!' first_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView").info['text'] d.press('right') d.sleep(15) assert d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView" ).exists, 'song play screen not found!' second_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView").info['text'] assert not second_song_name == first_song_name, 'switch song failed!' d.press('right') d.sleep(15) assert d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView" ).exists, 'song play screen not found!' third_song_name = d(resourceId='com.xiaomi.mimusic:id/title').child( className="android.widget.TextView").info['text'] assert not third_song_name == second_song_name, 'switch song failed!' d.press('back') d.sleep(2) d.press('back')
def testLaunchAndExitMediaExplorer(self): for i in xrange(4): d.press('right') assert d(text="高清播放器").exists, 'Media Explorer icon not found!' d(text="高清播放器").click.wait() assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text='设备').wait.exists( timeout=5000), 'launch Media Explorer failed!' assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text="视频").wait.exists( timeout=5000), 'launch Media Explorer failed!' d.press('back') d.sleep(3) d.press('back') assert d(text="高清播放器").wait.exists( timeout=10000), 'exit from Media Explorer failed!'
def tearDown(self): """ called after each test method end or exception occur. """ self.after_install = d.server.adb.cmd( 'shell pm list package -3').communicate()[0].split() del_apk = [ i.split('=')[1] for i in self.after_install if i not in self.before_install ] for apk in del_apk: d.server.adb.cmd('shell pm uninstall %s' % apk) d.sleep(3) for i in xrange(8): d.press('back') d.press('home') d.press('home')
def testPlayOnlineVideoLongBACK(self): """ launch app store and exit """ #d.start_activity('--activity-clear-task', component='com.duokan.duokantv/.MainActivity') assert d(text="在线影视").exists, 'Online Video icon not found!' d(text="在线影视").sibling(className='android.view.View').click.wait() #menu_hot_highlight_focus_png = os.path.join(PIC_DIR, 'menu_hot_highlight_focus.png') #menu_hot_highlight_nofocus_png = os.path.join(PIC_DIR, 'menu_hot_highlight_nofocus.png') #preview_shoucang_png = os.path.join(PIC_DIR, 'video_preview_sub_shoucang.png') #preview_pinglun_png = os.path.join(PIC_DIR, 'video_preview_sub_pinglun.png') if d.find('menu_hot_highlight_focus.png', threshold=0.01, timeout=30): d.press('down') d.sleep(2) d.press('enter') elif d.find('menu_hot_highlight_nofocus.png', timeout=30): d.press('enter') else: assert False, 'launch video failed' d.expect('video_preview_sub_shoucang.png', threshold=0.05, timeout=30) d.sleep(2) d.press('enter') assert d(resourceId='com.duokan.duokantv:id/main_frame').wait.exists( timeout=30000), 'video not start!' #assert not d.find('video_preview_sub_shoucang.png', timeout=30), 'video not start!' d.sleep(1200) assert not d(textContains='播放失败').exists or not d( textContains='无法获取视频地址').exists or not d( textContains="正在读取视频信息").exists, 'Video start failed!' d.press('back') d.expect('video_preview_sub_shoucang.png', threshold=0.05, timeout=30) d.press('back')
def testWifiOpenAndClose(self): d.start_activity('--activity-clear-task', component='com.android.settings/.Settings') d(text="无线和网络").wait.exists(timeout=2000) #d(className="android.widget.ListView", resourceId="android:id/list").child(text='WLAN').click.wait() #d(text="WLAN").click.wait() d.press('enter') d(resourceId='android:id/action_bar').child(text='WLAN').wait.exists( timeout=3000) if d(className='android.widget.Switch', text='打开').exists: d.press('right') d.sleep(2) d.press('up') d.sleep(2) for i in xrange(10): d.press('enter') assert d(resourceId='android:id/action_bar').child( text='关闭').wait.exists(timeout=3000), 'wifi close failed!' d.press('enter') assert d(resourceId='android:id/action_bar').child( text='打开').wait.exists(timeout=3000), 'wifi open failed!' assert d(resourceId='android:id/list').child( text='已连接').wait.exists( timeout=20000), 'wifi connect failed!' elif d(className='android.widget.Switch', text='关闭').exists: d.press('right') d.sleep(2) d.press('up') d.sleep(2) for i in xrange(10): d.press('enter') assert d(resourceId='android:id/action_bar').child( text='打开').wait.exists(timeout=3000), 'wifi close failed!' assert d(resourceId='android:id/list').child( text='已连接').wait.exists( timeout=20000), 'wifi connect failed!' d.press('enter') assert d(resourceId='android:id/action_bar').child( text='打开').wait.exists(timeout=3000), 'wifi open failed!'
def testInstallAndUninstallGame(self): """ launch app store and exit """ assert d(text="游戏中心").exists, 'Game Center icon not found!' d(text="游戏中心").sibling(className='android.view.View').click.wait() assert d(resourceId='android:id/content').child(text="推荐").wait.exists( timeout=20000), 'Launch Game Center failed!' d.sleep(5) d.press('left') d.sleep(2) d.press('left') d.sleep(2) d.press('left') d.sleep(2) d.press('down') d.sleep(2) d.press('enter') d.sleep(3) #if d(resourceId='com.xiaomi.mibox.gamecenter:id/update', text='打开').wait.exists(timeout=5000): if d(className='android.widget.Button', text='启 动').wait.exists(timeout=5000): #self.after_install = d.server.adb.cmd('shell pm list package -3').communicate()[0].split() #del_apk = [i.split('=')[1] for i in self.after_install if i not in self.before_install] #for apk in del_apk: # d.server.adb.cmd('shell pm uninstall %s' % apk) # d.sleep(3) assert d(resourceId='com.xiaomi.mibox.gamecenter:id/uninstall', text='卸载').wait.exists( timeout=5000), 'uninstall buuton not found!' #d(resourceId='com.xiaomi.mibox.gamecenter:id/uninstall', text='卸载').click.wait() d.press('right') d.sleep(3) d.press('right') d.sleep(3) d.press('enter') assert d(text='取消').wait.exists( timeout=5000), 'cancel button not found!' d.press('left') d.sleep(3) d.press('enter') assert d(resourceId='com.xiaomi.mibox.gamecenter:id/pop_selector_2' ).wait.exists(timeout=5000), 'return button not found!' d.press('enter') assert d(className='android.widget.FrameLayout').child( text="热门精选").wait.exists( timeout=5000), 'game main screen not found!' #elif d(resourceId='com.xiaomi.mibox.gamecenter:id/app_install_button', text='安装').exists: elif d(className='android.widget.Button', text='安 装').exists: d(className='android.widget.Button', text='安 装').click.wait() d.sleep(60) #assert d(resourceId='com.xiaomi.mibox.gamecenter:id/update', text='打开').wait.exists(timeout=40000), 'install game failed in 30 seconds!' assert d(className='android.widget.Button', text='启 动').wait.exists( timeout=5000), 'install game failed in 30 seconds!' #d.press('left') #d.sleep(2) #d.press('left') #d.sleep(2) #d.press('left') #d.sleep(2) #d.press('down') #d.sleep(2) #d.press('enter') #d.sleep(3) #assert d(resourceId='com.xiaomi.mibox.gamecenter:id/uninstall', text='卸载').wait.exists(timeout=5000), 'uninstall buuton not found!' ##d(resourceId='com.xiaomi.mibox.gamecenter:id/uninstall', text='卸载').click.wait() #d.press('right') #d.sleep(3) #d.press('right') #d.sleep(3) #d.press('enter') #assert d(text='取消').wait.exists(timeout=5000), 'cancel button not found!' #d.press('left') #d.sleep(3) #d.press('enter') #assert d(resourceId='com.xiaomi.mibox.gamecenter:id/pop_selector_2').wait.exists(timeout=5000), 'return button not found!' #d.press('enter') #assert d(className='android.widget.FrameLayout').child(text="热门精选").wait.exists(timeout=5000), 'game main screen not found!' self.after_install = d.server.adb.cmd( 'shell pm list package -3').communicate()[0].split() del_apk = [ i.split('=')[1] for i in self.after_install if i not in self.before_install ] for apk in del_apk: d.server.adb.cmd('shell pm uninstall %s' % apk) d.sleep(3) assert d( className='android.widget.Button', text='安 装').wait.exists(timeout=18000), 'uninstall game failed' d.press('back') assert d(resourceId='android:id/content').child( text="推荐").wait.exists( timeout=5000), 'game main screen not found!' else: assert False, 'game preview screen not appear!' d.press('back')
def testPlayVideoBetweenApp_short(self): """ Suma: play a video Step1: click " video online" Step2: verify the new screen was luanched successfully Step3: click the top video Step4: verify the new screen was luanched successfully Step4: click "play icon" to play the video. Step5: """ #APP1 VST d.start_activity( '--activity-clear-task', component= 'net.myvst.v2/.component.activity.homepage.LancherActivity') assert d(text="最新推荐").wait.exists( timeout=30000), "最新推荐 not found on screen" d.press('right') d.sleep(2) d.press('enter') assert d(text="收藏").wait.exists( timeout=15000), "收藏 not found on screen" d.press('enter') d.sleep(120) d.press('back') d.press('back') d.sleep(5) d.press('back') assert d(text="最新推荐").wait.exists( timeout=15000), "最新推荐 not found on screen" d.press('back') d.sleep(2) d.press('enter') ##return to home d.sleep(3) #enter APP2 APP2 = '优酷' ###for i in xrange(8): ### d.press('right') ###assert d(text=APP2 ).wait.exists(timeout=3000), "优酷 not found on screen" ###d(text=APP2).click.wait() d.start_activity('--activity-clear-task', component="com.youku.tv/.WelcomeActivity") assert d(text="首页").wait.exists( timeout=20000), " 首页 not found on screen" d(text="首页").click.wait() d.press('down') d.sleep(2) d.press('right') d.sleep(2) d.press('enter') assert d(text="收藏").wait.exists( timeout=15000), "收藏 not found on screen" d.press('enter') d.sleep(120) d.press('back') #assert d(text='确定').wait.exists(timeout=5000), "结束观看 not found on screen" #d(text='确定').click.wait() d.press('enter') d.sleep(5) assert d(text='收藏').wait.exists( timeout=15000), "收藏 not found on screen" d.press('back') assert d(text='首页').wait.exists( timeout=15000), "首页 not found on screen" d.press('back') d.press('back') ##return to home d.sleep(3) #APP3 = '搜狐视频TV版' d.start_activity('--activity-clear-task', component='com.sohutv.tv/.activity.WelcomeActivity') assert d(text="推荐").wait.exists( timeout=20000), " 推荐 not found on screen" d.press('enter') d.sleep(120) d.press('back') d.sleep(3) d.press('back') d.sleep(2) d.press('left') d.sleep(2) d.press('enter')
def testPlayLocalVideo(self): """ launch app store and exit """ for i in xrange(5): d.press('right') assert d(text="高清播放器").exists, 'Media Explorer icon not found!' d(text="高清播放器").click.wait() assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text='设备').wait.exists( timeout=5000), 'launch Media Explorer failed!' assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/entry_name', text="视频").wait.exists( timeout=5000), 'launch Media Explorer failed!' d.press('right') d.sleep(2) d.press('right') d.sleep(2) d.press('down') d.sleep(2) d.press('enter') assert d(resourceId='com.xiaomi.mitv.mediaexplorer:id/device_label', text="移动存储设备").wait.exists( timeout=10000), 'enter Device list screen failed!' d.press('enter') assert d(className="android.widget.ListView").child( text="视频").wait.exists( timeout=10000), 'enter USB device list failed!' d.press('enter') assert d(className="android.widget.ListView").child( resourceId="com.xiaomi.mitv.mediaexplorer:id/iv_image" ).wait.exists(timeout=10000), 'enter USB device video list failed!' for i in xrange(16): for j in xrange(random.randint(0, 16)): d.press('down') d.sleep(1) for k in xrange(random.randint(0, 8)): d.press('up') d.sleep(1) d.press('enter') assert d(className="android.widget.ListView").child( resourceId="com.xiaomi.mitv.mediaexplorer:id/iv_image" ).wait.gone(timeout=10000), 'start to play video failed!' d.sleep(600) d.press('back') assert d(className="android.widget.ListView").child( resourceId="com.xiaomi.mitv.mediaexplorer:id/iv_image" ).wait.exists(timeout=10000), 'enter USB device video list failed!'