Esempio n. 1
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('==============================================')
Esempio n. 2
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)  # 不同模式 对应不同的游戏过程
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)
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)
Esempio n. 5
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]
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)