def setUp(cls): """启动应用""" cls.login = TloginPage() cls.home = ThomePage() cls.user = TuserCenterPage() cls.question = QuestionBankPage() cls.filter = FilterPage()
def setUp(cls): """启动应用""" cls.login = TloginPage() cls.home = ThomePage() cls.question = QuestionBankPage() cls.detail = QuestionDetailPage() cls.game = GamesPage() cls.filter = FilterPage()
def setUp(cls): """启动应用""" cls.login = TloginPage() cls.home = ThomePage() cls.question = QuestionBankPage() cls.paper = PaperDetailPage() cls.game = GamesPage() cls.change_image = ChangeImage() cls.filter = FilterPage()
def setUp(cls): """启动应用""" cls.login = TloginPage() cls.home = ThomePage() cls.user = TuserCenterPage() cls.filter = FilterPage() cls.question = QuestionBankPage() cls.recommend = RecommendPage() cls.release = ReleasePage()
def setUp(cls): """启动应用""" cls.login = TloginPage() cls.home = ThomePage() cls.user = TuserCenterPage() cls.filter = FilterPage() cls.collect = CollectionPage() cls.question = QuestionBankPage() cls.basket = QuestionBasketPage() cls.detail = QuestionDetailPage()
def test_paper_detail_album(self): self.login.app_status() # 判断APP当前状态 if self.home.wait_check_page(): # 页面检查点 self.home.click_tab_question() # 进入首页后 点击 题库tab if self.question.wait_check_page('题单'): # 页面检查点 self.question.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): paper = self.filter.test_paper() if self.filter.selected(paper) == 'false': self.filter.click_test_paper() # 点击 试卷 self.filter.commit_button() # 确定按钮 else: self.filter.commit_button() # 确定按钮 if self.question.wait_check_page('试卷'): # 页面检查点 print('试卷:') item = self.question.question_name() # 获取name item[0][2].click() # 点击第X个试卷 if self.paper.wait_check_page(): # 页面检查点 self.paper.share_button() # 分享 按钮 if self.paper.wait_check_share_page(): self.paper.share_page_info() # 分享页面 信息 self.paper.school_upload_img() # 学校徽标 if self.paper.wait_check_change_page(): print('学校徽标- 上传照片') self.upload_img_operate() # 学校徽标 上传图片操作 time.sleep(2) self.paper.qr_upload_img() # 二维码 if self.paper.wait_check_exchange_page(): print('二维码- 上传照片') self.upload_img_operate() # 二维码 上传图片操作 time.sleep(2) self.question.back_up_button() # 返回 试卷详情页 if self.paper.wait_check_page(): # 页面检查点 self.question.back_up_button() # 返回题库页面 if self.question.wait_check_page('试卷'): self.home.click_tab_hw() else: print('未进入题库页面') else: Toast().find_toast(VALID_LOGIN_TOAST.login_failed()) print("未进入主界面")
def test_assign_paper(self): self.login.app_status() # 判断APP当前状态 if self.home.wait_check_page(): # 页面检查点 self.home.click_tab_question() # 进入首页后 点击 题库tab if self.question.wait_check_page('题单'): # 页面检查点 self.question.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): paper = self.filter.test_paper() if self.filter.selected(paper) == 'false': self.filter.click_test_paper() # 点击 试卷 self.filter.commit_button() # 确定按钮 else: self.filter.commit_button() # 确定按钮 if self.question.wait_check_page('试卷'): # 页面检查点 print('试卷:') item = self.question.question_name() # 获取name if self.question.judge_question_lock(): lock = self.question.question_lock() # 锁定的试卷数 item[0][len(lock)+2].click() # 点击第X个试卷 todo 根据lock数点击未lock的 else: item[0][2].click() # 点击第X个试卷 if self.paper.wait_check_page(): # 页面检查点 title = self.paper_detail_operate() # 试卷详情页 具体操作 self.paper.recommend_button() # 推荐按钮 Toast().find_toast('操作成功') # 获取toast time.sleep(2) self.paper.collect_button() # 收藏按钮 Toast().find_toast('成功加入收藏') # 获取toast time.sleep(2) self.assign_paper_operate() # 布置试卷 具体操作 self.question.verify_collect_result(title, '试卷') # 我的收藏 验证收藏结果 self.question.back_up_button() # 返回按钮 if TuserCenterPage().wait_check_page(): self.home.click_tab_hw() # 返回首页 else: print('未进入题库页面') else: Toast().find_toast(VALID_LOGIN_TOAST.login_failed()) print("未进入主界面")
def verify_collect_result(self, menu, var): """验证 添加收藏 结果""" if self.wait_check_page(var): ThomePage().click_tab_profile() # 个人中心 if TuserCenterPage().wait_check_page(): TuserCenterPage().click_mine_collect() # 我的收藏 if CollectionPage().wait_check_page(): print('------------------------------------------') print('我的收藏:') FilterPage().all_element() if var == '大题': self.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): FilterPage().click_game_list() # 点击大题 FilterPage().commit_button() # 确定按钮 elif var == '试卷': self.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): CollectionPage().click_test_paper() # 点击试卷 FilterPage().commit_button() # 确定按钮 if CollectionPage().wait_check_page(): item = self.question_name() # 获取 menu1 = item[1][0] if '提分' in menu: menu = menu[:-2] if menu != menu1: print('★★★ Error- 加入收藏失败', menu, menu1) else: for z in range(len(item[0])): print(item[1][z]) if CollectionPage().wait_check_page(): CollectionPage().menu_button(0) # 为了保证脚本每次都可以运行,故将加入收藏的题单取消收藏 time.sleep(1) CollectionPage().cancel_collection() # 取消收藏
def test_paper_detail_photo(self): self.login.app_status() # 判断APP当前状态 if self.home.wait_check_page(): # 页面检查点 self.home.click_tab_question() # 进入首页后 点击 题库tab if self.question.wait_check_page('题单'): # 页面检查点 self.question.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): time.sleep(1) FilterPage().test_paper() # 点击 试卷 FilterPage().commit_button() # 确定按钮 print('试卷:') item = self.question.question_name() # 获取name item[0][2].click() # 点击第X个试卷 if self.paper.wait_check_page(): # 页面检查点 self.paper.share_button() # 分享 按钮 if self.paper.wait_check_share_page(): self.paper.share_page_info() # 分享页面 信息 self.paper.help_button() # ?按钮 if self.paper.wait_check_help_page(): i = 0 while i < 2: self.question.screen_swipe_up( 0.5, 0.9, 0.1, 1000) i += 1 self.question.screen_swipe_down( 0.5, 0.2, 0.9, 1000) self.question.back_up_button() # 返回按钮 time.sleep(2) # if self.paper.wait_check_share_page(): # 页面检查点 self.paper.school_upload_img() # 学校徽标 if self.paper.wait_check_change_page(): print('学校徽标- 拍照') self.upload_img_operate() # 学校徽标 上传图片操作 time.sleep(2) self.paper.qr_upload_img() # 二维码 if self.paper.wait_check_exchange_page(): print('二维码- 拍照') self.upload_img_operate() # 二维码 上传图片操作 time.sleep(2) self.question.back_up_button( ) # 返回 试卷详情页 if self.paper.wait_check_page( ): # 页面检查点 self.question.back_up_button( ) # 返回题库页面 if self.question.wait_check_page( '试卷'): self.home.click_tab_hw() else: print('未进入题库页面') else: Toast().find_toast(VALID_LOGIN_TOAST.login_failed()) print("未进入主界面")
def __init__(self): self.filter = FilterPage()
class CollectionPage(BasePage): """我的收藏 页面""" def __init__(self): self.filter = FilterPage() @teststeps def wait_check_page(self): """以“title:我的收藏”的text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'我的收藏')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def filter_button(self): """以“筛选 按钮”的id为依据""" self.driver\ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/filter") \ .click() @teststep def more_button(self): """以“更多 按钮”的class name为依据""" self.driver \ .find_element_by_class_name("android.widget.ImageView") \ .click() @teststep def label_manage_button(self): """以“标签管理 按钮”的class name为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'标签管理')]") \ .click() @teststep def the_end(self): """以“没有更多了”的text为依据""" item = self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'没有更多了')]") \ .text return item @teststep def question_basket(self): """以 右下角“题筐 按钮”的id为依据""" self.driver \ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/fab_pool") \ .click() @teststep def back_up_button(self): """以“返回按钮”的class name为依据""" self.driver \ .find_element_by_class_name("android.widget.ImageButton") \ .click() @teststep def menu_button(self, index): """以 条目右侧“菜单按钮”的id为依据""" self.driver\ .find_elements_by_id("com.vanthink.vanthinkteacher.debug:id/iv_eg")[index] \ .click() # 标签管理 @teststeps def wait_check_manage_page(self): """以“title:老师测试版”的text为依据 //android.widget.TextView[contains(@resource-id,'com.vanthink.vanthinkteacher.debug:id/fb_add_label')]""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'老师测试版')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False # 菜单 内容 @teststep def put_to_basket(self): """以 菜单- 加入题筐 的text为依据""" self.driver\ .find_element_by_xpath("//android.widget.TextView[contains(@text,'加入题筐')]") \ .click() @teststep def stick_label(self): """以 菜单- 贴标签 的text为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'贴标签')]") \ .click() @teststep def recommend_to_school(self): """以 菜单- 推荐到学校 的text为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'推荐到学校')]") \ .click() @teststep def cancel_collection(self): """以 菜单- 取消收藏 的text为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'取消收藏')]") \ .click() # 贴标签 @teststeps def wait_check_label_page(self): """以“title:贴标签”的text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'贴标签')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def save_button(self): """以 贴标签 - 保存按钮 的id为依据""" self.driver \ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/certain") \ .click() @teststep def check_box(self, index): """以 贴标签 - 单选框 的id为依据""" self.driver \ .find_elements_by_id("com.vanthink.vanthinkteacher.debug:id/cb_checked")[index] \ .click() @teststep def add_label(self): """以 贴标签 - 创建标签 的id为依据""" self.driver \ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/fb_add_label") \ .click() @teststeps def wait_check_tips_page(self): """以“icon”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,'com.vanthink.vanthinkteacher.debug:id/md_title')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def tips_title(self): """title""" item = self.driver \ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/md_title").text print(item) return item @teststep def input(self): """输入框""" ele = self.driver \ .find_element_by_id("android:id/input") return ele @teststep def character_num(self): """字符数""" ele = self.driver \ .find_element_by_id("com.vanthink.vanthinkteacher.debug:id/md_minMax").text return ele @teststep def click_negative_button(self): """以“取消按钮”的id为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'取消')]") \ .click() @teststep def click_positive_button(self): """以“确认按钮”的id为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'确定')]") \ .click() @teststep def positive_button(self): """以“确认按钮”的id为依据""" ele = self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'确定')]") value = ele.get_attribute('enabled') return value # 资源类型 @teststeps def all_element(self): """页面内所有class name为android.widget.TextView的元素""" ele = self.driver \ .find_elements_by_class_name("android.widget.TextView") # for i in range(len(ele)): # print(ele[i].text) return ele @teststep def click_test_paper(self): """以“试卷”的text为依据""" self.driver \ .find_element_by_xpath("//android.widget.TextView[contains(@text,'试卷')]")\ .click() @teststeps def filter_all_element(self): """页面内所有class name为android.widget.TextView的元素""" ele = self.all_element() count = [] for i in range(len(ele)): if ele[i].text == '资源类型': count.append(i) elif ele[i].text == '自定义标签': count.append(i) elif ele[i].text == '活动类型': count.append(i) elif ele[i].text == '系统标签': count.append(i) break return ele, count @teststeps def filter_content(self, ele, index): """筛选的所有label""" content = [] for i in range(len(index)): if i + 1 == len(index): print('---------------------') for j in range(ele[1][i], len(ele[0]) - 2): print(ele[0][j].text) content.append(ele[0][j].text) else: print('---------------------') for j in range(ele[1][i], ele[1][i + 1]): print(ele[0][j].text) content.append(ele[0][j].text) return content @teststeps def source_type_selected(self, ele, index): """选中的资源类型""" if self.filter.selected(self.filter.question_menu()) == 'true': # 题单 print('题单:') var = self.filter_content(ele, index) self.label_judge(var, index, 3) else: if self.filter.selected(self.filter.game_list()) == 'true': # 大题 var = self.filter_content(ele, index) self.label_judge(var, index, 4) else: if self.filter.selected(self.filter.test_paper()) == 'true': # 试卷 var = self.filter_content(ele, index) self.label_judge(var, index, 2) @teststeps def label_judge(self, var, index, count): """有无 自定义标签时,判断不同资源类型标签数""" if '自定义标签' in var: if len(index) != count: print('★★★ Error- 标签少了', var) else: # 没有自定义标签 if len(index) + 1 != count: # 加1是为了 匹配参数值 print('★★★ Error- 标签少了', var)
def test_paper_share_edittext(self): self.login.app_status() # 判断APP当前状态 if self.home.wait_check_page(): # 页面检查点 self.home.click_tab_question() # 进入首页后 点击 题库tab if self.question.wait_check_page('题单'): # 页面检查点 self.question.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): paper = self.filter.test_paper() if self.filter.selected(paper) == 'false': self.filter.click_test_paper() # 点击 试卷 self.filter.commit_button() # 确定按钮 else: self.filter.commit_button() # 确定按钮 if self.question.wait_check_page('试卷'): # 页面检查点 print('试卷:') print('------------------') item = self.question.question_name() # 获取name item[0][2].click() # 点击第X个试卷 if self.paper.wait_check_page(): # 页面检查点 self.paper.share_button() # 分享 按钮 if self.paper.wait_check_share_page(): self.paper.share_name() # 页面名称 name = self.paper.share_name_edit() # 编辑框 DelEditText().del_text(name) name.send_keys('123') print('修改为:', '123') print('------------------') time.sleep(1) self.paper.share_school() school = self.paper.share_school_edit() DelEditText().del_text(school) school.send_keys('school') print('修改为:', 'school') print('------------------') time.sleep(1) self.paper.share_contact() contact = self.paper.share_contact_edit() DelEditText().del_text(contact) contact.send_keys('1234') print('修改为:', '1234') print('------------------') time.sleep(1) # self.share_control_operate() # 分享控件 self.question.back_up_button() # 返回 试卷详情页 if self.paper.wait_check_page(): # 页面检查点 self.question.back_up_button() # 返回题库页面 if self.question.wait_check_page('试卷'): self.question.filter_button() # 筛选按钮 if FilterPage().wait_check_page(): # 页面检查点 FilterPage().question_menu() # 点击 题单 FilterPage().commit_button() # 确定按钮 if self.question.wait_check_page('题单'): self.home.click_tab_hw() else: print('未进入题库页面') else: Toast().find_toast(VALID_LOGIN_TOAST.login_failed()) print("未进入主界面")