Example #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()
Example #2
0
class ResultPage(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.wait = WaitElement()

    @teststep
    def wait_check_result_page(self):
        """结果页 以今日已练单词图片的Id为依据"""
        locator = (By.ID, self.id_type() + 'word_count')
        return self.wait.wait_check_element(locator)

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

    @teststep
    def wait_check_share_page(self):
        """打卡页,以分享图片id为依据"""
        locator = (By.ID, self.id_type() + "share_img")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_next_grade(self):
        """再来一组 以继续挑战的图片的Id为依据"""
        locator = (By.ID, self.id_type() + "level_up_hint")
        return self.wait.wait_check_element(locator)

    @teststep
    def wait_check_study_times_limit_page(self):
        """练习次数已用完页面检查点"""
        locator = (By.ID, self.id_type() + "error_img")
        return self.wait.wait_check_element(locator)

    @teststep
    def date(self):
        """时间日期"""
        locator = (By.ID, self.id_type() + 'date')
        return self.wait.wait_find_element(locator).text

    @teststep
    def today_word(self):
        """今日已练单词"""
        locator = (By.ID, self.id_type() + 'word_count')
        return self.wait.wait_find_element(locator).text

    @teststep
    def already_remember_word(self):
        """已被单词"""
        locator = (By.ID, self.id_type() + 'all_word_count')
        return self.wait.wait_find_element(locator).text

    @teststep
    def word_detail_info(self):
        """复习新词组"""
        locator = (By.ID, self.id_type() + 'text')
        return self.wait.wait_find_element(locator).text

    @teststep
    def share_button(self):
        """打卡"""
        locator = (By.ID, self.id_type() + 'punch_clock')
        self.wait.wait_find_element(locator).click()
        time.sleep(2)

    @teststep
    def rank_button(self):
        """右上角排名按钮"""
        locator = (By.ID, self.id_type() + 'rank')
        self.wait.wait_find_element(locator).click()
        time.sleep(3)

    @teststep
    def more_again_button(self):
        """再来一组"""
        print('再来一组', '\n')
        locator = (By.ID, self.id_type() + 'again')
        self.wait.wait_find_element(locator).click()

    @teststep
    def level_up_text(self):
        """单词已练完说明"""
        locator = (By.ID, self.id_type() + 'level_up_hint')
        ele = self.wait.wait_find_element(locator)
        print(ele.text)

    @teststep
    def no_study_btn(self):
        """不练了"""
        locator = (By.ID, self.id_type() + 'cancel')
        self.wait.wait_find_element(locator).click()

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

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

    @teststep
    def nex_level_text(self):
        locator = (By.XPATH, "//android.widget.TextView[@index,0]")
        ele = self.wait.wait_find_element(locator)
        print('已选年级 :%s' % ele.text)
        print('-' * 30, '\n')

    @teststep
    def confirm_button(self):
        """继续练习"""
        locator = (By.ID, self.id_type() + "confirm")
        self.wait.wait_find_element(locator).click()

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

    @teststep
    def share_page_operate(self):
        """分享页面操作"""
        if self.wait_check_share_page():
            self.wx_btn().click()
            if self.wait_check_wx_login_page():
                self.wx_back_up_btn().click()
            else:
                print('❌❌❌ 未进入微信登陆页面')

        if self.wait_check_share_page():
            self.wx_friend().click()
            if self.wait_check_wx_login_page():
                self.wx_back_up_btn().click()
            else:
                print('❌❌❌ 未进入微信登陆页面')

        if self.wait_check_share_page():
            self.save_img().click()
            if not Toast().find_toast('已保存到本地'):
                print('❌❌❌ 未发现保存图片提示')
            self.click_back_up_button()

    @teststeps
    def check_result_word_data(self, new_word_count, new_explain_words_count,
                               already_recite_count, group_count):
        """结果页面"""
        print(' <结果页>:')
        print('今日已练单词:%s' % self.today_word())
        print('日期:%s' % self.date())
        print(self.already_remember_word())
        print(self.word_detail_info())
        today_word_count = int(self.today_word())  # 今日已练单词 (复习+ 新词)
        already_count = int(
            re.findall(r'\d+', self.already_remember_word())[0])  # 已背单词
        detail = re.findall(r'\d+', self.word_detail_info())  # 最后一句统计文本
        study_group_count = int(detail[0])  # 已练组数
        recite_count = int(detail[1])  # 复习个数
        new_set_words = int(detail[2])  # 新词个数
        new_explain_count = int(detail[3])  # 新释义个数

        if already_count != new_word_count:
            print('❌❌❌ 已学单词数不正确,应为', new_word_count)

        if today_word_count != recite_count + new_set_words + new_explain_count:
            print('❌❌❌ 今日已练单词不等于复习+新词+新释义, 应为',
                  recite_count + new_set_words + new_explain_count)

        if study_group_count != group_count + 1:
            print('❌❌❌ 已练组数不正确, 应为', group_count + 1)

        if new_set_words != new_word_count:
            print('❌❌❌ 新词学单词数不正确,应为', new_word_count)

        if new_explain_count != new_explain_words_count:
            print('❌❌❌ 新释义单词个数不正确, 应为', new_explain_words_count)

        if recite_count != already_recite_count:
            print('❌❌❌ 复习单词个数不正确, 应为', already_recite_count)

        if recite_count > 27:
            if group_count == 0:
                if new_word_count != 0:
                    print('❌❌❌ 复习个数大于等于28个, 不应存在新词个数')
            else:
                print('❌❌❌ 复习组数非第一组, 但是复习个数大于27')
        else:
            if new_word_count == 0:
                print('❌❌❌ 复习单词个数小于28, 新词个数为0')
            else:
                if group_count == 0:
                    if new_word_count not in range(3, 11):
                        print('❌❌❌ 复习单词个数小于28, 第一组新词个数不在3-10之间')
                else:
                    if new_word_count < 3:
                        print('❌❌❌ 复习单词个数小于28,非第一组新词个数小于3个')

    @teststep
    def back_to_home(self):
        self.home.click_back_up_button()
        if self.home.wait_check_tips_page():
            self.home.commit_button()
        if self.home.wait_check_word_title():
            self.home.click_back_up_button()
            if self.home.wait_check_home_page():  # 页面检查点
                print('返回主界面')

    @teststeps
    def result_page_handle(self,
                           new_word_count,
                           new_explain_words_count,
                           already_recite_count,
                           group_count,
                           study_model=1):
        """结果页处理"""
        if self.wait_check_result_page():
            print('进入结果页面')
            self.check_result_word_data(new_word_count,
                                        new_explain_words_count,
                                        already_recite_count,
                                        group_count)  # 结果页元素
            self.share_button()  # 打卡
            group_num = 6 if study_model == 1 else 9
            GameCommonEle().share_page_operate()  # 炫耀一下页面
            if self.wait_check_result_page():
                self.more_again_button()  # 再练一次
                if group_count == group_num:
                    if not self.wait_check_study_times_limit_page():
                        self.base_assert.except_error('练习次数已达到顶峰值, 未显示练完提示页面')
                    else:
                        print('你已练完今日单词, 保持适度才能事半功倍哦!休息一下,明天再练吧')
                if self.wait_check_next_grade():  # 继续挑战页面
                    self.level_up_text()
                    self.confirm_button().click()