def check_word_is_only_has_vocab_apply(self, explain_id, new_explain_words,
                                        stu_id):
     """查看单词是否只有词汇运用"""
     if explain_id in new_explain_words:
         print('此单词是新释义单词')
         word_level = WordDataHandlePage().get_level_by_explain_id(
             explain_id, stu_id)
         lager_level_count = WordDataHandlePage(
         ).check_has_other_studied_explain(explain_id, stu_id, word_level)
         if lager_level_count:
             print('❌❌❌ 存在F值比此单词大的解释,单词复习只有词汇运用,不应在此游戏中出现')
    def test_have_different_teacher(self):
        """测试拥有不同老师,不同班级的情况"""
        if self.home.wait_check_home_page():
            test_class_num = VANCLASS_ID
            van_num = test_class_num.copy()
            QuitAddClass().apply_class_operate(van_num)
            web_driver = Driver()
            web_driver.set_driver()
            for x in TEACHER_ACCOUNT:
                AssignWord().assign_wordbook_operate(test_class_num, x, STU_PASSWORD)
                LoginWebPage().logout_operate()

            web_driver.quit_web()
            if self.home.wait_check_home_page():
                stu_info = UserCenterPage().get_user_info()
                stu_id = stu_info[0]
                teacher_trans_ids = WordDataHandlePage().get_teacher_words_trans_id(stu_id)
                if self.home.wait_check_home_page():
                    self.home.click_hk_tab(1)  # 点击 背单词
                    if self.word_rebuild.wait_check_start_page():  # 开始页面检查点
                        self.word_rebuild.word_start_button()  # 点击 Go按钮
                        word_info = FlashCard().scan_game_operate(is_exit=True)
                        WorldBookPublicPage().check_word_order_is_right(teacher_trans_ids, word_info[0])
                    if self.word_rebuild.wait_check_continue_page():
                        self.word_rebuild.click_back_up_button()
 def test_have_class(self, test_class_num):
     """测试有老师的情况, 一个班或者多个班的情况"""
     if self.home.wait_check_home_page():
         van_num = test_class_num.copy()
         QuitAddClass().apply_class_operate(van_num)
         web_driver = GetWebDriver()
         web_driver.set_driver()
         AssignWord().assign_wordbook_operate(test_class_num,
                                              TEACHER_ACCOUNT[0],
                                              STU_PASSWORD)
         web_driver.quit_web()
         if self.home.wait_check_home_page():
             stu_info = UserCenterPage().get_user_info()
             stu_id = stu_info[0]
             teacher_trans_ids = WordDataHandlePage(
             ).get_teacher_words_trans_id(stu_id)
             if self.home.wait_check_home_page():
                 self.home.click_hk_tab(1)  # 点击 背单词
                 if self.word_rebuild.wait_check_start_page():  # 开始页面检查点
                     self.word_rebuild.word_start_button()  # 点击 Go按钮
                     word_info = FlashCard().scan_game_operate(is_exit=True)
                     WorldBookPublicPage().check_word_order_is_right(
                         teacher_trans_ids, word_info[0])
                 if self.word_rebuild.wait_check_continue_page():
                     self.word_rebuild.click_back_up_button()
Esempio n. 4
0
 def setUp(cls):
     cls.result = unittest.TestResult()
     cls.base_assert = ExpectingTest(cls, cls.result)
     cls.home = HomePage()
     cls.login = LoginPage()
     cls.word_rebuild = WordBookRebuildPage()
     cls.data = WordDataHandlePage()
     cls.mine = MineWordsPage()
     cls.login.app_status()  # 判断APP当前状态
     BasePage().set_assert(cls.base_assert)
