class ResultPage(BasePage): def __init__(self): self.home = HomePage() self.wait = WaitElement() @teststep def wait_check_result_page(self): """结果页 以今日已练单词图片的Id为依据""" locator = (By.ID, self.id_type() + 'word_count') return self.wait.wait_check_element(locator) @teststep def wait_check_wx_login_page(self): """微信登陆页面检查点""" locator = (By.XPATH, '//android.widget.TextView[contains(@text,"登录微信")]') return self.wait.wait_check_element(locator) @teststep def wait_check_share_page(self): """打卡页,以分享图片id为依据""" locator = (By.ID, self.id_type() + "share_img") return self.wait.wait_check_element(locator) @teststep def wait_check_next_grade(self): """再来一组 以继续挑战的图片的Id为依据""" locator = (By.ID, self.id_type() + "level_up_hint") return self.wait.wait_check_element(locator) @teststep def wait_check_study_times_limit_page(self): """练习次数已用完页面检查点""" locator = (By.ID, self.id_type() + "error_img") return self.wait.wait_check_element(locator) @teststep def date(self): """时间日期""" locator = (By.ID, self.id_type() + 'date') return self.wait.wait_find_element(locator).text @teststep def today_word(self): """今日已练单词""" locator = (By.ID, self.id_type() + 'word_count') return self.wait.wait_find_element(locator).text @teststep def already_remember_word(self): """已被单词""" locator = (By.ID, self.id_type() + 'all_word_count') return self.wait.wait_find_element(locator).text @teststep def word_detail_info(self): """复习新词组""" locator = (By.ID, self.id_type() + 'text') return self.wait.wait_find_element(locator).text @teststep def share_button(self): """打卡""" locator = (By.ID, self.id_type() + 'punch_clock') self.wait.wait_find_element(locator).click() time.sleep(2) @teststep def rank_button(self): """右上角排名按钮""" locator = (By.ID, self.id_type() + 'rank') self.wait.wait_find_element(locator).click() time.sleep(3) @teststep def more_again_button(self): """再来一组""" print('再来一组', '\n') locator = (By.ID, self.id_type() + 'again') self.wait.wait_find_element(locator).click() @teststep def level_up_text(self): """单词已练完说明""" locator = (By.ID, self.id_type() + 'level_up_hint') ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def no_study_btn(self): """不练了""" locator = (By.ID, self.id_type() + 'cancel') self.wait.wait_find_element(locator).click() @teststep def wx_btn(self): """微信按钮""" locator = (By.ID, self.id_type() + 'weixin') return self.wait.wait_find_element(locator) @teststep def wx_friend(self): """朋友圈""" locator = (By.ID, self.id_type() + 'weixin_friends') return self.wait.wait_find_element(locator) @teststep def nex_level_text(self): locator = (By.XPATH, "//android.widget.TextView[@index,0]") ele = self.wait.wait_find_element(locator) print('已选年级 :%s' % ele.text) print('-' * 30, '\n') @teststep def confirm_button(self): """继续练习""" locator = (By.ID, self.id_type() + "confirm") self.wait.wait_find_element(locator).click() @teststep def wx_back_up_btn(self): """微信页面返回按钮""" locator = (By.ACCESSIBILITY_ID, '返回') return self.wait.wait_find_element(locator) @teststep def share_page_operate(self): """分享页面操作""" if self.wait_check_share_page(): self.wx_btn().click() if self.wait_check_wx_login_page(): self.wx_back_up_btn().click() else: print('❌❌❌ 未进入微信登陆页面') if self.wait_check_share_page(): self.wx_friend().click() if self.wait_check_wx_login_page(): self.wx_back_up_btn().click() else: print('❌❌❌ 未进入微信登陆页面') if self.wait_check_share_page(): self.save_img().click() if not Toast().find_toast('已保存到本地'): print('❌❌❌ 未发现保存图片提示') self.click_back_up_button() @teststeps def check_result_word_data(self, new_word_count, new_explain_words_count, already_recite_count, group_count): """结果页面""" print(' <结果页>:') print('今日已练单词:%s' % self.today_word()) print('日期:%s' % self.date()) print(self.already_remember_word()) print(self.word_detail_info()) today_word_count = int(self.today_word()) # 今日已练单词 (复习+ 新词) already_count = int( re.findall(r'\d+', self.already_remember_word())[0]) # 已背单词 detail = re.findall(r'\d+', self.word_detail_info()) # 最后一句统计文本 study_group_count = int(detail[0]) # 已练组数 recite_count = int(detail[1]) # 复习个数 new_set_words = int(detail[2]) # 新词个数 new_explain_count = int(detail[3]) # 新释义个数 if already_count != new_word_count: print('❌❌❌ 已学单词数不正确,应为', new_word_count) if today_word_count != recite_count + new_set_words + new_explain_count: print('❌❌❌ 今日已练单词不等于复习+新词+新释义, 应为', recite_count + new_set_words + new_explain_count) if study_group_count != group_count + 1: print('❌❌❌ 已练组数不正确, 应为', group_count + 1) if new_set_words != new_word_count: print('❌❌❌ 新词学单词数不正确,应为', new_word_count) if new_explain_count != new_explain_words_count: print('❌❌❌ 新释义单词个数不正确, 应为', new_explain_words_count) if recite_count != already_recite_count: print('❌❌❌ 复习单词个数不正确, 应为', already_recite_count) if recite_count > 27: if group_count == 0: if new_word_count != 0: print('❌❌❌ 复习个数大于等于28个, 不应存在新词个数') else: print('❌❌❌ 复习组数非第一组, 但是复习个数大于27') else: if new_word_count == 0: print('❌❌❌ 复习单词个数小于28, 新词个数为0') else: if group_count == 0: if new_word_count not in range(3, 11): print('❌❌❌ 复习单词个数小于28, 第一组新词个数不在3-10之间') else: if new_word_count < 3: print('❌❌❌ 复习单词个数小于28,非第一组新词个数小于3个') @teststep def back_to_home(self): self.home.click_back_up_button() if self.home.wait_check_tips_page(): self.home.commit_button() if self.home.wait_check_word_title(): self.home.click_back_up_button() if self.home.wait_check_home_page(): # 页面检查点 print('返回主界面') @teststeps def result_page_handle(self, new_word_count, new_explain_words_count, already_recite_count, group_count, study_model=1): """结果页处理""" if self.wait_check_result_page(): print('进入结果页面') self.check_result_word_data(new_word_count, new_explain_words_count, already_recite_count, group_count) # 结果页元素 self.share_button() # 打卡 group_num = 6 if study_model == 1 else 9 GameCommonEle().share_page_operate() # 炫耀一下页面 if self.wait_check_result_page(): self.more_again_button() # 再练一次 if group_count == group_num: if not self.wait_check_study_times_limit_page(): self.base_assert.except_error('练习次数已达到顶峰值, 未显示练完提示页面') else: print('你已练完今日单词, 保持适度才能事半功倍哦!休息一下,明天再练吧') if self.wait_check_next_grade(): # 继续挑战页面 self.level_up_text() self.confirm_button().click()
class PurchasePage(BasePage): def __init__(self): self.home = HomePage() self.user_center = UserCenterPage() self.wait = WaitElement() @teststep def wait_check_buy_page(self): """以“购买”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'在线客服')]") return self.wait.wait_check_element(locator) @teststep def wait_check_help_center_page(self): """以“帮助中心”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'帮助中心')]") return self.wait.wait_check_element(locator) @teststep def wait_check_card_page(self): """以“优惠购买”的id 为依据""" locator = (By.ID, self.id_type() + "discount_pay") return self.wait.wait_check_element(locator) @teststep def wait_check_agreement_page(self): """以“购买协议”的xpath 为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'购买协议')]") return self.wait.wait_check_element(locator) @teststep def wait_check_pay_confirm_page(self): """以“支付确认”的xpath 为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'支付确认')]") return self.wait.wait_check_element(locator) @teststep def wait_check_parent_pay_page(self): """以“支付完成”的ID 为依据""" locator = (By.ID, self.id_type() + "pay_complete") return self.wait.wait_check_element(locator) @teststep def wait_check_magic_page(self): """以“支付完成”的ID 为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'在线助教家长端')]") return self.wait.wait_check_element(locator) @teststep def online_server(self): """在线客服""" locator = (By.ID, self.id_type() + 'goToCustomerService') return self.wait.wait_find_element(locator) @teststep def magics(self): locator = (By.ID, self.id_type() + 'function_des') return self.wait.wait_find_elements(locator) @teststep def upgrade_button(self): """马上购买""" locator = (By.ID, self.id_type() + 'goToUpgrade') return self.wait.wait_find_element(locator) @teststep def discount_buy(self): """优惠购买""" locator = (By.ID, self.id_type() + 'discount_pay') return self.wait.wait_find_element(locator) @teststep def card_type(self): """优惠卡类型""" locator = (By.ID, self.id_type() + 'one') return self.wait.wait_find_elements(locator) @teststep def check_radio(self, card_name): """选项按钮""" locator = ( By.XPATH, '//android.widget.TextView[contains(@text, "{}")]/../preceding-sibling::' 'android.widget.RadioButton'.format(card_name)) return self.wait.wait_find_element(locator) @teststep def card_price(self, card_name): """卡片的价格 根据卡的类型获取""" locator = ( By.XPATH, '//android.widget.TextView[contains(@text, "{}")]/../following-sibling::' 'android.widget.LinearLayout/android.widget.TextView'.format( card_name)) return self.wait.wait_check_element(locator) @teststep def selected_card(self): """已选卡型""" locator = (By.ID, self.id_type() + 'current_vip_card_hint') return self.wait.wait_find_element(locator) @teststep def direct_buy_button(self): locator = (By.ID, self.id_type() + 'pay') return self.wait.wait_find_element(locator) @teststep def confirm_pay_button(self): locator = (By.ID, self.id_type() + 'pay') return self.wait.wait_find_element(locator) @teststep def discount_buy_button(self): """优惠购买按钮""" locator = (By.ID, self.id_type() + 'discount_pay') return self.wait.wait_find_element(locator) @teststep def agreement(self): """购买协议""" locator = (By.ID, self.id_type() + 'pay_agreement') return self.wait.wait_find_element(locator) @teststep def ali_pay_tab(self): """支付宝支付""" locator = (By.XPATH, '//android.widget.TextView[contains(@text,"支付宝代付")]') return self.wait.wait_find_element(locator) @teststep def wechat_pay_tab(self): """微信支付""" locator = (By.XPATH, '//android.widget.TextView[contains(@text,"微信代付")]') return self.wait.wait_find_element(locator) @teststep def parent_check_button(self): locator = (By.ID, self.id_type() + 'pay_agreement') return self.wait.wait_find_element(locator) @teststep def get_all_text_view(self): """获取页面所有不为空的文本值""" locator = (By.CLASS_NAME, 'android.widget.TextView') ele = self.wait.wait_find_elements(locator) all_text = [ ele[i].text for i in range(len(ele)) if ele[i].text != '' and ele[i].text is not None ] return all_text @teststep def online_server_ele_check(self): self.online_server().click() if self.wait_check_help_center_page(): print('在线助教客服二维码') self.home.click_back_up_button() @teststep def magic_ele_check(self): all_magics = self.magics() all_magics[random.randint(0, len(all_magics) - 1)].click() if self.wait_check_magic_page(): print('法宝详情页....\n') self.home.click_back_up_button() if self.wait_check_buy_page(): pass @teststep def switch_card(self): """切换卡片""" card_type = self.card_type() for card in card_type: card.click() check_radio = self.check_radio(card.text) if check_radio.get_attribute('checked') != 'true': print('❌❌❌ Error-- 选项按钮状态未发生变化') current_card = self.selected_card() if card.text.split(' ')[0] != current_card.text: print('❌❌❌ Error-- 当前卡的类型与所选类型不一致') else: print('已选择', current_card.text, '\n') if '年卡' in card.text: card_price = self.card_price(card.text) discount_button = self.discount_buy_button() if '优惠价' in card_price.text: if discount_button.get_attribute('enabled') != 'true': print('❌❌❌ Error-- 有优惠价,但是优惠购买按钮置灰', card.text) else: if discount_button.get_attribute('enabled') != 'false': print('❌❌❌ Error-- 无优惠价,但是优惠购买按钮未置灰', card.text) @teststep def check_agreement(self): agreement = self.agreement() location = agreement.location self.driver.tap([ (location['x'] + 520, location['y'] + 50), ]) if self.wait_check_agreement_page(): print('在线助教【提分版】购买协议 .....') self.home.screen_swipe_down(0.5, 0.5, 0.9, 1500) self.home.click_back_up_button() @teststep def direct_buy(self): if self.wait_check_card_page(): self.direct_buy_button().click() if self.wait_check_pay_confirm_page(): self.pay_confirm_page_ele_operate() self.parent_check_button().click() self.confirm_pay_button().click() if self.wait_check_parent_pay_page(): self.ali_pay_tab().click() time.sleep(2) self.parent_page_ele_operate() self.wechat_pay_tab().click() time.sleep(2) self.parent_page_ele_operate() @teststep def magics_page_ele_operate(self): """法宝页面元素信息""" text = self.get_all_text_view() if len(text) != 16: print('❌❌❌ Error-- 页面元素缺失', text) else: magic_types = numpy.reshape(text[6:-1], (3, 3)) print("<" + text[0] + '页面>', '\n', '学生:', text[1], '\n', '手机:', text[2], '\n', '提示:', text[4] + text[5], '\n', '法宝:', '\n', magic_types, '\n') @teststep def buy_page_ele_operate(self): """购买页面(优惠卡类型) 页面""" text = self.get_all_text_view() print(len(text)) if len(text) not in range(18, 21): print('❌❌❌ Error-- 页面元素缺失', text) else: print( '<选择优惠卡页面>\n' '学生:', text[1], '\n', '手机:', text[2], '\n', '提示:', text[4] + text[5], '\n', ) if len(text) == 20: print( '优惠卡类型', '\n', text[6], text[7], '\n', text[8], text[9], '\n', text[10], text[11], text[12], '\n', text[13], text[14], text[15], '\n', '协议:', text[16], '\n', '已选类型:', text[17], '\n', text[18], text[19], '\n', ) else: print( '优惠卡类型', '\n', text[6], text[7], '\n', text[8], text[9], '\n', text[10], text[11], '\n', text[12], text[13], '\n', '协议:', text[14], '\n', '已选类型:', text[15], '\n', text[16], text[17], '\n', ) @teststep def pay_confirm_page_ele_operate(self): text = self.get_all_text_view() if len(text) != 12: print('❌❌❌ Error-- 页面元素缺失', text) else: print('<支付确认页面>\n' '学生:', text[1], '\n', '手机:', text[2], '\n', '卡型:', text[6], '\n', "价格:", text[4] + text[5], '\n', text[7] + ":", '\n', text[8], text[9], text[10], '\n', text[11], '\n') @teststep def parent_page_ele_operate(self): text = self.get_all_text_view() if len(text) != 9: print('❌❌❌ Error-- 页面元素缺失', text) else: print( '<' + text[0] + "页面>", '\n', text[1], text[2], '\n', '卡型:', text[3], '\n', '价格:', text[4] + text[5], '\n', text[6], '\n', text[7], '\n', text[8], '\n', ) @teststep def back_to_home(self): self.home.click_back_up_button() if self.wait_check_pay_confirm_page(): self.home.click_back_up_button() if self.wait_check_card_page(): self.home.click_back_up_button() if self.wait_check_buy_page(): self.home.click_back_up_button() if self.user_center.wait_check_user_center_page(): self.home.click_tab_hw() if self.home.wait_check_home_page(): print('返回主界面')