class MedalPage(BasePage): wait = WaitElement() @teststep def medal_icon(self): locator = (By.ID, self.id_type() + 'medal') return self.wait.wait_find_element(locator) @teststep def wait_check_medal_page(self): """勋章页面检查点""" locator = (By.XPATH, '//android.widget.TextView[contains(@text,"我的勋章")]') return self.wait.wait_check_element(locator) @teststep def wait_check_medal_img_page(self): locator = (By.ID, self.id_type() + 'img') return self.wait.wait_check_element(locator) @teststep def medals(self): """奖牌""" locator = (By.ID, self.id_type() + 'des') return self.wait.wait_find_elements(locator) @teststep def medal_content(self): """置灰奖牌的说明""" locator = (By.ID, self.id_type() + 'text') return self.wait.wait_find_element(locator).text
class PhoneReset(BasePage): """修改手机号页面""" wait = WaitElement() @teststep def wait_check_page(self): """以“title:手机号码”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'手机号')]") return self.wait.wait_check_element(locator) @teststep def et_phone(self): """以“手机号”的id为依据""" locator = (By.ID, self.id_type() + 'et_phone') return self.wait.wait_find_element(locator) @teststep def verify(self): """以“验证码”的id为依据""" locator = (By.ID, self.id_type() + 'verify_input') return self.wait.wait_find_element(locator) @teststep def count_time(self): """以“获取验证码按钮”的id为依据""" locator = (By.ID, self.id_type() + 'count_time') self.wait.wait_find_element(locator).click() @teststep def btn_certain(self): """以“确定按钮”的id为依据""" locator = (By.ID, self.id_type() + 'btn_certain') self.wait.wait_find_element(locator).click()
class HonorPage(BasePage): """华为7.0""" wait = WaitElement() # 拍照 华为7.0 @teststeps def wait_check_camera_page(self): """以 “拍照键”的resource-id为依据""" locator = (By.ID, "com.huawei.camera:id/shutter_button") return self.wait.wait_check_element(locator) # 第一页面 @teststep def click_camera_button(self): """以相机拍照按钮""" print('点击 拍照按钮') locator = (By.ID, "com.huawei.camera:id/shutter_button") self.wait.wait_find_element(locator).click() # 第二页面 @teststeps def wait_check_retake_page(self, var=10): """以 “”的resource-id为依据""" locator = (By.ID, "com.huawei.camera:id/btn_cancel") return self.wait.wait_check_element(locator) @teststep def click_done_button(self): """相机'完成'按钮""" print('点击 完成按钮') locator = (By.ID, "com.huawei.camera:id/btn_done") self.wait.wait_find_element(locator).click() @teststep def click_retake_button(self): """相机'retake'按钮""" print('点击 重拍按钮') locator = (By.ID, "com.huawei.camera:id/btn_cancel") self.wait.wait_find_element(locator).click() # 相册 华为7.0 @teststep def wait_check_album_page(self, var=10): """相册 的resource-id为依据""" locator = (By.ID, "com.android.gallery3d:id/album_name") return self.wait.wait_check_element(locator) @teststep def open_album(self): """打开 第二个相册""" print('进入相册') locator = (By.ID, "com.android.gallery3d:id/album_name") self.wait.wait_find_elements(locator)[1].click() @teststep def wait_check_picture_page(self): """选择图片 的为依据""" locator = (By.ID, "com.android.gallery3d:id/head_actionmode_title") return self.wait.wait_check_element(locator)
class MessageCenter(BasePage): """消息中心页面""" wait = WaitElement() @teststep def wait_check_page(self): """以“title:消息中心”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'消息中心')]") return self.wait.wait_check_element(locator) @teststep def iv_read_count(self): """以“未读消息数”的id为依据""" locator = (By.ID, self.id_type() + 'iv_read') ele = self.wait.wait_find_elements(locator) return len(ele) @teststep def message_count(self): """以“消息总数”的class_name为依据""" locator = (By.CLASS_NAME, "android.widget.RelativeLayout") return self.wait.wait_find_elements(locator) @teststep def click_message(self): """以“消息”的class_name为依据""" locator = (By.CLASS_NAME, "android.widget.RelativeLayout") self.wait.wait_find_element(locator).click() @teststep def del_message(self, size, rollsize=1): """以“删除消息”的class_name为依据""" # # 设定系数 # a = 554.0 / 1080 # b = 1625.0 / 1794 elements = self.message_count() print('len(elements):', len(elements)) # for i in range(len(elements)) @teststep def click_negative_button(self): """以“取消按钮”的id为依据""" locator = (By.ID, self.id_type() + "md_buttonDefaultNegative") self.wait.wait_find_element(locator).click() @teststep def click_positive_button(self): """以“确认按钮”的id为依据""" locator = (By.ID, self.id_type() + "md_buttonDefaultPositive") self.wait.wait_find_element(locator).click() @teststep def back_up_button(self): """以“返回按钮”的class_name为依据""" locator = (By.CLASS_NAME, "android.widget.ImageButton") self.wait.wait_find_element(locator).click()
class Privacy(BasePage): """版权申诉""" wait = WaitElement() @teststep def wait_check_page(self): """以“title:版权申诉”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'版权申诉')]") return self.wait.wait_check_element(locator)
class ProtocolPage(BasePage): """注册协议""" wait = WaitElement() @teststep def wait_check_page(self): """以“title:注册协议”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'注册协议')]") return self.wait.wait_check_element(locator)
class SimulatorPage(BasePage): """夜神模拟器""" wait = WaitElement() # 模拟器 5.1 @teststep def wait_check_album_page(self, var=10): """以相册title:“选择照片”的text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'选择照片')]") return self.wait.wait_check_element(locator) @teststep def choose_album_mul(self): """5.1 模拟器 选择相册370,720""" print('选择相册') ClickBounds().click_bounds(560, 270)
class PwdReset(BasePage): """修改密码页面所有控件信息""" wait = WaitElement() @teststep def wait_check_page(self): """以“title:重置密码”的xpath @text为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'重置密码')]") return self.wait.wait_check_element(locator) @teststep def pwd_origin(self): """以“原始密码”的id为依据""" locator = (By.ID, self.id_type() + 'pwd_origin') return self.wait.wait_find_element(locator) @teststep def pwd_new(self): """以“新密码”的id为依据""" locator = (By.ID, self.id_type() + 'pwd_new') return self.wait.wait_find_element(locator) @teststep def pwd_confirm(self): """以“新密码二次确认”的id为依据""" locator = (By.ID, self.id_type() + 'pwd_confirm') return self.wait.wait_find_element(locator) @teststep def pwd_checkbox(self): """以“显示密码”的id为依据""" locator = (By.ID, self.id_type() + 'pwd_visible') self.wait.wait_find_element(locator).click() @teststep def confirm_button(self): """以“完成按钮”的id为依据""" locator = (By.ID, self.id_type() + 'pwd_complete') self.wait.wait_find_element(locator).click()
class PunchActivityPage(BasePage): library = LibraryGamePage() wait = WaitElement() @teststep def wait_check_alert_punch_tip_page(self): locator = ( By.XPATH, '//android.widget.ImageView[contains(@content-desc, "21天打卡活动")]') return self.wait.wait_check_element(locator) @teststep def wait_check_home_punch_notice_page(self): """主页的打卡提示页面检查点""" locator = ( By.XPATH, '//android.support.v7.widget.RecyclerView/android.view.ViewGroup[2]' ) return self.wait.wait_find_element(locator) @teststep def wait_check_activity_book_item_page(self): """打卡页面检查点""" locator = (By.ID, self.id_type() + 'activitie_book_item') return self.wait.wait_check_element(locator, timeout=10) @teststep def wait_check_class_list_page(self): """班级列表页面检查点""" locator = (By.CLASS_NAME, 'android.widget.ListView') return self.wait.wait_check_element(locator) @teststep def wait_check_punch_lock_icon_page(self, book_id): """打卡锁图标检查点""" locator = ( By.XPATH, '//android.widget.TextView[@content-desc="{}"]/following-sibling::' 'android.widget.ImageView[@index="3"]'.format(book_id)) return self.wait.wait_check_element(locator) @teststep def wait_check_select_checkpoint_page(self): """选择关卡页面检查点""" locator = (By.ID, self.id_type() + 'progress_topic') return self.wait.wait_check_element(locator) @teststep def wait_check_share_tip_page(self): """炫耀一下按钮提示页面检查点""" locator = (By.XPATH, '//*[contains(@text, "“炫耀一下”才算完成任务呦~")]') return self.wait.wait_check_element(locator) @teststep def wait_check_checkpoint_continue_tip_by_index_page(self, index): """关卡继续提示页面检查点""" locator = ( By.XPATH, '//android.support.v7.widget.RecyclerView/android.view.ViewGroup[@index="{}"]/' 'android.widget.ImageView[contains(@resource-id, "tit")]'.format( index)) return self.wait.wait_check_element(locator) @teststep def wait_check_page_has_continue_tip_page(self): """检查关卡页面是否存在继续按钮""" locator = ( By.XPATH, '//android.support.v7.widget.RecyclerView/android.view.ViewGroup/' 'android.widget.ImageView[contains(@resource-id, "tit")]') return self.wait.wait_check_element(locator) @teststep def close_alert_tip(self): locator = (By.XPATH, '//android.widget.ImageView[@index=1]') return self.wait.wait_find_element(locator) @teststep def click_alert_tip(self): """点击弹出的打卡页面""" locator = (By.XPATH, '//*[@resource-id="android:id/content"]/' 'android.view.ViewGroup/android.widget.ImageView') self.wait.wait_find_element(locator).click() @teststep def home_page_punch_tab(self): """主页进入打卡页面的tab""" locator = ( By.XPATH, '//android.support.v7.widget.RecyclerView/android.view.ViewGroup[2]' ) return self.wait.wait_find_element(locator) @teststep def change_class_btn(self): """切换班级按钮""" locator = (By.ID, self.id_type() + 'spinner_bar') return self.wait.wait_find_element(locator) @teststep def class_list(self): """班级列表""" locator = (By.ID, self.id_type() + 'spinner_bar_item') return self.wait.wait_find_elements(locator) @teststep def activity_title(self): """活动名称""" locator = (By.ID, self.id_type() + 'activity_title') return self.wait.wait_find_element(locator) @teststep def punch_books(self): """打卡列表""" locator = (By.ID, self.id_type() + 'entry_tv') return self.wait.wait_find_elements(locator) @teststep def punch_book_status(self, book_id): """打卡书籍状态""" locator = ( By.XPATH, '//android.widget.TextView[@content-desc="{}"]/preceding-sibling::' 'android.widget.ImageView[contains(@resource-id, "activitie_book_item")]' .format(book_id)) ele = self.wait.wait_find_element(locator) return self.attr.get_cont_desc(ele) @teststep def punch_book_id(self, index): """获取图书id""" locator = (By.ID, self.id_type() + 'entry_tv') ele = self.wait.wait_find_elements(locator) return self.attr.get_cont_desc(ele[index]) @teststep def punch_page_back_icon(self): """打卡页面退出按钮""" locator = (By.ID, self.id_type() + 'back_but') return self.wait.wait_find_element(locator) @teststep def checkpoint_list(self): """关卡列表""" locator = (By.ID, self.id_type() + 'selector_circle_tv') return self.wait.wait_find_elements(locator) @teststep def share_btn(self): """炫耀一下按钮""" locator = (By.ID, self.id_type() + 'progress_topic') return self.wait.wait_find_element(locator) @teststep def close_home_activity_tip(self): """关闭首页的弹窗信息""" if self.wait_check_alert_punch_tip_page(): self.close_alert_tip().click() time.sleep(1) @teststep def checkpoint_core_process(self, stu_id, activity_class_info): if not self.wait_check_activity_book_item_page(): self.base_assert.except_error("从主页点击打卡tab未进入打卡页面") else: self.change_class_btn().click() if self.wait_check_class_list_page(): class_list = self.class_list() for x in class_list: class_id = self.attr.get_cont_desc(x) print('班级:', x.text, '班级id:', class_id) if class_id not in list(activity_class_info.keys()): self.base_assert.except_error( '查询本班级不存在打卡活动, 但是该班级名称出现在打卡班级列表中') random_index = random.randint(0, len(class_list) - 1) select_class = self.class_list()[random_index] select_class_id = self.attr.get_cont_desc(select_class) class_punch_info = activity_class_info[select_class_id] select_activity_id = class_punch_info['活动id'] select_class.click() if not self.wait_check_activity_book_item_page(): self.base_assert.except_error('选择班级后未进入打卡页面') else: page_activity_name = self.activity_title() if class_punch_info['活动名称'] != page_activity_name: self.base_assert.except_error("页面展示的活动名称与查询名称不一致") if len(self.punch_books()) != len( class_punch_info['书籍信息']): self.base_assert.except_error('页面展示的书籍个数与查询所得个数不一致') PunchSqlHandle().delete_student_activity_record( stu_id, select_activity_id) return class_punch_info['书籍信息'] @teststep def punch_page_select_book_operate(self, book_info, nickname): """打卡页面书籍选择""" punch_books = self.punch_books() print('书籍个数:', len(punch_books)) book_id_info = {} for i, x in enumerate(punch_books): quoted_id = self.attr.get_cont_desc(x) book_id = PunchSqlHandle().get_activity_book_id_by_quoted_id( quoted_id) book_id_info[quoted_id] = book_id if int(book_id) not in list(book_info.keys()): self.base_assert.except_error('此书不应在打卡书籍列表中') book_status = self.punch_book_status(quoted_id) if book_status == '0': if not self.wait_check_punch_lock_icon_page(quoted_id): self.base_assert.except_error('图书状态不可点击, 但未发现解锁锁图标') x.click() if not Toast().find_toast('今天的书已经读完啦'): self.base_assert.except_error('点击未解锁图书, 未弹出提示') select_quoted_id = self.punch_book_id(index=0) select_book_id = book_id_info[select_quoted_id] book_count = book_info[select_book_id] self.punch_books()[0].click() if not self.wait_check_select_checkpoint_page(): self.base_assert.except_error('点击已解锁书籍, 未进入通关页面') else: if len(self.checkpoint_list()) != book_count: self.base_assert.except_error('关卡个数与数据查询个数不一致') if len(self.checkpoint_list()) > 10: self.base_assert.except_error('关卡个数大于10个') return select_quoted_id @teststep def checkpoint_page_operate(self, nickname, quoted_id): for x in range(len(self.checkpoint_list())): before_progress = self.attr.get_cont_desc(self.share_btn()) print('进入关卡前的进度:', before_progress) self.checkpoint_list()[x].click() if self.library.wait_check_game_page(): self.library.play_book_games(fq=1, half_exit=True) if self.wait_check_select_checkpoint_page(): if not self.wait_check_checkpoint_continue_tip_by_index_page( x): self.base_assert.except_error('关卡中途退出, 未发现继续学习图标') if self.attr.get_cont_desc(self.share_btn()) != before_progress: self.base_assert.except_error('中途退出后,书籍打卡进度发生变化') self.checkpoint_list()[x].click() if self.library.wait_check_game_page(): HomeworkGameOperate().homework_game_operate(nickname, judge_score=False, is_activity=True) if not self.wait_check_select_checkpoint_page(): self.click_back_up_button() self.library.result.all_game.word_spell.tips_operate() if self.wait_check_select_checkpoint_page(): if self.wait_check_checkpoint_continue_tip_by_index_page(x): self.base_assert.except_error('已全部做完其中之一关卡内部所有题, 依然继续学习图标') if self.attr.get_cont_desc(self.share_btn()) == before_progress: self.base_assert.except_error('已全部做其中之一完关卡内部所有题,书籍打卡进度未发生变化') if self.wait_check_select_checkpoint_page(): if self.attr.get_cont_desc(self.share_btn()) != '100': self.base_assert.except_error('已经完成所有关卡, 进入不为100') self.punch_page_back_icon().click() if self.wait_check_activity_book_item_page(): book_status = self.punch_book_status(quoted_id) if book_status == '0': self.base_assert.except_error( '关卡全部通过, 但是未点击分享按钮,图书状态不为未完成') self.punch_books()[0].click() if self.wait_check_select_checkpoint_page(): self.share_btn().click() GameCommonEle().share_page_operate() if self.wait_check_select_checkpoint_page(): self.punch_page_back_icon().click() if self.wait_check_activity_book_item_page(): book_status = self.punch_book_status(quoted_id) if book_status != '1': self.base_assert.except_error('关卡全部通过, 已点击分享按钮,图书状态不为已完成')
def __init__(self): self.sql_handler = WordTestSqlHandler() self.wait = WaitElement()
class WordTestResultPage(BasePage): def __init__(self): self.sql_handler = WordTestSqlHandler() self.wait = WaitElement() @teststep def wait_check_test_result_page(self): """测试结果页面检查点""" locator = (By.ID, self.id_type() + 'head') return self.wait.wait_check_element(locator) @teststep def wait_check_again_btn_page(self): locator = (By.ID, self.id_type() + 'again') return self.wait.wait_check_element(locator) @teststep def student_test_id(self): """当前测试id""" locator = (By.ID, self.id_type() + 'head') ele = self.wait.wait_find_element(locator) test_id = json.loads(ele.get_attribute('contentDescription'))['test_id'] return test_id @teststep def result_score(self): """结果得分""" locator = (By.ID, self.id_type() + 'score') ele = self.wait.wait_find_element(locator) return int(ele.text) @teststep def nickname(self): """用户名称""" locator = (By.ID, self.id_type() + 'name') ele = self.wait.wait_find_element(locator) return ele.text @teststep def test_count_summery(self): """测试总数总结""" locator = (By.ID, self.id_type() + 'word_num') ele = self.wait.wait_find_element(locator) return ele.text @teststep def test_record_summery(self): """测试记录总结""" locator = (By.ID, self.id_type() + 'record') ele = self.wait.wait_find_element(locator) return ele.text @teststep def share_btn(self): """打卡按钮""" locator = (By.ID, self.id_type() + 'clock') return self.wait.wait_find_element(locator) @teststep def wrong_again_btn(self): """错题再练按钮""" locator = (By.ID, self.id_type() + 'again') return self.wait.wait_find_element(locator) @teststep def result_back_btn(self): """结果页后退按钮""" locator = (By.ID, self.id_type() + 'back') return self.wait.wait_find_element(locator) @teststep def db_cal_fvalue_dict_operate(self, stu_id, word_dict, game_return, is_right=True): """单词结果页F值计算结果与从数据库获取结果进行对比 :param stu_id: 学生id :param is_right: 是否是正确单词列表 :param game_return: 游戏次数 0 首次测试 >0: 错题再练 :param word_dict: 比较的单词字典 :return cal_dict: F值变化后的dict """ cal_dict, db_dict = {}, {} for x in word_dict: cal_dict[x] = [] db_dict[x] = [] for y in word_dict[x]: fvalue = self.sql_handler.get_fvalue_by_word_explain_id(stu_id, int(x), y[0]) db_dict[x].append((y[0], fvalue)) if is_right: if y[1] < 5: cal_dict[x].append((y[0], y[1]+1)) else: cal_dict[x].append((y[0], y[1])) else: if y[1] == 5 and game_return >= 1: cal_dict[x].append((y[0], y[1] - 1)) else: cal_dict[x].append((y[0], y[1])) print('F值计算结果:', cal_dict) print('F值db结果:', db_dict) if cal_dict != db_dict: self.base_assert.except_error('结果页F值计算结果与数据库结果不一致') @teststep def star_score_check_operate(self, stu_id, pass_word_list, wrong_word_list): """星星积分核对操作 :param stu_id: 学生id :param pass_word_list: 测试通过单词列表 :param wrong_word_list: 测试未通过单词列表 """ star_score_result = self.sql_handler.get_student_test_star_score(stu_id) cal_score_value = sum([len(pass_word_list[x]) for x in pass_word_list]) cal_star_value = sum([len(wrong_word_list[x]) for x in wrong_word_list]) + cal_score_value if int(star_score_result['score']) != cal_score_value: self.base_assert.except_error("积分数与实际计算积分数不一致, 请核实。 student_data表数据为%d, 实际计算数据为%d" % (int(star_score_result['score']), cal_score_value)) if int(star_score_result["star"]) != cal_star_value: self.base_assert.except_error("星星数量与实际计算星星数不一致, 请核实。 student_data表数据为%d, 实际计算数据为%d" % (int(star_score_result['star']), cal_star_value)) @teststeps def check_result_page_data_operate(self, stu_id, nickname, test_word_dict, wrong_count, game_return): """结果页面数据校验 :param game_return: 做题次数 :param wrong_count: 错误单词个数 :param test_word_dict: 测试单词字典信息 :param stu_id: 学生id :param nickname: 学生昵称 """ if self.wait_check_test_result_page(): test_count = len(test_word_dict) page_score = self.result_score() print('测试得分:', page_score, '\n', '学生名称:', self.nickname(), '\n', self.test_count_summery(), '\n', self.test_record_summery()) wrong_word_list = dict_slice(test_word_dict, end=wrong_count) pass_word_list = dict_slice(test_word_dict, start=wrong_count) print('错误单词:', wrong_word_list) print('正确单词:', pass_word_list) self.db_cal_fvalue_dict_operate(stu_id, wrong_word_list, game_return, is_right=False) self.db_cal_fvalue_dict_operate(stu_id, pass_word_list, game_return, is_right=True) test_id = self.student_test_id() db_result_data = self.sql_handler.get_result_data(test_id) db_right_count = db_result_data[0] db_total_count = db_right_count + db_result_data[1] db_score = int(db_result_data[3]) split_time = db_result_data[2].split(':') db_spend_time = int(split_time[0] * 60) + int(split_time[1]) + (1 if int(split_time[2]) >= 30 else 0) pass_count = 0 if db_score < 90 else db_right_count if db_score != page_score: self.base_assert.except_error('测试分数与计算分数不一致,应为%d, 页面为%d' % (db_score, page_score)) if self.nickname() != nickname: self.base_assert.except_error("当前页面昵称与设置中昵称不一致") word_count = int(re.findall(r'\d+', self.test_count_summery())[0]) if db_total_count != word_count: self.base_assert.except_error("页面统计测试总数与实际个数不一致, 页面为%d,实际为%d" % (word_count, test_count)) record_info = re.findall(r'\d+', self.test_record_summery()) studied_words_count = WordDataHandlePage().get_student_studied_words_count(stu_id) if studied_words_count != int(record_info[0]): self.base_assert.except_error("页面已背单词个数与实际已背数量不一致, 页面为%d, 实际为%d" % (int(record_info[0]), studied_words_count)) if pass_count != int(record_info[1]): self.base_assert.except_error("页面测试通过单词个数与实际通过数量不一致, 页面为%d, 实际为%d" % (int(record_info[1]), pass_count)) if db_spend_time != int(record_info[2]): self.base_assert.except_error("页面统计时间与实际用时不一致,页面为%d, 实际为%d" % (int(record_info[2]), db_spend_time)) # self.star_score_check_operate(stu_id, pass_word_list, wrong_word_list) if page_score == 100: if self.wait_check_again_btn_page(): self.base_assert.except_error("得分为100分, 但是错题再练可点击") self.share_btn().click() GameCommonEle().share_page_operate() return wrong_word_list
class BuyTipsPage(BasePage): """购买提示 页面""" wait = WaitElement() @teststeps def wait_check_buy_page(self, var=20): """以“提示”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'提示')]") return self.wait.wait_check_element(locator) @teststeps def img_judge(self): """判断图片 是否存在""" locator = (By.CLASS_NAME, 'android.widget.ImageView') return self.wait.wait_find_element(locator) @teststeps def tips_title(self): """以“标题” 的id""" locator = (By.ID, self.id_type() + "head_hint") content = self.wait.wait_find_element(locator).text print(content) @teststeps def tips_content(self): """以“提示页面 页中文案”的xpath为依据""" locator = (By.XPATH, self.id_type() + "//android.widget.TextView[contains(@index,2)]") content = self.wait.wait_find_element(locator).text print(content) @teststep def goto_pay_button(self): """去购买 按钮 """ locator = (By.ID, self.id_type() + "goto_pay") self.wait.wait_find_element(locator).click() @teststep def goto_verification(self): """购买 验证 """ locator = (By.ID, self.id_type() + "goto_verification") return self.wait.wait_find_element(locator) # 购买 页面 @teststeps def wait_check_pay_page(self): """以“购买”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'购买')]") return self.wait.wait_find_element(locator) @teststep def st_icon(self): """学生头像 """ locator = (By.ID, self.id_type() + "avatar") return self.wait.wait_find_element(locator) @teststeps def st_name(self): """学生name """ locator = (By.ID, self.id_type() + "name") ele = self.wait.wait_find_element(locator) print(ele.text) @teststeps def st_phone(self): """学生 手机号""" locator = (By.ID, self.id_type() + "phone") ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def online_service(self): """在线客服""" locator = (By.ID, self.id_type() + "goToCustomerService") self.wait.wait_find_element(locator).click() @teststeps def buy_hint(self): """购买 提示信息""" locator = (By.ID, self.id_type() + "pay_hint") ele = self.wait.wait_find_element(locator) print(ele.text) @teststeps def hint_info(self): """提示信息""" locator = (By.ID, self.id_type() + "hint") ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def check_button(self): """卡前的 单选框 """ locator = (By.ID, self.id_type() + "check") return self.wait.wait_find_elements(locator) @teststep def card_name(self): """卡的类型:月卡、季卡、半年卡、年卡 """ locator = (By.ID, self.id_type() + "one") return self.wait.wait_find_elements(locator) @teststep def card_price(self): """卡的 价格 """ locator = (By.ID, self.id_type() + "two") return self.wait.wait_find_elements(locator) @teststeps def current_card(self): """目前选定的是X卡""" locator = (By.ID, self.id_type() + "current_vip_card_hint") ele = self.wait.wait_find_elements(locator) print('目前选中的卡为:', ele.text) @teststep def buy_agreement(self): """购买协议""" locator = (By.ID, self.id_type() + "pay_agreement") self.wait.wait_find_element(locator).click() @teststep def direct_buy_button(self): """直接购买""" locator = (By.ID, self.id_type() + "pay") return self.wait.wait_find_element(locator) @teststep def discount_pbuy_button(self): """优惠购买""" locator = (By.ID, self.id_type() + "discount_pay") return self.wait.wait_find_element(locator) # 在线客服 @teststeps def wait_check_help_page(self): """以“帮助中心”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'帮助中心')]") return self.wait.wait_check_element(locator) # 购买协议 @teststeps def wait_check_protocol_page(self, var=20): """以“购买协议”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'购买协议')]") return self.wait.wait_check_element(locator) # 支付确认 页面 @teststeps def wait_check_pay_confirm_page(self, var=20): """以“支付确认”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'支付确认')]") return self.wait.wait_check_element(locator) @teststeps def price_unit(self, index=1): """货币单位""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,0)]") ele = self.wait.wait_find_elements(locator) content = ele[index].text return content @teststeps def price_info(self): """价格""" locator = (By.ID, self.id_type() + 'money') return self.wait.wait_find_element(locator).text @teststeps def card_hint(self): """所购卡的 提示信息""" locator = (By.ID, self.id_type() + 'vip_type_hint') ele = self.wait.wait_find_element(locator) print(ele.text) @teststeps def pay_type(self): """wording:支付方式""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,0)]") ele = self.wait.wait_find_elements(locator) content = ele[2].text print(content) @teststep def pay_icon(self): """微信、支付宝、代付icon """ locator = (By.CLASS_NAME, "android.widget.ImageView") return self.wait.wait_find_elements(locator) @teststep def wechat_pay_check(self): """微信 单选框 """ locator = (By.ID, self.id_type() + "wechat_pay_check") return self.wait.wait_find_element(locator) @teststep def ali_pay_check(self): """支付宝 单选框 """ locator = (By.ID, self.id_type() + "ali_pay_check") return self.wait.wait_find_element(locator) @teststep def parent_pay_check(self): """家长代付 单选框 """ locator = (By.ID, self.id_type() + "parent_pay_check") return self.wait.wait_find_element(locator) @teststeps def pay_mode(self, index): """支付方式列表 wording:微信、支付宝、代付""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,2)]") ele = self.wait.wait_find_elements(locator) print(' ', ele[index].text) @teststep def confirm_pay_button(self): """确认支付 按钮""" locator = (By.ID, self.id_type() + 'pay') self.wait.wait_find_element(locator).click() @teststeps def pay_delay_tips(self): """支付延迟 说明""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,4)]") ele = self.wait.wait_find_element(locator) print(ele.text) # 微信支付 页面 # 支付宝支付 页面 # 家长代付 页面 @teststeps def wait_check_replace_page(self, var=20): """以“家长代付”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'家长代付')]") return self.wait.wait_check_element(locator) @teststeps def wechat_replace_pay(self): """微信代付 tab""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,0)]") return self.wait.wait_find_element(locator) @teststeps def ali_replace_pay(self): """支付宝代付 tab""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,0)]") return self.wait.wait_find_elements(locator)[1] @teststeps def card_type(self): """卡的类型""" locator = (By.ID, self.id_type() + 'card_type') ele = self.wait.wait_find_element(locator) print(ele.text) @teststeps def qr_code_hint(self): """wording:微信扫描二维码付款""" locator = (By.ID, self.id_type() + 'pay_type_hint') ele = self.wait.wait_find_element(locator) print(ele.text) @teststeps def qr_code_judge(self): """微信二维码""" locator = (By.ID, self.id_type() + 'qr_code') return self.wait.wait_check_element(locator) @teststeps def pay_finish_tips(self): """支付完成 提示""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,3)]") return self.wait.wait_check_element(locator) @teststep def pay_finish_button(self): """支付完成 按钮""" locator = (By.ID, self.id_type() + 'pay_complete') self.wait.wait_find_element(locator).click() @teststeps def pay_statement(self): """收款公司 声明""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,5)]") ele = self.wait.wait_find_element(locator) print(ele.text) # 支付结果 页面 -支付失败 @teststeps def wait_check_pay_result_page(self): """以“支付结果”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'支付结果')]") return self.wait.wait_check_element(locator) @teststeps def pay_result_img_judge(self): """支付结果页 图片""" locator = (By.ID, self.id_type() + 'pay_result_img') return self.wait.wait_check_element(locator, timeout=5) @teststeps def pay_result(self): """付款结果""" locator = (By.ID, self.id_type() + 'pay_result') ele = self.wait.wait_find_element(locator, timeout=5) print(ele.text) @teststeps def contact_services_tips(self): """联系客服 的提示""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,0)]") ele = self.wait.wait_find_element(locator, timeout=5) print(ele.text) @teststeps def qr_code_tips(self): """wording:"在线助教"客服二维码""" locator = (By.XPATH, "//android.widget.TextView[contains(@index,2)]") return self.wait.wait_check_element(locator, timeout=5) # 支付结果 页面 -支付成功 @teststeps def tips_goto_pay_operate(self): """去购买""" if self.wait_check_buy_page(10): if self.img_judge(): # 判断图片 是否存在 print('------------------------------') print('购买提示页:') self.tips_title() self.tips_content() self.goto_pay_button() # 去购买 按钮 self.buy_page_direct_operate() HomePage().click_back_up_button() # 返回 购买提示页 if self.wait_check_buy_page(10): self.goto_verification().click() # 已有【提分版】, 去验证 Toast().find_toast('已更新账户信息') @teststeps def buy_page_direct_operate(self): """购买页 操作 -- 直接购买""" if self.wait_check_pay_page(): # 购买页 检查点 print('------------------------------') print('购买页:') self.st_icon() # 学生头像 self.st_name() # 学生name self.st_phone() # 手机号 self.buy_hint() # 购买提示 self.hint_info() # 提分版 权力 self.online_services_operate() # 在线客服 if self.wait_check_pay_page(): check = self.check_button() # 单选框 for i in range(len(check)): if GetAttribute().get_checked(check[i]) == 'true': if i != 3: print('❌❌❌ Error - 未默认选中 年卡') else: check[0].click() # 选择季卡 if GetAttribute().get_checked( self.check_button()[0]) == 'true': self.current_card() # 左下角 目前选中的卡 else: print('❌❌❌ Error - 未选中 月卡') card = self.card_name() # 卡的类型 price = self.card_price() # 卡的价格 if len(check) != len(card) != len(price) != 4: print('❌❌❌ Error - 卡的个数有误', len(check), len(card), len(price)) else: print('--------------------') for j in range(len(card)): print(card[j].text, price[j].text) print('--------------------') self.buy_agreement() # 购买协议 self.pay_confirm_operate() # 支付确认页 @teststeps def pay_confirm_operate(self): """支付确认页 操作""" direct = self.direct_buy_button() # 直接购买 按钮 if GetAttribute().get_enabled(direct) == 'true': direct.click() # 点击 直接购买 按钮 if self.wait_check_pay_confirm_page(): # 支付确认 页面检查点 print('------------------------------') print('支付确认页:') self.st_icon() # 学生头像 self.st_name() # 学生name self.st_phone() # 手机号 self.online_services_operate() # 在线客服 unit = self.price_unit() # 货币单位 print(unit, self.price_info()) # 价格 self.card_hint() # 卡的类型说明 print('-----------------') self.pay_type() # 支付方式 icon = self.pay_icon() # icon wechat_check = self.wechat_pay_check() # 微信单选框 if GetAttribute().get_checked(wechat_check) == 'false': print('❌❌❌ Error - 未默认选中 微信支付') for k in range(1, len(icon)): self.pay_mode(k) # 支付方式 print('-----------------') self.pay_delay_tips() # 支付延迟 说明 self.parent_replace_operate() # 家长代付 @teststeps def parent_replace_operate(self): """家长代付页 操作""" parent = self.parent_pay_check() # 家长代付 单选框 parent.click() self.confirm_pay_button() # 确认支付 按钮 if self.wait_check_replace_page(): # 家长代付页 检查点 print('------------------------------') print('家长代付页:') wechat_tab = self.wechat_replace_pay() # 微信代付 if GetAttribute().get_selected(wechat_tab) == 'false': print('❌❌❌ Error - 未默认选中 微信代付') else: ali_tab = self.ali_replace_pay() # 支付宝代付 print(ali_tab.text) ali_tab.click() # 切换到 支付宝代付 if GetAttribute().get_selected( self.ali_replace_pay()) == 'false': print('❌❌❌ Error - 未选中 支付宝代付') self.card_type() # 卡的类型 unit = self.price_unit(2) # 货币单位 print(unit, self.price_info()) # 价格 if self.qr_code_judge(): self.qr_code_hint() # xx扫描二维码付款 if not self.pay_finish_tips(): # 支付完成 提示 print("❌❌❌ Error - 无支付完成 提示") self.pay_statement() # 收款公司说明 self.pay_finish_operate() # 支付结果页 @teststeps def pay_finish_operate(self): """支付结果页 操作""" self.pay_finish_button() # 支付完成 按钮 if self.wait_check_pay_result_page(): # 支付结果页 检查点 print('------------------------------') print('支付结果页:') if self.pay_result_img_judge(): self.pay_result() # 支付结果 self.contact_services_tips() # 联系客服的提示 if self.img_judge(): if not self.qr_code_tips(): # "在线助教"客服二维码 print('❌❌❌ Error - 无文案:"在线助教"客服二维码') @teststeps def online_services_operate(self): """在线客服""" self.online_service() # 点击在线客服 if self.wait_check_help_page(): HomePage().click_back_up_button()
def __init__(self): self.common = WordDataHandlePage() self.wait = WaitElement()
class WordBookRebuildPage(BasePage): def __init__(self): super().__init__() self.data = WordDataHandlePage() self.public = WorldBookPublicPage() self.wait = WaitElement() self.data_dir = 'app/honor/student/word_book_rebuild/test_data/' @teststep def wait_check_start_page(self): """将'你准备好了吗?'作为 单词本首页 页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text, '你准备好了吗?')]") return self.wait.wait_check_element(locator, timeout=5) @teststep def wait_check_continue_page(self): """单词继续学习页面检查点""" locator = (By.ID, self.id_type() + "word_continue") return self.wait.wait_check_element(locator, timeout=5) @teststep def wait_check_start_wrong_again_page(self): """错题题再练页面""" locator = (By.ID, self.id_type() + "word_continue") return self.wait.wait_check_element(locator, timeout=5) @teststep def wait_check_game_title_page(self): """游戏标题页面检查点""" locator = (By.ID, self.id_type() + 'tv_title') return self.wait.wait_check_element(locator) @teststep def word_start_button(self): # Go标志按钮 locator = (By.ID, self.id_type() + "word_start") self.wait.wait_find_element(locator).click() time.sleep(3) @teststep def word_continue_button(self): """继续练习按钮""" locator = (By.ID, self.id_type() + "word_continue") self.wait.wait_find_element(locator).click() time.sleep(3) @teststep def total_word(self): """已背单词 数""" locator = (By.ID, self.id_type() + 'total') ele = self.wait.wait_find_element(locator) return int(ele.text) @teststep def confirm_btn(self): """错题再练开始练习按钮""" locator = (By.ID, self.id_type() + 'confirm') return self.wait.wait_find_element(locator) @teststep def write_words_to_file(self, file_name, file_value): """将数据存入文件""" with open(self.data_dir + file_name, 'w', encoding='utf-8') as f: if '.json' in file_name: json.dump(file_value, f, ensure_ascii=False) elif '.txt' in file_name: f.write(','.join(file_value)) @teststep def read_words_info_from_file(self, file_name): """从json文件中读取数据""" file_value = 0 with open(self.data_dir + file_name, 'r', encoding='utf-8') as f: if '.json' in file_name: file_value = json.load(f) elif '.txt' in file_name: file_value = [x for x in f.read().split(',') if x] return file_value @teststep def set_do_right_by_familiar_type(self, familiar_type, group_count): """根据标熟类型设置是否做对""" do_right = 0 if familiar_type in [1, 2, 3]: do_right = False elif familiar_type in [4, 5]: if group_count == 0: do_right = True else: do_right = False return do_right @teststep def group_operate(self, need_recite_count): """分组操作""" if need_recite_count <= 10: # 个数小于10 分为一组 group = [need_recite_count] elif 10 < need_recite_count < 21: # 个数为11-20 分为两组 group = [ floor(need_recite_count / 2), need_recite_count - floor(need_recite_count / 2) ] else: if need_recite_count > 30: # 个数为 20 -30 或者 >30(做30处理) 分三组 need_recite_count = 30 third_division = floor(need_recite_count / 3) second_division = floor((need_recite_count - third_division) / 2) reset_part = need_recite_count - third_division - second_division group = [third_division, second_division, reset_part] return group @teststep def check_new_word_after_recite_process(self, flash_result, group_recite_count, group_count, study_model=1): """校验新词奖励个数""" boundary_value = 28 if study_model == 1 else 17 # 根据学习类型设置边界值 if flash_result: if group_count == 0: if group_recite_count < boundary_value: if len(flash_result[0]) > 10: print('❌❌❌ 新词奖励个数大于10个') else: if len(flash_result[0]) not in range(3, 11): print('❌❌❌ 复习的新词奖励个数不在3-10之间', len(flash_result[0])) else: if group_recite_count < boundary_value: print('❌❌❌ 复习个数小于“{}”, 未有新词奖励'.format(boundary_value)) @teststep def from_wordbook_back_to_home(self): """从单词本中退回主页面""" self.click_back_up_button() GameCommonEle().tips_operate() if self.wait_check_continue_page(): self.click_back_up_button() @teststep def normal_study_new_word_operate(self, stu_id, flash_result, do_right): """单词学习过程""" group_word_answers = flash_result[-1] group_word_explains = list(flash_result[0].values()) star_words = flash_result[2] familiar_explain_ids = list(flash_result[1].keys()) group_new_explain_words = flash_result[3] remove_familiar = list( np.setdiff1d(group_word_explains, familiar_explain_ids)) remove_repeat_words = list( np.setdiff1d(remove_familiar, group_new_explain_words)) remove_repeat_count = len(remove_repeat_words) print('本组所有单词:', group_word_explains) print('本组标星单词:', star_words) print('本组标熟单词:', familiar_explain_ids) print('本组不去新释义做题数:', remove_familiar) print('本组新释义单词:', group_new_explain_words) print('本组去除重复单词数:', remove_repeat_count, '\n') while self.wait_check_game_title_page(): title_ele = self.public.game_title() game_title = title_ele.text mode_id = int( title_ele.get_attribute('contentDescription').split(' ')[1]) if '闪卡练习' in game_title and mode_id == 2: copy_count = FlashCard().flash_copy_model( star_words, group_new_explain_words) if self.wait_check_game_title_page(): if copy_count != len(star_words): self.base_assert.except_error('标星个数与抄写个数不一致') elif '单词拼写(新词)' in game_title or '单词拼写(新释义)' in game_title: spell_count = SpellingWord().new_word_spell_operate( flash_result[1], group_new_explain_words) print('单词拼写个数', spell_count) if self.wait_check_game_title_page(): if spell_count != len(familiar_explain_ids): self.base_assert.except_error('标熟个数与拼写个数不一致') elif '词汇选择(新词)' in game_title: if do_right: # 词汇选择做对操作 VocabularyChoose().right_listen_select_operate( stu_id, remove_repeat_count, group_new_explain_words) else: # 词汇选择随机选择操作 VocabularyChoose().normal_listen_select_operate( remove_repeat_count, group_new_explain_words) elif '连连看' in game_title: MatchingWord().link_link_game_operate(len(remove_familiar), group_word_answers) elif '还原单词' in game_title: if do_right: # 还原单词做对操作 WordRestore().right_restore_word_operate( stu_id, remove_repeat_count, group_new_explain_words) else: # 还原单词做错后做对操作 WordRestore().restore_word_operate( stu_id, remove_repeat_count, group_new_explain_words) elif '单词听写' in game_title: if do_right: # 单词听写做对操作 ListenSpellWordPage().right_listen_spell_operate( stu_id, remove_repeat_count, group_new_explain_words) else: # 单词听写做错后做对操作 ListenSpellWordPage().normal_listen_spell_operate( remove_repeat_count, group_new_explain_words) else: break return remove_repeat_words @teststep def recite_word_operate(self, stu_id, level, wrong_again_words, right_explains): """单词复习过程""" recite_new_explains = self.data.get_recite_new_explains( stu_id, level) # 已学新释义单词,需跳过单词拼写游戏 recite_new_words = self.data.get_word_list_by_explains( stu_id, recite_new_explains) print('新释义解释:', recite_new_explains) print('新释义单词:', recite_new_words) print('新释义单词个数:', len(recite_new_words), '\n') right_words = self.data.get_word_list_by_explains( stu_id, right_explains) print('新词非标熟且全对单词:', right_words) print('新词非标熟且全对个数', len(right_words), '\n') recite_b_explains = self.data.get_recite_level_one_explains( stu_id) # 获取一轮复习单词的个数 recite_b_words = self.data.get_word_list_by_explains( stu_id, recite_b_explains) # 根据解释id获取单词 print('B轮需要复习的解释:', recite_b_explains) print('B轮需要复习的单词:', recite_b_words) print('B轮需要复习的个数:', len(recite_b_words), '\n') vocab_select_words = list(np.setdiff1d(recite_b_words, right_words)) vocab_select_count = len(vocab_select_words) # 词汇选择或者词汇运用的个数 print('B轮词汇选择单词:', vocab_select_words) print('B轮词汇选择个数:', vocab_select_count, '\n') only_apply_explains = list( np.intersect1d(recite_new_explains, right_explains)) # 只有词汇运用的单词 only_apply_words = list(np.intersect1d(recite_new_words, right_words)) print('B轮单独复习词汇运用的解释:', only_apply_explains) print('B轮单独复习词汇运用的单词:', only_apply_words) print('B轮单独复习词汇运用个数:', len(only_apply_words), '\n') recite_b_vocab_apply_words = list( np.hstack((vocab_select_words, only_apply_words))) recite_b_vocab_apply_count = len(recite_b_vocab_apply_words) print('B轮复习词汇运用单词:', recite_b_vocab_apply_words) print('B轮复习词汇运用个数:', recite_b_vocab_apply_count, '\n') recite_b_spell_explains = list( np.setdiff1d(recite_b_explains, recite_new_explains)) # 需要复习单词拼写的单词 recite_b_spell_words = self.data.get_word_list_by_explains( stu_id, recite_b_spell_explains) print('B轮单词拼写解释:', recite_b_spell_explains) print('B轮单词拼写单词:', recite_b_spell_words) print('B轮单词拼写单词个数:', len(recite_b_spell_words), '\n') recite_cde_vocab_apply_explains = self.data.get_recite_level_more_than_one_explains( stu_id, level) # 获取F值=level的解释id recite_cde_vocab_apply_words = self.data.get_word_list_by_explains( stu_id, recite_cde_vocab_apply_explains) # 根据解释id获取单词 print('C/D/E轮词汇运用的解释:', recite_cde_vocab_apply_explains) print('C/D/E轮词汇运用的单词:', recite_cde_vocab_apply_words) print('C/D/E轮词汇运用的个数:', len(recite_cde_vocab_apply_words), '\n') recite_cde_spell_explains = list( np.setdiff1d(recite_cde_vocab_apply_explains, recite_new_explains)) # 需要复习单词拼写的单词 recite_cde_spell_words = self.data.get_word_list_by_explains( stu_id, recite_cde_spell_explains) print('C/D/E轮单词拼写解释:', recite_cde_spell_explains) print('C/D/E轮单词拼写单词:', recite_cde_spell_words) print('C/D/E轮单词拼写单词个数:', len(recite_cde_spell_words), '\n') all_vocab_select_words = vocab_select_words all_vocab_apply_words = list( set( list( np.hstack((recite_b_vocab_apply_words, recite_cde_vocab_apply_words))))) all_spell_words = list( set(list(np.hstack( (recite_b_spell_words, recite_cde_spell_words))))) print('词汇选择总数:', len(all_vocab_select_words)) print('词汇运用总数:', len(all_vocab_apply_words)) print('单词拼写总数:', len(all_spell_words), '\n') vocab_select_group = self.group_operate(len(all_vocab_select_words)) vocab_apply_group = self.group_operate(len(all_vocab_apply_words)) word_spell_group = self.group_operate(len(all_spell_words)) all_group = [vocab_select_group, vocab_apply_group, word_spell_group] max_length = max((len(l) for l in all_group)) reform_group = list( map(lambda x: x + [0] * (max_length - len(x)), all_group)) vocab_select_group = reform_group[0] vocab_apply_group = reform_group[1] word_spell_group = reform_group[2] print('词汇选择分组:', vocab_select_group) print('词汇运用分组:', vocab_apply_group) print('单词拼写分组:', word_spell_group, '\n') for x in range(len(vocab_select_group)): while self.wait_check_game_title_page(): title_ele = self.public.game_title() game_title = title_ele.text print(game_title) mode_id = int( title_ele.get_attribute('contentDescription').split()[1]) if '词汇选择(复习)' in game_title: if len(recite_b_words) < 3: # 若F=1的单词个数小于3 ,则不应出现词汇选择 self.base_assert.except_error('一轮复习单词不足3个,不应出现词汇选择游戏') if not vocab_select_group[x]: self.base_assert.except_error('词汇选择分组为0, 不应出现词汇选择游戏') if mode_id == 1: # mode=1 , 根据单词选解释游戏 VocabularyChoose().vocab_select_choice_explain( vocab_select_group[x], wrong_again_words) else: # mode=2, 根据解释选单词 VocabularyChoose().vocab_select_choice_word( stu_id, vocab_select_group[x], wrong_again_words) if '词汇选择(复习)' in self.public.game_title( ).text: # 判断一组结束后是否还会出现词汇选择游戏 self.base_assert.except_error('词汇选择个数与计算个数不一致!') break elif '词汇运用(复习)' in game_title: if not vocab_apply_group[x]: self.base_assert.except_error('词汇运用分组为0, 不应出现词汇运用游戏') VocabularyChoose().vocab_apply( stu_id, vocab_apply_group[x], right_words, recite_new_explains) # 词汇运用游戏过程 if self.wait_check_game_title_page(): if '词汇运用(复习)' in self.public.game_title( ).text: # 判断一组结束后是否还会出现词汇选择游戏 self.base_assert.except_error('词汇运用组数与计算个数不一致!') break elif '单词拼写(复习)' in game_title: # 单词拼写游戏 if not word_spell_group[0]: self.base_assert.except_error('单词拼写分组为0, 不应出现单词拼写戏') SpellingWord().recite_word_spell_operate( stu_id, word_spell_group[x], recite_new_explains, only_apply_explains) if self.wait_check_game_title_page(): if '单词拼写(复习)' in self.public.game_title().text: self.base_assert.except_error('单词拼写(复习)个数与计算个数不一致') break else: break return len(recite_b_words) + len(recite_cde_vocab_apply_words)
def __init__(self): self.home = HomePage() self.van = VanclassPage() self.wait = WaitElement()
class MeizuPage(BasePage): """魅族5.1""" wait = WaitElement() # 拍照 魅族5.1 @teststeps def wait_check_camera_page(self): """以 “拍照键”的resource-id为依据""" locator = (By.ID, "com.meizu.media.camera:id/shutter_btn") return self.wait.wait_check_element(locator) # 第一页面 @teststep def click_camera_button(self): """以相机拍照按钮""" time.sleep(2) print('点击 拍照按钮') locator = (By.ID, "com.meizu.media.camera:id/shutter_btn") return self.wait.wait_find_element(locator).click() # 第二页面 @teststeps def wait_check_retake_page(self): """以 “”的resource-id为依据""" locator = (By.ID, "com.meizu.media.camera:id/btn_retake") return self.wait.wait_check_element(locator) @teststep def click_done_button(self): """相机'完成'按钮""" print('点击 保存按钮') locator = (By.ID, "com.meizu.media.camera:id/btn_done") self.wait.wait_find_element(locator).click() @teststep def click_retake_button(self): """相机'retake'按钮""" print('点击 重拍按钮') locator = (By.ID, "com.meizu.media.camera:id/btn_retake") self.wait.wait_find_element(locator).click() # 第三页面 @teststep def wait_check_save_page(self): """取消 按钮 的为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text, '取消')]") return self.wait.wait_check_element(locator) @teststep def click_save_button(self): """相机保存按钮""" print('点击 完成按钮') locator = (By.XPATH, "//android.widget.TextView[contains(@text,'完成')]") self.wait.wait_find_element(locator).click() @teststep def click_cancel_button(self): """相机取消按钮""" print('点击 取消按钮') locator = (By.XPATH, "//android.widget.TextView[contains(@text,'取消')]") self.wait.wait_find_element(locator).click() # 相册 魅族5.1 @teststep def wait_check_album_page(self): """最新tab 的单个内容 的resource-id为依据""" locator = (By.ID, "com.meizu.media.gallery:id/thumbnail") return self.wait.wait_check_element(locator) @teststeps def wait_check_album_list_page(self): """相册列表页面检查点""" locator = (By.ID, "com.meizu.media.gallery:id/album_cover") return self.wait.wait_check_element(locator) # 第一页面 @teststep def click_album(self): """进入相册tab""" print('进入相册列表页') locator = (By.XPATH, "//android.widget.TextView[contains(@text,'相册')]") self.wait.wait_find_element(locator).click() @teststep def wait_check_all_picture_page(self): """所有图片 的为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text, '所有图片')]") return self.wait.wait_check_element(locator) @teststep def open_album(self): """打开 第一个相册""" print('选择相册') locator = (By.XPATH, "com.meizu.media.gallery:id/album_name") self.wait.wait_find_elements(locator)[0].click() # 第二页面 检查点用 wait_check_album_list_page() @teststep def choose_image(self): """选择相册图片""" print('选择照片') locator = (By.ID, "com.meizu.media.gallery:id/thumbnail") self.wait.wait_find_elements(locator)[0].click() # 第三页面 @teststep def wait_check_photo_page(self): """ 确定 按钮 的resource-id为依据""" locator = (By.ID, "com.meizu.media.gallery:id/fragment_container") return self.wait.wait_check_element(locator) @teststep def commit_button(self): """相册确定按钮""" print('点击 确定按钮') locator = (By.XPATH, "//android.widget.TextView[contains(@text,'确定')]") self.wait.wait_find_element(locator).click() @teststep def back_up_button(self): """相册返回按钮""" locator = (By.ID, "android:id/home") self.wait.wait_find_element(locator).click()
class ListenHomePage(BasePage): wait = WaitElement() @teststep def wait_check_listen_everyday_home_page(self): locator = (By.XPATH, '//android.widget.TextView[contains(@text, "每日一听")]') return self.wait.wait_check_element(locator) @teststep def wait_check_degrade_page(self): locator = (By.XPATH, '//android.widget.TextView[contains(@text, "是否感觉题太难了")]') return self.wait.wait_check_element(locator) @teststep def wait_check_certificate_page(self): locator = (By.XPATH, '//android.widget.Button[contains(@text, "炫耀一下")]') return self.wait.wait_check_element(locator) @teststep def wait_check_share_page(self): locator = (By.XPATH, '//android.widget.Button[contains(@text, "微信好友")]') return self.wait.wait_check_element(locator) @teststep def wait_today_limit_img_page(self): locator = (By.ID, self.id_type() + 'error_img') return self.wait.wait_check_element(locator) @teststep def level_button(self): """等级""" locator = (By.ID, self.id_type() + 'level') return self.wait.wait_find_element(locator) @teststep def history_button(self): """历史记录""" locator = (By.ID, self.id_type() + 'history') return self.wait.wait_find_element(locator) @teststep def rank_button(self): """排行榜""" locator = (By.ID, self.id_type() + 'rank') return self.wait.wait_find_element(locator) @teststep def start_button(self): """开始""" locator = (By.ID, self.id_type() + 'start') return self.wait.wait_find_element(locator) @teststep def excise_time(self): """练习时间""" locator = (By.ID, self.id_type() + 'time') return self.wait.wait_find_element(locator) @teststep def start_excise_button(self): """开始练习""" locator = (By.ID, self.id_type() + 'action_two') return self.wait.wait_find_element(locator) @teststep def commit_button(self): """确定""" locator = (By.ID, self.id_type() + 'confirm') return self.wait.wait_find_element(locator)
def __init__(self): self.home = HomePage() self.user_center = UserCenterPage() self.wait = WaitElement()
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('返回主界面')
class VanclassPage(BasePage): """ 班级 页面""" wait = WaitElement() @teststeps def wait_check_page(self): """以“班级列表页面 添加班级 按钮”为依据""" locator = (By.ID, "{}add".format(self.id_type())) return self.wait.wait_check_element(locator, timeout=5) @teststep def wait_check_van_list_page(self): """班级列表页面检查点""" locator = (By.ID, "{}class_name".format(self.id_type())) return self.wait.wait_check_element(locator) @teststeps def wait_check_quit_vanclass(self, class_name): """退出班级页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'{}')]".format( class_name)) return self.wait.wait_check_element(locator) @teststep def wait_check_empty_tips(self): """暂时没有数据""" locator = (By.ID, self.id_type() + "load_empty") return self.wait.wait_check_element(locator, timeout=5) @teststeps def swp(self): self.screen_swipe_up(0.5, 0.8, 0.2, 1000) @teststep def vanclass_name(self): """班级名称""" locator = (By.ID, self.id_type() + "class_name") return self.wait.wait_find_elements(locator) @teststep def vanclass_no(self): """班号""" locator = (By.ID, self.id_type() + "class_no") return self.wait.wait_find_elements(locator) @teststep def st_count(self): """学生人数""" locator = (By.ID, self.id_type() + "count") return self.wait.wait_find_elements(locator) @teststep def add_class_button(self): """以“添加班级 按钮”的id为依据""" locator = (By.ID, self.id_type() + "add") self.wait.wait_find_element(locator).click() # 申请入班 @teststeps def wait_check_apply_page(self): """以“title: 添加班级”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'添加班级')]") return self.wait.wait_check_element(locator) @teststep def wait_check_no_class_page(self): locator = (By.ID, self.id_type() + "status_error_hint_view") return self.wait.wait_check_element(locator) @teststeps def all_element(self): """页面内所有class name为android.widget.TextView的元素""" ele = self.driver.find_elements_by_class_name( "android.widget.TextView") content = [] for i in range(len(ele)): # print(ele[i].text) content.append(ele[i].text) # print('++++++++++++++++') return ele, content @teststep def apply_teacher_name(self): """老师名称""" locator = (By.ID, self.id_type() + "tv_teacher_name") return self.wait.wait_find_element(locator).text @teststep def apply_vanclass_no(self): """班号""" locator = (By.ID, self.id_type() + "tv_class_no") return self.wait.wait_find_element(locator).text @teststep def remark_name_modify(self): """备注名称 输入框""" locator = (By.ID, self.id_type() + "et_remark_name") return self.wait.wait_find_element(locator) @teststep def apply_class_button(self): """以“申请入班 按钮”的id为依据""" locator = (By.ID, self.id_type() + "tv_apply") self.wait.wait_find_element(locator).click() time.sleep(2) # 班级 详情页 @teststeps def wait_check_vanclass_page(self, var): """以“title: 班级名称”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'%s')]" % var) return self.wait.wait_check_element(locator) @teststep def teacher_name(self): """老师名称 title""" locator = (By.ID, self.id_type() + "tv_teacher_title") return self.wait.wait_find_element(locator).text @teststep def teacher_name_modify(self): """老师名称""" locator = (By.ID, self.id_type() + "tv_teacher") return self.wait.wait_find_element(locator).text @teststep def class_name(self): """班级名称 title""" locator = (By.ID, self.id_type() + "class_name") return self.wait.wait_find_elements(locator) @teststep def class_name_modify(self): """班级名称 编辑""" locator = (By.ID, self.id_type() + "tv_class_name") return self.wait.wait_find_element(locator).text @teststep def school_name(self): """学校名称""" locator = (By.ID, self.id_type() + "tv_school_title") return self.wait.wait_find_element(locator).text @teststep def school_name_modify(self): """学校名称 编辑""" locator = (By.ID, self.id_type() + "tv_school") return self.wait.wait_find_element(locator).text @teststep def score_ranking(self): """积分排行榜""" locator = (By.ID, self.id_type() + "rl_score_ranking") self.wait.wait_find_element(locator).click() @teststep def star_ranking(self): """星星排行榜""" locator = (By.ID, self.id_type() + "rl_star_ranking") self.wait.wait_find_element(locator).click() @teststep def vanclass_hw(self): """本班作业""" locator = (By.ID, self.id_type() + "rl_homework") self.wait.wait_find_element(locator).click() @teststep def quit_vanclass(self): """退出班级 按钮""" locator = (By.ID, self.id_type() + "tv_quit_class") self.wait.wait_find_element(locator).click() # 退出班级 @teststeps def wait_check_quit_page(self): """以“title: 退出班级”为依据""" locator = (By.ID, self.id_type() + "quit") return self.wait.wait_check_element(locator) @teststep def phone_name(self): """手机号""" locator = (By.ID, self.id_type() + "tv_phone") ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def code_input(self): """验证码 输入框""" locator = (By.ID, self.id_type() + "code") return self.wait.wait_find_element(locator) @teststep def get_code_button(self): """获取 验证码""" locator = (By.ID, self.id_type() + "count_time") return self.wait.wait_find_element(locator) @teststep def sonic_code_judge(self): """语音验证码""" locator = (By.ID, self.id_type() + "tv_sonic_code") return self.wait.wait_check_element(locator, timeout=5) @teststep def sonic_code(self): """语音验证码""" locator = (By.ID, self.id_type() + "tv_sonic_code") ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def quit_button(self): """退出班级 按钮""" locator = (By.ID, self.id_type() + "quit") self.wait.wait_find_element(locator).click() @teststep def get_vanclass_id(self): """获取班级id""" vanclass_ids = [] HomePage().click_test_vanclass() if self.wait_check_page(): vanclass_ids = self.vanclass_no() HomePage().click_tab_hw() return [x.text.split(':')[1] for x in vanclass_ids]
class QuitAddClass(BasePage): def __init__(self): self.home = HomePage() self.van = VanclassPage() self.wait = WaitElement() @teststep def wait_check_vanclass_page(self): """班级页面检查点""" locator = (By.CLASS_NAME, self.id_type() + "class_name") return self.wait.wait_check_element(locator) @teststep def class_num(self): """班号""" locator = (By.ID, self.id_type() + 'class_no') return self.wait.wait_find_elements(locator) @teststep def quit_all_class_operate(self): """退出班级操作""" self.home.click_test_vanclass() # 班级tab if self.van.wait_check_page(): # 班级页面检查点 self.home.screen_swipe_down(0.5, 0.2, 0.9, 1000) while self.wait_check_vanclass_page(): if self.van.wait_check_page(): van_name = self.van.class_name()[0].text self.van.class_name()[0].click() self.quit_tips_operate(van_name) # 退出班级提示框 @teststep def quit_tips_operate(self, van_name): """退出班级 具体操作""" if self.van.wait_check_vanclass_page(van_name): # 页面检查点 self.van.quit_vanclass() # 退出班级 按钮 self.home.tips_operate_commit() # 提示框 print('确定 退出') print('------------------------------') if self.van.wait_check_quit_page(): self.van.phone_name() # 提示 value = verify_find(STU_ACCOUNT, 'quitClass') # 获取验证码 self.van.code_input().send_keys(value) # 输入验证码 print(STU_ACCOUNT) print('验证码:', value) self.van.quit_button() # 退出班级 按钮 @teststep def apply_class_operate(self, test_class_num): """加入班级操作""" self.home.click_test_vanclass() # 班级tab if self.van.wait_check_page(): # 班级页面检查点 if self.van.wait_check_van_list_page(): class_nums = self.class_num() van_names = [] while len(van_names) < len(class_nums): # 非测试班级则退出,是则保留 for i, num in enumerate(self.class_num()): class_name = self.van.class_name()[i].text van_num = num.text.split(':')[1] if class_name in van_names: continue else: van_names.append(class_name) if van_num not in test_class_num: # 检验是否已加入测试班级 num.click() # 不是测试班级的 self.quit_tips_operate(class_name) # 退出班级 else: test_class_num.remove(van_num) if len(test_class_num): for x in test_class_num: if self.van.wait_check_page(): self.van.add_class_button() # 若没有班级列表 if self.home.wait_check_tips_page(): # 页面检查点 self.home.input().send_keys(x) # 输入班级号 self.home.commit_button() # 点击确定按钮 if self.van.wait_check_apply_page(): print('班级:', self.van.class_name_modify()) print('班号:', self.van.apply_vanclass_no()) print('老师:', self.van.apply_teacher_name()) self.van.remark_name_modify().send_keys('Test') # 输入昵称 self.van.apply_class_button() # 申请入班 按钮 print('-'*30, '\n') self.home.click_tab_hw()
class ExamPage(BasePage): """试卷页面""" home = HomePage() answer = AnswerPage() wait = WaitElement() @teststep def wait_check_exam_title_page(self): """以 试卷的标题作为 页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'试卷')]") return self.wait.wait_check_element(locator) @teststep def wait_check_exam_counter_page(self): """以 做试卷时的计时作为 页面检查点""" locator = (By.ID, self.id_type() + "time_container") return self.wait.wait_check_element(locator) @teststep def wait_check_exam_confirm_page(self): """以 试卷确认的标题作为 页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'试卷确认')]") return self.wait.wait_check_element(locator) @teststep def wait_check_rank_page(self): """以 炫耀一下的text作为 页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'炫耀一下')]") return self.wait.wait_check_element(locator) @teststep def wait_check_end_page(self): """等待 滑到底提示""" locator = (By.XPATH, '//android.widget.TextView[contains(@text,"到底啦 下拉刷新试试")]') return self.wait.wait_check_element(locator, timeout=5) @teststep def exam_names(self): """试卷名称""" locator = (By.ID, self.id_type() + 'tv_name') return self.wait.wait_find_elements(locator) @teststep def finish_count(self): """完成人数""" locator = (By.ID, self.id_type() + 'tv_finishcount') return self.wait.wait_find_elements(locator) @teststep def finish_status(self): """完成状态""" locator = (By.ID, self.id_type() + 'rtv_mode') return self.wait.wait_find_elements(locator) @teststep def get_all_text(self): """获取所有文本""" locator = (By.CLASS_NAME, 'android.widget.TextView') return self.wait.wait_find_elements(locator) @teststep def click_start_exam_button(self): """点击 开始考试""" locator = (By.ID, self.id_type() + 'start_write') self.wait.wait_find_element(locator).click() @teststep def index_group(self): locator = (By.ID, self.id_type() + 'recyclerview') return self.wait.wait_find_elements(locator) @teststep def close_answer(self): """关闭答题卷页面""" locator = (By.ID, self.id_type() + 'answerclose') self.wait.wait_find_element(locator).click() @teststep def exam_back_to_home(self): self.home.click_back_up_button() if self.wait_check_exam_title_page(): self.home.click_back_up_button() if self.home.wait_check_home_page(): print('返回主页面') @teststeps def select_one_exam(self): """随机选择一个试卷""" exams_info = {} # 将试卷存入一个字典当周,以试卷名作为key,试卷描述与完成状态作为value while True: exams = self.exam_names() finish_status = self.finish_status() # 试卷完成状态 finish_count = self.finish_count() # 试卷几人完成 for i in range(len(exams)): exams_info[exams[i].text] = finish_status[ i].text + ' -- ' + finish_count[i].text if not self.wait_check_end_page(): # 没有发现滑动到底的则进行滑动 self.home.screen_swipe_up(0.5, 0.9, 0.7, 1000) else: # exams_info[exams[-1].text] = finish_status[-1].text + ' -- ' + finish_count[-1].text self.home.screen_swipe_down(0.5, 0.2, 0.9, 1000) break for name in exams_info.keys(): print(name, ' ', exams_info[name]) exam = self.exam_names()[0] test_name = exam.text print('选择试卷:', test_name) exam.click() print('------------------------------\n') return test_name @teststeps def exam_confirm_ele_operate(self): """确认页面 文本展示""" ele = self.get_all_text() print('\n<试卷确认页面>:\n') self.print_exam_info(ele) print(ele[14].text + '\n' + ele[15].text + '\n' + ele[16].text + '\n' + ele[17].text) # 说明 print('--------------------------------\n') return int(ele[9].text) @teststep def print_exam_info(self, ele): """打印出试卷头部信息""" print(ele[1].text, ':', ele[2].text) # 试卷名称 print(ele[5].text, ':', ele[3].text + ele[4].text) # 试卷模式 print(ele[8].text, ':', ele[6].text + ele[7].text) # 时间 print(ele[11].text, ':', ele[9].text + ele[10].text) # 题数 print(ele[13].text, ':', ele[12].text) # 限制 @teststeps def get_ques_name(self, total): """获取所有题型""" if self.wait_check_exam_counter_page(): self.answer.answer_check_button().click() if self.answer.wait_check_answers_page(): tip_num = [] tips = [] while True: titles = self.answer.question_titles() for i, x in enumerate(titles): if x.text in tips: continue else: if i == len(titles) - 1: self.home.screen_swipe_up(0.5, 0.87, 0.7, 1000) ques_num = self.answer.ques_num(x.text) num = int(re.findall(r'\d+', ques_num)[0]) tips.append(x.text) print(x.text, ' ', ques_num) tip_num.append(num) if sum(tip_num) < total: self.home.screen_swipe_up(0.5, 0.9, 0.4, 1000) else: break self.close_answer() print('--------------------------------\n') return tips @teststeps def play_examination(self, tips, exam_json): """做题过程""" if self.wait_check_exam_counter_page(): self.answer.answer_check_button().click() # 查看答题卷 if self.answer.wait_check_answers_page(): index = 0 while index < len(tips): title_list = [ x.text for x in self.answer.question_titles() ] # 题型数组 print(title_list) if tips[index] in title_list: first_index = self.answer.tip_index( tips[index]) # 题型的第一道题 ques_num = self.answer.ques_num( tips[index]) # 题数描述 (共*题) num = int(''.join(re.findall(r'\d+', ques_num))) # 从描述中获取题数 first_index[0].click() # 点击第一题进入习题 self.exam_process(tips[index], num, exam_json) # 对应习题的游戏过程 self.answer.answer_check_button().click( ) # 游戏结束后点击答题卷进入下一题 if self.answer.wait_check_answers_page(): pass index = index + 1 else: self.home.screen_swipe_up(0.5, 0.8, 0.4, 2000) if self.answer.wait_check_answers_page(): self.answer.submit_tip_operate() # 交卷 if self.wait_check_rank_page(): self.exam_back_to_home() # 返回 @teststeps def exam_process(self, title, num, exam_json): print('\n-------%s-共%d题------\n' % (title, num)) if '听后选择' in title: ListenSelect().play_listening_select_game(num, exam_json) self.answer.wait_result_btn_enabled() elif '猜词游戏' in title: GuessingWord().play_guessing_word_game(num, exam_json) elif '单项选择' in title: SingleChoice().play_single_choice_game(num, exam_json) elif '词汇选择' in title: VocabSelect().play_vocab_select_game(num, exam_json) elif '单词拼写' in title: WordSpell().play_word_spell_game(num, exam_json) elif '单词听写' in title: ListenSpell().play_listen_spell_game(num, exam_json) elif '连词成句' in title: Conjunctions().play_conjunctions_game(num, exam_json) elif '还原单词' in title: RestoreWord().play_restore_word_game(num, exam_json) elif '连连看' in title: WordMatch().play_word_match_game(num, exam_json) elif '强化炼句' in title: SentenceEnhance().play_sentence_enhance_game(num, exam_json) elif '听音连句' in title: ListenSentence().play_listen_sentence_game(num, exam_json) elif '句型转换' in title: ExamSentenceExchange().play_sentence_exchange_game(num, exam_json) elif '完形填空' in title: ClozeTest().play_cloze_test_game(num, exam_json) elif '选词填空' in title: BlankCloze().play_bank_cloze_game(num, exam_json) elif '补全文章' in title: CompleteText().play_complete_article_game(num, exam_json) elif '阅读理解' in title: ReadUnderstand().play_read_understand_game(num, exam_json) else: pass
class ResignExamPage(WebHomePage): wait = WaitElement() @teststep def wait_check_home_page(self): """首页页面检查点""" time.sleep(2) locator = (By.XPATH, '//*[text()=" 创建班级"]') self.wait.wait_check_element(locator) def wait_check_mine_item_pool_page(self): """我的题库页面检查点""" time.sleep(3) locator = (By.XPATH, '//*[text()="我的"]') self.wait.wait_check_element(locator) def wait_check_exam_tab_page(self): """试卷页面""" time.sleep(2) locator = (By.XPATH, '//*[text()="卷子名称"]') self.wait.wait_check_element(locator) def wait_check_mine_exam_page(self): """我的试卷页面检查点""" time.sleep(2) locator = (By.XPATH, '//*[text()="我的自创"]') self.wait.wait_check_element(locator) def wait_check_exam_detail_page(self): """试卷详情页面检查点""" time.sleep(2) locator = (By.XPATH, '//*[text()="开始答卷"]') self.wait.wait_check_element(locator) def wait_check_delete_tip_page(self): """删除作业提示页面检查点""" locator = (By.CLASS_NAME, 'el-message-box__content') self.wait.wait_check_element(locator) def wait_check_publish_tip_page(self): """删除作业提示页面检查点""" time.sleep(2) locator = (By.XPATH, '//*[contains(text(),"试卷为【提分版】功能")]') self.wait.wait_check_element(locator) def wait_check_assign_page(self): """布置试卷页面检查点""" time.sleep(2) locator = (By.XPATH, '//*[contains(text(),"考试信息")]') self.wait.wait_check_element(locator) def logo(self): """logo""" locator = (By.ID, 'logo') return self.wait.wait_find_element(locator) def exam_label(self): """试卷""" locator = (By.CSS_SELECTOR, '.head-banner-container .tab-group .tab') return self.wait.wait_find_elements(locator)[-1] def mine_label(self): """我的""" locator = (By.CSS_SELECTOR, '.head-bottom-nav .page-container a') return self.wait.wait_find_elements(locator)[-1] def exam_list(self): """试卷列表""" locator = (By.CSS_SELECTOR, '.page-content-container .testbank-list tbody tr') return self.wait.wait_find_elements(locator) def exam_name(self, ele): """试卷名称""" name = ele.find_element_by_xpath('./td[1]/div/span') print('\n布置试卷:', name.text) return name def delete_btn(self): """删除试卷""" locator = (By.CSS_SELECTOR, '.test-detail .controls button:nth-child(4)') return self.wait.wait_find_element(locator) def publish_confirm_btn(self): """发布试卷确定按钮""" locator = (By.CSS_SELECTOR, '.dialog-footer .el-button--primary') return self.wait.wait_find_element(locator) def delete_confirm_btn(self): """删除提示信息确定按钮""" locator = (By.CSS_SELECTOR, '.el-message-box__btns .el-button--primary') return self.wait.wait_find_element(locator) def assign_exam_btn(self): """布置试卷""" locator = (By.CSS_SELECTOR, '.test-detail .controls button:nth-child(2)') return self.wait.wait_find_element(locator) def student_card(self): """学生列表""" locator = (By.CSS_SELECTOR, '.student-card') return self.wait.wait_find_elements(locator) def vanclass_label(self): """班级标签""" locator = (By.CSS_SELECTOR, '.choose-students li span.name') return self.wait.wait_find_elements(locator) def publish_btn(self): """发布试卷按钮""" locator = (By.CSS_SELECTOR, '.head-banner-container button') return self.wait.wait_find_element(locator) def reassign_exam_operate(self): LoginWebPage().login_operate(TeacherAccount.Account[-1][0], TeacherAccount.Account[-1][1]) # 登陆操作 if self.wait_check_home_page(): # 进入我的试卷 self.mine_bank_pool().click() if self.wait_check_mine_item_pool_page(): self.mine_label().click() time.sleep(3) self.exam_label().click() time.sleep(3) while True: # 若试题>4, 则删除多余部分, 若等于4 ,则随机布置一个试卷 if len(self.exam_list()) <= 5: random_index = random.randint(0, 3) self.exam_name(random_index).click() if self.wait_check_exam_detail_page(): self.assign_exam_btn().click() # 布置试卷 if self.wait_check_assign_page(): vanclass_label = self.vanclass_label( ) # 选择MVP班级所有学生 for x in vanclass_label: if x.text == 'MVP': x.click() break time.sleep(2) self.publish_btn().click() # 发布试卷 if self.wait_check_publish_tip_page(): self.driver.execute_script( "document.getElementsByClassName('dialog-footer').item(0)" ".getElementsByTagName('button').item(1).click()" ) time.sleep(3) break else: delete_name = self.exam_name(self.exam_list()[0]) print("删除试卷:", delete_name.text) delete_name.click() if self.wait_check_exam_detail_page(): self.delete_btn().click() # 删除试卷 time.sleep(2) if self.wait_check_delete_tip_page(): self.driver.execute_script( "document.getElementsByClassName('el-message-box__btns').item(0)" ".getElementsByTagName('button').item(1).click()" ) time.sleep(3)
class PixelPage(BasePage): """Pixel 8.1""" wait = WaitElement() # 拍照 @teststep def wait_check_camera_page(self): """选择图片 的为依据""" locator = (By.ID, "com.google.android.GoogleCamera:id/camera_switch_button") return self.wait.wait_check_element(locator) # 第一页面 @teststep def click_retake_button(self): """相机'切换前置后置摄像头'按钮""" print('切换前置后置摄像头') locator = (By.ID, "com.google.android.GoogleCamera:id/camera_switch_button") self.wait.wait_find_element(locator).click() @teststep def click_camera_button(self): """以相机拍照按钮""" print('点击 拍照按钮') locator = (By.ID, "com.google.android.GoogleCamera:id/center_placeholder") self.wait.wait_find_element(locator).click() @teststep def cancel_button(self): """以相机 左上角 取消按钮""" print('点击 取消按钮') locator = (By.CLASS_NAME, "android.view.View") self.wait.wait_find_elements(locator)[1].click() # 第二页面 @teststeps def wait_check_retake_page(self, var=10): """以 “”的resource-id为依据""" locator = (By.ID, "com.google.android.GoogleCamera:id/retake_button") return self.wait.wait_check_element(locator) @teststep def click_done_button(self): """相机'完成'按钮""" print('点击 完成按钮') self.driver \ .find_element_by_id("com.google.android.GoogleCamera:id/shutter_button") \ .click() @teststep def click_retake_button(self): """相机'retake'按钮""" print('点击 重拍按钮') self.driver \ .find_element_by_id("com.google.android.GoogleCamera:id/retake_button") \ .click() # 相册 @teststep def wait_check_album_page(self, var=10): """相册 的resource-id为依据""" locator = (By.ID, "com.google.android.apps.photos:id/title") try: WebDriverWait(self.driver, var, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def open_album(self): """打开 第二个相册""" print('选择相册') self.driver \ .find_elements_by_id("com.google.android.apps.photos:id/title")[2] \ .click() @teststep def wait_check_picture_page(self): """图片 的class_name为依据""" locator = (By.CLASS_NAME, "android.view.ViewGroup") try: WebDriverWait(self.driver, 10, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False # 权限询问页面 @teststep def wait_check_permission_page(self): """ 的id为依据""" locator = (By.ID, "com.android.packageinstaller:id/permission_message") try: WebDriverWait(self.driver, 5, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def permission_allow_button(self): """允许 按钮""" self.driver \ .find_element_by_id("com.android.packageinstaller:id/permission_allow_button") \ .click()
def __init__(self): super().__init__() self.data = WordDataHandlePage() self.public = WorldBookPublicPage() self.wait = WaitElement() self.data_dir = 'app/honor/student/word_book_rebuild/test_data/'
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 ProgressPage(BasePage): def __init__(self): self.common = WordDataHandlePage() self.wait = WaitElement() @teststep def wait_check_progress_page(self): locator = (By.XPATH, "//android.widget.TextView[contains(@text,'单词本进度')]") return self.wait.wait_check_element(locator) @teststep def wait_check_sys_label_page(self): locator = (By.XPATH, "//android.widget.TextView[contains(@text,'{}')]".format( '三年级 (系统)')) return self.wait.wait_check_element(locator) @teststep def word_progress_icon(self): """词书进度""" locator = (By.ID, self.id_type() + 'word_statistics') self.wait.wait_find_element(locator).click() @teststep def first_turn(self): """一轮""" locator = (By.ID, self.id_type() + 'first_time') ele = self.wait.wait_find_element(locator) print(ele.text, end=',') @teststep def third_turn(self): """三轮""" locator = (By.ID, self.id_type() + 'three_time') ele = self.wait.wait_find_element(locator) print(ele.text, end=',') @teststep def total(self): """总数""" locator = (By.ID, self.id_type() + 'total') ele = self.wait.wait_find_element(locator) print(ele.text) @teststep def label_name(self): """标签名称""" locator = (By.ID, self.id_type() + 'name') return self.wait.wait_find_element(locator) @teststep def word_statistics(self, name): """单词数据""" locator = ( By.XPATH, "//android.widget.TextView[contains(@text,'{}')]/following-sibling::" "android.widget.TextView".format(name)) return self.wait.wait_find_element(locator).text @teststep def find_pencil_icon(self): try: self.driver.find_element_by_id(self.id_type() + 'img') return True except: return False @teststep def get_word_homework_names(self, stu_id): """获取标签名称""" word_homework_id = self.common.get_all_word_homework_ids(stu_id) word_homework_names = [ self.common.get_word_homework_name(x) for x in word_homework_id ] return word_homework_names @teststep def progress_ele_check(self, stu_id): """页面元素打印""" print("\n----<词书进度页面>----\n") self.first_turn() # 一轮 self.third_turn() # 三轮 self.total() # 总数 label_name = self.get_word_homework_names(stu_id) # 数据库标签名称 label_info = collections.OrderedDict() while True: labels = self.label_name() # 页面标签名 for l in labels: statics = self.word_statistics(l.text) label_info[l.text] = statics if self.wait_check_sys_label_page(): break else: self.screen_swipe_down(0.5, 0.9, 0.5, 2000) self.judge_studying_icon(list(label_info.keys()), label_name) # 进行中 词书判断 sys_labels = [x for x in list(label_info.keys()) if '系统' in x] no_revoke_sys_label = [x for x in sys_labels if '已撤销' not in x] if len(no_revoke_sys_label) != 0: if len(no_revoke_sys_label) != 1: print('❌❌❌ Error-- 有多个系统词书存在,未被撤销词书数量不为1', no_revoke_sys_label) key_list = list( map(lambda x: x[:-7] if '进行中' in x else x, list(label_info.keys()))) word_book_list = list( map(lambda x: x[:-4] if '已撤销' in x else x, key_list)) label_name.sort() word_book_list.sort() if label_name == word_book_list: print("词书标签与数据库一致") for label in list(label_info.keys()): word_data = label_info[label] count = re.findall(r'\d+', word_data) print(label, '\t', word_data) print('一轮单词数:', count[1], ' 三轮单词数:', count[0], ' 单词总数:', count[2], '\n') if '进行中' in label: homework_name = label[:-7] elif '已撤销' in label: homework_name = label[:-4] else: homework_name = label homework_id = self.common.get_word_homework_id_by_name( homework_name) label_id = self.common.get_student_label_id_by_homework_id( stu_id, homework_id) word_list = self.common.get_wordbank_by_label_id(label_id) if int(count[2]) == len(word_list): print('单词总数数验证正确') else: print('❌❌❌ Error-- 总数与数据库数据不匹配', count[2]) self.count_compare(stu_id, homework_id, int(count[1]), int(count[0])) else: print('❌❌❌ Error-- 词书标签与数据库不一致', word_book_list) @teststep def count_compare(self, stu_id, word_homework_id, first_count, third_count): """获取对应熟练度的单词数,并与页面数字比较""" count = self.common.get_words_count(stu_id, word_homework_id) # 返回单词id 与单词熟练度 if count[0] == first_count: print('一轮单词数验证正确') else: print('❌❌❌ Error-- 一轮单词数与数据库不匹配') if count[1] == third_count: print('三轮单词数验证正确') else: print('❌❌❌ Error-- 三轮单词数与数据库不匹配') print('----------------------------------\n') @teststep def judge_studying_icon(self, label_info_keys, label_name): doing_word_book = [x for x in label_info_keys if '进行中' in x] if len(doing_word_book) == 1: if doing_word_book[0][:-7] == label_name[-1]: print('正在练习的词书核实正确', doing_word_book[0][:-7], '\n') else: print('❌❌❌ Error-- 正在练习的词书与数据库不一致!', label_name[-1], '\n') else: print('❌❌❌ Error-- 正在练习的词书与不止一个!', doing_word_book, '\n')
class RankingPage(BasePage): """单词本 - 排行榜""" def __init__(self): self.home = HomePage() self.wait = WaitElement() @teststeps def wait_check_rank_page(self): """以“学生测试版”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'学生测试版')]") return self.wait.wait_check_element(locator) @teststep def total(self): locator = (By.ID, self.id_type() + 'total') ele = self.wait.wait_find_element(locator) return ele.text @teststep def click_rank_icon(self): """点击排行榜图标""" locator = (By.ID, self.id_type() + 'rank') self.wait.wait_find_element(locator).click() @teststep def choose_class(self): """班级展示 及切换""" locator = (By.ID, "android:id/text1") self.wait.wait_find_element(locator).click() time.sleep(2) @teststep def classes_ele(self): """班级展示 及切换""" locator = (By.ID, "android:id/text1") return self.wait.wait_find_elements(locator) @teststep def word_num(self): """单词数""" locator = (By.ID, self.id_type() + "tv_score") ele = self.wait.wait_find_element(locator) return ele.text @teststep def word_type(self): """wording:词""" locator = (By.ID, self.id_type() + "type") ele = self.wait.wait_find_element(locator) return ele.text @teststep def share_button(self): """炫耀一下""" locator = (By.ID, self.id_type() + "share") self.wait.wait_find_element(locator).click() @teststep def rank_num(self): """班级排名""" locator = (By.ID, self.id_type() + "tv_ranking") ele = self.wait.wait_find_element(locator) return ele.text @teststep def order_num(self): """排名 数字""" locator = (By.ID, self.id_type() + "tv_order") return self.wait.wait_find_elements(locator) @teststep def st_icon(self): """头像""" locator = (By.ID, self.id_type() + "iv_head") return self.wait.wait_find_elements(locator) @teststep def st_name(self): """学生姓名""" locator = (By.ID, self.id_type() + "tv_name") return self.wait.wait_find_elements(locator) @teststep def st_score(self): """提示title""" locator = (By.ID, self.id_type() + "tv_score") return self.wait.wait_find_elements(locator) @teststep def students_name(self): """排行榜里学生名称""" locator = (By.XPATH, '//android.widget.RelativeLayout/android.widget.TextView' '[contains(@resource-id, "{}tv_name")]'.format( self.id_type())) return self.wait.wait_find_elements(locator) @teststep def students_score(self): """排行榜中学生背的单词数""" locator = (By.XPATH, '//android.widget.RelativeLayout/android.widget.TextView' '[contains(@resource-id,"{}tv_score")]'.format( self.id_type())) return self.wait.wait_find_elements(locator) # 炫耀一下 @teststeps def wait_check_share_page(self): """以“title: 炫耀一下”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'炫耀一下')]") return self.wait.wait_check_element(locator) @teststep def play_rank_word(self, total_word): print('排行榜 页面\n') self.choose_class() time.sleep(2) classes = self.classes_ele() for i in range(len(classes)): stu_class = self.classes_ele()[i].text self.classes_ele()[i].click() time.sleep(3) self.ele_operate(stu_class, total_word) if i != len(classes) - 1: self.choose_class() else: print('排行榜浏览结束') WordBookRebuildPage().click_back_up_button() @teststep def ele_operate(self, stu_class, total_word): word_type = self.word_type() class_rank = self.rank_num() print('当前所在班级:', stu_class) score = self.st_score()[0].text print('已背:', score + word_type) if int(score) != int(total_word): print('❌❌❌ Error - 次数与主页面单词数不一致!') else: print('单词数核实一致!') print('当前班级排名:', class_rank) self.share_button() if self.wait_check_share_page(): self.home.click_back_up_button() if self.wait_check_rank_page(): self.rank_numbers_info() def get_student_rank_info(self, students_info, i): student_names = self.students_name() student_scores = self.students_score() order = self.order_num() for j in range(len(student_names)): if i == 0: if j <= 2: if order[i].text != '': print('❌❌❌ Error - 名次位于第三名没有小皇冠标识') if student_names[j].text in students_info.keys(): continue else: students_info[student_names[j].text] = student_scores[j].text return students_info @teststep def rank_numbers_info(self): students_info = {} student_names = self.students_name() if len(student_names) >= 6: for i in range(2): students_info = self.get_student_rank_info(students_info, i) self.home.screen_swipe_up(0.5, 0.8, 0.3, 1000) else: self.get_student_rank_info(students_info, i=0) self.home.screen_swipe_down(0.5, 0.2, 0.9, 1000) print("\n排行榜情况如下(只显示班级前10名 + 自己的名次)") for name in students_info.keys(): score = students_info[name] print(name, '\t', score) time.sleep(3) print('----------------------------------')
class HomePage(BasePage): """app主页面元素信息""" wait = WaitElement() @teststeps def wait_check_home_page(self, is_raise=False): """以“做试卷”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'做试卷')]") return self.wait.wait_check_element(locator, timeout=10) @teststeps def wait_check_expert_page(self): """以“做试卷”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'通知')]") return self.wait.wait_check_element(locator) @teststeps def wait_check_word_title(self): """将'单词本'作为 单词本首页 页面检查点""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'单词本')]") return self.wait.wait_check_element(locator) @teststep def click_hk_tab(self, index): """以“口语练习、做单词、做习题、做试卷” 的id""" locator = (By.ID, self.id_type() + 'notice') self.wait.wait_find_elements(locator)[index - 1].click() @teststep def homework(self): """以“口语、作业或者试卷列表内条目”的id为依据""" locator = (By.ID, self.id_type() + 'tv_homework_name') return self.wait.wait_find_elements(locator) @teststeps def end_judge(self): """元素:到底啦 下拉刷新试试""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'到底啦 下拉刷新试试')]") return self.wait.wait_check_element(locator) # 关于图书馆的定位 @teststep def wait_check_recommend_more_btn_page(self): """推荐栏的发现更多按钮""" locator = ( By.XPATH, "//*[@text='推荐']/following-sibling::android.widget.TextView") return self.wait.wait_check_element(locator) @teststep def wait_check_mine_more_btn_page(self): """推荐栏的发现更多按钮""" locator = ( By.XPATH, "//*[@text='我的阅读']/following-sibling::android.widget.TextView") return self.wait.wait_check_element(locator) @teststep def check_more(self): """查看更多""" locator = (By.ID, self.id_type() + 'more') return self.wait.wait_find_elements(locator) @teststep def home_school_name(self): """主页学校名称""" ele = self.driver.find_element_by_id(self.id_type() + 'common_toolbar') ele_child = ele.find_elements_by_xpath('.//android.widget.TextView') return ele_child[0].text.split('•')[1] @teststep def tab_books(self, tab_name): """推荐书籍""" locator = ( By.XPATH, '//*[@text="{}"]/../following-sibling::android.widget.FrameLayout/' 'android.widget.LinearLayout/android.widget.LinearLayout'.format( tab_name)) ele = self.wait.wait_find_elements(locator) text = [ x.find_element_by_xpath('.//android.widget.TextView').text for x in ele ] return text # 公共元素- 底部四个tab元素:作业、试卷、个人中心、图书馆 @teststep def click_tab_library(self): """下方图书馆Tab""" locator = (By.ID, self.id_type() + 'tab_lib_icon') self.wait.wait_find_element(locator).click() @teststep def click_tab_hw(self): """以“学习tab”的id为依据""" locator = (By.ID, self.id_type() + 'tab_hw_icon') self.wait.wait_find_element(locator).click() @teststep def click_test_vanclass(self): """以“班级tab”的id为依据""" locator = (By.ID, self.id_type() + 'tab_class_icon') self.wait.wait_find_element(locator).click() @teststep def click_tab_profile(self): """以“个人中心tab”的id为依据""" locator = (By.ID, self.id_type() + 'tab_profile') self.wait.wait_find_element(locator).click() @teststep def click_back_up_button(self): """以“返回按钮”的class name为依据""" locator = (By.ACCESSIBILITY_ID, "转到上一层级") self.wait.wait_find_element(locator).click() @teststeps def all_element(self): """页面内所有class name为android.widget.TextView的元素""" locator = (By.CLASS_NAME, "android.widget.TextView") return self.wait.wait_find_elements(locator) # 温馨提示 页面 @teststeps def wait_check_tips_page(self, var=10): """以“icon”为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id," "'{}md_title')]".format(self.id_type())) return self.wait.wait_check_element(locator) @teststep def tips_title(self): """温馨提示title""" locator = (By.ID, self.id_type() + 'md_title') return self.wait.wait_find_element(locator).text @teststep def tips_content(self): """温馨提示 具体内容""" locator = (By.ID, self.id_type() + 'md_content') return self.wait.wait_find_element(locator).text @teststep def input(self): """输入框""" locator = (By.ID, "android:id/input") return self.wait.wait_find_element(locator) @teststep def cancel_button(self): """取消 按钮""" locator = (By.ID, self.id_type() + "md_buttonDefaultNegative") self.wait.wait_find_element(locator).click() @teststep def commit_button(self): """确定 按钮""" locator = (By.ID, self.id_type() + "md_buttonDefaultPositive") self.wait.wait_find_element(locator).click() @teststep def commit(self): """确定 按钮""" locator = (By.ID, self.id_type() + "md_buttonDefaultPositive") return self.wait.wait_find_element(locator) @teststeps def wait_activity(self): """获取当前页面activity""" self.driver.implicitly_wait(2) activity = self.driver.current_activity return activity @teststeps def homework_count(self): """获取作业title列表第一个页面的作业 """ homework_list = self.homework() homework_title = [x.text for x in homework_list] # 获取作业title列表 return homework_title, homework_list @teststeps def homework_count_2(self): """获取作业title列表非第一页的作业 及 页面内最后一个作业的title 以及 元素 '到底啦 下拉刷新试试' """ homework_title = [] homework_list = self.homework() for i in range(0, len(homework_list)): homework_title.append(homework_list[i].text) # 获取作业title列表 # print(len(homework_title), len(homework_list)) item = homework_list[len(homework_list) - 1].text # 最后一个作业的title tips = self.end_judge() # 判断元素 '到底啦 下拉刷新试试' 是否存在 # print('tips:', tips) return tips, item, homework_title, homework_list @teststeps def swipe_operate(self, var, homework, game): """滑屏 操作""" print('----------------------') if len(var) == 10: last_one = var[len(var) - 2] # 滑动前页面内最后一个作业title else: last_one = var[len(var) - 1] # 滑动前页面内最后一个作业title self.screen_swipe_up(0.5, 0.75, 0.25, 1000) item = self.homework_count_2() if item[0] is True: # 滑到底部 print('滑动后到底部') index = [] for i in range(0, len(item[2])): if item[2][i] == last_one: index.append(i) break count = self.homework_exist(index[0] + 1, item[2], item[3], homework, game) return count else: # print('滑动后未到底部') if last_one in item[2]: index_2 = [] for j in range(0, len(item[2])): if item[2][j] == last_one: index_2.append(j) count = self.homework_exist(index_2[0] + 1, item[2], item[3], homework, game) else: count = self.homework_exist(0, item[2], item[3], homework, game) if len(count) == 0: return self.swipe_operate(item[2], homework, game) else: return count @teststeps def homework_exist(self, index, title, homework, item, game): """判断该作业是否存在 -- 若存在,统计小游戏的个数""" homework_count = [] result = [] for ind in range(index, len(title)): if title[ind] == item: homework_count.append(ind) break # print('homework_count:', homework_count) if len(homework_count) != 0: for i in homework_count: homework[i].click() result.append(Homework().games_count(0, game, item)[0]) else: print('no have该作业') return result @teststeps def tips_operate_commit(self): """温馨提示 页面信息 -- 确定""" if self.wait_check_tips_page(): # 温馨提示 页面 print('--------------------------') self.tips_title() self.tips_content() self.commit_button() # 确定按钮 print('--------------------------') @teststeps def tips_operate_cancel(self): """温馨提示 页面信息 -- 取消""" if self.wait_check_tips_page(): # 温馨提示 页面 print('--------------------------') self.tips_title() self.tips_content() self.cancel_button() # 取消按钮 print('--------------------------')
def __init__(self): self.home = HomePage() self.wait = WaitElement()