Пример #1
0
    def exam_operate(self, do_right, half_exit, mine_answer_info):
        if self.wait_check_exam_page():
            self.answer_card_icon().click()
        if self.wait_check_answer_card_page():
            bank_numbers = self.exam_bank_num()
            for x in range(len(bank_numbers)):
                if half_exit:
                    if x == 1:
                        self.exit_icon().click()
                        time.sleep(1)
                        break

                is_blank = False
                bank_numbers[x].click()
                if self.wait_check_exam_page():
                    game_container = self.game_container()
                    bank_id = self.bank_id()
                    print('题目id:', bank_id)
                    right_answer = PassionSQLHandle().get_ques_right_answer(bank_id)
                    print('正确答案:', right_answer)
                    mine_answer = 0
                    if game_container == 'dx-container':
                        mine_answer = SingleChoiceGame().single_choice_do_process(do_right=do_right, right_answer=right_answer)
                    elif game_container == 'bq-container':
                        is_blank = True
                        mine_answer = FillBlankGame().fill_blank_process(counter=2, do_right=do_right, right_answer=right_answer)
                    print('我的答案:', mine_answer)
                    mine_answer_info[bank_id] = mine_answer
                    self.answer_card_icon().click()
                    time.sleep(2)
                if self.wait_check_answer_card_page():
                    if 'filled' not in self.exam_bank_num()[x].get_attribute('class'):
                        self.base_assert.except_error('该题已做完, 但是答题卡页面显示未完成')
                    if is_blank:
                        if not do_right:
                            if 'success' in self.exam_bank_num()[x].get_attribute('class'):
                                self.base_assert.except_error('该填空题未做全对, 但是结果页显示正确')

                print('-'*30, '\n')
            if not half_exit:
                self.submit_btn().click()
                self.alert_tip_operate()
    def section_single_choice_operate(self, all_do_right, answer_info=None, is_half_exit=False, bank_count=None,
                                      interval_counter=None, wrong_counter=None, wrong_note=None,
                                      wrong_choice_info=None, do_one=False):
        """同步练习单选操作
            :param do_one: 是否只做一道题
            :param answer_info: 正确答案
            :param wrong_choice_info: 错题信息
            :param bank_count 单选总个数
            :param wrong_counter 错题错误次数
            :param interval_counter 间隔统计列表
            :param wrong_note 错题本记录
            :param is_half_exit 是否中途退出
            :param all_do_right 是否做全对
        """
        index, wrong_id = 0, 0
        exit_id = 0
        while self.wait_check_single_choice_page():
            bank_id = self.bank_id()
            question = self.question()
            print('题目id:', bank_id)
            print('问题:', question)
            if answer_info:
                right_answer = answer_info[bank_id]
            else:
                right_answer = PassionSQLHandle().get_ques_right_answer(bank_id)
            print('正确答案:', right_answer)
            if not all_do_right:
                if is_half_exit:
                    if index == 1:
                        exit_id = bank_id
                        self.exit_icon().click()
                        break
                if index == 0:
                    if wrong_choice_info:
                        wrong_id = list(wrong_choice_info.keys())[0]
                    else:
                        wrong_choice_info[bank_id] = []
                        wrong_id = bank_id

                if bank_count < 2:
                    interval_counter.append(('选择', bank_id))
                    self.single_choice_do_process(do_right=True, right_answer=right_answer)
                else:
                    if bank_id != wrong_id or wrong_counter[0] >= 2:
                        if bank_id == wrong_id:
                            wrong_note[bank_id] = (right_answer, 'dx')
                        interval_counter.append(('选择', bank_id))
                        self.single_choice_do_process(do_right=True, right_answer=right_answer)
                    else:
                        wrong_counter[0] += 1
                        self.single_choice_do_process(right_answer=right_answer)
                        interval_counter.append(('选择', bank_id))
            else:
                self.single_choice_do_process(do_right=True, right_answer=right_answer)
            self.next_btn().click()
            time.sleep(0.5)
            index += 1
            if self.wait_check_explain_page():
                print(self.section_select_explain())
            self.next_btn().click()
            time.sleep(1)
            print('-'*30, '\n')
            if do_one:
                break
        return exit_id