Esempio n. 5
0
    def test_new_word(self, do_right=False):
        """测试新词"""
        if self.home.wait_check_home_page():

            # 取消所有班级布置的单词
            # for x in TEACHER_ACCOUNT:
            #     AssignWord().revoke_van_class_wordbook_operate(x, STU_PASSWORD)
            #     LoginWebPage().logout_operate()
            # QuitAddClass().quit_all_class_operate()

            stu_info = UserCenterPage().get_user_info()  # 获取学生信息
            stu_id = stu_info[0]
            WordDataHandlePage().clear_student_word_data(stu_id)  # 清除学生已学单词记录
            self.word_info = {}
            # WordDataHandlePage().clear_word_finish_date(stu_id)

            if self.home.wait_check_home_page():
                self.home.click_hk_tab(1)  # 点击 背单词
                if self.word_rebuild.wait_check_start_page():  # 开始页面检查点
                    self.word_rebuild.word_start_button()  # 点击 Go按钮

                elif self.word_rebuild.wait_check_continue_page(
                ):  # 若为继续页面,则说明未清除缓存
                    self.base_assert.except_error('缓存未清除成功')
                    self.word_rebuild.word_continue_button()

                recite_words, all_words = [], []  # 复习单词, 新词
                for x in range(2):
                    if self.word_rebuild.wait_check_game_title_page():
                        #  闪卡学习过程 返回闪卡题数,标星标熟
                        flash_result = FlashCard().flash_study_model(
                            stu_id, self.word_info, x, do_right)
                        if flash_result:
                            group_new_explain_words = flash_result[
                                3]  # 每组新释义单词
                            all_words.append(len(
                                flash_result[0]))  # 把每组新词个数加入新词数组
                            self.new_explain_words.extend(
                                group_new_explain_words)  # 将新释义单词加入新释义数组中
                            # 其他新词游戏过程
                            self.word_rebuild.normal_study_new_word_operate(
                                stu_id, flash_result, do_right)  # 游戏过程
                    if ResultPage().wait_check_result_page():
                        # 结果页单词统计核实
                        ResultPage().result_page_handle(
                            len(self.word_info), len(self.new_explain_words),
                            len(recite_words), x)
                self.word_rebuild.click_back_up_button()
                self.home.tips_operate_commit()
 def test_no_class_word_data(self):
     """测试没有班级时候的"""
     if self.home.wait_check_home_page():
         QuitAddClass().quit_all_class_operate()
         stu_info = UserCenterPage().get_user_info()
         stu_id = stu_info[0]
         sys_trans_ids = WordDataHandlePage().get_sys_words_trans_id(stu_id)
         if self.home.wait_check_home_page():
             self.home.click_hk_tab(1)  # 点击 背单词
             if self.word_rebuild.wait_check_start_page():  # 开始页面检查点
                 self.word_rebuild.word_start_button()  # 点击 Go按钮
                 word_info = FlashCard().scan_game_operate(is_exit=True)
                 WorldBookPublicPage().check_word_order_is_right(
                     sys_trans_ids, word_info[0], sys_only=True)
             if self.word_rebuild.wait_check_continue_page():
                 self.word_rebuild.click_back_up_button()
    def right_listen_spell_operate(self, stu_id, bank_count, new_explain_words):
        """单词听写做对操作"""
        print('===== 🌟🌟 单词听写模式(新词)(一次做对) 🌟🌟 =====\n')
        for x in range(bank_count):
            self.next_btn_judge('false', self.fab_commit_btn)  # 下一题 按钮 判断加 点击操作
            explain_id = self.word_public.get_explain_id(self.input_wrap_side())
            right_answer = WordDataHandlePage().get_word_by_explain_id(stu_id, explain_id)
            for alpha in list(right_answer):
                self.key.games_keyboard(alpha)  # 输入单词的大写字母

            self.next_btn_operate('true', self.fab_commit_btn)  # 下一题 按钮 判断加 点击操作
            explain = self.word_explain()
            if explain_id in new_explain_words:
                print('❌❌❌ 此单词为新释义,不应出现单词听写游戏')
            print('解释:', explain.text)
            print('我输入的:', right_answer)
            self.next_btn_operate('true', self.fab_next_btn)  # 下一题
            time.sleep(2)
            print('-' * 30, '\n')
        time.sleep(5)
Esempio n. 8
0
 def __init__(self):
     self.common = WordDataHandlePage()
     self.wait = WaitElement()
