def setUpClass(cls): Log = Logger() Log.info("========%s测试开始:========" % __class__.__name__) nowtime = time.strftime("%Y%m%d%H%M") driver = webdriver.Remote(appium_url, desired_caps) cls.nowtime=nowtime cls.Log=Log cls.driver=driver # 判断是否有弹窗,并关闭 Main(driver).close_ad() Main(driver).close_update() Mine(driver).stay_location() Main(driver).into_Mainpage(1)
def test_rightAnswer(self): self.Log.info("[智能练习:偷窥答案全部做对]测试开始") while True: try: title = Question(self.driver).confirm_type() if "单" in title: Question(self.driver).right_answer() elif "多" in title: Question(self.driver).right_answer() Move(self.driver).swipLeft() else: Move(self.driver).swipLeft() except Exception as e: break self.driver.save_screenshot(Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e try: rate = int(Result(self.driver).get_rate()) self.assertEqual(rate,100) except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("正确率是100%,[智能练习:偷窥答案全部做对]测试结束") finally: Main(self.driver).back()
def test_customAnswer(self): self.Log.info("[智能练习]测试开始") while True: try: title = Question(self.driver).confirm_type() if "单" in title: Question(self.driver).single_choice("A") elif "多" in title: Question(self.driver).multiple_choice(["A", "B"]) Move(self.driver).swipLeft() else: Move(self.driver).swipLeft() except Exception as e: break self.driver.save_screenshot(Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e try: rate=Result(self.driver).get_rate() except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("进入测试结果页,[智能练习]测试结束,正确率为%s%%"%rate) finally: Main(self.driver).back()
def stay_location(self): try: WebDriverWait(self.driver, 5, 0.2).until( EC.visibility_of_element_located( (By.ID, mine_username_location))) except: # Login(self.driver).account_login() Mine(self.driver).into_login() try: WebDriverWait(self.driver, 10, 0.2).until( EC.visibility_of_element_located( (By.ID, account_login_location))) except Exception as e: raise e else: self.driver.find_element_by_id(account_login_location).click() try: WebDriverWait(self.driver, 10, 0.2).until( EC.visibility_of_element_located( (By.ID, account_location))) except Exception as e: raise e else: # 判断是否有输入,有输入则清楚后输入 self.driver.find_element_by_id(account_location).clear() self.driver.find_element_by_id(account_location).send_keys( account) self.driver.find_element_by_id(password_location).clear() self.driver.find_element_by_id(password_location).send_keys( password) self.driver.find_element_by_id(login_botton_location).click() Main(self.driver).close_update()
def submit(self): self.driver.find_element_by_id(submit_location).click() try: WebDriverWait(self.driver, 2, 0.2).until(EC.visibility_of_element_located((By.ID, confirm_window))) except: pass else: Main(self.driver).click_windows("确定")
def setUpClass(cls): Logger().info("========%s测试开始========" % __class__.__name__) nowtime = time.strftime("%Y%m%d%H%M") Log = Logger() driver = webdriver.Remote(appium_url, desired_caps) cls.nowtime = nowtime cls.Log = Log cls.driver = driver Main(driver).close_ad()
def test_everydayExercise_right(self): self.Log.info("[每日一练:偷窥答案全部做对]测试开始") Main(self.driver).into_Mainpage(1) Home(self.driver).shot_menu("每日一练") try: WebDriverWait(self.driver, 10, 0.5).until( EC.visibility_of_element_located((By.NAME, "再做一遍"))) except: pass else: self.driver.find_element_by_name("再做一遍").click() while True: try: title = Question(self.driver).confirm_type() if "单" in title: Question(self.driver).right_answer() elif "多" in title: Question(self.driver).right_answer() Move(self.driver).swipLeft() else: Move(self.driver).swipLeft() except Exception as e: break self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e try: rate = int(Result(self.driver).get_rate()) self.assertEqual(rate, 100) except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("正确率是100%,[每日一练:偷窥答案全部做对]测试结束") finally: Main(self.driver).back()
def test_seeAnswer(self): self.Log.info("偷窥答案测试开始") Question(self.driver).see_answer() try: self.assertIsNotNone(answer_location) except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("偷窥答案生效,测试结束") finally: Main(self.driver).back()
def test_everydayExercise(self): self.Log.info("[每日一练]测试开始") Main(self.driver).into_Mainpage(1) Home(self.driver).shot_menu("每日一练") try: WebDriverWait(self.driver, 5, 0.2).until( EC.visibility_of_element_located((By.NAME, "再做一遍"))) except: pass else: self.driver.find_element_by_name("再做一遍").click() while True: try: title = Question(self.driver).confirm_type() if "单" in title: Question(self.driver).single_choice("A") elif "多" in title: Question(self.driver).multiple_choice(["A", "B"]) Move(self.driver).swipLeft() else: Move(self.driver).swipLeft() except Exception as e: break self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e try: rate = Result(self.driver).get_rate() except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("进入测试结果页,[每日一练]测试结束,正确率为%s%%" % rate) finally: Main(self.driver).back()
def test_questionPage_submit(self): #试题页面交卷按钮验证 self.Log.info("试题页面交卷测试开始") Question(self.driver).single_choice("A") Question(self.driver).submit() try: rate = Result(self.driver).get_rate() except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("进入测试结果页,正确率为%s%%,[智能练习:答题卡页面交卷]测试结束" % rate ) finally: Main(self.driver).back()
def test_share(self): self.Log.info("分享按钮测试开始") self.driver.find_element_by_id(share_location).click() try: self.assertIsNotNone(share_menu_location) except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("弹出分享菜单,测试结束") finally: self.driver.find_element_by_id(cancel_share_location).click() Main(self.driver).back()
def test_iscollect(self): self.Log.info("收藏试题测试开始") collect_name1=self.driver.find_element_by_id(collect_location).text Question(self.driver).collect() collect_name2=self.driver.find_element_by_id(collect_location).text try: self.assertNotEqual(collect_name1,collect_name2) except Exception as e: self.driver.save_screenshot( Project_path.Image_path + "%s_%s.png" % (sys._getframe().f_code.co_name, self.nowtime)) raise e else: self.Log.info("收藏按钮生效,测试结束") finally: Main(self.driver).back()
def account_login(self, account=account, password=password): self.into_account_login() try: WebDriverWait(self.driver, 10, 0.2).until( EC.visibility_of_element_located((By.ID, account_location))) except Exception as e: raise e else: #判断是否有输入,有输入则清楚后输入 self.driver.find_element_by_id(account_location).clear() self.driver.find_element_by_id(account_location).send_keys(account) self.driver.find_element_by_id(password_location).clear() self.driver.find_element_by_id(password_location).send_keys( password) self.driver.find_element_by_id(login_botton_location).click() Main(self.driver).close_update()
def quit_account(self): try: WebDriverWait(self.driver, 5, 0.2).until( EC.visibility_of_element_located( (By.ID, mine_username_location))) except Exception as e: raise e else: self.driver.find_element_by_id(mine_username_location).click() try: WebDriverWait(self.driver, 10, 0.2).until( EC.visibility_of_element_located( (By.ID, quit_login_button_location))) except Exception as e: raise e else: self.driver.find_element_by_id( quit_login_button_location).click() Main(self.driver).click_windows("确定")
def __init__(self, driver): self.driver = driver Main(self.driver).into_Mainpage(1)
def __init__(self, driver): self.driver = driver try: Main(self.driver).into_Mainpage(4) except: pass
def setUp(self): Main(self.driver).close_ad() Main(self.driver).close_update() Mine(self.driver).stay_unlocation()