Esempio n. 1
0
    def flash_copy_model(self, star_words, new_explain_words):
        """闪卡抄写模式"""
        print('===== 🌟🌟 闪卡抄写模式 🌟🌟 =====\n')
        index = 0
        while self.wait_check_copy_page():
            word = self.copy_word()
            word_explain = self.copy_explain()
            explain_id = word_explain.get_attribute('contentDescription')
            self.copy_input().click()
            if explain_id in new_explain_words:
                if '新释义' not in self.game_title().text:
                    self.base_assert.except_error('❌❌❌ 该单词为新释义单词,但是标题未标明新释义字样')

            if explain_id not in star_words:
                self.base_assert.except_error('❌❌❌ 单词未标星,但是有抄写模式 ' + word)
            print("单词:%s\n解释:%s" % (word, word_explain.text))
            random_str = random.sample(string.ascii_lowercase, len(word) + 1)
            if index == 1:
                for i, alpha in enumerate(list(random_str)):
                    Keyboard().keyboard_operate(alpha, i)
                if len(self.copy_word()) > len(word):
                    self.base_assert.except_error('❌❌❌ 输入栏可输入超过抄写单词长度的单词')
                for y in range(len(self.copy_word())):
                    Keyboard().games_keyboard('backspace')

            for i, alpha in enumerate(list(word)):
                Keyboard().keyboard_operate(alpha, i)
            time.sleep(5)
            index += 1
            print('-' * 30, '\n')
        return index
    def word_spell_play_process(self,
                                game_mode,
                                do_right=False,
                                right_answer=None):
        """单词拼写游戏做对操作"""
        if game_mode == 1:
            if do_right:
                for i in range(len(right_answer)):
                    Keyboard().keyboard_operate(right_answer[i], i)
            else:
                random_str = ''.join(
                    random.sample(string.ascii_lowercase, random.randint(2,
                                                                         5)))
                for j in range(len(random_str)):
                    Keyboard().keyboard_operate(random_str[j], j)
        else:
            page_wait_input_word = self.spell_word().text[1::2]
            print('页面字符:', page_wait_input_word)

            if do_right:
                answer_word_list = list(right_answer)
                input_word_list = [
                    x for x, y in zip(answer_word_list,
                                      list(page_wait_input_word)) if x != y
                ]
                for x in range(len(input_word_list)):
                    Keyboard().keyboard_operate(input_word_list[x], x)
            else:
                input_count = len(re.findall(r'_', self.spell_word().text))
                for x in range(input_count):
                    Keyboard().games_keyboard(
                        random.choice(string.ascii_lowercase))
 def listen_spell_play_operate(self, do_right=False, right_answer=None):
     """单词听写对错操作"""
     if do_right:
         for j in range(len(right_answer)):  # 输入正确答案
             Keyboard().games_keyboard(right_answer[j])
     else:
         random_length = random.randint(3, 5)  # 创建随机字母
         random_string = ''.join(
             random.sample(string.ascii_letters, random_length))
         for j in range(len(random_string)):  # 输入随机字母
             Keyboard().games_keyboard(random_string[j])
    def flash_copy_game_operate(
        self,
        fq,
        half_exit,
        star_list=None,
    ):
        star_words = [] if fq == 1 else star_list
        if self.wait_check_copy_page():
            total_num = self.rest_bank_num()
            for x in range(total_num):
                self.click_voice()
                self.rate_judge(total_num, x)
                copy_word = self.copy_word()
                print('单词:', copy_word)
                if half_exit:
                    if x == 1:
                        self.click_back_up_button()
                        self.tips_operate()
                        break

                if x % 2 == 0:  # 奇数题
                    if fq == 1:  # 若为第一次
                        self.star_button().click()  # 标星
                        star_words.append(copy_word)
                        print('加入标星单词')
                    else:  # 若为第二次 校验是否被标星
                        if GetAttribute().get_selected(
                                self.star_button()) == 'true':
                            print('标星校验正确')
                        else:
                            self.base_assert.except_error('单词已标星但标星按钮未被选中')

                self.copy_input().click()
                time.sleep(1)
                if x == 1:
                    random_str = random.sample(string.ascii_lowercase,
                                               4)  # 随机输入错误单词,
                    for j, s in enumerate(random_str):
                        Keyboard().keyboard_operate(s, j)
                    print('输入单词:', ''.join(random_str))

                    if self.copy_word() != copy_word:  # 验证是否跳转到下一题
                        self.base_assert.except_error('输入错误单词可以进入下一题')

                    for y in range(4):  # 清除输入的单词
                        Keyboard().games_keyboard('backspace')
                    time.sleep(1)

                for j, s in enumerate(list(copy_word)):  # 输入抄写单词
                    Keyboard().keyboard_operate(s, j)
                time.sleep(3)
                print('-' * 30, '\n')
            return total_num, star_words
Esempio n. 5
0
 def sentence_strengthen_play_process(self,
                                      do_right=False,
                                      right_answer=None):
     """强化炼句对错操作"""
     if do_right:
         for word in right_answer:
             for x in list(word):
                 Keyboard().games_keyboard(x)
             time.sleep(0.5)
             Keyboard().games_keyboard('enter')
     else:
         input_count = self.get_rich_text_input_count()
         print('页面需要输入栏个数:', input_count)
         for j in range(input_count):
             random_str = random.sample(string.ascii_letters,
                                        random.randint(2, 4))  # 随机输入2个字母
             for x in random_str:
                 Keyboard().games_keyboard(x)
             time.sleep(0.5)
             Keyboard().games_keyboard('enter')
Esempio n. 6
0
 def __init__(self):
     self.result = ResultPage()
     self.get = GetAttribute()
     self.key = Keyboard()