Esempio n. 9
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')
class VocabularyChoose(VocabChoiceGame):
    """词汇选择"""
    def __init__(self):
        self.data = WordDataHandlePage()

    @teststeps
    def normal_listen_select_operate(self, bank_count, new_explain_words):
        """《词汇选择》 - 听音选词模式 具体操作"""
        print('===== 🌟🌟 词汇选择(新词) 听音选词模式(第一遍选错,第二遍选择正确) 🌟🌟=====\n')
        print('题目个数:', bank_count)
        answer_word, all_words = [], []

        while len(all_words) < bank_count:
            self.next_btn_judge('false', self.fab_next_btn)
            self.listen_choice_speak_icon().click()  # 点击发音按钮
            options = self.vocab_options()  # 获取当前页面所有选项
            if not answer_word:  # 正确答案列表为空
                opt_index = random.randint(0, len(options) - 1)  # 随机选择一个选项
                opt_text = options[opt_index].text
                options[opt_index].click()
                self.next_btn_judge('true', self.fab_next_btn)  # 检查下一步按钮的状态

                print('选择答案为:', opt_text)
                if self.wait_check_explain_page():  # 检验是否出现解释页面
                    explain = self.vocab_word_explain()
                    explain_id = explain.get_attribute('contentDescription')

                    if explain_id in new_explain_words:
                        self.base_assert.except_error('此单词为新释义,不应出现词汇选择游戏')
                    print('解释:', explain.text)
                else:
                    self.base_assert.except_error('解释文本未出现')

                right_answer = self.vocab_right_answer()  # 正确答案
                if right_answer == opt_text:
                    print('选择正确')
                    all_words.append(right_answer)
                else:
                    print('选择错误,正确答案为', right_answer)
                    answer_word.append(right_answer)
            else:  # 正确答案列表不为空-- 上一题选择错误
                for y in options:
                    if y.text == answer_word[0]:  # 点击正确答案
                        y.click()
                        self.next_btn_judge('true', self.fab_next_btn)  # 检查下一步按钮的状态
                        if self.wait_check_explain_page():
                            explain = self.vocab_word_explain()
                            explain_id = explain.get_attribute('contentDescription')
                            if explain_id in new_explain_words:
                                self.base_assert.except_error('此单词为新释义,不应出现词汇选择游戏')
                            all_words.append(y.text)
                            print('答案正确:%s' % answer_word[0])
                            print('解释:%s' % explain.text)
                        else:
                            self.base_assert.except_error('Error-- 解释文本未出现')
                        break
                answer_word.clear()
            self.sound_icon().click()
            self.fab_next_btn().click()   # 下一题 按钮 状态判断 加点击
            time.sleep(2)
            print('-' * 30, '\n')

    @teststeps
    def right_listen_select_operate(self, stu_id, bank_count, new_explain_words):
        print('===== 🌟🌟 词汇选择(新词) 听音选词模式(一次做对模式) 🌟🌟 =====\n')
        for x in range(bank_count):
            self.next_btn_judge("false", self.fab_next_btn)  # 下一题 按钮 状态判断 加点击
            voice_btn = self.listen_choice_speak_icon()
            explain_id = voice_btn.get_attribute('contentDescription')
            if explain_id in new_explain_words:
                self.base_assert.except_error('此单词为新释义,不应出现词汇选择游戏')
            right_word = self.data.get_word_by_explain_id(stu_id, explain_id)
            for y in self.vocab_options():
                if y.text == right_word:
                    print('选择选项:', y.text)
                    y.click()
                    if not self.wait_check_explain_page():
                        self.base_assert.except_error('点击选项未出现解释文本!')
                    else:
                        print("解释:", self.vocab_word_explain().text)
                    break
            self.sound_icon().click()
            self.fab_next_btn().click()   # 下一题 按钮 状态判断 加点击
            time.sleep(2)
            print('-' * 30, '\n')


    @teststeps
    def vocab_select_choice_explain(self, bank_count, wrong_again_words):
        """《词汇选择》 - 选解释模式
        :param bank_count: 题目个数
        :param wrong_again_words: 错题再练单词
        """
        print('====== 🌟🌟 词汇选择 - 根据单词选解释模式(复习)🌟🌟 =====\n')
        recite_words = []
        for x in range(bank_count + 2):
            self.next_btn_operate('false', self.fab_next_btn)  # 下一题 按钮 判断加 点击操作
            self.sound_icon().click()  # 点击发音按钮
            word = self.vocab_question()  # 题目
            print('题目:', word.text)

            explain_id = word.get_attribute('contentDescription')     # 获取正确解释id

            if explain_id in recite_words:
                self.base_assert.except_error('单词已选过, 再次出现')

            right_explain = self.data.get_explain_by_id(explain_id)      # 根据id获取正确解释文本
            options = self.vocab_options()      # 遍历选项,点击和正确答案一样的解释
            for y in options:
                if x in [2, 3]:                 # 次序为【2,3】连续选择错误
                    if right_explain not in y.text:
                        if x == 2:
                            wrong_again_words.append(explain_id)
                        print('选择错误答案:', y.text)
                        print('正确答案为:', right_explain)
                        y.click()
                        break
                elif right_explain in y.text:
                    print('选择答案:', y.text)
                    recite_words.append(explain_id)
                    y.click()
                    break

            print('正确答案:', right_explain)
            self.fab_next_btn().click()  # 下一题 按钮 状态判断 加点击
            time.sleep(2)
            print('-'*30, '\n')

    @teststeps
    def vocab_select_choice_word(self, stu_id, bank_count, wrong_again_words):
        """《词汇选择》 - 根据解释选单词"""
        recite_words = []
        print('===== 🌟🌟 词汇选择-选单词模式(复习)🌟🌟 =====\n')
        for x in range(bank_count + 2):
            self.next_btn_judge('false', self.fab_next_btn)  # 下一题 按钮 判断加 点击操作
            item = self.vocab_question()  # 题目
            print('题目:', item.text)
            explain_id = item.get_attribute('contentDescription')

            if explain_id in recite_words:
                self.base_assert.except_error('单词已选过, 再次出现')

            right_word = self.data.get_word_by_explain_id(stu_id, explain_id)   # 根据解释id获取正确单词
            options = self.vocab_options()  # 遍历选项,点击和word一样的单词
            for y in options:
                if x in [2, 3]:                 # 次序为【2,3】连续选择错误
                    if y.text != right_word:
                        if x == 2:
                            wrong_again_words.append(explain_id)
                        print('选择错误答案:', y.text)
                        print('正确答案为:', right_word)
                        y.click()
                        break
                elif y.text == right_word:
                    print('选择答案:', y.text)
                    recite_words.append(explain_id)
                    y.click()
                    break
            if self.wait_check_voice_page():
                self.sound_icon().click()
            else:
                self.base_assert.except_error(' Error-- 声音按钮未出现')
            self.fab_next_btn().click()  # 下一题 按钮 状态判断 加点击
            time.sleep(2)
            print('-'*30, '\n')

    @teststeps
    def vocab_apply(self, stu_id,  bank_count, right_words, recite_new_explain_words):
        """词汇运用"""
        print('===== 🌟🌟 词汇运用 --句子选单词模式(复习) 🌟🌟 =====\n')
        recite_words = []
        for x in range(bank_count):
            self.next_btn_judge('false', self.fab_next_btn)
            item = self.vocab_question()  # 题目
            print('题目:%s' % item.text)
            explain_id = item.get_attribute('contentDescription')           # 根据题目获取explain——id
            if explain_id in recite_words:
                self.base_assert.except_error('单词已复习过, 单词未去重!')

            if explain_id in right_words and explain_id not in recite_new_explain_words:
                self.base_assert.except_error('单词新词时做全对, 复习时不为新释义单词, 不应出现词汇运用游戏')

            right_answer = self.data.get_word_by_explain_id(stu_id, explain_id)     # 根据解释id获取正确单词
            self.apply_hint_button().click()  # 点击提示按钮
            self.next_btn_judge('false', self.apply_hint_button)  # 提示按钮 状态判断
            if not self.wait_vocab_apply_explain_page():
                self.base_assert.except_error('点击提示后未发现句子解释文本')
            else:
                sentence_explain = self.apply_sentence_explain()
                print('单词解释:', sentence_explain)

            for y in self.vocab_options():
                if y.text == right_answer:
                    recite_words.append(explain_id)
                    print('选择答案:', y.text)
                    y.click()
                    break

            if self.wait_check_voice_page():
                self.sound_icon().click()
            else:
                self.base_assert.except_error('Error-- 声音按钮未出现')
            self.fab_next_btn().click()   # 下一题 按钮 状态判断 加点击
            time.sleep(2)
            print('-'*30, '\n')
 def __init__(self):
     self.data = WordDataHandlePage()
