コード例 #1
0
class QuitAddClass(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.van = VanclassPage()
        self.wait = WaitElement()

    @teststep
    def wait_check_vanclass_page(self):
        """班级页面检查点"""
        locator = (By.CLASS_NAME, self.id_type() + "class_name")
        return self.wait.wait_check_element(locator)

    @teststep
    def class_num(self):
        """班号"""
        locator = (By.ID, self.id_type() + 'class_no')
        return self.wait.wait_find_elements(locator)

    @teststep
    def quit_all_class_operate(self):
        """退出班级操作"""
        self.home.click_test_vanclass()                          # 班级tab
        if self.van.wait_check_page():                           # 班级页面检查点
            self.home.screen_swipe_down(0.5, 0.2, 0.9, 1000)
            while self.wait_check_vanclass_page():
                if self.van.wait_check_page():
                    van_name = self.van.class_name()[0].text
                    self.van.class_name()[0].click()
                    self.quit_tips_operate(van_name)             # 退出班级提示框

    @teststep
    def quit_tips_operate(self, van_name):
        """退出班级 具体操作"""
        if self.van.wait_check_vanclass_page(van_name):    # 页面检查点
            self.van.quit_vanclass()                       # 退出班级 按钮
            self.home.tips_operate_commit()                # 提示框
            print('确定 退出')
            print('------------------------------')
            if self.van.wait_check_quit_page():
                self.van.phone_name()  # 提示
                value = verify_find(STU_ACCOUNT, 'quitClass')  # 获取验证码
                self.van.code_input().send_keys(value)         # 输入验证码
                print(STU_ACCOUNT)
                print('验证码:', value)
                self.van.quit_button()                         # 退出班级 按钮

    @teststep
    def apply_class_operate(self, test_class_num):
        """加入班级操作"""
        self.home.click_test_vanclass()                        # 班级tab
        if self.van.wait_check_page():                         # 班级页面检查点
            if self.van.wait_check_van_list_page():
                class_nums = self.class_num()
                van_names = []
                while len(van_names) < len(class_nums):       # 非测试班级则退出,是则保留
                    for i, num in enumerate(self.class_num()):
                        class_name = self.van.class_name()[i].text
                        van_num = num.text.split(':')[1]
                        if class_name in van_names:
                            continue
                        else:
                            van_names.append(class_name)

                            if van_num not in test_class_num:      # 检验是否已加入测试班级
                                num.click()                         # 不是测试班级的
                                self.quit_tips_operate(class_name)            # 退出班级
                            else:
                                test_class_num.remove(van_num)

            if len(test_class_num):
                for x in test_class_num:
                    if self.van.wait_check_page():
                        self.van.add_class_button()                         # 若没有班级列表
                        if self.home.wait_check_tips_page():     # 页面检查点
                            self.home.input().send_keys(x)       # 输入班级号
                            self.home.commit_button()            # 点击确定按钮
                        if self.van.wait_check_apply_page():
                            print('班级:', self.van.class_name_modify())
                            print('班号:', self.van.apply_vanclass_no())
                            print('老师:', self.van.apply_teacher_name())
                            self.van.remark_name_modify().send_keys('Test')   # 输入昵称
                            self.van.apply_class_button()  # 申请入班 按钮
                        print('-'*30, '\n')
        self.home.click_tab_hw()
コード例 #2
0
class PurchasePage(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.user_center = UserCenterPage()
        self.wait = WaitElement()

    @teststep
    def wait_check_buy_page(self):
        """以“购买”的xpath @text为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'在线客服')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_help_center_page(self):
        """以“帮助中心”的xpath @text为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'帮助中心')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_card_page(self):
        """以“优惠购买”的id 为依据"""
        locator = (By.ID, self.id_type() + "discount_pay")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_agreement_page(self):
        """以“购买协议”的xpath 为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'购买协议')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_pay_confirm_page(self):
        """以“支付确认”的xpath 为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'支付确认')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_parent_pay_page(self):
        """以“支付完成”的ID 为依据"""
        locator = (By.ID, self.id_type() + "pay_complete")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_magic_page(self):
        """以“支付完成”的ID 为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'在线助教家长端')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def online_server(self):
        """在线客服"""
        locator = (By.ID, self.id_type() + 'goToCustomerService')
        return self.wait.wait_find_element(locator)

    @teststep
    def magics(self):
        locator = (By.ID, self.id_type() + 'function_des')
        return self.wait.wait_find_elements(locator)

    @teststep
    def upgrade_button(self):
        """马上购买"""
        locator = (By.ID, self.id_type() + 'goToUpgrade')
        return self.wait.wait_find_element(locator)

    @teststep
    def discount_buy(self):
        """优惠购买"""
        locator = (By.ID, self.id_type() + 'discount_pay')
        return self.wait.wait_find_element(locator)

    @teststep
    def card_type(self):
        """优惠卡类型"""
        locator = (By.ID, self.id_type() + 'one')
        return self.wait.wait_find_elements(locator)

    @teststep
    def check_radio(self, card_name):
        """选项按钮"""
        locator = (
            By.XPATH,
            '//android.widget.TextView[contains(@text, "{}")]/../preceding-sibling::'
            'android.widget.RadioButton'.format(card_name))
        return self.wait.wait_find_element(locator)

    @teststep
    def card_price(self, card_name):
        """卡片的价格  根据卡的类型获取"""
        locator = (
            By.XPATH,
            '//android.widget.TextView[contains(@text, "{}")]/../following-sibling::'
            'android.widget.LinearLayout/android.widget.TextView'.format(
                card_name))
        return self.wait.wait_check_element(locator)

    @teststep
    def selected_card(self):
        """已选卡型"""
        locator = (By.ID, self.id_type() + 'current_vip_card_hint')
        return self.wait.wait_find_element(locator)

    @teststep
    def direct_buy_button(self):
        locator = (By.ID, self.id_type() + 'pay')
        return self.wait.wait_find_element(locator)

    @teststep
    def confirm_pay_button(self):
        locator = (By.ID, self.id_type() + 'pay')
        return self.wait.wait_find_element(locator)

    @teststep
    def discount_buy_button(self):
        """优惠购买按钮"""
        locator = (By.ID, self.id_type() + 'discount_pay')
        return self.wait.wait_find_element(locator)

    @teststep
    def agreement(self):
        """购买协议"""
        locator = (By.ID, self.id_type() + 'pay_agreement')
        return self.wait.wait_find_element(locator)

    @teststep
    def ali_pay_tab(self):
        """支付宝支付"""
        locator = (By.XPATH,
                   '//android.widget.TextView[contains(@text,"支付宝代付")]')
        return self.wait.wait_find_element(locator)

    @teststep
    def wechat_pay_tab(self):
        """微信支付"""
        locator = (By.XPATH,
                   '//android.widget.TextView[contains(@text,"微信代付")]')
        return self.wait.wait_find_element(locator)

    @teststep
    def parent_check_button(self):
        locator = (By.ID, self.id_type() + 'pay_agreement')
        return self.wait.wait_find_element(locator)

    @teststep
    def get_all_text_view(self):
        """获取页面所有不为空的文本值"""
        locator = (By.CLASS_NAME, 'android.widget.TextView')
        ele = self.wait.wait_find_elements(locator)
        all_text = [
            ele[i].text for i in range(len(ele))
            if ele[i].text != '' and ele[i].text is not None
        ]
        return all_text

    @teststep
    def online_server_ele_check(self):
        self.online_server().click()
        if self.wait_check_help_center_page():
            print('在线助教客服二维码')
            self.home.click_back_up_button()

    @teststep
    def magic_ele_check(self):
        all_magics = self.magics()
        all_magics[random.randint(0, len(all_magics) - 1)].click()
        if self.wait_check_magic_page():
            print('法宝详情页....\n')
            self.home.click_back_up_button()
            if self.wait_check_buy_page():
                pass

    @teststep
    def switch_card(self):
        """切换卡片"""
        card_type = self.card_type()
        for card in card_type:
            card.click()
            check_radio = self.check_radio(card.text)
            if check_radio.get_attribute('checked') != 'true':
                print('❌❌❌ Error-- 选项按钮状态未发生变化')
            current_card = self.selected_card()
            if card.text.split(' ')[0] != current_card.text:
                print('❌❌❌ Error-- 当前卡的类型与所选类型不一致')
            else:
                print('已选择', current_card.text, '\n')

            if '年卡' in card.text:
                card_price = self.card_price(card.text)
                discount_button = self.discount_buy_button()
                if '优惠价' in card_price.text:
                    if discount_button.get_attribute('enabled') != 'true':
                        print('❌❌❌ Error-- 有优惠价,但是优惠购买按钮置灰', card.text)
                else:
                    if discount_button.get_attribute('enabled') != 'false':
                        print('❌❌❌ Error-- 无优惠价,但是优惠购买按钮未置灰', card.text)

    @teststep
    def check_agreement(self):
        agreement = self.agreement()
        location = agreement.location
        self.driver.tap([
            (location['x'] + 520, location['y'] + 50),
        ])
        if self.wait_check_agreement_page():
            print('在线助教【提分版】购买协议 .....')
            self.home.screen_swipe_down(0.5, 0.5, 0.9, 1500)
            self.home.click_back_up_button()

    @teststep
    def direct_buy(self):
        if self.wait_check_card_page():
            self.direct_buy_button().click()
            if self.wait_check_pay_confirm_page():
                self.pay_confirm_page_ele_operate()
                self.parent_check_button().click()
                self.confirm_pay_button().click()
                if self.wait_check_parent_pay_page():
                    self.ali_pay_tab().click()
                    time.sleep(2)
                    self.parent_page_ele_operate()

                    self.wechat_pay_tab().click()
                    time.sleep(2)
                    self.parent_page_ele_operate()

    @teststep
    def magics_page_ele_operate(self):
        """法宝页面元素信息"""
        text = self.get_all_text_view()
        if len(text) != 16:
            print('❌❌❌ Error-- 页面元素缺失', text)
        else:
            magic_types = numpy.reshape(text[6:-1], (3, 3))
            print("<" + text[0] + '页面>', '\n', '学生:', text[1], '\n', '手机:',
                  text[2], '\n', '提示:', text[4] + text[5], '\n', '法宝:', '\n',
                  magic_types, '\n')

    @teststep
    def buy_page_ele_operate(self):
        """购买页面(优惠卡类型) 页面"""
        text = self.get_all_text_view()
        print(len(text))
        if len(text) not in range(18, 21):
            print('❌❌❌ Error-- 页面元素缺失', text)
        else:
            print(
                '<选择优惠卡页面>\n'
                '学生:',
                text[1],
                '\n',
                '手机:',
                text[2],
                '\n',
                '提示:',
                text[4] + text[5],
                '\n',
            )
            if len(text) == 20:
                print(
                    '优惠卡类型',
                    '\n',
                    text[6],
                    text[7],
                    '\n',
                    text[8],
                    text[9],
                    '\n',
                    text[10],
                    text[11],
                    text[12],
                    '\n',
                    text[13],
                    text[14],
                    text[15],
                    '\n',
                    '协议:',
                    text[16],
                    '\n',
                    '已选类型:',
                    text[17],
                    '\n',
                    text[18],
                    text[19],
                    '\n',
                )
            else:
                print(
                    '优惠卡类型',
                    '\n',
                    text[6],
                    text[7],
                    '\n',
                    text[8],
                    text[9],
                    '\n',
                    text[10],
                    text[11],
                    '\n',
                    text[12],
                    text[13],
                    '\n',
                    '协议:',
                    text[14],
                    '\n',
                    '已选类型:',
                    text[15],
                    '\n',
                    text[16],
                    text[17],
                    '\n',
                )

    @teststep
    def pay_confirm_page_ele_operate(self):
        text = self.get_all_text_view()
        if len(text) != 12:
            print('❌❌❌ Error-- 页面元素缺失', text)
        else:
            print('<支付确认页面>\n'
                  '学生:', text[1], '\n', '手机:', text[2], '\n', '卡型:', text[6],
                  '\n', "价格:", text[4] + text[5], '\n', text[7] + ":", '\n',
                  text[8], text[9], text[10], '\n', text[11], '\n')

    @teststep
    def parent_page_ele_operate(self):
        text = self.get_all_text_view()
        if len(text) != 9:
            print('❌❌❌ Error-- 页面元素缺失', text)
        else:
            print(
                '<' + text[0] + "页面>",
                '\n',
                text[1],
                text[2],
                '\n',
                '卡型:',
                text[3],
                '\n',
                '价格:',
                text[4] + text[5],
                '\n',
                text[6],
                '\n',
                text[7],
                '\n',
                text[8],
                '\n',
            )

    @teststep
    def back_to_home(self):
        self.home.click_back_up_button()
        if self.wait_check_pay_confirm_page():
            self.home.click_back_up_button()
            if self.wait_check_card_page():
                self.home.click_back_up_button()
                if self.wait_check_buy_page():
                    self.home.click_back_up_button()
                    if self.user_center.wait_check_user_center_page():
                        self.home.click_tab_hw()
                        if self.home.wait_check_home_page():
                            print('返回主界面')
コード例 #3
0
class RankingPage(BasePage):
    """单词本 - 排行榜"""
    def __init__(self):
        self.home = HomePage()
        self.wait = WaitElement()

    @teststeps
    def wait_check_rank_page(self):
        """以“学生测试版”为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'学生测试版')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def total(self):
        locator = (By.ID, self.id_type() + 'total')
        ele = self.wait.wait_find_element(locator)
        return ele.text

    @teststep
    def click_rank_icon(self):
        """点击排行榜图标"""
        locator = (By.ID, self.id_type() + 'rank')
        self.wait.wait_find_element(locator).click()

    @teststep
    def choose_class(self):
        """班级展示 及切换"""
        locator = (By.ID, "android:id/text1")
        self.wait.wait_find_element(locator).click()
        time.sleep(2)

    @teststep
    def classes_ele(self):
        """班级展示 及切换"""
        locator = (By.ID, "android:id/text1")
        return self.wait.wait_find_elements(locator)

    @teststep
    def word_num(self):
        """单词数"""
        locator = (By.ID, self.id_type() + "tv_score")
        ele = self.wait.wait_find_element(locator)
        return ele.text

    @teststep
    def word_type(self):
        """wording:词"""
        locator = (By.ID, self.id_type() + "type")
        ele = self.wait.wait_find_element(locator)
        return ele.text

    @teststep
    def share_button(self):
        """炫耀一下"""
        locator = (By.ID, self.id_type() + "share")
        self.wait.wait_find_element(locator).click()

    @teststep
    def rank_num(self):
        """班级排名"""
        locator = (By.ID, self.id_type() + "tv_ranking")
        ele = self.wait.wait_find_element(locator)
        return ele.text

    @teststep
    def order_num(self):
        """排名 数字"""
        locator = (By.ID, self.id_type() + "tv_order")
        return self.wait.wait_find_elements(locator)

    @teststep
    def st_icon(self):
        """头像"""
        locator = (By.ID, self.id_type() + "iv_head")
        return self.wait.wait_find_elements(locator)

    @teststep
    def st_name(self):
        """学生姓名"""
        locator = (By.ID, self.id_type() + "tv_name")
        return self.wait.wait_find_elements(locator)

    @teststep
    def st_score(self):
        """提示title"""
        locator = (By.ID, self.id_type() + "tv_score")
        return self.wait.wait_find_elements(locator)

    @teststep
    def students_name(self):
        """排行榜里学生名称"""
        locator = (By.XPATH,
                   '//android.widget.RelativeLayout/android.widget.TextView'
                   '[contains(@resource-id, "{}tv_name")]'.format(
                       self.id_type()))
        return self.wait.wait_find_elements(locator)

    @teststep
    def students_score(self):
        """排行榜中学生背的单词数"""
        locator = (By.XPATH,
                   '//android.widget.RelativeLayout/android.widget.TextView'
                   '[contains(@resource-id,"{}tv_score")]'.format(
                       self.id_type()))
        return self.wait.wait_find_elements(locator)

    # 炫耀一下
    @teststeps
    def wait_check_share_page(self):
        """以“title: 炫耀一下”为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'炫耀一下')]")
        return self.wait.wait_check_element(locator)

    @teststep
    def play_rank_word(self, total_word):
        print('排行榜 页面\n')
        self.choose_class()
        time.sleep(2)
        classes = self.classes_ele()
        for i in range(len(classes)):
            stu_class = self.classes_ele()[i].text
            self.classes_ele()[i].click()
            time.sleep(3)
            self.ele_operate(stu_class, total_word)
            if i != len(classes) - 1:
                self.choose_class()
            else:
                print('排行榜浏览结束')
        WordBookRebuildPage().click_back_up_button()

    @teststep
    def ele_operate(self, stu_class, total_word):
        word_type = self.word_type()
        class_rank = self.rank_num()
        print('当前所在班级:', stu_class)
        score = self.st_score()[0].text
        print('已背:', score + word_type)
        if int(score) != int(total_word):
            print('❌❌❌ Error - 次数与主页面单词数不一致!')
        else:
            print('单词数核实一致!')

        print('当前班级排名:', class_rank)
        self.share_button()
        if self.wait_check_share_page():
            self.home.click_back_up_button()
            if self.wait_check_rank_page():
                self.rank_numbers_info()

    def get_student_rank_info(self, students_info, i):
        student_names = self.students_name()
        student_scores = self.students_score()
        order = self.order_num()

        for j in range(len(student_names)):
            if i == 0:
                if j <= 2:
                    if order[i].text != '':
                        print('❌❌❌ Error - 名次位于第三名没有小皇冠标识')
            if student_names[j].text in students_info.keys():
                continue
            else:
                students_info[student_names[j].text] = student_scores[j].text
        return students_info

    @teststep
    def rank_numbers_info(self):
        students_info = {}
        student_names = self.students_name()
        if len(student_names) >= 6:
            for i in range(2):
                students_info = self.get_student_rank_info(students_info, i)
                self.home.screen_swipe_up(0.5, 0.8, 0.3, 1000)
        else:
            self.get_student_rank_info(students_info, i=0)
        self.home.screen_swipe_down(0.5, 0.2, 0.9, 1000)
        print("\n排行榜情况如下(只显示班级前10名 + 自己的名次)")
        for name in students_info.keys():
            score = students_info[name]
            print(name, '\t', score)
        time.sleep(3)
        print('----------------------------------')
コード例 #4
0
class WordTestPage(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.sql_handler = WordTestSqlHandler()
        self.spell = SpellWordGame()
        self.wait = WaitElement()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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