Пример #3
0
 def __init__(self):
     self.data = PassionSQLHandle()
Пример #4
0
class GameStudy(PassionCommonEle):
    """知识点识记"""
    def __init__(self):
        self.data = PassionSQLHandle()

    @teststep
    def wait_check_another_group_page(self):
        """再来一组页面检查点"""
        locator = (By.XPATH, '//p[contains(text(),"再来一组")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststep
    def wait_check_complete_knowledge_page(self):
        """完成知识点页面检查的点"""
        locator = (By.XPATH, '//p[contains(text(),"复习一遍")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststep
    def wait_check_complete_section_page(self):
        """小节练习完成页面检查点"""
        locator = (By.XPATH, '//p[contains(text(),"完成本节同步练习")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststep
    def wait_check_start_knowledge_page(self):
        """知识点开始页面检查点"""
        locator = (By.XPATH, '//p[contains(text(),"学习知识点")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststep
    def wait_check_start_section_page(self):
        """小节练习开始页面检查点"""
        locator = (By.XPATH, '//p[contains(text(),"完成本小节知识点")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststep
    def wait_check_complete_chapter_page(self):
        """小节练习开始页面检查点"""
        locator = (By.XPATH, '//p[contains(text(),"学完了本章知识点")]')
        return self.get_wait_check_page_result(locator, timeout=3)

    @teststeps
    def section_knowledge_operate(self,
                                  wrong_note,
                                  is_half_exit=False,
                                  do_right=False,
                                  is_order_study=False):  # 进入游戏过程
        right_answer, exit_text, = 0, 0
        wrong_blank_list = {}
        blank_wrong_counter = [0]
        interval_counter = []
        while self.wait_check_hk_wrap_page():
            attr = self.game_container()
            if attr == 'zsd-container':  # 闪卡练习
                right_answer = FlashGame().flash_game_operate()

            elif attr == 'xt-container':  # 补全文章
                CompleteTextGame().complete_text_operate(right_answer)

            elif attr == 'bq-container':  # 填空
                bank_count = len(list(right_answer.keys()))
                FillBlankGame().fill_blank_operate(
                    do_right,
                    bank_count=bank_count,
                    answer_info=right_answer,
                    interval_counter=interval_counter,
                    wrong_note=wrong_note,
                    wrong_counter=blank_wrong_counter,
                    wrong_bank_info=wrong_blank_list)

            if self.wait_check_another_group_page():
                if not is_order_study:
                    exit_text = self.start_text()
                print(self.start_text(), '\n')
                if is_half_exit:
                    self.exit_icon().click()
                    time.sleep(2)
                    break
                else:
                    self.click_start_button()
                    time.sleep(2)
                    self.section_knowledge_operate(
                        wrong_note,
                        is_half_exit=False,
                        do_right=do_right,
                        is_order_study=is_order_study)

            if not is_order_study:
                if self.wait_check_complete_knowledge_page():
                    print(self.start_text(), '\n')
                    self.exit_icon().click()
                    time.sleep(2)
                    break
            else:
                if self.wait_check_start_section_page():
                    exit_text = self.start_text()
                    print('=' * 10 + "同步练习提示" + '=' * 10, '\n')
                    print(exit_text, '\n')
                    self.exit_icon().click()
                    time.sleep(2)
                    break
        print('小节退出提示:', exit_text, '\n')
        return exit_text

    @teststeps
    def section_sync_operate(self,
                             wrong_note,
                             is_half_exit=False,
                             section_id=0,
                             do_right=False,
                             is_order_study=False):
        """同步练习操作"""
        dx_bank_count, tk_bank_count = 0, 0
        interval_counter = []
        dx_wrong_counter, tk_wrong_counter = [0], [0]
        wrong_bank_info, wrong_choice_info = {}, {}
        exit_id, exit_text = 0, 0
        if not is_order_study:
            dx_bank_count, tk_bank_count = self.data.get_section_sync_ques(
                section_id)
            print('该小节第一组单选总题数:', dx_bank_count)
            print('该小节第一组填空总题数:', tk_bank_count, '\n')

        while self.wait_check_hk_wrap_page():
            attr = self.game_container()
            if attr == 'dx-container':
                exit_id = SingleChoiceGame().\
                    section_single_choice_operate(all_do_right=do_right, is_half_exit=is_half_exit,
                                                  interval_counter=interval_counter, bank_count=dx_bank_count,
                                                  wrong_counter=dx_wrong_counter, wrong_note=wrong_note,
                                                  wrong_choice_info=wrong_choice_info)

            elif attr == 'bq-container':
                exit_id = FillBlankGame().fill_blank_operate(
                    all_do_right=do_right,
                    is_half_exit=is_half_exit,
                    bank_count=tk_bank_count,
                    interval_counter=interval_counter,
                    wrong_note=wrong_note,
                    wrong_counter=tk_wrong_counter,
                    wrong_bank_info=wrong_bank_info)

            if self.wait_check_complete_section_page():  # 新的一组开始学习
                print(self.start_text())
                self.exit_icon().click()
                time.sleep(2)
                break

            if is_order_study:
                if self.wait_check_start_knowledge_page(
                ) or self.wait_check_complete_chapter_page():
                    exit_text = self.start_text()
                    print(exit_text, '\n')
                    self.exit_icon().click()
                    time.sleep(2)
                    break
        if not do_right:
            print(interval_counter)
            self.interval_counter_check(interval_counter, dx_bank_count,
                                        tk_bank_count)
        return exit_id, exit_text

    @teststep
    def interval_counter_check(self, interval_counter, select_count,
                               blank_count):
        bank_type = [x[0] for x in interval_counter]
        bank_id = [x[1] for x in interval_counter]
        if select_count and blank_count:
            if select_count < 2:
                if blank_count > 1:
                    if bank_type != ['选择', '填空', '填空', '填空', '填空', '填空']:
                        self.base_assert.except_error(
                            '选择题数为1,填空题大于1,统计间隔与计算间隔不一致')
                elif blank_count == 1:
                    if bank_type != ['选择', '填空']:
                        self.base_assert.except_error(
                            '选择题数为1,填空题为1,统计间隔与计算间隔不一致')
            else:
                if blank_count == 1:
                    if bank_id[0] != bank_id[3]:
                        self.base_assert.except_error('错题间隔不正确')
                    if bank_type[2] != '填空':
                        self.base_assert.except_error('选择错题之间未发现填空题')
                else:
                    split_bank_id = bank_id[:7]
                    for i, x in enumerate(split_bank_id):
                        if i % 3 == 0:
                            if x != bank_id[0]:
                                self.base_assert.except_error(
                                    '错题间隔有误, 该题应为{}, 实际为{}'.format(
                                        bank_id[0], x))
                        if i % 3 == 2:
                            if bank_type[i] != '填空':
                                self.base_assert.except_error('选择错题间隔中未夹杂填空题')
    def fill_blank_operate(self,
                           all_do_right,
                           bank_count=0,
                           is_half_exit=False,
                           answer_info=None,
                           interval_counter=None,
                           wrong_note=None,
                           wrong_counter=None,
                           wrong_bank_info=None,
                           do_one=False):
        """填空题处理过程
            :param wrong_bank_info: 填空错题信息
            :param do_one: 是否只做一道题
            :param answer_info: 正确答案
            :param bank_count 单选总个数
            :param wrong_counter 错题错误次数
            :param interval_counter 间隔统计列表
            :param wrong_note 错题本记录
            :param is_half_exit 是否中途退出
            :param all_do_right 是否做全对
        """

        print('========= 填空游戏 =========\n')
        index, wrong_bank_id, exit_id = 0, 0, 0
        wrong_index = []
        while self.wait_check_fill_blank_page():
            bank_id = self.bank_id()
            if answer_info:
                right_answer = answer_info[bank_id]
            else:
                right_answer = PassionSQLHandle().get_ques_right_answer(
                    bank_id)
            print('题目id:', bank_id)
            print(self.blank_content())
            print('正确答案:', right_answer)
            if not all_do_right:
                if index == 0:
                    if wrong_bank_info:
                        wrong_bank_id = list(wrong_bank_info.keys())[0]
                    else:
                        wrong_bank_info[bank_id] = []
                        wrong_bank_id = bank_id

                if is_half_exit:
                    if index == 1:
                        exit_id = bank_id
                        self.exit_icon().click()
                        time.sleep(2)
                        break

                if bank_count < 2:
                    interval_counter.append(('填空', bank_id))
                    input_answer = self.fill_blank_process(
                        do_right=True, right_answer=right_answer)
                else:
                    if bank_id != wrong_bank_id or wrong_counter[0] >= 2:
                        if bank_id == wrong_bank_id:
                            wrong_note[bank_id] = (right_answer, 'tk')
                            interval_counter.append(('填空', bank_id))
                            mine_input_answer = wrong_bank_info[bank_id]
                            for i, x in enumerate(self.blank_input()):
                                if mine_input_answer[i].lower(
                                ) != right_answer[i].lower():
                                    if x.text:
                                        self.base_assert.except_error(
                                            '本填空未做对,但是再次进入此题填空不为空')
                                    x.click()
                                    x.send_keys(right_answer[i])
                                else:
                                    if x.text.lower() != right_answer[i].lower(
                                    ):
                                        self.base_assert.except_error(
                                            '本填空已做对, 但是再次进入填空上文本不是正确答案')
                            self.next_btn().click()
                            wrong_index.append(index)
                            input_answer = right_answer
                        else:
                            interval_counter.append(('填空', bank_id))
                            input_answer = self.fill_blank_process(
                                do_right=True, right_answer=right_answer)
                    else:
                        wrong_counter[0] += 1
                        interval_counter.append(('填空', bank_id))
                        input_answer = self.fill_blank_process(
                            counter=wrong_counter[0],
                            right_answer=right_answer)
                        wrong_bank_info[bank_id] = input_answer
                        wrong_index.append(index)
            else:
                input_answer = self.fill_blank_process(
                    do_right=True, right_answer=right_answer)
            print('我的答案:', input_answer)
            time.sleep(1)
            result_mine_answer = [
                x.text.split()[0] for x in self.blank_result()
            ]
            print('结果页我的答案:', result_mine_answer)
            if [
                    x for x, y in zip(input_answer, result_mine_answer)
                    if x.lower() != y.lower()
            ]:
                self.base_assert.except_error('输入答案与页面展示答案不一致')
            self.next_btn().click()
            time.sleep(1)
            index += 1
            print('-' * 30, '\n')
            if do_one:
                break
        return exit_id
Пример #6
0
class ChapterPage(CommonElePage):
    def __init__(self):
        self.data = PassionSQLHandle()

    @teststep
    def wait_chapter_page(self):
        """章节目录页面检查点"""
        locator = (By.CSS_SELECTOR, '.chapter-list')
        return self.get_wait_check_page_result(locator)

    @teststep
    def wait_check_chapter_video_page(self):
        """章节导学视频按钮页面检查点"""
        locator = (By.CSS_SELECTOR, '.video-entry')
        return self.get_wait_check_page_result(locator)

    @teststep
    def wait_check_video_page(self):
        """视频页面检查点"""
        locator = (By.CSS_SELECTOR, '.player')
        return self.get_wait_check_page_result(locator)

    @teststep
    def chapter_list(self):
        """章节目录列表"""
        ele = self.driver.find_elements_by_css_selector('.chapter-list li')
        return ele

    @teststep
    def chapter_finish_status(self):
        """章节完成列表"""
        ele = self.driver.find_element_by_css_selector(
            '.content .total div:nth-child(1) p:nth-child(1)')
        return ele.text.strip()

    @teststep
    def section_num(self):
        """小节个数"""
        ele = self.driver.find_element_by_css_selector(
            '.total p:nth-child(1) span')
        return int(ele.text)

    @teststep
    def knowledge_num(self):
        """知识点个数"""
        ele = self.driver.find_element_by_css_selector(
            '.total p:nth-child(2) span')
        return int(ele.text)

    @teststep
    def chapter_exam_score(self):
        """章考核分数"""
        ele = self.driver.find_element_by_css_selector(
            '.total p:nth-child(3) span')
        return ele.text

    @teststep
    def order_study_btn(self):
        """顺序学习按钮"""
        ele = self.driver.find_element_by_css_selector(
            '.content .right .el-button:nth-child(1)')
        return ele

    @teststep
    def chapter_exam_btn(self):
        """章节考试"""
        ele = self.driver.find_element_by_css_selector(
            '.content .right .el-button:nth-child(2)')
        return ele

    @teststep
    def section_progress_list(self):
        """小节学习进度"""
        ele = self.driver.find_elements_by_css_selector('.progress')
        return [x.text.strip() for x in ele]

    @teststep
    def chapter_video_btn(self):
        """章节导学视频按钮"""
        ele = self.driver.find_element_by_css_selector('.icon-video')
        return ele

    @teststep
    def section_father_box_ele(self):
        """小节父级元素"""
        ele = self.driver.find_elements_by_css_selector('.section')
        return ele

    @teststep
    def section_progress(self, section_ele):
        """小节进度"""
        ele = section_ele.find_element_by_css_selector('.status')
        return ele.text.strip()

    @teststep
    def section_name(self, section_ele):
        """小节名称"""
        ele = section_ele.find_element_by_css_selector('p')
        return ele.text

    @teststep
    def section_knowledge_btn(self, section_ele):
        """知识点识记"""
        ele = section_ele.find_elements_by_css_selector('a')
        return ele[3]

    @teststep
    def section_sync_exercise(self, section_ele):
        """同步练习按钮"""
        ele = section_ele.find_elements_by_css_selector('a')
        return ele[2]

    @teststep
    def section_printer_icon(self, section_ele):
        """打印按钮"""
        ele = section_ele.find_element_by_css_selector('.icon-printer')
        return ele

    @teststep
    def more_section_sync_btn(self, section_ele):
        """更多同步练习按钮"""
        ele = section_ele.find_element_by_css_selector('.icon-list')
        return ele

    # ===== 章节目录页面元素和数据校验 =====
    @teststep
    def chapter_num_check(self, book_id, chapter_num):
        """主页页面章节个数校验"""
        db_chapter_num = self.data.get_book_chapter_num(book_id)
        if db_chapter_num != chapter_num:
            self.base_assert.except_error('主页页面章节个数与数据库查询个数不一致')

    @teststep
    def check_chapter_is_available(self, book_id):
        """判断章节状态是否正确"""
        active_chapter = []
        for x in self.chapter_list():
            chapter_info = self.data.get_chapter_id_and_available_value(
                book_id, x.text.strip())
            print(x.text, chapter_info)
            if chapter_info[1]:
                if 'disable' in x.get_attribute('class'):
                    self.base_assert.except_error('此章节为上架状态, 但是页面显示不可点击 ' +
                                                  x.text)
                else:
                    active_chapter.append((x, chapter_info[0]))
            else:
                if 'active' in x.get_attribute('class'):
                    self.base_assert.except_error('此章节为下架状态, 但是页面显示可点击 ' +
                                                  x.text)
        print('-' * 30, '\n')
        return active_chapter

    @teststep
    def check_shelves_chapter_data(self, book_id, chapter_id):
        """对已上架的章节的导学、小节、知识点进行验证"""
        chapter_has_video = self.data.get_chapter_have_video(chapter_id)
        if chapter_has_video:
            if not self.wait_check_chapter_video_page():
                self.base_assert.except_error("查询得本章节具有章节导学视频, 但是页面没有导学显示")
            # else:
            #     self.chapter_video_btn().click()
            #     if not self.wait_check_video_page():
            #         self.base_assert.except_error('点击章节导学按钮, 未出现视频页面')
            #     else:
            #         WKGame().wk_game_operate()
        else:
            if self.wait_check_chapter_video_page():
                self.base_assert.except_error("查询得本章节不具有章节导学视频, 但是页面却显示")

        section_num = self.section_num()
        db_section_info = self.data.get_chapter_section_ids(chapter_id)
        active_section_id = [x[0] for x in db_section_info if x[1]]
        print('本章节所有小节id', db_section_info)
        print('本章节已上架小节id', active_section_id)
        print('页面小节数:', section_num)
        print('数据库查询小节数:', len(db_section_info))
        if len(db_section_info) != section_num:
            self.base_assert.except_error("查询到的小节数与页面展示的个数不一致,查询为 %d, 页面为 %d" %
                                          (len(db_section_info), section_num))

        knowledge_num = self.knowledge_num()
        db_knowledge_num = sum([
            self.data.get_section_knowledge_num_by_id(book_id, x)
            for x in active_section_id
        ])
        print('页面知识点数:', knowledge_num)
        print('数据库查询知识点总数:', db_knowledge_num)
        if db_knowledge_num != knowledge_num:
            self.base_assert.except_error('查询到的知识点个数与页面显示个数不一致, 查询为%d, 页面为%d' %
                                          (db_knowledge_num, knowledge_num))
        print('-' * 30, '\n')
        return chapter_id

    @teststep
    def check_chapter_finish_status(self):
        """校验章节完成状态"""
        chapter_status = self.chapter_finish_status()
        section_progress_list = self.section_progress_list()
        # if '已完成' in chapter_status:
        #     if '100%' not in section_progress_list:
        #         self.base_assert.except_error("小节中不存在已完成状态,")
        pass

    @teststep
    def check_section_available_status(self, book_id, chapter_id):
        """校验小节知识点状态"""
        active_section_index = []
        section_list = self.section_father_box_ele()
        print('小节个数:', len(section_list))
        for i in range(len(section_list)):
            if self.wait_chapter_page():
                section_ele = self.section_father_box_ele()[i]
                section_name = self.section_name(section_ele)
                section_info = self.data.get_chapter_id_and_available_value(
                    book_id, section_name, chapter_id)
                print(section_name, section_info)
                section_id = section_info[0]
                section_ava_value = section_info[1]
                sync_exercise_btn = self.section_sync_exercise(section_ele)
                more_exercise_btn = self.more_section_sync_btn(section_ele)
                for ele in [sync_exercise_btn, more_exercise_btn]:
                    if 'active' not in ele.get_attribute('class'):
                        sync_exercise_btn.click()
                        if self.wait_check_error_tip_page():
                            print(self.error_content())
                        else:
                            self.base_assert.except_error(
                                "小节未开始,点击按钮未提示请先完成小节练习/同步练习")
                        time.sleep(3)

                self.section_knowledge_btn(section_ele).click()
                if section_ava_value:
                    if self.wait_check_error_tip_page():
                        print(self.error_content())

                    if not self.wait_check_start_study_page():
                        self.base_assert.except_error("小节已上架,点击知识点识记未出现开始学习页面")
                    else:
                        active_section_index.append((i, section_id))
                        self.exit_icon().click()
                        time.sleep(3)
                else:
                    if self.wait_check_error_tip_page():
                        print(self.error_content())
                    else:
                        self.base_assert.except_error('小节已下架, 点击知识点识记未出现错误提示')
        print('-' * 30, '\n')
        return active_section_index