Esempio n. 7
0
class WordSpelling(BasePage):
    """单词拼写"""
    def __init__(self):
        self.result = ResultPage()
        self.get = GetAttribute()
        self.key = Keyboard()

    # 以下为 共有元素
    @teststeps
    def wait_check_page(self):
        """以“title:单词拼写”的ID为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'单词拼写')]")
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_play_page(self):
        """以“rate”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'{}rate')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def rate(self):
        """获取作业数量"""
        rate = self.driver\
            .find_element_by_id(self.id_type() + "rate").text
        return rate

    @teststep
    def time(self):
        """获取作业时间"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "time").text
        return ele

    @teststep
    def click_voice(self):
        """页面内喇叭量按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "play_voice") \
            .click()

    @teststeps
    def word(self):
        """展示的Word"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        word = ele[1::2]
        print('study_word:', word)
        return word

    @teststep
    def explain(self):
        """展示的翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_explain").text
        return word

    @teststep
    def finish_word(self):
        """完成答题 之后 展示的Word 前后含额外字符:aa"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        return word[1::2]

    # 默写模式 特有元素
    @teststeps
    def dictation_word(self):
        """展示的Word"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        value = ele[::2]
        return value

    @teststeps
    def dictation_word_judge(self):
        """判断是否展示Word"""
        try:
            self.driver \
                .find_element_by_id(self.id_type() + "tv_word")
            return True
        except Exception:
            return False

    @teststep
    def under_line(self):
        """展示的横线"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "underline")
        return ele

    @teststep
    def hint_button(self):
        """提示按钮"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "hint")
        return ele

    # 下一步 按钮之后 答案页展示的答案
    @teststep
    def mine_answer(self):
        """展示的Word  前后含额外字符:aa"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        return word[1::2]

    @teststep
    def question(self):
        """展示的翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_explain").text
        return word

    @teststep
    def correct(self):
        """展示的答案"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_answer").text
        return word

    @teststeps
    def correct_judge(self):
        """判断 答案是否展示"""
        try:
            self.driver \
                .find_element_by_id(self.id_type() + "tv_answer")
            return True
        except Exception:
            return False

    # 默写模式 答案页特有元素
    @teststep
    def dictation_finish_word(self):
        """完成答题 之后 展示的Word  前后不含额外字符:aa"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        return word[::2]

    @teststep
    def dictation_mine_answer(self):
        """展示的Word  前后不含额外字符:aa"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        return word[::2]

    # 以下为答案详情页面元素
    @teststeps
    def wait_check_detail_page(self):
        """以“answer”的ID为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@resource-id," +
                   self.id_type() + "tv_answer)]")
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def result_voice(self, index):
        """语音按钮"""
        self.driver \
            .find_elements_by_id(self.id_type() + "iv_speak")[index] \
            .click()

    @teststep
    def result_answer(self, index):
        """单词"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_answer")[index].text
        return ele

    @teststep
    def result_explain(self, index):
        """解释"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_hint")[index].text
        return ele

    @teststep
    def result_mine(self, index):
        """我的"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "iv_mine")[index]
        value = self.get.get_selected(ele)
        return value

    @teststeps
    def diff_type(self, tpe):
        """选择 不同模式小游戏的 游戏方法"""
        print(tpe)
        time.sleep(2)
        if tpe == '默写模式':
            answer = self.dictation_pattern()
        elif tpe == '自定义':
            answer = self.custom_pattern()
        else:  # 随机模式
            answer = self.random_pattern()
        return answer

    @teststeps
    def random_pattern(self):
        """《单词拼写 随机模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                var = []  # 随机消除的字母
                count = []  # 做错的题目
                answer = []  # return值 与结果页内容比对
                timestr = []  # 获取每小题的时间

                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 判断加 点击操作

                    explain = self.explain()  # 解释
                    word = self.word()  # 未缺失的字母
                    value = word_spelling_operate(explain)  # 数据字典

                    item = word.replace('_', '')
                    if self.is_alphabet(item):  # 未缺失的内容为字母
                        if value != word:  # 随机消除的字母消除了
                            for j in range(len(value)):
                                if value[j] != word[j]:
                                    print('缺失的字母:', value[j])
                                    var.append(j)
                                    self.keyboard_operate(
                                        j, value[j])  # 点击键盘 具体操作

                    answer.append(self.finish_word())  # 我的答案
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断加 点击操作

                    self.result_operate(answer, count, i, timestr,
                                        self.mine_answer())  # 下一步按钮后的答案页面 测试
                    Homework().next_button_operate('true')  # 下一题 按钮 判断加 点击操作
                    print('======================================')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                return rate, answer, var

    @teststeps
    def custom_pattern(self):
        """《单词拼写 自定义模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                count = []  # 做错的题目
                answer = []  # return值 与结果页内容比对
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 判断加 点击操作

                    explain = self.explain()  # 解释
                    word = self.word()  # 未缺失的字母
                    value = word_spelling_operate(explain)  # 数据字典

                    item = word.replace('_', '')
                    if self.is_alphabet(item):  # 未缺失的内容为字母
                        if len(word) != 0:
                            if value != word:  # 自定义消除的字母消除了
                                for j in range(len(value)):
                                    if value[j] != word[j]:
                                        print('缺失的字母:', value[j])
                                        self.keyboard_operate(
                                            j, value[j])  # 点击键盘 具体操作
                            else:
                                print('❌❌❌ Error - 自定义消除的字母未消除', word)
                                for j in range(0, len(value) - 1):
                                    if value[j] != word[j]:
                                        print('❌❌❌ Error - 未自定义消除的字母%s也消除了' %
                                              value[j])

                    answer.append(self.finish_word())  # 我的答案
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击

                    self.result_operate(answer, count, i, timestr,
                                        self.mine_answer())  # 下一步按钮后的答案页面 测试
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击

                    print('======================================')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                return rate, answer

    @teststeps
    def dictation_pattern(self):
        """《单词拼写 默写模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                count = []
                answer = []  # return值 与结果页内容比对
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 判断 加点击

                    explain = self.explain()  # 解释
                    value = word_spelling_operate(explain)  # 数据字典

                    if self.dictation_word_judge():  # 默写模式 - 字母未全部消除
                        print('❌❌❌ Error - 单词拼写 默写模式 - 字母未全部消除')

                    if i in range(2, 5, 2):
                        hint = self.hint_button()  # 提示按钮
                        if self.get.get_enabled(hint) == 'true':
                            hint.click()  # 点击 提示按钮
                            if self.get.get_enabled(hint) != 'false':
                                print('❌❌❌ Error - 点击后提示按钮enabled属性为:',
                                      self.get.get_enabled(hint))

                            if self.dictation_word_judge():  # 出现首字母提示
                                word = self.dictation_word()
                                if len(word) == 1 and word == value[0]:
                                    print('点击提示出现首字母提示', word)
                                else:
                                    print('❌❌❌ Error - 点击提示未出现首字母提示')
                        else:
                            print('❌❌❌ Error - 提示按钮enabled属性为:',
                                  self.get.get_enabled(hint))

                    for j in range(len(value)):
                        self.keyboard_operate(j, value[j])  # 点击键盘 具体操作

                    answer.append(self.dictation_finish_word())  # 我的答案
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击

                    self.result_operate(
                        answer, count, i, timestr,
                        self.dictation_mine_answer())  # 下一步按钮后的答案页面 测试
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击
                    print('======================================')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                return rate, answer

    @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 result_operate(self, answer, count, i, timestr, mine):
        """下一步按钮后的答案页面"""
        # mine 为 答案页面展示的 我的答题结果
        print('----------------------')
        result = answer[len(answer) - 1]
        print('我的答案:', result)
        print('我的答题结果:', mine)
        if self.correct_judge():  # 展示的答案元素存在说明回答错误
            correct = self.correct()  # 正确答案
            if len(mine) <= len(correct):  # 输入少于或等于单词字母数的字符
                if mine.lower() != result.lower():  # 展示的 我的答题结果 是否与我填入的一致
                    print('Error - 字符数少于或等于时:', mine.lower(), result.lower())
            else:  # 输入过多的字符
                if correct + mine[len(correct):].lower() != correct + result[
                        len(correct):].lower():  # 展示的 我的答题结果 是否与我填入的一致
                    print('Error - 字符输入过多时:',
                          correct + mine[len(correct):].lower(),
                          correct + result[len(correct):].lower())

            for k in range(len(correct)):  # 测试 答案判断是否正确
                if result[k] not in correct:
                    count.append(i)  # 做错的题目
                    break
        else:  # 回答正确
            if mine.lower() != result.lower():  # 展示的 我的答题结果 是否与我填入的一致
                print('Error - 展示的答题结果 与我填入的不一致:', mine.lower(),
                      result.lower())

        if i == 1:  # 第2题
            j = 0
            print('多次点击发音按钮:')
            while j < 4:
                print(j)
                self.click_voice()  # 多次点击发音按钮
                j += 1
            time.sleep(1)
        else:
            self.click_voice()  # 点击 发音按钮
        timestr.append(self.time())  # 统计每小题的计时控件time信息

    @teststeps
    def result_detail_page(self, rate):
        """查看答案 操作过程"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.check_result_button()  # 结果页 查看答案 按钮
            if self.result.wait_check_detail_page():
                print('======================================')
                print('查看答案:')
                self.error_sum(rate)
                time.sleep(2)
            print('==============================================')

    @teststeps
    def error_sum(self, rate):
        """查看答案 - 点击答错的题 对应的 听力按钮"""
        print('题数:', int(rate))
        for i in range(0, int(rate)):
            print('解释:', self.result_explain(i))  # 解释
            print('单词:', self.result_answer(i))  # 正确word
            print('对错标识:', self.result_mine(i))  # 对错标识
            print('-----------------------------------')
            self.result_voice(i)  # 点击发音按钮
        self.result.back_up_button()  # 返回结果页

    @teststeps
    def study_again(self, tpe):
        """再练一遍 操作过程"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.again_button()  # 结果页 再练一遍 按钮
            print('再练一遍:')
            self.diff_type(tpe)  # 不同模式 对应不同的游戏过程
