def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver,self.mode)
def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode)
class UnsupportTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver,self.mode) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down',e def common_check(self,model,infoid): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver,'true') clear_notification(self.driver) #推送一条不支持的新闻 self.jpush.push_article(model,infoid) ret = get_push_el(self.driver,timeout=20) assert len(ret)==1 open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) assert self.driver.current_activity == ACTIVITY.get('unsupport') # contexts = self.driver.contexts # self.driver.switch_to.context(contexts[-1]) # el = self.driver.find_element_by_tag_name('img') # print dir(el) print u'Step %s:推送不识别类型可正确跳转到提示界面测试:OK' % (str(step)) step+=1 #excute TestCase def testBasic(self): unsupport = [789,123] self.common_check(*unsupport)
class NotificationClearTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def test(self): self.case_id = get_case(__file__) step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) msg1 = u'test1' self.jpush.push_notification(msg1) ret = get_push_info(self.driver) assert ret[0] == msg1 clear_notification(self.driver) ret = get_push_info(self.driver) assert ret == False print u'Step %s:推送类型为notification测试:OK' % (str(step)) step += 1 self.result = True
class NotificationClearTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver, self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e #excute TestCase def testBasic(self): go_to_settings(self.driver) sleep(WAIT_TIME) assert get_push_state(self.driver) == 'true' def testCloseAndOpen(self): step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) msg1 = u'test1' print self.jpush.push_notification(msg1) ret = get_push_info(self.driver) assert ret[0] == msg1 clear_notification(self.driver) ret = get_push_info(self.driver) assert ret == False print u'Step %s:推送类型为notification测试:OK' % (str(step)) step += 1
class CityPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver, self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e #excute TestCase def testCityPush(self): step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) app_location = '宜昌' push_location = '大悟' push_location_code = self.db.get_domaincode_by_name(push_location) app_location_code = self.db.get_domaincode_by_name(app_location) #print push_location_code,app_location_code msg1 = u'test' assert set_location(self.driver, app_location) push_info_a = self.db.get_push_info_by_name(NORMAL_ARTICLE) print self.jpush.push_notification(msg1, audience=push_location_code) ret = get_push_info(self.driver) assert ret == False clear_notification(self.driver) sleep(WAIT_TIME) print u'Step %s:无法接受其他地域推送测试:OK' % (str(step)) step += 1 print self.jpush.push_notification(msg1, audience=app_location_code) ret = get_push_info(self.driver) assert ret[0] == msg1 clear_notification(self.driver) sleep(WAIT_TIME) print u'Step %s:可正确接收地域推送测试:OK' % (str(step)) step += 1 print self.jpush.push_notification(msg1) ret = get_push_info(self.driver) assert ret[0] == msg1 clear_notification(self.driver) sleep(WAIT_TIME) print u'Step %s:可正确接收全部地区推送测试:OK' % (str(step)) step += 1
def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' #下载新包并重新安装 assert download_and_install() #self.desired_caps['appActivity'] = ACTIVITY.get('first_start') self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) try: self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) except Exception, e: pass
def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' #下载新包并重新安装 assert download_and_install() #self.desired_caps['appActivity'] = ACTIVITY.get('first_start') self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) try: self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) except Exception, e: pass
class AudioPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def article_audio_check(self, article): step = 1 sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret click_audio_in_webview(self.driver) #切换回NATIVE并暂停播放 assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) print u'Step %s:推送含音频的新闻详情页时,客户端能打开详情页并播放测试:OK' % (str(step)) step += 1 return True def audio_check(self, article): step = 1 sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, *AUDIO_PAUSE) print u'Step %s:推送音频时,客户端进入音频详情页自动播放测试:OK' % (str(step)) step += 1 return True def play_audio_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, * AUDIO_PAUSE) and self.driver.find_element( *AUDIO_TITLE).text == AUDIO_ARTICLE_B back(self.driver) assert element_exsist(self.driver, *SEARCH_CANCEL) print u'Step %s:播放音频详情页时,收到音频详情页B推送并点击时,音频A立刻停止播放详情页音频B,返回时音频A播放器销毁,直接回到音频A的上一页面:OK' % ( str(step)) step += 1 self.driver.find_element(*SEARCH_CANCEL).click() get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret back(self.driver) assert element_exsist( self.driver, *AUDIO_PAUSE_IN_ARTICLE) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的音频A时,收到其他音频详情页音频B推送,点击查看通知,音频A立刻停止播放详情页音频B,返回时文章页中的音频A播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_article_check(self): step = 1 sleep(WAIT_TIME) self.driver.find_element(*INFORMATION).click() get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + AUDIO_ARTICLE click_audio_in_webview(self.driver) back(self.driver) assert element_exsist(self.driver, *SEARCH_CANCEL) assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + NORMAL_AUDIO_ARTICLE_B print u'Step %s:播放音频详情页音频A时,收到文章页中嵌入的音频B推送,点击查看通知时,音频A继续播放,点击播放音频B,音频A停止、播放音频B,返回时音频A播放器销毁,直接回到音频A的上一页面:OK' % ( str(step)) step += 1 self.driver.find_element(*SEARCH_CANCEL).click() get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + NORMAL_AUDIO_ARTICLE click_audio_in_webview(self.driver) back(self.driver) assert element_exsist( self.driver, *AUDIO_PAUSE_IN_ARTICLE) == False and element_exsist( self.driver, 'class', 'UIAWebView') assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + NORMAL_AUDIO_ARTICLE_B print u'Step %s:播放文章页中的音频A时,收到文章页中嵌入的音频B推送,点击查看通知时,音频A继续播放,点击播放音频B,音频A停止、播放音频B,返回时文章页中的音频A播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_audio_video_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(VIDEO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, *TOP_NOTIFICATION) == False back(self.driver) assert element_exsist(self.driver, *SEARCH_CANCEL) print u'Step %s:播放音频详情页音频时,收到视频详情页推送,点击查看通知,音频立刻停止播放视频,返回时音频播放器销毁,直接回到音频的上一页面:OK' % ( str(step)) step += 1 self.driver.find_element(*SEARCH_CANCEL).click() get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) push_info = self.db.get_push_info_by_name(VIDEO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, *TOP_NOTIFICATION) == False back(self.driver) assert element_exsist( self.driver, *AUDIO_PAUSE_IN_ARTICLE) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的音频时,收到视频详情页推送,点击查看通知,音频立刻停止播放视频,返回时文章页中的音频播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_audio_video_article_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(NORMAL_VIDEO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + AUDIO_ARTICLE click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *TOP_NOTIFICATION) == False back(self.driver) assert element_exsist(self.driver, *SEARCH_CANCEL) print u'Step %s:播放音频详情页音频时,收到文章页中嵌入视频的推送,点击查看通知时音频仍在播放,点击播放视频时,音频立刻停止正确播放视频,返回时音频播放器销毁,直接回到音频的上一页面:OK' % ( str(step)) step += 1 self.driver.find_element(*SEARCH_CANCEL).click() get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) push_info = self.db.get_push_info_by_name(NORMAL_VIDEO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + NORMAL_AUDIO_ARTICLE click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *TOP_NOTIFICATION) == False back(self.driver) assert element_exsist( self.driver, *AUDIO_PAUSE_IN_ARTICLE) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的音频时,收到文章页中嵌入视频的推送,点击查看通知时音频仍在播放,点击播放视频时,音频立刻停止正确播放视频,返回时文章页中的音频播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True #excute TestCase def testAudio(self): self.case_id = get_case(__file__) self.result = self.audio_check(AUDIO_ARTICLE) #excute TestCase def testArticleAudio(self): self.case_id = get_case(__file__) self.result = self.article_audio_check(NORMAL_AUDIO_ARTICLE) def testPlayAudio(self): #2-4055 self.case_id = get_case(__file__) self.result = self.play_audio_check() def testPlayAudioArticle(self): #2-4056 self.case_id = get_case(__file__) self.result = self.play_article_check() def testPlayAudioWithVideoPush(self): #2-4057 self.case_id = get_case(__file__) self.result = self.play_audio_video_check() def testPlayAudioWithVideoArticlePush(self): #2-4058 self.case_id = get_case(__file__) self.result = self.play_audio_video_article_check()
class AudioPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def article_audio_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) click_audio_in_webview(self.driver) #切换回NATIVE并暂停播放 self.driver.switch_to.context(self.driver.contexts[0]) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:推送含音频的新闻详情页时,客户端能打开详情页并播放测试:OK' % (str(step)) step += 1 return True def audio_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:推送音频时,客户端进入音频详情页自动播放测试:OK' % (str(step)) step += 1 return True def play_audio_check(self): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) self.driver.find_element_by_id(INFORMATION).click() get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) and self.driver.find_element_by_id( AUDIO_TITLE).text == AUDIO_ARTICLE_B back(self.driver) assert self.driver.current_activity == ACTIVITY.get('search') open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == AUDIO_ARTICLE_B close_notification(self.driver) print u'Step %s:播放音频详情页时,收到音频详情页B推送并点击时,音频A立刻停止播放详情页音频B,返回时音频A播放器销毁,直接回到音频A的上一页面:OK' % ( str(step)) step += 1 back(self.driver) clear_notification(self.driver) get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) back(self.driver) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) == False assert self.driver.current_activity == ACTIVITY.get( NORMAL_AUDIO_ARTICLE) open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == AUDIO_ARTICLE_B close_notification(self.driver) print u'Step %s:播放文章页中的音频A时,收到其他音频详情页音频B推送,点击查看通知,音频A立刻停止播放详情页音频B,返回时文章页中的音频A播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_article_check(self): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) self.driver.find_element_by_id(INFORMATION).click() get_to_article_by_search(self.driver, AUDIO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == AUDIO_ARTICLE close_notification(self.driver) sleep(WAIT_TIME) click_audio_in_webview(self.driver) back(self.driver) assert self.driver.current_activity == ACTIVITY.get('search') open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == NORMAL_AUDIO_ARTICLE_B close_notification(self.driver) print u'Step %s:播放音频详情页音频A时,收到文章页中嵌入的音频B推送,点击查看通知时,音频A继续播放,点击播放音频B,音频A停止、播放音频B,返回时音频A播放器销毁,直接回到音频A的上一页面:OK' % ( str(step)) step += 1 back(self.driver) clear_notification(self.driver) get_to_article_by_search(self.driver, NORMAL_AUDIO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == NORMAL_AUDIO_ARTICLE close_notification(self.driver) sleep(WAIT_TIME) click_audio_in_webview(self.driver) back(self.driver) assert element_exsist(self.driver, 'id', AUDIO_PAUSE) == False assert self.driver.current_activity == ACTIVITY.get( NORMAL_AUDIO_ARTICLE) open_notifications(self.driver) assert self.driver.find_element_by_id( NOTIFICATION_AUDIO_TITLE).text == NORMAL_AUDIO_ARTICLE_B close_notification(self.driver) print u'Step %s:播放文章页中的音频A时,收到文章页中嵌入的音频B推送,点击查看通知时,音频A继续播放,点击播放音频B,音频A停止、播放音频B,返回时文章页中的音频A播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True #excute TestCase def testAudio(self): self.case_id = get_case(__file__) self.result = self.audio_check(AUDIO_ARTICLE) #excute TestCase def testArticleAudio(self): self.case_id = get_case(__file__) self.result = self.article_audio_check(NORMAL_AUDIO_ARTICLE) def testPlayAudio(self): self.case_id = get_case(__file__) self.result = self.play_audio_check() def testPlayAudioArticle(self): self.case_id = get_case(__file__) self.result = self.play_article_check()
class VideoPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def live_video_check(self, article): step = 1 sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret for i in range(20): if not self.driver.find_element(*VIDEO_CLOSE).is_displayed(): self.driver.find_element(*VIDEO_ITEM).click() sleep(1) if self.driver.find_element(*VIDEO_CLOSE).is_displayed() and not \ self.driver.find_element(*VIDEO_PROGRESS).is_displayed(): print u'Step %s:推送直播类型视频,客户端以直播类型播放测试:OK' % (str(step)) step += 1 return True return False def video_check(self, article): step = 1 sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret for i in range(20): if not self.driver.find_element(*VIDEO_CLOSE).is_displayed(): self.driver.find_element(*VIDEO_ITEM).click() if self.driver.find_element(*VIDEO_PROGRESS).is_displayed(): print u'Step %s:推送非直播类型视频,客户端以非直播类型播放测试:OK' % (str(step)) step += 1 return True return False def play_video_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, VIDEO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(VIDEO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) and self.driver.find_element( *VIDEO_TITLE_PLAYING).text == VIDEO_ARTICLE_B back(self.driver) sleep(WAIT_TIME) assert self.driver.find_element( *VIDEO_TITLE_PLAY_BEFORE).text == VIDEO_ARTICLE and element_exsist( self.driver, *VIDEO_FULL_SCREEN) == False print u'Step %s:播放视频详情页视频A时,收到其他视频详情页视频B推送,点击查看通知,视频A立刻停止、播放视频B,返回时视频A停止播放,但视频详情页显示正常:OK' % ( str(step)) step += 1 search_article_to_index(self.driver) get_to_article_by_search(self.driver, NORMAL_VIDEO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) push_info = self.db.get_push_info_by_name(VIDEO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) and self.driver.find_element( *VIDEO_TITLE_PLAYING).text == VIDEO_ARTICLE_B back(self.driver) assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的视频A时,收到其他视频详情页视频B推送,点击查看通知,视频A立刻停止、播放视频B,返回时文章页中的视频A播放器销毁,但文章页面正常显示。:OK' % ( str(step)) step += 1 return True def play_article_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, VIDEO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(NORMAL_VIDEO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret click_audio_in_webview(self.driver) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) back(self.driver) assert self.driver.find_element( *VIDEO_TITLE_PLAY_BEFORE).text == VIDEO_ARTICLE and element_exsist( self.driver, *VIDEO_FULL_SCREEN) == False play_video(self.driver) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) print u'Step %s:播放视频详情页视频A时,收到文章页中嵌入的视频B推送,点击查看通知时视频A停止播放,点击播放视频B,视频B正确播放,返回时视频A播放器销毁,视频详情页页面仍存在,手动点击可重新播放视频A:OK' % ( str(step)) step += 1 search_article_to_index(self.driver) get_to_article_by_search(self.driver, NORMAL_VIDEO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) push_info = self.db.get_push_info_by_name(NORMAL_VIDEO_ARTICLE_B) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret click_audio_in_webview(self.driver) #print ret assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) back(self.driver) assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的视频A时,收到文章页中嵌入的视频B推送,点击查看通知时视频A停止播放,点击播放视频B,视频B正确播放,返回时文章页中的视频A播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_video_audio_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, VIDEO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, * AUDIO_PAUSE) and self.driver.find_element( *AUDIO_TITLE).text == AUDIO_ARTICLE back(self.driver) sleep(WAIT_TIME) assert self.driver.find_element( *VIDEO_TITLE_PLAY_BEFORE).text == VIDEO_ARTICLE and element_exsist( self.driver, *VIDEO_FULL_SCREEN) == False assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + AUDIO_ARTICLE play_video(self.driver) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) assert element_exsist(self.driver, *TOP_NOTIFICATION) == False print u'Step %s:播放视频详情页视频时,收到音频详情页音频推送,点击查看通知,视频立刻停止、播放音频,返回时视频播放器销毁,视频详情页面仍存在,可手动点击重新播放视频,此时音频播放器销毁:OK' % ( str(step)) step += 1 search_article_to_index(self.driver) get_to_article_by_search(self.driver, NORMAL_VIDEO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) push_info = self.db.get_push_info_by_name(AUDIO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret assert element_exsist(self.driver, * AUDIO_PAUSE) and self.driver.find_element( *AUDIO_TITLE).text == AUDIO_ARTICLE back(self.driver) assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的视频时,收到音频详情页音频推送,点击查看通知,视频立刻停止、播放音频,返回时文章页中的视频播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True def play_video_audio_article_check(self): step = 1 sleep(WAIT_TIME) get_to_article_by_search(self.driver, VIDEO_ARTICLE, self.mode) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret #print ret click_audio_in_webview(self.driver) assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) back(self.driver) assert self.driver.find_element( *VIDEO_TITLE_PLAY_BEFORE).text == VIDEO_ARTICLE and element_exsist( self.driver, *VIDEO_FULL_SCREEN) == False assert self.driver.find_element( *TOP_NOTIFICATION).text == u'正在播放:' + NORMAL_AUDIO_ARTICLE play_video(self.driver) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) assert element_exsist(self.driver, *TOP_NOTIFICATION) == False print u'Step %s:播放视频详情页视频时,收到文章页中嵌入的音频推送,点击查看通知时视频停止播放,点击播放音频,音频正确播放,返回时视频播放器销毁,视频详情页页面仍存在,手动点击可重新播放视频,音频播放器销毁A:OK' % ( str(step)) step += 1 search_article_to_index(self.driver) get_to_article_by_search(self.driver, NORMAL_VIDEO_ARTICLE, self.mode) sleep(WAIT_TIME) click_audio_in_webview(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, *VIDEO_FULL_SCREEN) push_info = self.db.get_push_info_by_name(NORMAL_AUDIO_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret click_audio_in_webview(self.driver) #print ret assert element_exsist(self.driver, *AUDIO_PAUSE_IN_ARTICLE) back(self.driver) assert element_exsist(self.driver, * VIDEO_FULL_SCREEN) == False and element_exsist( self.driver, 'class', 'UIAWebView') print u'Step %s:播放文章页中的视频时,收到文章页中嵌入的音频推送,点击查看通知时视频停止播放,点击播放音频,音频正确播放,返回时文章页中的视频播放器销毁,但文章页面正常显示:OK' % ( str(step)) step += 1 return True #excute TestCase def testLive(self): self.case_id = get_case(__file__) self.result = self.live_video_check(LIVE_VIDEO_ARTICLE) def testVideo(self): self.case_id = get_case(__file__) self.result = self.video_check(VIDEO_ARTICLE) def testPlayVideo(self): #2-4059 self.case_id = get_case(__file__) self.result = self.play_video_check() def testPlayVideoArticle(self): #2-4060 self.case_id = get_case(__file__) self.result = self.play_article_check() def testPlayVideoWithAudioPush(self): #2-4061 self.case_id = get_case(__file__) self.result = self.play_video_audio_check() def testPlayVideoWithAudioArticlePush(self): #2-4062 self.case_id = get_case(__file__) self.result = self.play_video_audio_article_check()
class MultiPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver,self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id,self.result,self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down',e def common_check(self): step = 1 #发表评论 type_title = self.driver.find_element_by_id('com.cnhubei.dxxwhw:id/tv_typetitle').text print type_title assert type_title == u'精彩评论' print u'Step %s:评论页存在精彩评论测试:OK' % (str(step)) step+=1 #excute TestCase def testPushMsg(self): step = 1 self.case_id = get_case(__file__) clear_notification(self.driver) t = Thread(target=self.driver.background_app,args=(20,)) t.start() msg1 = u'test1' msg2 = u'test2' self.jpush.push_notification(msg1) self.jpush.push_notification(msg2) ret = get_push_info(self.driver) ret = [x.strip() for x in ret] assert len(ret) == 2 and msg1 in ret and msg2 in ret print u'Step %s:推送多条消息时测试:OK' % (str(step)) step+=1 self.result = True def test(self): self.case_id = get_case(__file__) step = 1 clear_notification(self.driver) t = Thread(target=self.driver.background_app,args=(20,)) t.start() msg1 = u'test1' msg2 = u'test2' push_info_a = self.db.get_push_info_by_name(NORMAL_ARTICLE) push_info_b = self.db.get_push_info_by_name(PHOTO_ARTICLE) self.jpush.push_article(push_info_a['model'],push_info_a['infoid'],msg =msg1) self.jpush.push_article(push_info_b['model'],push_info_b['infoid'],msg =msg2) ret = get_push_info(self.driver) ret = [x.strip() for x in ret] assert len(ret) == 2 and msg1 in ret and msg2 in ret print u'Step %s:推送多条新闻时测试:OK' % (str(step)) step+=1 self.result = True
class JpushBasicTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver,self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id,self.result,self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down',e def test(self): self.case_id = get_case(__file__) step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver,'true') clear_notification(self.driver) msg1 = u'test1' self.jpush.push_notification(msg1) ret = get_push_info(self.driver) assert ret[0] ==msg1 print u'Step %s:推送开关打开时可接收推送测试:OK' % (str(step)) step+=1 #关闭推送并测试10秒内是否收的到 clear_notification(self.driver) assert set_push_state(self.driver,'false') msg2 = u'test2' self.jpush.push_notification(msg2) sleep(WAIT_TIME) ret = get_push_info(self.driver,timeout=20) assert ret == False print u'Step %s:推送关闭时无法接收推送测试:OK' % (str(step)) step+=1 #等待20秒打开推送 sleep(20) assert set_push_state(self.driver,'true') assert get_push_info(self.driver)[0] == msg2 print u'Step %s:消息保留时间内打开通知开关接收推送测试:OK' % (str(step)) step+=1 #关闭网络后推送,等待20秒打开网络 assert set_push_state(self.driver,'true') clear_notification(self.driver) change_network(self.driver,'none') msg3 = u'test3' self.jpush.push_notification(msg3) sleep(WAIT_TIME) ret = get_push_info(self.driver,timeout=20) assert ret == False sleep(20) change_network(self.driver,'wifi') assert get_push_info(self.driver,timeout=20)[0] == msg3 assert set_push_state(self.driver,'true') print u'Step %s:消息保留时间内重新打开网络接收推送测试:OK' % (str(step)) step+=1 self.result = True
class ArticlePushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:点击普通新闻推送跳转测试:OK' % (str(step)) step += 1 #验证工具栏存在 elements_list = [ TOOLBAR_ITEM, COMMENT_INPUT, SHARE_BUTTON, COLLECT_BOTTON ] for el in elements_list: assert element_exsist(self.driver, 'id', el) == True print u'Step %s:正文页工具栏显示测试:OK' % (str(step)) step += 1 self.driver.find_element_by_id(SHARE_BUTTON).click() assert element_exsist(self.driver, 'id', SHARE_METHOD_IMAGE) click_center(self.driver) print u'Step %s:正文页推送分享测试:OK' % (str(step)) step += 1 content = u'中文' + str(randint(1, 100)) send_comment_with_input(self.driver, content) sleep(5) slide_left(self.driver) assert self.driver.current_activity == ACTIVITY.get('comment') print u'Step %s:左划进入评论页测试:OK' % (str(step)) step += 1 new_comment = self.driver.find_element_by_id(COMMENT) info = get_comment_info(self.driver, new_comment, 0) check_reply_elements = check_comment(self.driver, new_comment) assert check_reply_elements == 1 assert info[3] == content print u'Step %s:正文页发表评论测试结果:OK' % (str(step)) step += 1 return True #excute TestCase def test(self): self.case_id = get_case(__file__) self.result = self.common_check(NORMAL_ARTICLE)
class PushBackTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, article): step = 1 sleep(WAIT_TIME) print self.driver.current_activity go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) setting_to_index(self.driver) push_info = self.db.get_push_info_by_name(article) #退出客户端并发送推送 quit_app(self.driver) self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) #print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) #返回上级页面并验证是否为主页 back(self.driver) assert self.driver.current_activity == ACTIVITY.get('index') assert element_exsist(self.driver, 'id', MENU_ICON) or element_exsist( self.driver, 'id', BUTTON_CANCEL) print u'Step %s:客户端未启动时打开推送内容,点击返回能回到客户端首页测试:OK' % (str(step)) step += 1 def start_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) settings_activity = self.driver.current_activity push_info = self.db.get_push_info_by_name(article) #在设置页面点击推送 self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) #print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) #返回上级页面并验证是否为主页 back(self.driver) assert self.driver.current_activity == settings_activity print u'Step %s:客户端启动时打开推送内容,点击返回能回到上级页面首页测试:OK' % (str(step)) step += 1 #excute TestCase def testBasic(self): self.common_check(NORMAL_ARTICLE) def testStart(self): self.start_check(NORMAL_ARTICLE)
class PushBackTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, article): step = 1 sleep(WAIT_TIME) print self.driver.current_activity go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) #退出客户端并发送推送 quit_app(self.driver) self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) #print ret assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) #返回上级页面并验证是否为主页 back(self.driver) sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get('index') assert element_exsist(self.driver, 'id', SEARCH_BUTTON) or element_exsist( self.driver, 'id', UPDATE_DIALOG) print u'Step %s:纯文字新闻推送,点击调起客户端测试:OK' % (str(step)) step += 1 return True def basic_check(self, article): step = 1 sleep(WAIT_TIME) print self.driver.current_activity go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) #退出客户端并发送推送 quit_app(self.driver) self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) #print ret assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) #返回上级页面并验证是否为主页 back(self.driver) sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get('index') assert element_exsist(self.driver, 'id', SEARCH_BUTTON) or element_exsist( self.driver, 'id', UPDATE_DIALOG) print u'Step %s:客户端未启动时打开推送内容,点击返回能回到客户端首页测试:OK' % (str(step)) step += 1 return True def start_check(self, article): step = 1 sleep(WAIT_TIME) self.driver.find_element(*HEAD).click() push_info = self.db.get_push_info_by_name(article) #在报料页面点击推送 self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = confirm_push(self.driver, timeout=20) assert ret sleep(WAIT_TIME) assert element_exsist(self.driver, 'class', 'UIAWebView') #返回上级页面并验证是否为报料页面 back(self.driver) assert element_exsist(self.driver, *MY_CLUE_BUTTON) print u'Step %s:客户端启动时打开推送内容,点击返回能回到上级页面测试:OK' % (str(step)) step += 1 return True def home_check(self, article): step = 1 sleep(WAIT_TIME) clear_notification(self.driver) get_to_article_by_search(self.driver, NORMAL_ARTICLE, self.mode) sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) #退出客户端并发送推送 self.driver.quit() self.jpush.push_article(push_info['model'], push_info['infoid']) #sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) #print ret assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() #sleep(WAIT_TIME) #print ret #返回上级页面并验证是否为主页 back(self.driver) sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', SEARCH_BUTTON) or element_exsist( self.driver, 'id', UPDATE_DIALOG) print u'Step %s:客户端在新闻详情页后台时,打开推送的内容后,点击返回,能够回到客户端在后台时保留的页面(安卓只能回到1级页面):OK' % ( str(step)) step += 1 get_to_article_by_search(self.driver, ZHUANTI_ARTICLE, self.mode) sleep(WAIT_TIME) push_info = self.db.get_push_info_by_name(article) #退出客户端并发送推送 home(self.driver) self.jpush.push_article(push_info['model'], push_info['infoid']) sleep(WAIT_TIME) ret = get_push_el(self.driver, timeout=20) #print ret assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) #返回上级页面并验证是否为主页 back(self.driver) sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get('index') assert element_exsist(self.driver, 'id', SEARCH_BUTTON) or element_exsist( self.driver, 'id', UPDATE_DIALOG) print u'Step %s:客户端在专题详情页后台时,打开推送的内容后,点击返回,能够回到客户端在后台时保留的页面(安卓只能回到1级页面):OK' % ( str(step)) step += 1 return True #excute TestCase # def testBasic(self): # self.case_id = get_case(__file__) # self.result = self.common_check(NORMAL_ARTICLE) def testStart(self): self.case_id = get_case(__file__) self.result = self.start_check(NORMAL_ARTICLE) # def testHome(self): # self.case_id = get_case(__file__) # self.result = self.home_check(NORMAL_ARTICLE) def testBack(self): self.case_id = get_case(__file__) self.result = self.start_check(NORMAL_ARTICLE)
class MultiPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver, self.mode) sleep(WAIT_TIME) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self): step = 1 #发表评论 type_title = self.driver.find_element_by_id( 'com.cnhubei.dxxwhw:id/tv_typetitle').text print type_title assert type_title == u'精彩评论' print u'Step %s:评论页存在精彩评论测试:OK' % (str(step)) step += 1 #excute TestCase def testPushMsg(self): step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) msg1 = u'test1' msg2 = u'test2' self.jpush.push_notification(msg1) self.jpush.push_notification(msg2) ret = get_push_info(self.driver) assert len(ret) == 2 and msg1 in ret and msg2 in ret print u'Step %s:推送多条消息时测试:OK' % (str(step)) step += 1 def testPushArticle(self): step = 1 go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) msg1 = u'test1' msg2 = u'test2' push_info_a = self.db.get_push_info_by_name(NORMAL_ARTICLE) push_info_b = self.db.get_push_info_by_name(PHOTO_ARTICLE) self.jpush.push_article(push_info_a['model'], push_info_a['infoid'], msg=msg1) self.jpush.push_article(push_info_b['model'], push_info_b['infoid'], msg=msg2) ret = get_push_info(self.driver) print ret assert len(ret) == 2 and msg1 in ret and msg2 in ret print u'Step %s:推送多条新闻时测试:OK' % (str(step)) step += 1
class UnsupportTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, model, infoid): step = 1 sleep(WAIT_TIME) #推送一条不支持的新闻 self.jpush.push_article(model, infoid) ret = confirm_push(self.driver, timeout=20) assert ret sleep(WAIT_TIME) texts = self.driver.find_elements_by_class_name('UIAStaticText') texts = [x.text for x in texts] assert MSG.get('unsupport') in texts print u'Step %s:推送不识别类型可正确跳转到提示界面测试:OK' % (str(step)) step += 1 #推送一条不支持的新闻 push_info = self.db.get_push_info_by_name(UNSUPPORT_ARTICLE) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = confirm_push(self.driver, timeout=20) assert ret texts = self.driver.find_elements_by_class_name('UIAStaticText') texts = [x.text for x in texts] assert u'不识别测试' in texts # contexts = self.driver.contexts # self.driver.switch_to.context(contexts[-1]) # el = self.driver.find_element_by_tag_name('img') # print dir(el) print u'Step %s:客户端不识别的model新闻有对应的web页时,打开对应的web页:OK' % (str(step)) step += 1 return True #excute TestCase def testNonContent(self): unsupport = [789, 123] self.case_id = get_case(__file__) self.result = self.common_check(*unsupport)
class ArticlePushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:点击普通新闻推送跳转测试:OK' % (str(step)) step += 1 #验证工具栏存在 elements_list = [ TOOLBAR_ITEM, COMMENT_ITEM, SHARE_BUTTON, COLLECT_BOTTON ] for el in elements_list: print el assert element_exsist(self.driver, 'id', el) == True print u'Step %s:正文页工具栏显示测试:OK' % (str(step)) step += 1 #验证左划进入评论 slide_left(self.driver) sleep(WAIT_TIME) assert self.driver.current_activity == ACTIVITY.get('comment') print u'Step %s:左划进入评论页测试:OK' % (str(step)) step += 1 #excute TestCase def testBasic(self): self.common_check(NORMAL_ARTICLE)
class VideoPushTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def live_video_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() #sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', LIVE_VIDEO_BAR) == True assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:推送直播类型视频,客户端以直播类型播放测试:OK' % (str(step)) step += 1 return True def video_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 #print ret open_notifications(self.driver) ret[0].click() #sleep(WAIT_TIME) assert element_exsist(self.driver, 'id', LIVE_VIDEO_BAR) == False assert self.driver.current_activity == ACTIVITY.get(article) print u'Step %s:推送非直播类型视频,客户端以非直播类型播放测试:OK' % (str(step)) step += 1 return True #excute TestCase def testLive(self): self.case_id = get_case(__file__) self.result = self.live_video_check(LIVE_VIDEO_ARTICLE) def testVideo(self): self.case_id = get_case(__file__) self.result = self.video_check(VIDEO_ARTICLE)
class UnsupportTest(unittest.TestCase): def setUp(self): #self.testcases = conf.readcfg(__file__) self.desired_caps = desired_caps print 'Test Start...................................' self.result = 'f' self.msg = '' self.tsl = TestlinkHandler() self.mode = MODE self.db = DbLib() self.jpush = JpushHandler() #self.api = ChnlRequest(self.mode) self.driver = webdriver.Remote(APPIUM_URL, self.desired_caps) self.webview = WebviewHandler(self.driver) start_to_index(self.driver, self.mode) def tearDown(self): print 'Test End...................................' try: self.tsl.set_tc_status(self.case_id, self.result, self.msg) self.driver.quit() except Exception as e: print u'测试失败,失败环节:tear down', e def common_check(self, model, infoid): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) #推送一条不支持的新闻 self.jpush.push_article(model, infoid) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get('unsupport') ret = self.webview.get_content_in_webview() print ret assert MSG.get('unsupport') in ret # contexts = self.driver.contexts # self.driver.switch_to.context(contexts[-1]) # el = self.driver.find_element_by_tag_name('img') # print dir(el) print u'Step %s:推送不识别类型可正确跳转到提示界面测试:OK' % (str(step)) step += 1 return True def content_check(self, article): step = 1 sleep(WAIT_TIME) go_to_settings(self.driver) sleep(WAIT_TIME) assert set_push_state(self.driver, 'true') clear_notification(self.driver) #推送一条不支持的新闻 push_info = self.db.get_push_info_by_name(article) self.jpush.push_article(push_info['model'], push_info['infoid']) ret = get_push_el(self.driver, timeout=20) assert len(ret) == 1 open_notifications(self.driver) ret[0].click() sleep(WAIT_TIME) print self.driver.current_activity assert self.driver.current_activity == ACTIVITY.get('unsupport') ret = self.webview.get_content_in_webview() assert u'不识别测试' in ret # contexts = self.driver.contexts # self.driver.switch_to.context(contexts[-1]) # el = self.driver.find_element_by_tag_name('img') # print dir(el) print u'Step %s:推送不识别类型可正确跳转到提示界面测试:OK' % (str(step)) step += 1 return True #excute TestCase def testNonContent(self): unsupport = [789, 123] self.case_id = get_case(__file__) self.result = self.common_check(*unsupport) def testContent(self): self.case_id = get_case(__file__) self.result = self.content_check(UNSUPPORT_ARTICLE)