Esempio n. 12
0
    def flash_study_model(self, stu_id, word_info, group_count, do_right):
        """:param word_info: 记录今日所做的所有新
           :param group_count: 做的组数
           :param stu_id: 学生id
           :param do_right: 是否做全对
        """
        """学习模式  新词操作"""

        familiar_words, all_words = {}, {}
        group_word_answer = {}
        star_words, group_new_explain_words = [], []
        index = 0
        while self.wait_check_flash_study_page():
            if index == 0:
                print('===== 🌟🌟 闪卡练习 学习模式 🌟🌟 =====\n')
            word = self.english_study()
            if self.wait_check_explain_page():

                self.next_btn_judge('true', self.fab_next_btn)
                explain = self.study_word_explain()  # 解释
                sentence = self.study_sentence()
                sentence_explain = self.study_sentence_explain()
                sentence_author = self.author()
                explain_id = explain.get_attribute('contentDescription').split(
                    ' ')[0]

                print('单词:', word, '\n', '解释:', explain.text, '\n', '句子:',
                      sentence, '\n', '句子解释:', sentence_explain, '\n', '推荐老师:',
                      sentence_author, '\n')

                if '新释义' in self.game_title().text:
                    if not self.wait_check_dragger_btn():
                        self.base_assert.except_error('★★★ 单词为新释义吗, 但是未发现拖拽按钮')
                    else:
                        if word in list(word_info.keys()):
                            self.old_explain_tab_ele_check(word_info, word)

                    group_new_explain_words.append(explain_id)
                    if WordDataHandlePage().check_has_other_studied_explain(
                            stu_id, explain_id):
                        print('此单词为新释义单词')
                    else:
                        print('❌❌❌ 该单词不为新释义单词,但是标题出现新释义字样')

                if word in list(all_words.keys()):  # 判断单词是否去重
                    print('❌❌❌ 本组已存在本单词,单词未去重!')
                else:
                    all_words[word] = explain_id
                    group_word_answer[explain.text] = word

                if word not in list(word_info.keys()):
                    word_info[word] = {
                        "explain_id": [explain_id],
                        'explain': [explain.text],
                        'sentence': [sentence],
                        'sentence_explain':
                        [sentence_explain + sentence_author],
                    }
                else:
                    explain_id_list = word_info[word]['explain_id']
                    if explain_id in explain_id_list:
                        print('❌❌❌ 该解释已作为新词出现过')
                    else:
                        word_info[word]['explain_id'].append(explain_id)
                        word_info[word]['explain'].append(explain.text)
                        word_info[word]['sentence'].append(sentence)
                        word_info[word]['sentence_explain'].append(
                            sentence_explain + sentence_author)

                self.pattern_switch()  # 切换到 全英模式

                if self.wait_check_explain_page():  # 校验是否成功切换
                    self.base_assert.except_error('❌❌❌ 切换全英模式, 依然存在解释')

                self.pattern_switch()  # 切换回 英汉模式
                if not do_right:
                    if index % 2 == 0:  # 标熟
                        if index == 2:
                            self.familiar_button().click()
                            if self.familiar_button().text != '取消熟词':
                                self.base_assert.except_error(
                                    '❌❌❌ 点击熟词后内容未发生变化')
                            self.familiar_button().click()
                            if self.familiar_button().text != '设置熟词':
                                self.base_assert.except_error(
                                    '❌❌❌ 点击熟词后内容未发生变化')

                        self.familiar_button().click()
                        self.check_alert_tip_operate(
                            index, group_count)  # 判断首次标熟是否有提示

                        familiar_words[explain_id] = word

                    if index in [0, 1, 3]:
                        if index == 1:
                            self.star_button().click()  # 标星
                            if self.star_button().get_attribute(
                                    'selected') != 'true':
                                self.base_assert.except_error(
                                    '❌❌❌ 点击标星按钮后,按钮未点亮')
                            self.star_button().click()
                            if self.star_button().get_attribute(
                                    'selected') != 'false':
                                self.base_assert.except_error(
                                    '❌❌❌ 取消标星后,按钮未置灰')
                        self.star_button().click()  # 标星
                        self.check_alert_tip_operate(
                            index, group_count)  # 判断首次标星是否有提示
                        star_words.append(explain_id)
            else:
                self.base_assert.except_error('❌❌❌ 默认不是英汉模式')

            self.next_btn_operate('true', self.fab_next_btn)
            # self.next_word(index, word)
            index += 1
            print('-' * 30, '\n')
        return all_words, familiar_words, star_words, group_new_explain_words, group_word_answer
