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)
Exemple #2
0
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')
Exemple #3
0
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 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('----------------------------------')
Exemple #5
0
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()
Exemple #6
0
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('返回主界面')
Exemple #7
0
class WordTestPage(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.sql_handler = WordTestSqlHandler()
        self.spell = SpellWordGame()
        self.wait = WaitElement()

    @teststep
    def wait_check_no_test_word_page(self):
        """测试次数不足页面检查点"""
        locator = (By.XPATH, '//android.widget.Button[contains(@text,"确定")]')
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_start_test_page(self):
        """开始测试页面检查点"""
        locator = (By.XPATH, '//android.widget.Button[contains(@text,"开始复习")]')
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_preview_word_page(self):
        """单词预览页面检查点"""
        locator = (By.ID, self.id_type() + "start")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_select_word_count_page(self):
        """单词测试数页面检查点"""
        locator = (By.ID, self.id_type() + "num_hint")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_test_game_page(self):
        """单词测试游戏页面检查点"""
        locator = (By.ID, self.id_type() + "time")
        return self.wait.wait_check_element(locator)

    @teststep
    def word_count_select_tab(self):
        """单词测试数选项"""
        locator = (
            By.XPATH,
            '//android.support.v7.widget.RecyclerView[contains(@resource-id, "test_num_container")]/'
            'android.view.ViewGroup/android.widget.TextView')
        return self.wait.wait_find_elements(locator)

    @teststep
    def word_test_type(self):
        """测试类型"""
        locator = (
            By.XPATH,
            "//android.support.v7.widget.RecyclerView[contains(@resource-id, 'test_type_container')]/"
            "android.view.ViewGroup/android.widget.TextView")
        return self.wait.wait_find_elements(locator)

    @teststep
    def click_word_test_tab(self):
        """点击单词测试按钮"""
        locator = (By.ID, self.id_type() + "word_test")
        self.wait.wait_find_element(locator).click()

    @teststep
    def click_confirm_btn(self):
        """点击复习或者确定按钮"""
        locator = (By.ID, self.id_type() + "next")
        self.wait.wait_find_element(locator).click()

    @teststep
    def click_start_test_btn(self):
        """点击开始测试按钮"""
        locator = (By.ID, self.id_type() + "start")
        self.wait.wait_find_element(locator).click()

    @teststep
    def preview_explain(self):
        """预览单词"""
        locator = (By.ID, self.id_type() + "explain")
        return self.wait.wait_find_elements(locator)

    @teststep
    def preview_voice_icon(self, explain):
        """预览单词喇叭图标"""
        locator = (By.XPATH,
                   '//android.widget.TextView[@text="{}"]/preceding-sibling'
                   '::android.widget.ImageView'.format(explain))
        return self.wait.wait_find_element(locator)

    @teststep
    def preview_word(self, explain):
        """预览单词解释"""
        locator = (By.XPATH,
                   '//android.widget.TextView[@text="{}"]/preceding-sibling::'
                   'android.widget.TextView[contains(@resource-id,"word")]'.
                   format(explain))
        return self.wait.wait_find_element(locator)

    @teststep
    def test_select_page_operate(self, tab_index):
        """单词测试数页面操作过程"""
        if self.wait_check_select_word_count_page():
            select_tab = self.word_count_select_tab()
            test_type = self.word_test_type()
            for x in select_tab:
                if '50' in x.text:
                    if x.get_attribute('selected') != 'true':
                        self.base_assert.except_error('单词个数没有默认选择50')
                    break

            if test_type[0].get_attribute("selected") != "true":
                self.base_assert.except_error("默写类型没有被选中")

            test_count = int(select_tab[tab_index].text)
            print('test_count:', test_count)
            if test_count is None:
                self.base_assert.except_error('未获取单词个数')

            select_tab[tab_index].click()
            self.click_confirm_btn()
            return test_count

    @teststep
    def get_test_word_list(self, fvalue_glt_3_words, test_fail_words,
                           test_pass_words, tab_index):
        """获取测试单词数
            :param fvalue_glt_3_words: 未测且F值大于3的单词
            :param test_fail_words:  测试失败单词
            :param test_pass_words: 测试通过单词
            :param tab_index: 选择题目个数
        """
        # 测试数量小于未测单词数   取未测单词数[:测试数量]
        # 测试数量大于未测单词数  需补充测试未通过单词 获取补充数量 测试数-未测单词数
        # 若补充数小于测试未通过数, 去补充数,测试单词未未测+未通过[:补充]
        # 若补充数大于测试未通过单词数,需补充测试通过单词 获取补充数量2 补充数 - 未通过单词
        # 若补充数量2小于测试通过单词数, 测试数为  未测 + 未通过 + 通过[:补充数量2]
        # 若补充数量2大于测试通过单词数, 测试数为  未测 + 未通过 + 通过

        test_count = self.test_select_page_operate(tab_index)
        dcg_value = test_count - len(fvalue_glt_3_words)
        if dcg_value <= 0:
            test_word_list = dict_slice(fvalue_glt_3_words, end=test_count)
        else:
            test_word_list = fvalue_glt_3_words
            if dcg_value <= len(test_fail_words):
                fail_words = dict_slice(test_fail_words, end=dcg_value)
                test_word_list.update(fail_words)
            else:
                test_word_list.update(test_fail_words)
                ddf_value = dcg_value - len(test_pass_words)
                if ddf_value <= 0:
                    pass_words = dict_slice(test_pass_words, end=dcg_value)
                else:
                    pass_words = test_pass_words
                test_word_list.update(pass_words)
        return test_word_list if test_word_list else {}

    @teststeps
    def check_preview_word_operate(self, test_word_info):
        """预览单词校验操作"""
        # 循环遍历单词与解释,对比已获得的测试单词,判断是否在测试列表中,解释是否合并或者相同
        test_answer = {}
        word_id_list = []
        if self.wait_check_preview_word_page():
            explain_list = []
            while len(explain_list) < len(test_word_info):
                if self.wait_check_preview_word_page():
                    preview_explain = self.preview_explain()
                    for i, x in enumerate(preview_explain):
                        if x.text in explain_list:
                            continue
                        else:
                            word = self.preview_word(x.text)
                            word_id = word.get_attribute('contentDescription')
                            word_id_list.append(word_id)
                            explain_list.append(x.text)
                            test_answer[x.text] = word.text

                            if word_id not in list(test_word_info.keys()):
                                self.base_assert.except_error(
                                    '此单词不在测试单词列表内, 但是出现在预览列表中 ' + word_id)
                            else:
                                explain_info = test_word_info[word_id]
                                query_explains = self.sql_handler.get_word_explain_list(
                                    explain_info)
                                page_explain_list = x.text.split(';')
                                page_explain_list.sort()
                                query_explains.sort()
                                if query_explains != page_explain_list:
                                    self.base_assert.except_error(
                                        "页面单词不等于单词解释集合 " + word_id)

                                voice_icon = self.preview_voice_icon(x.text)
                                voice_icon.click()
                self.screen_swipe_up(0.5, 0.9, 0.45, 1000)
            print('页面单词id列表, ', word_id_list)
        return test_answer, word_id_list

    @teststeps
    def play_test_word_spell_operate(self,
                                     test_count,
                                     test_answer,
                                     do_pass,
                                     no_wrong=False):
        """单词默写游戏过程
           :param no_wrong: 是否做全对
           :param test_count: 测试单词个数
           :param test_answer: 预览时记录的答案
           :param do_pass: 测试是否达到90%
        """
        if self.wait_check_test_game_page():
            game_count = self.spell.rest_bank_num()
            if test_count != game_count:
                self.base_assert.except_error("默写数量与测试单词数不一致")

            if no_wrong:
                wrong_count = 0
            else:
                if do_pass:
                    wrong_count = floor(game_count * 0.1)
                else:
                    wrong_count = floor(game_count * 0.1) + 2

            timer = []
            game_word_id_list = []
            wrong_index = list(range(wrong_count))
            for x in range(game_count):
                self.spell.next_btn_judge(
                    'false', self.spell.fab_commit_btn)  # 判断下一题按钮状态
                self.spell.rate_judge(game_count, x)  # 校验剩余题数
                explain = self.spell.word_explain().text
                print('解释:', explain)

                if x in wrong_index:
                    self.spell.word_spell_play_process(game_mode=1)
                    self.spell.next_btn_operate("true",
                                                self.spell.fab_commit_btn)
                    if not self.spell.wait_check_right_answer_page():
                        self.base_assert.except_error("拼写单词错误,提交后未显示正确答案" +
                                                      explain)
                    else:
                        print("正确答案:", self.spell.right_answer_word())
                else:
                    right_answer = test_answer[explain]
                    self.spell.word_spell_play_process(
                        game_mode=1, do_right=True, right_answer=right_answer)
                    self.spell.next_btn_operate("true",
                                                self.spell.fab_commit_btn)
                    print('正确答案:', right_answer)

                mine_input_word = self.spell.spell_word()
                word_id = mine_input_word.get_attribute('contentDescription')
                game_word_id_list.append(word_id)
                print('输入答案:', mine_input_word.text[::2])
                timer.append(self.spell.bank_time())

                self.spell.click_voice()
                self.spell.fab_next_btn().click()
                print('-' * 30, '\n')
            self.spell.judge_timer(timer)  # 时间校验
            return wrong_count, game_word_id_list