Esempio n. 8
0
class ChoiceWordCloze(BasePage):
    """选词填空"""
    def __init__(self):
        self.bounds = ClickBounds()
        self.result = ResultPage()
        self.get = GetAttribute()
        self.key = Keyboard()

    @teststeps
    def wait_check_page(self):
        """以“title:选词填空”的xpath-index为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@text,'选词填空')]")
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_play_page(self):
        """以“rate”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                             + self.id_type() + "rate)]")
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def rate(self):
        """获取作业数量"""
        rate = self.driver\
            .find_element_by_id(self.id_type() + "rate").text
        return rate

    @teststep
    def font_middle(self):
        """第一个Aa"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "font_middle")
        return ele

    @teststep
    def font_large(self):
        """第二个Aa"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "font_large")
        return ele

    @teststep
    def font_great(self):
        """第三个Aa"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "font_great")
        return ele

    @teststep
    def prompt(self):
        """提示词"""
        self.driver\
            .find_element_by_id(self.id_type() + "prompt").click()

    @teststep
    def bounds_prompt(self):
        """提示词按钮"""
        ele = self.driver\
            .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1]
        return ele

    @teststep
    def prompt_content(self):
        """提示词内容"""
        ele = self.driver \
            .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1].text
        return ele

    @teststep
    def click_blank(self):
        """点击页面 提示词弹框 以外空白处,弹框消失"""
        self.bounds.click_bounds(67.5, 1119.5)
        time.sleep(1)

    @teststep
    def time(self):
        """获取作业时间"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "time").text
        return ele

    # 查看答案 页面
    @teststeps
    def wait_check_detail_page(self):
        """以“answer”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                             + self.id_type() + "tv_answer)]")
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def content_value(self):
        """获取整个 外框元素"""
        ele = self.driver\
            .find_element_by_id(self.id_type() + "tb_content")
        return ele

    @teststeps
    def content_desc(self):
        """点击输入框,激活小键盘"""
        content = self.get.get_description(self.content_value())
        item_x = re.match(".*\[(.*)\].*\[", content)  # x值
        item_y = re.match(".*\[(.*)\].*", content)  # y值
        x = item_x.group(1).split(',')  # 所有输入框y值的列表
        y = item_y.group(1).split(',')  # 所有输入框x值的列表
        return x, y

    @teststeps
    def get_result(self):
        """点击输入框,激活小键盘"""
        content = self.get.get_description(self.content_value())
        value = re.match("\\[(.+?)\\]", content)  # answer
        answer = value.group(1).split(',')  # 所有输入框值的列表
        print('正确答案:', answer)
        self.click_blank()
        return answer

    @teststeps
    def choice_word_filling(self):
        """《选词填空》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                timestr = []
                self.prompt()  # 右上角 提示词
                time.sleep(1)
                content = self.prompt_content()  # 取出提示内容
                self.click_blank()  # 点击空白处 弹框消失
                word_list = content.split('   ')  # 取出单词列表
                print('待输入的单词:', word_list)

                self.font_operate()  # Aa文字大小切换按钮 切换 及状态统计

                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 状态判断 加点击

                    if i == 0:  # 获取第一个输入框的坐标,点击激活小键盘
                        item = self.content_desc()
                        loc = self.get_element_location(self.content_value())  # 文章元素左上角 顶点坐标
                        x = float(item[0][i]) + loc[0]+55.0  # 55.0为点击输入框中心点的偏移量
                        y = float(item[1][i]) + loc[1]
                        self.driver.tap([(x, y)])  # 点击激活输入框
                    else:
                        self.key.games_keyboard('enter')  # 点击回车键进入下一题

                    word = word_list[i]  # 单词
                    print('study_word:', word)
                    if len(word_list) >= int(rate):
                        for index in range(len(word)):
                            if index == 4:
                                self.key.games_keyboard('capslock')  # 点击键盘 切换到 大写字母
                                self.key.games_keyboard(word[index].upper())  # 点击键盘对应 大写字母
                                self.key.games_keyboard('capslock')  # 点击键盘 切换到 小写字母
                            else:
                                self.key.games_keyboard(word[index])  # 点击键盘对应字母
                    else:
                        self.key.games_keyboard('a')  # 点击键盘对应字母

                    timestr.append(self.time())  # 统计每小题的计时控件time信息

                Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击
                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('==================================================')
                return rate

    @teststeps
    def check_detail_page(self, rate, homework_title, game_title):
        """查看答案页面面"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.check_result_button()  # 结果页 查看答案 按钮

            if self.result.wait_check_detail_page():  # 页面检查点
                print('查看答案页面:')
                item = self.get_result()
                print('excel-opeate:')
                for i in range(len(item)):
                    print('----------------------')
                    ExcelUtil().data_write(rate, homework_title, game_title, item[i])
                self.result.back_up_button()

    @teststeps
    def font_operate(self):
        """Aa文字大小切换按钮 状态判断 及 切换操作"""
        x = []
        y = []
        middle = self.font_middle()  # first
        large = self.font_large()  # second
        great = self.font_great()  # third

        i = 0
        j = 0
        while i < 3:
            bounds = self.content_desc()  # 获取输入框坐标
            print(self.get.get_checked(middle), self.get.get_checked(large), self.get.get_checked(great))

            if self.get.get_checked(middle) == 'false':
                if self.get.get_checked(large) == 'false':
                    x.insert(2, bounds[0][0])
                    y.insert(2, bounds[1][0])
                    print('当前选中的Aa按钮为第3个:', bounds[0][0], bounds[1][0])
                    j = 3
                else:
                    if self.get.get_checked(large) == 'true':
                        x.insert(1, bounds[0][0])
                        y.insert(1, bounds[1][0])
                        print('当前选中的Aa按钮为第2个:', bounds[0][0], bounds[1][0])
                        j = 2
            else:
                x.insert(0, bounds[0][0])
                y.insert(0, bounds[1][0])
                print('当前选中的Aa按钮为第1个:', bounds[0][0], bounds[1][0])
                j = 1

            if j == 1:
                large.click()
            elif j == 2:
                great.click()
            else:
                middle.click()
            i += 1
            print('--------------------------------------------')
            time.sleep(2)

        if not float(y[2]) > float(y[1]) > float(y[0]):
            print('❌❌❌ Error - Aa文字大小切换按钮:', y)
        print('==============================================')
 def __init__(self):
     self.get = GetAttribute()
     self.key = Keyboard()
class FlashCardPage(BasePage):
    """闪卡练习"""
    def __init__(self):
        self.get = GetAttribute()
        self.key = Keyboard()

    @teststeps
    def wait_check_page(self):
        """以“title:闪卡练习”的ID为依据"""
        locator = (By.XPATH,
                   "//android.widget.ImageView[contains(@resource-id,"
                   "'{}iv_star')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def wait_check_tip_num(self, num):
        """查看题目数量是否发生改变"""
        locator = (
            By.XPATH,
            "//android.widget.ImageView[contains(@text,'{}')]".format(num))
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def click_star(self):
        """闪卡练习页面内 标星按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "iv_star") \
            .click()

    @teststep
    def click_voice(self):
        """闪卡练习页面内音量按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "play_voice") \
            .click()

    @teststep
    def rate(self):
        """获取作业数量"""
        rate = self.driver\
            .find_element_by_id(self.id_type() + "rate").text
        return rate

    # 以下为学习模式 特有元素
    @teststep
    def english_study(self):
        """Word"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_english").text
        return word

    @teststep
    def explain_study(self):
        """翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_chinese").text
        return word

    @teststep
    def pattern_switch(self):
        """闪卡练习页面内  全英/英汉模式切换 按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "iv_rotate")\
            .click()
        time.sleep(1)

    # 英汉模式 的例句
    @teststeps
    def wait_check_sentence_page(self, var=20):
        """以“例句”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'{}sentence')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, var,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_explain_page(self, var=20):
        """以“例句解释”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'{}sentence_explain')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, var,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def sentence_study(self):
        """例句"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "sentence").text
        print('例句:', word)

    @teststep
    def sentence_explain_study(self):
        """例句翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "sentence_explain").text
        print('例句解释:', word)

    @teststep
    def sentence_author_study(self):
        """例句 提供老师"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "author").text
        print(word)

    @teststeps
    def click_blank(self):
        """点击空白处"""
        ClickBounds().click_bounds(430, 800)
        print('点击空白处,切换双页面:')
        time.sleep(1)

    # 以下为抄写模式 特有元素
    @teststep
    def word_copy(self):
        """闪卡练习- 抄写模式 内展示的Word"""
        ele = self.driver\
            .find_element_by_id(self.id_type() + "tv_word")
        return ele.text

    @teststep
    def english_copy(self):
        """单页面内 答题框填入的Word"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "english").text
        return word

    @teststep
    def explain_copy(self):
        """闪卡练习内展示的翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "chinese").text
        return word

    # 以下为闪卡练习 结果页
    @teststeps
    def wait_check_result_page(self, var=10):
        """以“title:答题报告”的ID为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'完成学习')]")
        try:
            WebDriverWait(self.driver, var,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def finish_study(self):
        """完成学习"""
        ele = self.driver \
            .find_element_by_xpath("//android.widget.TextView[contains(@index,0)]").text
        print(ele)
        return ele

    @teststeps
    def study_sum(self):
        """eg: study_sum:6个内容,0标记★;抄写模式"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "study_sum").text
        print(ele)
        return ele

    @teststep
    def study_again_button(self):
        """再练一遍"""
        self.driver \
            .find_element_by_id(self.id_type() + "textView") \
            .click()

    @teststep
    def star_again_button(self):
        """标星内容再练一遍"""
        self.driver \
            .find_element_by_id(self.id_type() + "tv_star_en") \
            .click()

    @teststep
    def star_button(self):
        """五星按钮"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "iv_select")
        return ele

    @teststep
    def voice_button(self, index):
        """语音按钮"""
        self.driver \
            .find_elements_by_id(self.id_type() + "iv_voice")[index] \
            .click()

    @teststep
    def result_word(self):
        """展示的Word"""
        ele = self.driver.find_elements_by_id(self.id_type() + "tv_word")
        return ele

    @teststep
    def result_explain(self):
        """展示的  解释"""
        word = self.driver \
            .find_elements_by_id(self.id_type() + "tv_explain")
        return word

    @teststeps
    def study_pattern(self):
        """《闪卡练习 学习模式》 游戏过程"""
        if self.wait_check_page():
            answer = []  # return值 与结果页内容比对
            rate = self.rate()
            for i in range(int(rate)):
                Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                Homework().next_button_judge('true')  # 下一题 按钮 状态判断

                # self.click_voice()  # 听力按钮
                if i in (2, 5):  # 第3、6题  进入全英模式
                    self.pattern_switch()  # 切换到 全英模式
                    print('切换到 全英模式:')
                    if self.wait_check_sentence_page(5):
                        self.sentence_study()  # 例句
                        self.sentence_author_study()  # 例句作者

                    word = self.english_study()  # 单词
                    print('单词:%s' % word)

                    self.pattern_switch()  # 切换到 英汉模式
                else:
                    if self.wait_check_explain_page(5):
                        self.sentence_study()  # 例句
                        self.sentence_explain_study()  # 例句解释
                        self.sentence_author_study()  # 例句作者

                    word = self.english_study()  # 单词
                    explain = self.explain_study()  # 解释
                    print('单词:%s, 解释:%s' % (word, explain))

                answer.append(self.english_study())

                if i in range(1, 9, 2):  # 点击star按钮
                    self.click_star()
                    # if i == 1:
                    #     self.tips_operate()

                if i == 3 and i != int(rate) - 1:  # 第四题 滑屏进入下一题
                    self.screen_swipe_left(0.9, 0.5, 0.1, 1000)
                    time.sleep(1)
                else:
                    if i == int(rate) - 1:  # 最后一题 尝试滑屏进入结果页
                        self.screen_swipe_left(0.9, 0.5, 0.1, 1000)
                        if self.wait_check_result_page(5):
                            print('❌❌❌ Error - 滑动页面进入了结果页')

                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击
                    time.sleep(1)
                print('-------------------------')
            print('=================================')
            return rate, answer

    @teststeps
    def copy_pattern(self):
        """《闪卡练习 抄写模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            answer = []  # return值 与结果页内容比对
            rate = self.rate()
            for i in range(int(rate)):
                if self.wait_check_page():
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    right_word = self.word_copy()
                    word = list(right_word)  # 展示的Word -- 转化为list形式
                    answer.append(right_word)
                    print("第%s题,单词是:%s" % (i + 1, right_word))
                    self.voice_operate(i)  # 听力按钮

                    for j in range(len(word)):
                        print(word[j])
                        if j == 5:
                            self.key.games_keyboard(
                                'capslock')  # 点击键盘 切换到 大写字母
                            self.key.games_keyboard(
                                word[j].upper())  # 点击键盘对应 大写字母
                        else:
                            if j == 6:
                                self.key.games_keyboard(
                                    'capslock')  # 点击键盘 切换到 小写字母
                            self.key.games_keyboard(
                                word[j].lower())  # 点击键盘对应字母
                    print('--------------------------------')
                time.sleep(4)
            print('=================================')
            return rate, answer

    @teststeps
    def voice_operate(self, i):
        """听力按钮 操作"""
        if i == 2:  # 第3题
            j = 0
            print('多次点击发音按钮:')
            while j < 4:
                self.click_voice()  # 多次点击发音按钮
                j += 1
            time.sleep(1)
        else:
            self.click_voice()  # 点击 发音按钮

    @teststeps
    def result_page(self, i, answer):
        """结果页操作"""
        self.finish_study()  # 完成学习
        self.study_sum()  # 学习结果

        word = self.result_word()
        print('判断是否滑动:', i)
        if len(word) <= int(i):
            # self.result_operate(int(i)-1, answer)
            # self.screen_swipe_up(0.5, 0.75, 0.35, 1000)
            self.result_operate(i, answer, int(i))
        else:
            name = word[len(word) - 1].text
            self.result_operate(len(word) - 1, answer)
            self.screen_swipe_up(0.5, 0.75, 0.35, 1000)

            index = self.result_operate_swipe(name)
            for j in range(5):
                if len(index) == 0:
                    self.screen_swipe_down(0.5, 0.75, 0.65, 1000)
                    index = self.result_operate_swipe(name)
                else:
                    break
            word = self.result_word()
            self.result_operate(len(word), answer, index[0])
        print('=================================')

    @teststeps
    def result_operate_swipe(self, name):
        """滑屏操作"""
        index = []
        word = self.result_word()
        for j in range(len(word)):
            if word[j].text == name:
                index.append(j)
                break
        return index

    @teststeps
    def result_operate(self, index, answer, k=0):
        """结果页 具体操作"""
        word = self.result_word()
        for i in range(len(word)):
            print(word[i].text, answer[i])
            if word[i].text != answer[i]:  # 结果页 展示的word与题目中是否一致
                print('❌❌❌ Error 查看答案页 展示的word与题中不一致')

        for index in range(k, int(index), 3):  # 点击 结果页 听力按钮
            self.voice_button(index)  # 结果页 - 听力按钮
            self.star_button()[index].click()  # 结果页 star 按钮

    @teststeps
    def selected_sum(self):
        """标星的数目统计"""
        var = self.star_button()  # 结果页star按钮
        ele = []  # 结果页标星的作业数
        for i in range(len(var)):
            if self.get.get_selected(var[i]) == 'true':
                ele.append(i)

        if len(ele) == 0:  # 结果页标星的作业数为0,则执行以下操作
            print('结果页标星的作业数为0, 点击star按钮:')
            for index in range(0, len(var), 2):
                self.star_button()[index].click()  # 结果页 star 按钮

            ele = []  # 结果页标星的作业数
            for i in range(len(var)):
                if self.get.get_selected(var[i]) == 'true':
                    ele.append(i)

            self.study_sum()  # 学习情况
            print('----------------')

        print('star按钮数目:', len(var))
        print('标星数:', len(ele))
        print('========================')
        return len(ele)
 def __init__(self):
     super().__init__()
     self.data = WordDataHandlePage()
     self.key = Keyboard()
     self.word_public = WorldBookPublicPage()
 def __init__(self):
     self.key = Keyboard()
     self.word_public = WorldBookPublicPage()
Esempio n. 13
0
 def __init__(self):
     self.result = ResultPage()
     self.key = Keyboard()
Esempio n. 14
0
class WordDictation(BasePage):
    """单词听写"""
    def __init__(self):
        self.result = ResultPage()
        self.key = Keyboard()

    @teststeps
    def wait_check_page(self):
        """以“title:单词听写”的xpath-index为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'单词听写')]")
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_play_page(self):
        """以“rate”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'{}rate')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def rate(self):
        """获取作业数量"""
        rate = self.driver \
            .find_element_by_id(self.id_type() + "rate").text
        return rate

    @teststep
    def time(self):
        """获取作业时间"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "time").text
        return ele

    @teststep
    def click_voice(self):
        """页面内音量按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "play_voice") \
            .click()

    @teststeps
    def word(self):
        """展示的Word  点击喇叭听写单词"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        word = ele.replace(' ', '')  # 删除空格
        return word

    # 下一步 按钮之后 答案页展示的答案
    @teststeps
    def mine_answer(self):
        """展示的Word """
        ele = self.driver \
            .find_element_by_id(self.id_type() + "tv_word").text
        word = ele.replace(' ', '')  # 删除空格
        return word

    @teststep
    def question(self):
        """展示的翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_explain").text
        return word

    @teststeps
    def correct(self):
        """展示的答案"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "tv_answer").text
        print('正确答案:', word)
        return word

    @teststep
    def correct_judge(self):
        """判断 答案是否展示"""
        ele = self.find_element(self.id_type() + "tv_answer")
        return ele

    # 以下为答案详情页面元素
    @teststeps
    def wait_check_detail_page(self):
        """以“answer”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'{}tv_answer')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def result_voice(self, index):
        """语音按钮"""
        self.driver \
            .find_elements_by_id(self.id_type() + "iv_speak")[index] \
            .click()

    @teststep
    def result_answer(self, index):
        """单词"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_answer")[index].text
        return ele

    @teststep
    def result_explain(self, index):
        """解释"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_hint")[index].text
        return ele

    @teststep
    def result_mine(self, index):
        """我的"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "iv_mine")[index].get_attribute("selected")
        return ele

    @teststeps
    def word_dictation(self):
        """《单词听写》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                count = []
                answer = []  # return值 与结果页内容比对
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 判断 加点击

                    self.word()  # 灰字文案:点击喇叭听写单词
                    self.click_voice()  # 点击喇叭

                    word = dictation_operate(i)  # 数据字典
                    if self.is_alphabet(word):  # 解释内容为word
                        for j in range(0, len(word)):
                            self.keyboard_operate(j, word[j])  # 点击键盘 具体操作

                    answer.append(self.word())  # 我的答案
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击

                    self.result_operate(answer, count, i, timestr,
                                        self.mine_answer())  # 下一步按钮后的答案页面 测试
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 加点击
                    print('--------------------------------------')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('==============================================')
                return rate, answer

    @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)  # 点击键盘对应字母
        Homework().next_button_judge('true')  # 测试 下一步 按钮的状态

    @teststeps
    def result_operate(self, answer, count, i, timestr, mine):
        """下一步按钮后的答案页面"""
        # mine 为 答案页面展示的 我的答题结果
        result = answer[len(answer) - 1]
        print('我的答案:', result)
        print('我的答题结果:', mine)
        if self.correct_judge():  # 展示的答案元素存在说明回答错误
            correct = self.correct()  # 正确答案
            if mine.lower() != result.lower():  # 展示的答题结果与我填入的答案不一致
                print('❌❌❌ Error - 展示的答题结果:%s 与我填入的答案:%s 不一致' % (mine, result))

            for k in range(len(correct)):  # 测试 答案判断是否正确
                if result[k] not in correct:
                    count.append(i)  # 做错的题目
                    break
        else:  # 回答正确
            if mine.lower() != result.lower():  # 展示的 我的答题结果 是否与我填入的一致
                print('❌❌❌ Error - 展示的答题结果 与我填入的不一致:', mine, result)

        if i == 1:  # 第2题
            j = 0
            print('多次点击发音按钮:')
            while j < 4:
                print(j)
                self.click_voice()  # 多次点击发音按钮
                j += 1
            time.sleep(1)
        else:
            self.click_voice()  # 点击 发音按钮
        timestr.append(self.time())  # 统计每小题的计时控件time信息

    @teststeps
    def result_detail_page(self, rate):
        """《单词听写》 查看答案 操作过程"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.check_result_button()  # 结果页 查看答案 按钮
            if self.result.wait_check_detail_page():
                if self.wait_check_detail_page():
                    print('查看答案:')
                    print('题数:', int(rate))
                    for i in range(int(rate)):
                        print('-----------------------------------')
                        print('解释:', self.result_explain(i))  # 解释
                        print('单词:', self.result_answer(i))  # 正确word
                        print('对错标识:', self.result_mine(i))  # 对错标识
                        self.result_voice(i)  # 点击发音按钮
                    self.result.back_up_button()  # 返回结果页
                    time.sleep(2)
            print('==============================================')

    @teststeps
    def study_again(self):
        """再练一遍 操作过程"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.again_button()  # 结果页 再练一遍 按钮
            print('再练一遍:')
            self.word_dictation()  # 游戏过程
class StrengthenSentence(BasePage):
    """强化炼句"""
    def __init__(self):
        self.bounds = ClickBounds()
        self.result = ResultPage()
        self.key = Keyboard()
        self.get = GetAttribute()

    # 以下为 共有元素
    @teststeps
    def wait_check_page(self):
        """以“title:强化炼句”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@text,'强化炼句')]")
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_play_page(self):
        """以“rate”的ID为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                             "'{}rate')]".format(self.id_type()))
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def rate(self):
        """获取作业数量"""
        rate = self.driver\
            .find_element_by_id(self.id_type() + "rate").text
        return rate

    @teststep
    def time(self):
        """获取作业时间"""
        rate = self.driver\
            .find_element_by_id(self.id_type() + "time").text
        return rate

    @teststep
    def content_value(self):
        """获取整个 外框元素"""
        ele = self.driver \
            .find_element_by_id(self.id_type() + "input2")
        return ele

    @teststeps
    def content_desc(self):
        """点击输入框,激活小键盘"""
        content = self.get.get_description(self.content_value())
        item_x = re.match(".*\[(.*)\].*\[", content)  # x值
        item_y = re.match(".*\[(.*)\].*", content)  # y值
        x = item_x.group(1).split(',')  # 所有输入框y值的列表
        y = item_y.group(1).split(',')  # 所有输入框x值的列表
        return x, y

    @teststeps
    def get_result(self):
        """点击输入框,激活小键盘"""
        content = self.get.get_description(self.content_value())
        value = re.match("\\[(.+?)\\]", content)  # answer
        answer = value.group(1).split(',')  # 所有输入框值的列表
        return answer

    @teststep
    def click_voice(self):
        """页面内音量按钮"""
        self.driver \
            .find_element_by_id(self.id_type() + "play_voice") \
            .click()

    @teststeps
    def sentence(self):
        """展示的句子"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "input2").text
        return word

    @teststep
    def explain(self):
        """展示的翻译"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "explain").text
        return word

    # 每小题回答完,下一步按钮后展示答案的页面
    @teststeps
    def correct_title(self):
        """展示的答案title:正确答案 的ID为依据"""
        locator = (By.ID, self.id_type() + "correct_title")
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def correct(self):
        """展示的答案"""
        word = self.driver \
            .find_element_by_id(self.id_type() + "correct").text
        ele = word[:-1]  # 去掉最后的标点符号
        return ele

    # 查看答案页面
    @teststeps
    def result_question(self):
        """展示的题目"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_hint")
        word = []
        for i in range(len(ele)):
            word.append(ele[i].text)
        return word

    @teststeps
    def result_answer(self):
        """展示的 正确答案"""
        ele = self.driver \
            .find_elements_by_id(self.id_type() + "tv_answer")
        word = []
        for i in range(len(ele)):
            word.append(ele[i].text)
        return word

    @teststep
    def result_mine_state(self, index):
        """我的答案对错标识 selected属性"""
        word = self.driver \
            .find_elements_by_id(self.id_type() + "iv_mine")[index].get_attribute('selected')
        return word

    @teststeps
    def diff_type(self, tpe):
        """选择 不同模式小游戏的 游戏方法"""
        print(tpe)
        if tpe == '默写模式':
            answer = self.dictation_pattern()
        elif tpe == '自定义模式':
            answer = self.custom_pattern()
        elif tpe == '简单模式':
            answer = self.easy_pattern()
        else:  # 复杂模式
            answer = self.random_pattern()
        return answer

    @teststeps
    def random_pattern(self):
        """《强化炼句 复杂模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                answer = []
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 判断加 点击操作

                    value = self.input_text()  # 激活输入框并进行输入
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断加 点击操作 ,进入答案页面

                    self.correct_judge(value, i)  # 判断答题是否正确
                    timestr.append(self.time())  # 统计每小题的计时控件time信息

                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断加 点击操作
                    print('-------------------------------')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('======================================================')
                return rate, answer

    @teststeps
    def custom_pattern(self):
        """《强化炼句 自定义模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                answer = []
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 状态判断 点击

                    value = self.input_text()  # 激活输入框并进行输入
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击
                    if self.correct_title():
                        result = self.correct_judge(value, i)  # 判断答题是否正确
                        answer.append(result[0])

                    timestr.append(self.time())  # 统计每小题的计时控件time信息
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击
                    print('-------------------------------')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('======================================================')
                return rate, answer

    @teststeps
    def easy_pattern(self):
        """《强化炼句 简单模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                answer = []
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 状态判断 点击

                    value = self.input_text()  # 激活输入框并进行输入
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击,进入答案页面

                    result = self.correct_judge(value, i)  # 判断答题是否正确
                    answer.append(result[0])
                    timestr.append(self.time())  # 统计每小题的计时控件time信息

                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击
                    print('-------------------------------')

                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('======================================================')
                return rate, answer

    @teststeps
    def dictation_pattern(self):
        """《强化炼句 默写模式》 游戏过程"""
        if self.wait_check_page():  # 页面检查点
            if self.wait_check_play_page():
                answer = []
                timestr = []  # 获取每小题的时间
                rate = self.rate()
                for i in range(int(rate)):
                    Homework().rate_judge(rate, i)  # 测试当前rate值显示是否正确
                    Homework().next_button_operate('false')  # 下一题 按钮 状态判断 点击

                    value = self.input_text()  # 激活输入框并进行输入
                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击,进入答案页面

                    result = self.correct_judge(value, i)  # 判断答题是否正确
                    answer.append(result[0])
                    timestr.append(self.time())  # 统计每小题的计时控件time信息

                    Homework().next_button_operate('true')  # 下一题 按钮 状态判断 点击
                    print('-----------------------------')
                Homework().now_time(timestr)  # 判断游戏界面 计时功能控件 是否在计时
                print('==================================================')
                return rate, answer

    @teststeps
    def input_text(self):
        """激活输入框 并 输入内容"""
        explain = self.explain()  # 解释的内容
        sentence = self.sentence().split(' ')  # 句子
        print('题目:', self.sentence())
        value = strength_sentence_operate(explain)  # 数据字典

        words = value.split(' ')  # 将句子分割成单词
        word = []
        for i in range(len(words)):
            if (self.is_alphabet(words[i])) and (words[i] not in sentence):
                word.append(words[i])

        for j in range(len(word)):
            item = self.content_desc()  # 获取输入框坐标
            loc = self.get_element_location(self.content_value())  # 文章元素左上角 顶点坐标
            x = float(item[0][j]) + loc[0]+55.0  # 55.0为点击输入框中心点的偏移量
            y = float(item[1][j]) + loc[1]
            self.driver.tap([(x, y)])  # 点击激活输入框

            for z in range(len(word[j])):
                if j == len(word)-1:
                    if word[j][z] in ['.', '?', '!']:  # 去掉最后的标点符号
                        break
                if z == 4 and z != len(word[j])-1:
                    self.key.games_keyboard('capslock')  # 点击键盘 切换到 大写字母
                    self.key.games_keyboard(word[j][z].upper())  # 点击键盘对应 大写字母
                    self.key.games_keyboard('capslock')  # 点击键盘 切换到 小写字母
                else:
                    if j == 2 and word[j][z] == "'":
                        self.key.games_keyboard(',')  # 第二小题  点击键盘 逗号
                    else:
                        self.key.games_keyboard(word[j][z])  # 点击键盘对应字母

        return value

    @teststeps
    def correct_judge(self, value, i):
        """每小题回答完,下一步按钮后展示答案的页面"""
        if self.correct_title():  # 展示的答案title元素是否存在
            result = self.get_result()  # content-desc的值
            answer = self.sentence()  # 展示的本人的答案

            for j in range(len(result)):
                for k in range(len(answer)):
                    if answer[k] == '{':
                        if len(answer) != 2:
                            if k == 0:  # 展示的本人的答案 result[j]
                                answer = result[j].strip() + answer[k + 2:]
                            elif k + 1 == len(answer) - 1:
                                if ' ' not in result[j]:
                                    answer = answer[:k - 1] + ' ' + result[j]
                                else:
                                    answer = answer[:k - 1] + result[j]
                            else:
                                if ' ' not in result[j]:
                                    answer = answer[:k - 1] + ' ' + result[j] + answer[k + 2:]
                                else:
                                    answer = answer[:k - 1] + result[j] + answer[k + 2:]
                            break

            if answer[len(answer)-1] == ' ':
                answer = answer[:-1]
            correct = self.correct()  # 展示的正确答案
            print('我的答案:', answer)
            if correct == value:  # 测试展示的答案是否正确
                if answer == correct:
                    print('回答正确')
                else:
                    print('回答错误')
            return answer, i

    @teststeps
    def study_again(self, tpe):
        """《强化炼句》 再练一遍 操作过程"""
        print('再练一遍 操作过程:')
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.again_button()  # 结果页 再练一遍 按钮
            result = self.diff_type(tpe)  # 强化炼句 - 游戏过程

            return '再练一遍按钮', result[0], result[1]

    @teststeps
    def check_detail_page(self, i, answer):
        """查看答案页面"""
        if self.result.wait_check_result_page():  # 结果页检查点
            self.result.check_result_button()  # 查看答案 按钮
            if self.result.wait_check_detail_page():
                print('结果页 - 查看答案 按钮:')
                if int(i) <= 16:
                    self.result_operate(answer)
                else:
                    item = self.result_question()
                    if int(i) % len(item) == 0:
                        page = int(int(i) / len(item))
                    else:
                        page = int(int(i) / len(item)) + 1
                    print('页数:', page)
                    for j in range(page):
                        last_one = self.result_operate(answer)  # 滑动前页面内最后一个小题- 做题结果
                        self.screen_swipe_up(0.5, 0.75, 0.35, 1000)
                        item_2 = self.result_question()  # 滑动后页面内的题目 的数量
                        if item_2[len(item_2) - 1].text == last_one:
                            print('到底啦', last_one)
                            self.result.back_up_button()
                            break
                        elif item_2[len(item_2) - 1].text == answer[len(answer) - 1]:
                            # 滑动后到底,因为普通情况下最多只有两页,滑动一次即可到底
                            print('滑动后到底', last_one)
                            k = []
                            for i in range(len(item_2) - 1, -1, -1):  # 倒序
                                if item_2[i].text == last_one:
                                    k.append(i + 1)
                                    break
                            self.result_operate(answer, k[0])
                            break
                        else:
                            continue
                    self.screen_swipe_down(0.5, 0.75, 0.35, 1000)
                time.sleep(2)
            self.result.back_up_button()

    @teststeps
    def result_operate(self, var, index=0):
        """查看答案页面 -- 展示的解释内容验证"""
        explain = self.result_question()  # 题目
        answer = self.result_answer()  # 正确答案
        print(answer, var)
        for i in range(index, len(explain)):
            count = []
            value = strength_sentence_operate(explain[i]).split(' ')
            if answer[i] == var[i]:  # 测试结果页 我的答案展示是否正确
                if answer[i] == value:  # 测试 正确答案
                    for j in range(len(var)):  # 我的答案 与 正确答案 比较
                        if var[j] != value[j]:  # 答案不正确 count+1
                            count.append(j)
                            if self.result_mine_state() != 'false':
                                print('❌❌❌ Error - 我的答案:%s 与 正确答案:%s 对错标识:%s' % (var[j], value[j], 'true'))
                        else:
                            if self.result_mine_state() != 'true':
                                print('❌❌❌ Error - 我的答案:%s 与 正确答案:%s 对错标识:%s' % (var[j], value[j], 'false'))
                        break
                else:
                    print('❌❌❌ Error - 正确答案:', answer[i], value)
            print('------------------------------------')
        return var[1][len(var[1]) - 1]
Esempio n. 16
0
class GameCommonEle(BasePage):
    keyboard = Keyboard()
    wait = WaitElement()
    """游戏公共元素"""
    @teststep
    def wait_check_end_tip_page(self):
        """游戏标题页面检查点"""
        locator = (By.XPATH,
                   '//android.widget.TextView[contains(@text, "到底啦 下拉刷新试试")]')
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_commit_btn_page(self):
        """提交按钮处页面检查点"""
        locator = (By.ID, self.id_type() + 'fab_commit')
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_share_area_page(self):
        """分享页面检查点"""
        locator = (By.ID, '{}share_area'.format(self.id_type()))
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_punch_share_page(self):
        """分享页面检查点"""
        locator = (By.ID, '{}share_img'.format(self.id_type()))
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_select_friend_page(self):
        """选择好友与群页面"""
        locator = (By.XPATH, "//android.widget.Button[@text='多选']")
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_friend_circle_page(self):
        """发表朋友圈页面"""
        locator = (By.XPATH, "//android.widget.Button[@text='发表']")
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_login_wechat_page(self):
        """微信登陆页面"""
        locator = (By.XPATH,
                   '//android.widget.TextView[contains(@text,"登录微信")]')
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_wechat_alert_tip_page(self):
        """弹框提示页面检查点"""
        locator = (By.XPATH,
                   '//android.widget.TextView[contains(@text,"保留此次编辑")]')
        return self.wait.wait_check_element(locator, timeout=3)

    @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 wait_check_word_container_by_index_and_id(self, index):
        """单词容器获取依据"""
        locator = (
            By.XPATH,
            "//*[@content-desc='{}' and contains(@resource-id, 'item_container')]"
            .format(index))
        return self.wait.wait_check_element(locator, timeout=2)

    @teststep
    def wait_check_sentence_container_by_content_desc(self, index):
        """句子容器获取依据"""
        locator = (
            By.XPATH,
            "//android.widget.LinearLayout[@content-desc='{}']".format(index))
        return self.wait.wait_check_element(locator, timeout=2)

    @teststep
    def wait_check_article_container_by_index(self, index):
        """文章类游戏容器获取依据"""
        locator = (
            By.XPATH,
            "//android.widget.LinearLayout[@index='{}']/android.view.ViewGroup"
            .format(index))
        return self.wait.wait_check_element(locator, timeout=2)

    @teststep
    def wait_check_tips_page(self):
        """提示页面检查点"""
        locator = (By.ID, '{}md_title'.format(self.id_type()))
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_play_voice_page(self):
        """喇叭播放按钮"""
        locator = (By.ID, '{}play_voice'.format(self.id_type()))
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_dragger_btn(self):
        """检查页面是否存在拖拽按钮"""
        locator = (By.ID, self.id_type() + "dragger")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_rich_text_page(self):
        """文章类游戏富文本元素页面检查点"""
        locator = (By.ID, '{}rich_text'.format(self.id_type()))
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_keyboard_page(self):
        """键盘页面检查"""
        locator = (By.ID, '{}keyboard_abc_view'.format(self.id_type()))
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def wait_check_permit_tab_page(self):
        """存储允许"""
        locator = (By.ID, 'com.android.packageinstaller:id/permission_message')
        return self.wait.wait_check_element(locator, timeout=5)

    @teststep
    def game_title(self):  # 题型标题
        locator = (By.ID, self.id_type() + 'tv_title')
        return self.wait.wait_find_element(locator)

    @teststep
    def game_mode_id(self):
        """获取题目的mode_id"""
        mode_id = int(self.game_title().get_attribute(
            'contentDescription').split('  ')[1])
        return mode_id

    @teststep
    def hide_keyboard_btn(self):
        """键盘隐藏按钮"""
        locator = (By.ID, self.id_type() + 'keyboard_hide')
        return self.wait.wait_find_element(locator)

    @teststep
    def rich_text(self):
        """文章类游戏文章文本"""
        locator = (By.ID, self.id_type() + 'rich_text')
        return self.wait.wait_find_element(locator)

    @teststep
    def question(self):
        """游戏问题"""
        locator = (By.ID, self.id_type() + 'question')
        return self.wait.wait_find_element(locator)

    @teststep
    def clear_btn(self):
        """清除按钮"""
        locator = (By.ID, self.id_type() + 'bt_clear')
        return self.wait.wait_find_element(locator)

    @teststep
    def tips_content(self):
        """提示 具体内容"""
        locator = (By.ID, self.id_type() + "md_content")
        return self.wait.wait_find_element(locator)

    @teststep
    def click_confirm_btn(self):
        """确定 按钮"""
        locator = (By.ID, self.id_type() + "md_buttonDefaultPositive")
        self.wait.wait_find_element(locator).click()

    @teststeps
    def tips_operate(self):
        """提示信息处理"""
        if self.wait_check_tips_page():
            # self.alert_operate()
            self.click_confirm_btn()  # 确定按钮
            time.sleep(2)

    @teststep
    def click_voice(self):
        """播放按钮"""
        self.driver. \
            find_element_by_id(self.id_type() + "play_voice") \
            .click()

    @teststep
    def fab_next_btn(self):
        """下一步按钮"""
        locator = (By.ID, self.id_type() + 'fab_next')
        return self.wait.wait_find_element(locator)

    @teststep
    def fab_commit_btn(self):
        """下一步提交按钮"""
        locator = (By.ID, self.id_type() + 'fab_commit')
        return self.wait.wait_find_element(locator)

    @teststep
    def commit_without_fab_btn(self):
        """下一步提交按钮不带fab"""
        locator = (By.ID, self.id_type() + 'commit')
        return self.wait.wait_find_element(locator)

    @teststep
    def opt_options(self):
        """选项 文本"""
        locator = (By.ID, self.id_type() + 'tv_item')
        return self.wait.wait_find_elements(locator)

    @teststep
    def opt_char(self):
        """选项 字母 ABCD"""
        locator = (By.ID, self.id_type() + 'tv_char')
        return self.wait.wait_find_elements(locator)

    @teststep
    def sound_icon(self):
        """喇叭按钮"""
        locator = (By.ID, self.id_type() + 'sound')
        return self.wait.wait_find_element(locator)

    @teststep
    def drag_btn(self):
        """拖拽按钮"""
        locator = (By.ID, '{}dragger'.format(self.id_type()))
        return self.wait.wait_find_element(locator)

    @teststep
    def font_middle(self):
        """第一个Aa"""
        locator = (By.ID, self.id_type() + "font_middle")
        return self.wait.wait_find_element(locator)

    @teststep
    def font_large(self):
        """第二个Aa"""
        locator = (By.ID, self.id_type() + "font_large")
        return self.wait.wait_find_element(locator)

    @teststep
    def font_great(self):
        """第三个Aa"""
        locator = (By.ID, self.id_type() + "font_great")
        return self.wait.wait_find_element(locator)

    @teststep
    def wechat(self):
        """微信"""
        locator = (By.ID, self.id_type() + 'weixin')
        return self.wait.wait_find_element(locator)

    @teststep
    def friends(self):
        """朋友圈"""
        locator = (By.ID, self.id_type() + "weixin_friends")
        return self.wait.wait_find_element(locator)

    @teststep
    def not_save_btn(self):
        """不保留按钮"""
        locator = (By.XPATH, "//android.widget.Button[contains(@text, '不保留')]")
        return self.wait.wait_find_element(locator)

    @teststep
    def download(self):
        """保存图片"""
        locator = (By.ID, self.id_type() + 'save_img')
        return self.wait.wait_find_element(locator)

    @teststep
    def wechat_back_up_btn(self):
        """微信页面退回按钮"""
        locator = (By.ACCESSIBILITY_ID, '返回')
        return self.wait.wait_find_element(locator)

    @teststeps
    def get_rich_text_input_count(self):
        """获取需要输入的个数"""
        sentence_desc = self.rich_text().get_attribute('contentDescription')
        input_num = len(
            [x for x in sentence_desc.split('##')[2].split(';') if x])
        return input_num

    @teststep
    def get_rich_text_answer(self):
        """获取我输入的答案"""
        desc = self.rich_text().get_attribute('contentDescription')
        return [
            x for x in desc.split('## ')[1].split('  ') if x and '(' not in x
        ]

    @teststep
    def rest_bank_num(self):
        """待完成题数"""
        locator = (By.ID, '{}rate'.format(self.id_type()))
        return int(self.wait.wait_find_element(locator).text)

    @teststep
    def bank_time(self):
        """题目时间"""
        locator = (By.ID, '{}time'.format(self.id_type()))
        ele = self.wait.wait_find_element(locator)
        time_str = re.findall(r'\d', ele.text)
        return int(time_str[0]) * 3600 + int(time_str[1]) * 60 + int(
            time_str[2]) * 10 + int(time_str[3])

    @teststeps
    def check_position_change(self):
        if self.wait_check_keyboard_page():
            self.hide_keyboard_btn().click()

        self.screen_swipe_down(0.5, 0.2, 0.9, 1000)
        if GetAttribute().get_checked(self.font_large()) == 'false':
            self.base_assert.except_error('页面未默认选择中等字体')

        # 依次点击Aa,并获取第一个填空的X轴位置,比较大小
        large_size = self.rich_text().size

        self.font_middle().click()
        time.sleep(1)
        middle_size = self.rich_text().size

        self.font_great().click()
        time.sleep(1)
        great_size = self.rich_text().size

        if large_size['height'] < middle_size['height']:
            self.base_assert.except_error('大字体变中等字体未发生变化')
        if great_size['height'] < large_size['height']:
            self.base_assert.except_error('超大字变大字体未发生变化')

    @teststeps
    def drag_up_down(self, drag_down=True):
        """拖拽操作"""
        if self.wait_check_dragger_btn():
            loc = self.get_element_location(self.drag_btn())  # 获取按钮坐标
            if drag_down:
                self.driver.swipe(loc[0] + 45, loc[1] + 45, loc[0] + 45,
                                  self.get_window_size()[1] - 20)  # 拖拽至最下方
            else:
                self.driver.swipe(loc[0] + 45, loc[1] + 45, loc[0] + 45,
                                  loc[1] - 450)  # 拖拽至最上方

    @teststeps
    def next_btn_judge(self, var, fun):
        """下一步按钮状态判断"""
        value = GetAttribute().get_enabled(fun())
        if value != var:  # 测试 下一步 按钮 状态
            self.base_assert.except_error('按钮 状态Error' + str(value))

    @teststeps
    def next_btn_operate(self, var, fun):
        """下一步按钮操作"""
        self.next_btn_judge(var, fun)
        fun().click()
        time.sleep(1.5)

    @teststep
    def get_last_text_id(self):
        """获取最后一个文本的属性"""
        last_text = self.driver.find_elements_by_class_name(
            'android.widget.TextView')
        last_text_id = last_text[-1].get_attribute('resourceId')
        if 'question' in last_text_id:
            return 'ques'
        elif 'item' in last_text_id:
            return 'opt'

    @teststep
    def get_ques_opt_scale(self):
        """获取包含题目或只有选项的屏幕占比"""
        ques_text = self.question().text
        ques_bank = self.driver.find_element_by_xpath(
            '//*[@text="{}"]/..'.format(ques_text))
        ques_options = self.driver.find_element_by_xpath(
            '//*[@text="{}"]/following-sibling::android.view.ViewGroup'.format(
                ques_text))
        screen_height = self.get_window_size()[1]
        ques_scale = float('%.2f' % (ques_bank.size['height'] / screen_height))
        opt_scale = float('%.2f' %
                          (ques_options.size['height'] / screen_height))
        return ques_scale, opt_scale

    @teststep
    def value_is_explain(self, dict_info):
        """判断字典的key是否都是数字"""
        pattern = re.compile(u'[\u4e00-\u9fa5]+')
        result = any([pattern.search(dict_info[x]) for x in dict_info])
        if result:
            return True
        else:
            return False

    @teststeps
    def judge_timer(self, timer):
        if len(timer) > 1:
            if any(timer[i + 1] > timer[i] for i in range(0, len(timer) - 1)):
                print('计时功能无误:', timer, '\n')
                return True
            else:
                self.base_assert.except_error('Error - 计时错误:' + str(timer) +
                                              '\n')
        else:  # 只有一道题
            print('只有一道题,时间为:', timer[0], '\n')
            return True

    @teststep
    def rate_judge(self, total, i):
        """待完成数校验"""
        current_rate = self.rest_bank_num()
        if int(current_rate) != total - i:
            self.base_assert.except_error('待完成数不正确 {} 应为:{}'.format(
                current_rate, total - i))

    @teststeps
    def share_page_operate(self):
        """分享页面具体操作"""
        if self.wait_check_punch_share_page():
            self.wechat().click()

            if not (self.wait_check_login_wechat_page()
                    or self.wait_check_select_friend_page()):
                self.base_assert.except_error('未跳转到微信登录页面')
            self.wechat_back_up_btn().click()

            if self.wait_check_punch_share_page():
                self.friends().click()
                if not (self.wait_check_login_wechat_page()
                        or self.wait_check_friend_circle_page()):
                    self.base_assert.except_error('未跳转到微信登录页面')
                self.wechat_back_up_btn().click()
                if self.wait_check_wechat_alert_tip_page():
                    self.not_save_btn().click()

            if self.wait_check_punch_share_page():
                self.download().click()
                if not Toast().find_toast('已保存到本地'):
                    if self.wait_check_permit_tab_page():
                        self.alert_operate()
                        if not Toast().find_toast('已保存到本地'):
                            self.base_assert.except_error('未发现保存图片提示')
                    else:
                        self.base_assert.except_error('未发现保存到本地提示')
                else:
                    print('图片已保存到本地')
                self.click_back_up_button()
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)
class ListenSpellWordPage(ListenSpellGame):
    """单词听写"""
    def __init__(self):
        self.key = Keyboard()
        self.word_public = WorldBookPublicPage()

    @teststep
    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)
    
    @teststeps
    def normal_listen_spell_operate(self, bank_count, new_explain_words):
        """《单词听写》 正常游戏过程"""
        print('===== 🌟🌟 单词听写模式(新词)(输错一次,输对一次) 🌟🌟 =====\n')
        answer_word = []
        for x in range(bank_count*2):
            if self.wait_check_listen_spell_word_page():
                self.click_voice()  # 点击播放按钮
                self.next_btn_judge('false', self.fab_commit_btn)  # 下一题 按钮 判断加 点击操作
                explain_id = self.word_public.get_explain_id(self.input_wrap_side())
                if explain_id in new_explain_words:
                    print('❌❌❌ 此单词为新释义,不应出现单词听写游戏')

                if not answer_word:    # 数组为空,说明上一题已回答正确,本题需随机填入字母以获取正确答案
                    self.key.games_keyboard(random.choice(string.ascii_lowercase))  # 随机输入一个小写字母
                    mine_input = self.input_word()  # 输入的答案
                    self.next_btn_operate('true', self.fab_commit_btn)
                    if self.wait_check_answer_word_page():  # 判断正确答案是否存在
                        correct_ans = self.right_answer()  # 获取正确答案
                        answer_word.append(correct_ans)
                        explain = self.word_explain()
                        print('解释:', explain.text)
                        print('我输入的答案:', mine_input)
                        print('正确答案为:', correct_ans)
                    else:
                        print("❌❌❌ Error - 未显示正确答案")

                else:   # 数组长度为1,说明已获取正确答案,直接输入正确答案即可
                    for alpha in list(answer_word[0]):
                        self.key.games_keyboard(alpha.upper())   # 输入单词的大写字母

                    print('我输入的单词:', answer_word[0].upper())
                    self.next_btn_operate('true', self.fab_commit_btn)      # 提交 判断加 点击操作
                    if self.input_word() != answer_word[0].lower():
                        print('❌❌❌ 输入单词大写后,点击确定,单词未变为小写字母')

                    if self.wait_check_answer_word_page():  # 判断正确答案是否出现
                        print("❌❌❌ Error -听写正确却显示正确答案")
                    explain = self.word_explain()
                    print('解释:', explain.text)
                    print('回答正确!')
                    answer_word.clear()
                self.next_btn_operate('true', self.fab_next_btn)  # 下一题
                time.sleep(2)
                print('-'*30, '\n')
        time.sleep(5)