Esempio n. 13
0
    def flash_different_familiar_operate(self, stu_id, word_info,
                                         familiar_type, group_count,
                                         first_group_familiar,
                                         word_has_different_explain):
        index, familiar_count = 0, 0
        familiar_words, all_words = {}, {}
        group_new_explain_words = []

        while self.wait_check_flash_study_page():
            if index == 0:
                if familiar_type == 1:
                    print('===== 🌟🌟 第一组单词标熟,第二组该单词不标熟(全对) 🌟🌟 =====\n')
                elif familiar_type == 2:
                    print('===== 🌟🌟 第一组单词不标熟,单词做错,第二组该单词标熟 🌟🌟 =====\n')
                elif familiar_type == 3:
                    print('===== 🌟🌟 第一组单词不标熟,单词做错, 第二组该单词不标熟(全对) 🌟🌟 =====\n')
                elif familiar_type == 4:
                    print('===== 🌟🌟 第一组单词不标熟,单词全对, 第二组该单词标熟 🌟🌟 =====\n')
                elif familiar_type == 5:
                    print('===== 🌟🌟 第一组单词不标熟, 单词全对, 第二组该单词不标熟(全对) 🌟🌟 =====\n')

            word = self.english_study()
            self.next_btn_judge('true', self.fab_next_btn)
            explain = self.study_word_explain()  # 解释
            explain_id = explain.get_attribute('contentDescription').split(
                ' ')[0]

            if '新释义' in self.game_title().text:
                group_new_explain_words.append(explain_id)
                if WordDataHandlePage().check_has_other_studied_explain(
                        stu_id, explain_id):
                    print('此单词为新释义单词')
                else:
                    print('❌❌❌ 该单词不为新释义单词,但是标题出现新释义字样')

            if word in list(all_words.keys()):  # 判断单词是否去重
                print('❌❌❌ 本组已存在本单词,单词未去重!')
            else:
                all_words[word] = explain_id

            if word not in list(word_info.keys()):
                word_info[word] = [explain_id]
            else:
                explain_id_list = word_info[word]
                if explain_id in explain_id_list:
                    print('❌❌❌ 该解释已作为新词出现过')
                else:
                    word_info[word].append(explain_id)

            print('单词:', word, '\n', '解释:', explain.text, '\n', '句子:',
                  self.study_sentence(), '\n', '句子解释:',
                  self.study_sentence_explain(), '\n', '推荐老师:', self.author(),
                  '\n')
            self.pattern_switch()  # 切换到 全英模式
            if self.wait_check_explain_page():  # 校验是否成功切换
                print('❌❌❌ 切换全英模式, 依然存在解释')
            self.pattern_switch()  # 切换回 英汉模式

            if familiar_type == 1:
                if group_count == 0:
                    familiar_count = self.first_group_familiar_operate(
                        word, explain_id, word_has_different_explain,
                        familiar_words, familiar_count)
                elif group_count == 1:
                    familiar_count = self.second_group_not_familiar_operate(
                        word, explain_id, first_group_familiar, familiar_words,
                        familiar_count)

            elif familiar_type == 2 or familiar_type == 4:
                if group_count == 0:
                    familiar_count = self.first_group_not_familiar_operate(
                        word, explain_id, word_has_different_explain,
                        familiar_words, familiar_count)
                elif group_count == 1:
                    familiar_count = self.second_group_familiar_operate(
                        word, explain_id, first_group_familiar, familiar_words,
                        familiar_count)

            elif familiar_type == 3 or familiar_type == 5:
                if group_count == 0:
                    familiar_count = self.first_group_not_familiar_operate(
                        word, explain_id, word_has_different_explain,
                        familiar_words, familiar_count)
                elif group_count == 1:
                    familiar_count = self.second_group_not_familiar_operate(
                        word, explain_id, first_group_familiar, familiar_words,
                        familiar_count)

            # self.next_word(index, word)
            self.next_btn_operate('true', self.fab_next_btn)
            index += 1
            print('-' * 30, '\n')
        return all_words, familiar_words, 0, group_new_explain_words
 def __init__(self):
     super().__init__()
     self.data = WordDataHandlePage()
     self.public = WorldBookPublicPage()
     self.wait = WaitElement()
     self.data_dir = 'app/honor/student/word_book_rebuild/test_data/'
