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 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 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
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 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