class 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)
Esempio n. 16
0
    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
 def __init__(self):
     super().__init__()
     self.data = WordDataHandlePage()
     self.key = Keyboard()
     self.word_public = WorldBookPublicPage()
class SpellingWord(SpellWordGame):
    """单词拼写"""
    def __init__(self):
        super().__init__()
        self.data = WordDataHandlePage()
        self.key = Keyboard()
        self.word_public = WorldBookPublicPage()


    @teststep
    def spell_right_word_operate(self, word):
        """单词拼写做对操作"""
        # self.hint_ele_operate(word)
        # self.key.games_keyboard('backspace')
        print('单词:', word)
        for j in range(0, len(word)):
            self.keyboard_operate(j, word[j])  # 点击键盘 具体操作


    @teststeps
    def new_word_spell_operate(self, familiar_word, new_explain_words):
        """单词拼写 - 《默写模式》游戏过程"""
        print('===== 🌟🌟 单词拼写 新词 🌟🌟 ======\n')
        print('标熟单词:', familiar_word, '\n')
        all_words = []
        value = 0
        index = 0
        while self.wait_check_normal_spell_page():
            explain_ele = self.word_explain()        # 解释
            explain = explain_ele.text
            explain_id = self.word_public.get_explain_id(explain_ele)
            self.next_btn_judge('false', self.fab_commit_btn)  # 下一题 按钮 状态判断

            if explain_id in new_explain_words:
                if '新释义' not in self.game_title().text:
                    print('❌❌❌ 该单词为新释义,但是标题没有显示新释义字样')

            print('解释:', explain)
            if explain in all_words:
                print('❌❌❌ 该单词在拼写单词中已经出现过!')
            else:
                all_words.append(explain)

            if explain_id not in list(familiar_word.keys()):
                print('❌❌❌ 单词未标熟,但是出现拼写', explain)
            else:
                value = familiar_word[explain_id]
                self.spell_right_word_operate(value)

            self.next_btn_operate('true', self.fab_commit_btn)         # 下一题 按钮 状态判断 加点击
            answer = self.spell_word().text[::2]  # 最终答案
            if answer != value.lower():
                print('❌❌❌ 大写字母未自动变为小写字母')
            # self.result_operate(answer, self.mine_answer())   # 下一步按钮后的答案页面 测试
            self.click_voice()
            self.next_btn_operate('true', self.fab_next_btn)
            time.sleep(2)
            index += 1
            print('-'*30, '\n')
        return index


    @teststeps
    def recite_word_spell_operate(self, stu_id, bank_count, recite_new_explain_words, only_apply_explains):
        """单词拼写 复习"""
        print('===== 🌟🌟 单词默写 复习 🌟🌟 ===== \n')
        for x in range(bank_count):
            explain = self.word_explain()  # 解释
            print('解释:', explain.text)
            explain_id = explain.get_attribute('contentDescription')
            if explain_id in recite_new_explain_words:
                print('❌❌❌ 此单词为新释义单词,不应出现单词拼写游戏')

            if explain_id in only_apply_explains:
                print('❌❌❌ 此单词为只有词汇运用单词, 不应出现在单词拼写中')

            self.next_btn_judge('false', self.fab_commit_btn)  # 下一题 按钮 状态判断
            right_word = self.data.get_word_by_explain_id(stu_id, explain_id)
            self.spell_right_word_operate(right_word)
            self.next_btn_operate('true', self.fab_commit_btn)
            print('我输入的:', right_word)

            if not self.wait_check_play_voice_page():
                print('❌❌❌ 点击提交按钮后未发现喇叭按钮')
            self.next_btn_operate('true', self.fab_next_btn)
            print('-'*30, '\n')


    # @teststeps
    # def dictation_pattern_mine(self, i, familiar_add, spell_word):
    #     """单词默写 我的单词"""
    #     if i == 0:
    #         print("\n单词拼写 - 默写模式(单词详情)\n")
    #     explain = self.word_explain()  # 题目
    #     value = self.data.get_word_by_explain(explain)
    #     familiars = self.data.get_familiar_words() + familiar_add
    #     intersect_list = list(set(value).intersection(set(familiars)))  # 取获取单词数组与标星单词数组的交集
    #     if i in range(0, 5):
    #         self.dictation_pattern_core(spell_word, word_type=1)
    #         if len(intersect_list) == 0:
    #             print('❌❌❌ Error-- 单词未被标熟却出现默写模式')
    #     else:
    #         FlashCard().tips_operate()
    #         for i in familiar_add:
    #             level = self.data.get_word_level(i)
    #             if level < 3:
    #                 print("❌❌❌ Error--提交未成功,单词熟练度未更改")

    @teststeps
    def hint_ele_operate(self, value):
        self.next_btn_judge('false', self.fab_commit_btn)  # 下一题 按钮 判断加 点击操作
        if self.wait_check_tv_word_or_random_page():  # 默写模式 - 字母未全部消除
            print('❌❌❌ Error - 单词拼写 默写模式 - 字母未全部消除')

        hint = self.hint_btn()  # 提示按钮
        if GetAttribute().get_enabled(hint) == 'true':
            hint.click()  # 点击 提示按钮
            if GetAttribute().get_enabled(self.hint_btn()) != 'false':
                print('❌❌❌ Error - 点击后提示按钮enabled属性错误')

            if self.wait_check_tv_word_or_random_page():  # 出现首字母提示
                first_word = self.spell_word().text[::2]
                if first_word == value[0]:
                    print('点击提示出现首字母提示', first_word)
                else:
                    print('点击提示出现首字母提示', first_word)
            else:
                print("❌❌❌ Error - 首字母提示未出现")
        else:
            print('❌❌❌ Error - 提示按钮enabled属性错误')

    @teststeps
    def result_operate(self, answer, mine):
        """下一步按钮后的答案页面"""
        print('我的答案:', answer)
        print('去除大小写结果:', mine)
        if self.wait_check_right_answer_page():
            correct = self.right_answer_word()  # 正确答案
            print('填写错误,正确答案:', correct)
            if len(mine) <= len(correct):  # 输入少于或等于单词字母数的字符
                if mine.lower() != answer.lower():  # 展示的 我的答题结果 是否与我填入的一致
                    print('❌❌❌ Error - 字符数少于或等于时:', mine.lower(), answer.lower())
            else:  # 输入过多的字符
                if correct + mine[len(correct):].lower() != correct + answer[len(correct):].lower():
                    # 展示的 我的答题结果 是否与我填入的一致
                    print('❌❌❌ Error - 字符输入过多时:', correct + mine[len(correct):].lower(), correct + answer[len(
                        correct):].lower())
        else:  # 回答正确
            if mine.lower() != answer.lower():  # 展示的 我的答题结果 是否与我填入的一致
                print('❌❌❌ Error - 展示的答题结果 与我填入的不一致:', mine.lower(), answer.lower())
            else:
                print('回答正确!')
        print('-'*30, '\n')

    @teststeps
    def keyboard_operate(self, j, value):
        """点击键盘 具体操作"""
        if j == 4:
            self.key.games_keyboard('capslock')  # 点击键盘 切换到 大写字母
            self.key.games_keyboard(value.upper())  # 点击键盘对应 大写字母
            self.key.games_keyboard('capslock')  # 点击键盘 切换到 小写字母
        else:
            self.key.games_keyboard(value)  # 点击键盘对应字母

    @teststeps
    def dictation_random_pattern_recite(self, stu_id, wrong_words):
        """错题再练 单词拼写 随机模式"""
        for x in range(len(wrong_words)):
            self.next_btn_judge('false', self.fab_commit_btn)
            explain = self.word_explain()
            print('解释:', explain.text)
            explain_id = explain.get_attribute('contentDescription')
            word = self.data.get_word_by_explain_id(stu_id, explain_id)
            print("正确单词:", word)
            tip_word = self.spell_word().text[1::2]
            print('提示词:', tip_word)

            right_word = [x for x in word if len(x) == len(tip_word)]
            alphas = [right_word[0][x] for x in range(len(right_word[0])) if tip_word[x] == '_']
            print(alphas)
            for k in range(len(alphas)):
                self.keyboard_operate(k, alphas[k])  # 点击键盘 具体操作
            print('填充后单词为:', self.spell_word().text[1::2])
            self.next_btn_operate('true', self.fab_commit_btn)
            if self.wait_check_play_voice_page():
                self.sound_icon().click()
            else:
                print('❌❌❌ 未发现声音按钮')
            self.next_btn_operate('true', self.fab_next_btn)  # 下一题 按钮 判断加 点击操作
            time.sleep(2)
 def __init__(self):
     self.mysql = WordTestSql()
     self.rebuild_handler = WordDataHandlePage()
class WordTestSqlHandler(BasePage):
    def __init__(self):
        self.mysql = WordTestSql()
        self.rebuild_handler = WordDataHandlePage()

    @teststep
    def get_f_glt_3_count(self, stu_id):
        """获取单词F值>=3的个数"""
        word_count = self.mysql.find_f_glt_3_count(stu_id)
        return word_count[0][0] if word_count else 0

    @teststep
    def get_student_test_star_score(self, stu_id):
        """获取测试的星星积分"""
        result = {}
        star_score_data = self.mysql.find_student_start_score_data(stu_id)
        for x in star_score_data:
            if x[0] in list(result.keys()):
                result['score'] = 0
            else:
                result[x[0]] = x[1]
        return result

    @teststep
    def get_result_data(self, test_id):
        """获取结果页结果"""
        result = self.mysql.find_test_result_data(test_id)
        return result[0]

    @teststep
    def get_test_words(self, stu_id, get_type, word_count=0):
        """获取学生单词F值>=3的单词个数
           :param word_count: 需要测试的单词数, 0 为该类型的全部单词
           :param get_type: 测试类型 1:F>=3 单词 2:测试未通过单词  3:测试通过单词
           :param stu_id 学生id
        """
        if get_type == 1:
            word_result = self.mysql.find_f_glt_3_words(stu_id)
        elif get_type == 2:
            word_result = self.mysql.find_test_fail_pass_words(stu_id)
        else:
            word_result = self.mysql.find_test_success_pass_words(stu_id)

        test_list = word_result[:word_count] if word_count else word_result
        word_info = {}
        for x in test_list:
            if str(x[0]) not in list(word_info.keys()):
                word_info[str(x[0])] = list(
                    self.mysql.find_student_translation_by_word_id(
                        stu_id, x[0]))
            else:
                continue
        return word_info

    @teststep
    def get_word_explain_list(self, explain_info):
        """获取测试单词对应解释列表"""
        explain_list = [
            self.rebuild_handler.get_explain_by_id(x[0]) for x in explain_info
        ]
        reform_list = ';'.join(explain_list).split(';')
        return reform_list

    @teststep
    def get_translation_count_by_word_id(self, test_id, word_ids):
        """获取解释个数根据单词id"""
        result = self.mysql.find_test_translation_by_word_ids(
            test_id, word_ids)
        return len(result)

    @teststep
    def get_fvalue_by_word_explain_id(self, stu_id, word_id, explain_id):
        """根据单词、解释id定位学生已被单词的F值"""
        result = self.mysql.find_student_word_fvalue_by_word_explain_id(
            stu_id, word_id, explain_id)
        return result[0][0] if result else -1

    @teststep
    def delete_student_test_data(self, stu_id):
        """删除学生单词测试相关数据"""
        student_test_ids = self.mysql.find_student_test_id(stu_id)
        if len(student_test_ids):
            for x in student_test_ids:
                self.mysql.delete_student_test_item_map(x[0])
        self.mysql.delete_student_test(stu_id)
        self.mysql.delete_student_test_record(stu_id)
        self.mysql.delete_student_test_overview(stu_id)
        self.mysql.delete_student_word_data(stu_id)