Exemple #1
0
 def __init__(self):
     self.login = LoginPage()
     self.home = HomePage()
     self.tips = BuyTipsPage()
     self.spell = SpellingWord()
     self.result = ResultPage()
     self.vchoose = VocabularyChoose()
     self.common = DataActionPage()
Exemple #2
0
 def setUp(cls):
     cls.home = HomePage()
     cls.mysql = MysqlData()
     cls.word = WordBook()
     cls.progress = ProgressPage()
     cls.login = LoginPage()
     cls.login.app_status()  # 判断APP当前状态
     DataActionPage().get_id_back_home()
class MatchingWord(BasePage):
    def __init__(self):
        self.homework = Homework()
        self.common =DataActionPage()

    """连连看"""
    @teststeps
    def get_wordList(self):
        """获取页面内所有 word &解释"""
        ele = self.driver \
            .find_elements_by_class_name("android.widget.TextView")
        return ele

    @teststeps
    def is_word(self, word):
        """判断 是否为字母"""
        pattern = re.compile(r'^[A-Za-z. ]+$')
        if  pattern.match(word):
            return True
        else:
            return False

    @teststeps
    def card_match(self,ll):
        if ll == 0:
            print('\n单词连连看模式(新词) \n')

        english = []  # 单词list
        english_index = []  # 单词在所有button中的索引
        explain = []  # 解释list
        explain_index = []  # 解释在所有button中的索引

        word_list = self.get_wordList()  # 获取所有buton
        for i in range(1, len(word_list)):
            if self.is_word(word_list[i].text):  # 如果是字母
                english.append(word_list[i].text)
                english_index.append(i)
            else:  # 如果是汉字
                explain.append(word_list[i].text)
                explain_index.append(i)
        print("英文序列:%s"%english_index,"\n英文单词:%s"%english, "\n解释序列:%s"%explain, "\n英文解释:%s\n"%explain_index)

        for j in range(len(explain)):  # 具体操作
            word = self.common.get_word_by_explain(explain[j])
            word_list[explain_index[j]].click()
            print('解释:%s'%explain[j])
            for k in range(len(english)):
                if english[k] == word:
                    word_list[english_index[k]].click()
                    print("单词:%s"%word)
                    break
            print ('----------------------------------')
        time.sleep(5)
 def test_mine_word(self):
     """我的单词"""
     if self.home.wait_check_page():  # 页面检查点
         DataActionPage().get_id_back_home()
         if self.home.wait_check_page():  # 页面检查点
             print('进入主界面')
             self.home.click_hk_tab(1)  # 点击 背单词
             if self.home.wait_check_word_title():  # 页面检查点
                 total = self.word.total_word()
                 self.mine.click_my_word_btn()
                 if self.mine.wait_check_mine_word_page():
                     if self.mine.no_word_tips():
                         self.mine.no_word_tip_text()
                     else:
                         self.mine.play_mine_word(total)
Exemple #5
0
 def __init__(self):
     self.attr = GetAttribute()
     self.homework = Homework()
     self.mysql = MysqlData()
     self.common = DataActionPage()
Exemple #6
0
class VocabularyChoose(BasePage):
    """词汇选择"""
    def __init__(self):
        self.attr = GetAttribute()
        self.homework = Homework()
        self.mysql = MysqlData()
        self.common = DataActionPage()

    @teststeps
    def wait_check_head_page(self):
        """以“词汇选择 -选单词模式”的 发音按钮 为依据"""
        locator = (By.ID, "com.vanthink.student.debug:id/tv_head")
        try:
            WebDriverWait(self.driver, 3,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_sentence_page(self):
        """以“词汇选择 -句子选单词模式”的 提示按钮 为依据"""
        locator = (
            By.XPATH,
            "//android.widget.TextView[contains(@resource-id,'com.vanthink.student.debug:id/hint')]"
        )
        try:
            WebDriverWait(self.driver, 2,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def check_voice_ele(self):
        try:
            self.driver.find_element_by_id(
                "com.vanthink.student.debug:id/fab_sound")
            return True
        except:
            return False

    @teststep
    def click_voice(self):
        """页面内音量按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/fab_sound") \
            .click()

    @teststep
    def question_content(self):
        """获取题目内容"""
        ele = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_head").text
        return ele

    @teststep
    def option_button(self):
        """获取四个选项"""
        ele = self.driver.find_elements_by_id(
            "com.vanthink.student.debug:id/option")
        return ele

    # 听音选词
    @teststep
    def explain(self):
        """选择答案后,出现中文解释"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/explain").text
        return word

    # 句子选单词
    @teststep
    def click_hint_button(self):
        """提示按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/hint").click()
        time.sleep(2)

    @teststep
    def sentence_explain(self):
        """点击 提示按钮后,出现中文解释"""
        explain = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_explain").text
        print('explain:', explain)
        return explain

    @teststep
    def hint_button_judge(self, var):
        """‘提示’按钮 状态判断"""
        item = self.driver.find_element_by_id(
            "com.vanthink.student.debug:id/hint").get_attribute(
                "enabled")  # ‘下一题’按钮
        if item != var:  # 测试 提示 按钮 状态
            print('★★★ 提示按钮 状态Error', item)

    @teststeps
    def vocab_select_choice_explain(self, i):
        """《词汇选择》 - 选解释模式"""
        if i == 0:
            print('\n词汇选择 - 根据单词选解释模式(复习)\n')
        self.homework.next_button_operate('false')  # 下一题 按钮 判断加 点击操作

        self.click_voice()  # 点击发音按钮
        word = self.question_content()  # 题目
        print('题目:', word)

        options = self.option_button()  #遍历选项,点击和word一样的单词
        for j in range(0, len(options)):
            find_word = self.common.get_word_by_explain(options[j].text)
            if word == find_word:
                print('选项解释:', options[j].text)
                options[j].click()
                break

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

    @teststeps
    def vocab_select_choice_word(self, i):
        """《词汇选择》 - 根据解释选单词"""
        if i == 0:
            print('\n词汇选择-选单词模式(复习)\n')

        self.homework.next_button_operate('false')  # 下一题 按钮 判断加 点击操作

        item = self.question_content()  # 题目
        print('题目:', item)
        word = self.common.get_word_by_explain(item)  # 根据解释获取单词

        options = self.option_button()  # 遍历选项,点击和word一样的单词
        for j in range(0, len(options)):
            if options[j].text == word:
                options[j].click()
                time.sleep(2)
                break

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

    @teststeps
    def vocab_select_listen_choice(self, answer, lc, fc, ws, star, familiar):
        """《词汇选择》 - 听音选词模式 具体操作"""
        if lc == 0:
            self.start_familiar_count_compare(fc, ws, star, familiar)
            print('\n词汇选择-听音选词模式(新词)\n')

        self.homework.next_button_operate('false')  # 下一题 按钮 判断加 点击操作

        self.click_voice()  # 点击发音按钮
        options = self.option_button()  # 获取当前页面所有选项

        if len(answer) == 0:  # 若answer为0,则说明上一选项为正确选项,随机选择
            options[random.randint(0, len(options) - 1)].click()
            explain = self.explain()
            word = self.common.get_word_by_explain(explain)
            self.options_statistic(answer, word, explain)  # 选择对错统计

        elif len(answer) == 1:  # 若answer为其他,则说明上一选项为错误选项,这一次需定向选择
            for i in range(0, len(options)):
                if options[i].text == answer[0]:
                    options[i].click()
                    exp = self.explain()
                    print('答案正确:%s\n解释:%s' % (answer[0], exp))
                    break

            del answer[:]
            print('-------------------------------------')
        self.homework.next_button_operate("true")  # 下一题 按钮 状态判断 加点击

    @teststep
    def start_familiar_count_compare(self, fc, ws, star, familiar):
        """标星和标熟个数的判断"""
        # 对上一游戏的标熟和标星进行个数验证
        if len(star) == fc:
            print('\n标星单词:', star)
            print('标星个数与闪卡抄写个数一致')
        else:
            print("★★★ Error--标星个数与闪卡抄写个数不一致!")

        if len(familiar) == ws:
            print('标熟单词', familiar)
            print('标熟个数与单词默写个数一致\n')
        else:
            print('★★★ Error--熟个数与单词默写个数不一致!')
        print('------------------------------------')

    @teststeps
    def vocab_apply(self, i):
        if i == 0:
            #词汇选择分组

            #单词拼写分组
            print('\n 词汇运用 --句子选单词模式(复习)\n')
        self.homework.next_button_operate('false')
        item = self.question_content()  #题目
        print('题目:%s' % item)

        self.click_hint_button()  #点击提示按钮
        self.hint_button_judge('false')  #提示按钮 状态判断

        explain = self.sentence_explain()
        word = self.mysql.find_word_by_sentence_exp(explain)  #根据中文获取缺少单词
        print('word:', word)

        options = self.option_button()  # 四个选项
        for i in range(0, len(options)):
            if options[i].text == word:
                options[i].click()
                break

        self.click_voice()
        self.homework.next_button_operate('true')
        print('----------------------------------')

    @teststeps
    def options_statistic(self, answer, word, explain):
        """选择对错统计"""
        options = self.option_button()  # 四个选项
        for i in range(0, len(options)):
            if self.attr.selected(options[i]) == "true":
                if options[i].text == word:
                    print('选择正确:%s\n解释:%s' % (options[i].text, explain))
                    print('----------------------------------')

                else:
                    answer.append(word)
                    print('选择错误,正确答案为:%s\n' % word)
Exemple #7
0
 def __init__(self):
     self.homework = Homework()
     self.home = HomePage()
     self.mysql = MysqlData()
     self.common = DataActionPage()
Exemple #8
0
class FlashCard(BasePage):
    """单词本 - 闪卡练习"""
    def __init__(self):
        self.homework = Homework()
        self.home = HomePage()
        self.mysql = MysqlData()
        self.common = DataActionPage()

    @teststeps
    def wait_check_study_page(self):
        """以“闪卡练习 -学习模式”的xpath-text为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'设置熟词')]")
        try:
            WebDriverWait(self.driver, 2,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_copy_page(self):
        """以“闪卡练习 -抄写模式”的xpath-text为依据"""
        locator = (By.ID, "com.vanthink.student.debug:id/english")
        try:
            WebDriverWait(self.driver, 2,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_sentence_page(self):
        """以“闪卡练习 -抄写模式”的xpath-text为依据"""
        locator = (By.ID, "com.vanthink.student.debug:id/sentence")
        try:
            WebDriverWait(self.driver, 2,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    # 学习模式
    @teststep
    def pattern_switch(self):
        """点击右上角的全英/英汉,切换模式"""
        self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/side")\
            .click()
        time.sleep(2)

    @teststep
    def author(self):
        """例句推荐老师"""
        english = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/author").text
        return english

    @teststep
    def english_study(self):
        """全英模式 页面内展示的word"""
        english = self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/tv_english").text
        return english

    @teststep
    def explain_study(self):
        """英汉模式 页面内展示的word解释"""
        explain = self.driver.find_element_by_id(
            "com.vanthink.student.debug:id/tv_chinese")
        return explain.text

    @teststep
    def sentence_study(self):
        """全英模式 页面内展示的句子"""
        english = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/sentence").text
        return english

    @teststep
    def sentence_explain_study(self):
        """英汉模式 页面内展示的句子解释"""
        explain = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/sentence_explain").text
        return explain

    @teststep
    def explain_copy(self):
        """抄写模式的单词翻译"""
        explain = self.driver.find_element_by_id(
            "com.vanthink.student.debug:id/chinese").text
        return explain

    @teststep
    def star_button(self):
        """星标按钮"""
        ele = self.driver.find_element_by_id(
            "com.vanthink.student.debug:id/iv_star")
        return ele

    @teststep
    def familiar_button(self):
        """熟词按钮"""
        ele = self.driver.find_element_by_id(
            "com.vanthink.student.debug:id/expert")
        return ele

    @teststep
    def click_star(self):
        """闪卡练习页面内五角星按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/iv_star") \
            .click()

    @teststep
    def click_familiar(self):
        """设置为熟词 按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/expert").click()

    # 抄写模式
    @teststep
    def word_copy(self):
        """闪卡练习- 抄写模式 内展示的Word"""
        ele = self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/tv_word").text
        return ele

    @teststep
    def english_copy(self):
        """单页面内 答题框填入的Word"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/english").text
        return word

    # 提示 页面
    @teststeps
    def wait_check_tips_page(self):
        """以“icon”为依据"""
        locator = (
            By.XPATH,
            "//android.widget.TextView[contains(@resource-id,'com.vanthink.student.debug:id/md_title')]"
        )
        try:
            WebDriverWait(self.driver, 3,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def tips_title(self):
        """提示title"""
        item = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/md_title").text
        print(item)
        return item

    @teststep
    def tips_content(self):
        """提示 具体内容"""
        item = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/md_content").text
        print(item + "\n")
        time.sleep(2)
        return item

    @teststep
    def commit_button(self):
        """确定 按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/md_buttonDefaultPositive") \
            .click()
        time.sleep(2)

    @teststep
    def skip_button(self):
        """放弃 按钮"""
        self.driver. \
            find_element_by_id ('com.vanthink.student.debug:id/md_buttonDefaultNeutral') \
            .click ()
        time.sleep(2)

    @teststep
    def cancel_button(self):
        """取消 按钮"""
        self.driver. \
            find_element_by_id ('com.vanthink.student.debug:id/md_buttonDefaultNegative') \
            .click ()

    @teststeps
    def tips_operate(self):
        """温馨提示 页面信息"""
        if self.wait_check_tips_page():  # 提示 页面
            self.tips_title()
            self.tips_content()
            self.commit_button()  # 确定按钮

    @teststeps
    def study_word_core(self):
        """闪卡练习学习模式 主要步骤"""
        word = self.english_study()  # 单词

        self.pattern_switch()  # 切换到 英汉模式
        explain = self.explain_study()  # 解释
        print('单词:%s\n解释:%s' % (word, explain))

        if self.wait_check_sentence_page():  # 判断句子是否存在
            sentence = self.sentence_study()  # 句子
            sen_explain = self.sentence_explain_study()  # 句子解释
            auth = self.author()  # 推荐老师
            print('句子:%s\n句子解释:%s\n推荐老师:%s' % (sentence, sen_explain, auth))

        self.pattern_switch()  # 切换到 全英模式
        self.homework.click_voice()
        return word

    ##学习模式
    @teststeps
    def study_new_word(self, i, star, familiar):
        """学习模式  新词操作"""
        if i == 0:
            print('\n闪卡练习-学习模式(新词)\n')

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

            if i == 5:
                self.click_star()  #取消标星
            else:
                star.append(word)

        if i in range(0, 10, 2):  # 点击标熟按钮
            self.click_familiar()
            self.tips_operate()
            if i == 4:
                self.click_familiar()  # 取消标熟
            else:
                familiar.append(word)

        self.next_word(i)

    @teststeps
    def study_mine_word(self, i, star_list, familiar_list, star_add,
                        familiar_add):
        """学习模式  单词详情操作"""
        if i == 0:
            print('\n闪卡练习-单词详情(我的单词)\n')

        if i in (range(0, 5)):
            word = self.study_word_core()

            if word in star_list:  #单词是否在标星数组中
                self.judge_word_is_star(i)  #判断单词星标是否被标注
                self.judge_word_is_familiar(familiar_list, word, i,
                                            familiar_add)  #判断单词是否同时被标熟
            else:
                if i == 1 or i == 3:
                    self.click_star()
                    self.tips_operate()
                    star_add.append(word)
                self.judge_word_is_familiar(familiar_list, word, i,
                                            familiar_add)  #判断单词是否被标熟

            self.next_word(i)  #下一单词滑屏还是点击按钮
        else:
            print('标星单词:', star_list + star_add)
            print('标熟单词:', familiar_list + familiar_add)
            print('-------------------------------------')
            self.home.back_up_button()

    @teststeps
    def next_word(self, i):
        """进入下一单词的方式"""
        if i == 1:  # 向左滑屏
            self.screen_swipe_left(0.8, 0.5, 0.1, 1000)
            time.sleep(1)
        else:
            self.homework.next_button_operate('true')
            time.sleep(1)

        print('-------------------------------------')

    @teststep
    def judge_word_is_star(self, i):
        """判断单词是否被标星"""
        if GetAttribute().selected(
                self.star_button()) == 'true':  # 判断但是标星是否被标注
            print('单词已标星')
            if i == 3:
                self.click_star()  # 取消标星
        else:
            print("★★★ Error--此题未被标星")

    @teststep
    def judge_word_is_familiar(self, familiar, word, i, familiar_add):
        """判断单词是否被标熟"""
        if word in familiar:
            if GetAttribute().selected(self.familiar_button()) == 'true':
                print("★★★ Error-- 此题未被标熟")
                self.click_familiar()
                self.tips_operate()
                familiar_add.append(word)
            else:
                print('单词已标熟')
        else:
            if i == 2 or i == 4:
                self.click_familiar()
                self.tips_operate()
                familiar_add.append(word)

    ##抄写模式
    @teststeps
    def copy_new_word(self, i):
        """抄写模式  新词操作"""
        if i == 0:
            print('\n闪卡练习-抄写模式(新词)\n')

        word = self.word_copy()
        self.copy_word_core(word)

    @teststeps
    def copy_mine_word(self, i, star_add):
        """抄写模式  我的单词操作"""
        if i == 0:
            print('\n闪卡练习-抄写模式((单词详情)\n')
        word = self.word_copy()
        if i in (range(0, 5)):
            star_words = self.common.get_star_words()
            self.copy_word_core(word)
            stars = star_words + star_add
            if word not in stars:
                print('★★★ Error-- 单词未被标星却出现抄写模式')
        else:
            self.home.back_up_button()  #若没有点击放弃,且i>=4,则点击 确定按钮
            if self.wait_check_tips_page():
                self.tips_operate()
        print('--------------------------')

    @teststeps
    def copy_word_core(self, word):
        """闪卡练习 抄写模式 主要步骤"""
        self.homework.click_voice()  # 听力按钮
        time.sleep(1)
        word_explain = self.explain_copy()
        print("单词:%s\n解释:%s" % (word, word_explain))
        if len(self.english_copy()) == 0:  # 抄写模式 消除全部字母
            for j in range(0, len(word)):
                if j == 4:
                    games_keyboard('capslock')  # 点击键盘 切换到 大写字母
                    games_keyboard(word[j].upper())  # 点击键盘对应 大写字母
                else:
                    if j == 5:
                        games_keyboard('capslock')  # 点击键盘 切换到 小写字母
                    games_keyboard(word[j].lower())  # 点击键盘对应字母
            time.sleep(3)
        print('--------------------------')
 def __init__(self):
     self.homework = Homework()
     self.common =DataActionPage()
class CleanDataPage(BasePage):
    def __init__(self):
        self.home = HomePage()
        self.common = DataActionPage()

    @teststep
    def wait_check_set_up_page(self):
        """以“设置” text 为依据"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@text,'设置')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def wait_check_grade_page(self):
        """以“请选择你所处的年级” text为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'请选择你所处年级')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def select_setting_up(self):
        """点击设置"""
        self.driver.\
            find_element_by_xpath("//android.widget.TextView[contains(@text,'设置')]")\
            .click()

    @teststep
    def select_clear_cache(self):
        """清除缓存"""
        self.driver. \
            find_element_by_xpath ("//android.widget.TextView[contains(@text,'清除缓存')]") \
            .click()

    @teststep
    def grade_btn(self):
        """点击年级"""
        self.driver. \
            find_element_by_xpath ("//android.widget.TextView[contains(@text,'年级')]") \
            .click ()

    @teststep
    def grade_options(self):
        """年级选项"""
        ele = self.driver.find_elements_by_id(
            'com.vanthink.student.debug:id/tv_grade')
        return ele

    @teststep
    def select_another_grade(self):
        """选择倒数第一个年级(只要此次年级和指定年级不一样都可以)"""
        grades = self.grade_options()
        grades[-1].click()

    @teststep
    def select_certain_grade(self):
        """选择指定年级 """
        xpath_ele = "//android.widget.TextView[contains(@text,'{}')]".format(
            gv.GRADE)
        self.driver. \
            find_element_by_xpath (xpath_ele).click ()

    @teststep
    def reset_grade(self):
        """重新选择年级"""
        self.clean_cache()  #清除缓存
        self.grade_btn()  #年级按钮
        if self.wait_check_grade_page():
            self.select_another_grade()  # 选择最后一个年级
            if self.home.wait_check_head_img():
                self.grade_btn()
                if self.wait_check_grade_page():
                    self.select_certain_grade()  # 重新选择三年级
        if self.home.wait_check_head_img():
            self.home.click_tab_home()

    @teststep
    def clean_cache(self):
        """清除缓存"""
        self.select_setting_up()  #设置按钮
        if self.wait_check_set_up_page():
            self.select_clear_cache()  #清空缓存
            Toast().find_toast("清除缓存成功")
        self.home.back_up_button()
        if self.home.wait_check_head_img():
            pass

    @teststep
    def clear_user_all_data(self):
        """清除数据库所有相关数据"""
        if self.home.wait_check_page():  # 页面检查点
            print('进入主界面')
            self.common.get_student_id()  #获取用户id
            self.common.delete_all_word()  #删除所有单词
            self.common.delete_all_record()  #删除去重记录
            self.common.delete_all_fluency_flag()  #删除标星标熟记录
            self.common.change_play_times(0)  #更改练习组数
            self.common.change_today_new_count(0)  #更改今日新词个数
            self.common.change_today_word_count(0)  #更改今日已练词数
            self.common.delete_all_star()  #删除所有星星
            self.common.delete_all_score()  #删除所有分数
            self.home.back_up_button()
            if self.home.wait_check_head_img():
                self.reset_grade()  #重置年级
Exemple #11
0
 def __init__(self):
     self.get = GetAttribute()
     self.homework = Homework()
     self.common = DataActionPage()
Exemple #12
0
class SpellingWord(BasePage):
    """单词拼写"""
    def __init__(self):
        self.get = GetAttribute()
        self.homework = Homework()
        self.common = DataActionPage()

    @teststeps
    def wait_check_page(self):
        """以“词汇选择 -句子选单词模式”的 提示按钮 为依据"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@resource-id,'com.vanthink.student.debug:id/hint')]")
        try:
            WebDriverWait(self.driver, 2, 0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def explain(self):
        """展示的翻译"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_explain").text
        return word

    @teststep
    def word(self):
        """展示的Word"""
        ele = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_word").text
        word = ele[1::2]
        print('word:', word)

    @teststep
    def mine_answer(self):
        """展示的Word  前后含额外字符:aa"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_word").text
        return word[::2]

    @teststep
    def finish_word(self):
        """完成答题 之后 展示的Word 每个字母之间有空格"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_word").text
        return word[::2]

    @teststep
    def correct_judge(self):
        """判断 答案是否展示"""
        try:
            self.driver.find_element_by_id("com.vanthink.student.debug:id/tv_answer")
            return True
        except:
            return False

    @teststep
    def correct(self):
        """展示的答案"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_answer").text
        return word

    # 默写模式
    @teststep
    def hint_button(self):
        """提示按钮"""
        ele = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/hint")
        return ele

    @teststeps
    def dictation_word_judge(self):
        """判断是否展示Word"""
        try:
            self.driver \
                .find_element_by_id("com.vanthink.student.debug:id/tv_word")
            return True
        except:
            return False

    @teststeps
    def dictation_word(self):
        """展示的Word"""
        ele = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/tv_word").text
        value = ele[::2]
        return value

    @teststeps
    def dictation_pattern_new(self, i):
        """单词默写 新词"""
        if i == 0:
            print('\n单词拼写 - 默写模式(新词)\n')
        self.dictation_pattern_core()

    @teststeps
    def dictation_pattern_recite(self, i,first_game):
        """单词默写 新词"""
        if i == 0:
            level1_count = self.common.get_different_level_words(1)  # 获取需要B轮复习的单词
            if level1_count != 0:
                if first_game[0] != '词汇选择(复习)':
                    print ('★★★ Error-第一个游戏不是B1的词汇选择游戏')
                else:
                    print ("B轮单词存在,首个游戏为 '词汇选择(复习)' 名称正确!")
            else:
                if first_game[0] != '词汇运用(复习)':
                    print ("★★★ Error-第一个游戏不是B2/C1/D1/E1的词汇运用游戏'")
                else:
                    print ("B轮单词已结束,首个游戏为 '词汇运用(复习)' 名称正确!\n")

            print ('\n单词拼写 - 默写模式(新词)\n')
        self.dictation_pattern_core ()


    @teststeps
    def dictation_pattern_mine(self, i,familiar_add):
        """单词默写 我的单词"""
        if i == 0:
            print ("\n单词拼写 - 默写模式(单词详情)\n")
        explain = self.explain ()  # 题目
        value = self.common.get_word_by_explain (explain)
        familiars = self.common.get_familiar_words () + familiar_add
        if i in range(0,5):
            self.dictation_pattern_core()
            if value not in familiars:
                print ('★★★ Error-- 单词未被标熟却出现默写模式')
        else:
            FlashCard().tips_operate()
            for i in familiar_add:
                level = self.common.get_word_level(i)
                if level < 3:
                    print("★★★ Error--提交未成功,单词熟练度未更改")


    def dictation_pattern_core(self):
        """单词拼写 - 《默写模式》游戏过程"""
        explain = self.explain ()  # 题目
        value = self.common.get_word_by_explain (explain)

        self.homework.next_button_operate ('false')  # 下一题 按钮 判断加 点击操作
        if self.dictation_word_judge ():  # 默写模式 - 字母未全部消除
            print ('★★★ Error - 单词拼写 默写模式 - 字母未全部消除')

        hint = self.hint_button ()  # 提示按钮

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

            if self.dictation_word_judge ():  # 出现首字母提示
                word = self.dictation_word ()
                if len (word) == 1:
                    if word == value[0]:
                        print ('点击提示出现首字母提示', word)
                    else:
                        print('点击提示出现首字母提示', word)
                        print ("★★★ Error - 首字母提示错误")
                else:
                    print ('★★★ Error - 提示字母不为一个')
            else:
                print ("★★★ Error - 首字母提示未出现")
        else:
            print ('★★★ Error - 提示按钮enabled属性错误')

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

        answer = self.finish_word ()  # 我的答案
        self.homework.next_button_operate ('true')  # 下一题 按钮 状态判断 加点击
        self.result_operate (answer, self.mine_answer ())  # 下一步按钮后的答案页面 测试
        self.homework.click_voice ()
        self.homework.next_button_operate ('true')  # 下一题 按钮 状态判断 加点击


    @teststeps
    def result_operate(self, answer, mine):
        """下一步按钮后的答案页面"""
        print('我的答案:', answer)
        print('答题结果:', mine)
        if self.correct_judge():
            correct = self.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('----------------------------------')

    @teststeps
    def keyboard_operate(self, j, value):
        """点击键盘 具体操作"""
        if j == 4:
            games_keyboard('capslock')  # 点击键盘 切换到 大写字母
            games_keyboard(value.upper())  # 点击键盘对应 大写字母
            games_keyboard('capslock')  # 点击键盘 切换到 小写字母
        else:
            games_keyboard(value)  # 点击键盘对应字母
Exemple #13
0
 def __init__(self):
     self.home = HomePage()
     self.mysql = MysqlData()
     self.word = WordBook()
     self.common = DataActionPage()
Exemple #14
0
 def __init__(self):
     self.common = DataActionPage()
Exemple #15
0
class ProgressPage(BasePage):
    def __init__(self):
        self.common = DataActionPage()

    @teststep
    def wait_check_progress_page(self):
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'单词本进度')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def word_progress_icon(self):
        """词书进度"""
        self.driver.\
            find_element_by_id('com.vanthink.student.debug:id/word_statistics')\
            .click()

    @teststep
    def first_turn(self):
        """一轮"""
        ele = self.driver.find_element_by_id(
            'com.vanthink.student.debug:id/first_time').text
        print(ele, end=',')

    @teststep
    def third_turn(self):
        """三轮"""
        ele = self.driver.find_element_by_id(
            'com.vanthink.student.debug:id/three_time').text
        print(ele, end=',')

    @teststep
    def total(self):
        """总数"""
        ele = self.driver.find_element_by_id(
            'com.vanthink.student.debug:id/total').text
        print(ele)

    @teststep
    def label_name(self):
        """标签名称"""
        ele = self.driver.find_elements_by_id(
            'com.vanthink.student.debug:id/name')
        return ele

    @teststep
    def word_statistics(self):
        """单词数据"""
        ele = self.driver.find_elements_by_id(
            "com.vanthink.student.debug:id/statistics")
        return ele

    @teststep
    def find_pencil_icon(self):
        try:
            self.driver.find_element_by_id('com.vanthink.student.debug:id/img')
            return True
        except:
            return False

    @teststep
    def progress_ele_check(self):
        """页面元素打印"""
        print("\n----<词书进度页面>----\n")

        self.first_turn()  # 一轮
        self.third_turn()  # 三轮
        self.total()  # 总数

        labels = self.label_name()  #页面标签名
        statistics = self.word_statistics()  #单词数据
        label_name = self.get_label_names()  #数据库标签名称

        for i in range(len(labels)):
            print(labels[i].text, '\t', statistics[i].text)

            labels_id = self.common.get_all_label_ids()  # 数据库标签id
            first_count = int(statistics[i].text.split("/")[1])  #一轮单词数
            third_count = int(statistics[i].text.split('/')[0])  #三轮单词数
            all_count = int(
                statistics[i].text.split('/')[2].split(' ')[0])  #单词总数
            print('一轮单词数:', first_count, ' 三轮单词数:', third_count, ' 单词总数:',
                  all_count, '\n')

            if third_count != all_count:
                if self.find_pencil_icon():
                    print('正在练习标记存在,验证成功\n')
                else:
                    print('★★★ Error--未发现正在练习标记!')

            for j in range(len(label_name)):
                if label_name[j] == labels[i].text.split(
                        '-')[-1]:  #数据库标签名与页面标签名对比
                    self.count_compare(labels_id[j], first_count, third_count,
                                       all_count)

    @teststep
    def get_label_names(self):
        """获取标签名称"""
        labels_id = self.common.get_all_label_ids()
        label_names = []
        for i in labels_id:
            name = self.common.get_label_name(i)
            label_names.append(name)
        return label_names

    @teststep
    def count_compare(self, label_id, first_count, third_count, total):
        """获取对应熟练度的单词数,并与页面数字比较"""
        count = self.common.get_words_count(label_id)  #返回单词id 与单词熟练度
        if count[0] == first_count:
            print('一轮单词数验证正确')
        else:
            print('★★★ Error-- 一轮单词数与数据库不匹配')

        if count[1] == third_count:
            print('三轮单词数验证正确')
        else:
            print('★★★ Error-- 三轮单词数与数据库不匹配')

        if count[2] == total:
            print('单词总数数验证正确')
        else:
            print('★★★ Error-- 单词总数与数据库不匹配')

        print('----------------------------------')
Exemple #16
0
class WordBook(BasePage):
    def __init__(self):
        self.login = LoginPage()
        self.home = HomePage()
        self.tips = BuyTipsPage()
        self.spell = SpellingWord()
        self.result = ResultPage()
        self.vchoose = VocabularyChoose()
        self.common = DataActionPage()

    """单词本"""

    @teststep
    def rank_button(self):
        """排行榜 按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/rank") \
            .click()

    @teststep
    def my_word_button(self):
        """我的单词 按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/my_word") \
            .click()

    @teststep
    def word_test_button(self):
        """单词测试 按钮"""
        self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/word_test") \
            .click()

    # 多种情况下的 单词本首页
    @teststeps
    def wait_check_start_page(self):
        """将'你准备好了吗?'作为 单词本首页 页面检查点"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'你准备好了吗?')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def wait_check_continue_page(self):
        """将'欢迎回来!继续上一次的练习吧?'作为 继续页面检查点"""
        locator = (
            By.XPATH,
            "//android.widget.TextView[contains(@text,'欢迎回来!继续上一次的练习吧?')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def word_start_button(self):  # Go标志按钮
        self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/word_start").click()

    @teststep
    def word_continue_button(self):  # 继续标志按钮
        self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/word_continue").click()

    @teststep
    def total_word(self):
        """已背单词 数"""
        word = self.driver \
            .find_element_by_id("com.vanthink.student.debug:id/total").text
        return word

    # 年级
    @teststeps
    def wait_check_class_page(self):
        """ 将'请选择你所处年级'作为 选择年级页面检查点"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'请选择你所处年级')]")
        try:
            WebDriverWait(self.driver, 3,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def grade_list(self):
        """ 年级列表 选择年级"""
        grades = self.driver \
            .find_elements_by_id("com.vanthink.student.debug:id/tv_grade")
        return grades

    # 做题过程
    @teststeps
    def wait_check_game_page(self):
        """ 将'title'作为 选择做题过程中 页面检查点"""
        locator = (
            By.XPATH,
            "//android.widget.TextView[contains(@resource-id,'com.vanthink.student.debug:id/tv_title')]"
        )
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    def game_title(self):  # 题型标题
        title = self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/tv_title")
        return title

    @teststeps
    def store_data(self, word_dict):  # 将单词/解释键值对 存入数据库中
        with open("word.json", 'w') as file:
            file.write(json.dumps(word_dict, ensure_ascii=False))

    @teststeps
    def load_data(self):
        """ 根据解释从中获取对应的英文单词"""
        with open("word.json", 'r') as file:
            word_dict = json.loads(file.read())
            return word_dict

    # 结果页
    @teststeps
    def wait_check_result_page(self):
        """将'单词本'作为 继续页面检查点"""
        locator = (By.XPATH,
                   "//android.widget.TextView[contains(@text,'单词本')]")
        try:
            WebDriverWait(self.driver, 10,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststep
    def result_text(self):  # 结果页面新词和复习描述
        result = self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/text")
        return result

    @teststep
    def get_word_count(self):  # 结果页已背单词描述
        count = self.driver\
            .find_element_by_id('com.vanthink.student.debug:id/all_word_count')
        return count

    @teststeps
    def click_again(self):
        """再来一组 按钮"""
        self.driver\
            .find_element_by_id("com.vanthink.student.debug:id/again")\
            .click()

    # 单词本 已背完
    @teststeps
    def wait_check_no_word_page(self):
        """将'单词本'作为 继续页面检查点"""
        locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id,"
                   "'com.vanthink.student.debug:id/status_error_hint_view')]")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    #次数达到限制
    @teststeps
    def wait_check_count_limit_page(self):
        locator = (By.ID, "com.vanthink.student.debug:id/error_img")
        try:
            WebDriverWait(self.driver, 5,
                          0.5).until(lambda x: x.find_element(*locator))
            return True
        except:
            return False

    @teststeps
    def limit_confirm_button(self):
        """次数限制页面的【确定】 按钮"""
        self.driver.\
            find_element_by_id('com.vanthink.student.debug:id/confirm')\
            .click()

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

    @teststep
    def more_group(self):
        """再来一组"""
        if self.wait_check_result_page():
            print('进入结果页面')
            self.result.get_result_all_ele()  # 结果页元素
            self.result.more_again_button()  # 再练一次
            self.play_word_book()
            self.result.result_page_handle()

    @teststeps
    def word_book_operate(self):
        """单词本 具体操作"""
        if self.wait_check_start_page():  # 页面检查点
            print("开始单词本练习")
            self.word_start_button()  # 点击 Go按钮
            """
            点击准备好后,有四种情况:
            1、未选择年级将跳转到年级选择页面
            2、进行新词游戏界面
            3、单词已练完的提示页面
            4、购买提示页面 
            """
            if self.wait_check_class_page():  # 页面检查点
                print("选择年级:")
                grades = self.grade_list()  # 年级列表
                for i in range(0, len(grades)):
                    if grades[i].text == gv.GRADE:
                        grades[i].click()
                        print('已选择', gv.GRADE)
                        break
                if self.wait_check_start_page():  # 页面检查点
                    self.word_start_button()  # 点击 Go按钮
                    self.play_word_book()  # 单词本 具体过程

            elif self.tips.wait_check_buy_page():  # 购买提示 页面检查点
                self.tips.tips_goto_pay_operate()  # 去购买 提示页面
                if self.wait_check_start_page():
                    self.home.back_up_button()

            elif self.result.wait_check_next_grade():
                """提示练习更高年级"""
                self.result.level_up_text()  #词汇升级提示
                self.result.no_study_btn()
                if self.wait_check_start_page():
                    self.home.back_up_button()

            elif self.wait_check_count_limit_page():
                print('今日练习次数已用完,休息一下,明天再练!')
                self.limit_confirm_button()  # 确定
                if self.wait_check_start_page():
                    self.home.back_up_button()

            elif self.wait_check_no_word_page():  # todo 无词可练
                print("单词已练完,暂不安排新词学习!!")

            else:
                if self.wait_check_game_page():
                    self.play_word_book()  # 单词本 具体过程

        elif self.wait_check_continue_page():  # 页面检查点
            print("继续单词本练习")
            self.word_continue_button()  # 点击 继续 按钮
            if self.wait_check_game_page():
                self.play_word_book(
                )  # 单词本 具体过程  # elif self.result.wait_check_again_image():  #     self.result.more_again_button()  #     self.play_word_book()

    @teststeps
    def play_word_book(self):
        """单词本游戏过程"""
        fs = fc = ws = vc = ll = rw = ls = 0
        vc_wse = vc_esw = va = ws_r = 0
        m_fs = m_fc = m_ws = 0
        """
        
        以下变量均为各个游戏的计数变量
        fs:闪卡 学习模式(flash study)
        fc:闪卡 抄写模式(flash copy)
        ws:单词默写模式(新词)(word spell)
        vc:词汇选择新词模式 (vocab choose)
        ll:连连看模式(link link)
        rw:还原单词模式(restore word)
        ls:单词听写模式(listen spell) 
        vc_wse:词汇选择根据单词选解释模式(复习)(vocab choose - word select explain)
        vc_esw:词汇选择根据解释选单词模式(复习)(vocab choose - explain select word)
        va:词汇运用模式(vocab apply)
        ws_r:单词默写模式(复习)(word spell recite)
        m_fs:我的单词——闪卡学习模式(mine flash study)
        m_fc: 我的单词--闪卡抄写模式(mine flash copy)
        """
        answer = []  # 词汇选择的答案是否正确
        star = []  #标星单词
        familiar = []  #标熟单词
        familiar_add = []  # 新增的标熟单词
        star_add = []  # 新增的标星单词

        first_game = []  #复习时首个游戏名称
        vocab_recite = []  #复习词汇选择的组数
        word_spell = []  #单词拼写(复习)的组数

        while True:
            if self.wait_check_game_page():  # 页面检查点
                #新词
                if self.game_title().text == "闪卡练习(新词)":
                    """闪卡练习模式有三种情况:
                    1、点击star星标会进行闪卡抄写模式
                    2、点击熟词后会进入单词默写模式
                    3、什么都不点会进入下一游戏模式
                    """
                    if FlashCard().wait_check_study_page():  # 页面检查点
                        if fs == 0:
                            first_game.append(self.game_title().text)

                        FlashCard().study_new_word(fs, star,
                                                   familiar)  # 闪卡 学习模式 游戏过程
                        fs = fs + 1

                    elif FlashCard().wait_check_copy_page():  # 页面检查点  标星
                        FlashCard().copy_new_word(fc)  # 闪卡 抄写模式 游戏过程
                        fc = fc + 1

                elif self.game_title().text == "单词拼写(新词)":  # 标熟
                    self.spell.dictation_pattern_new(ws)  # 单词拼写·默写模式 游戏过程
                    ws = ws + 1

                elif self.game_title().text == "词汇选择(新词)":
                    self.vchoose.vocab_select_listen_choice(
                        answer, vc, fc, ws, star, familiar)  # 词汇选择 听音选词 游戏过程
                    vc = vc + 1

                elif self.game_title().text == "连连看(新词)":
                    MatchingWord().card_match(ll)  # 连连看 游戏过程
                    ll = ll + 1

                elif self.game_title().text == "还原单词(新词)":
                    WordRestore().restore_word(rw)  # 还原单词 游戏过程
                    rw = rw + 1

                elif self.game_title().text == "单词听写(新词)":
                    WordDictation().word_dictation(ls, answer)  # 单词听写 游戏过程
                    ls = ls + 1

                #复习
                elif self.game_title().text == "词汇选择(复习)":
                    if vc_wse == 0 or vc_esw == 0:  #若进行词汇选择游戏,则将游戏标题存入第一游戏数组中
                        first_game.append(self.game_title().text)

                    if self.vchoose.wait_check_head_page():
                        if self.vchoose.check_voice_ele():
                            self.vchoose.vocab_select_choice_explain(
                                vc_wse)  # 词汇选择 选解释 游戏过程
                            vc_wse = vc_wse + 1
                        else:
                            self.vchoose.vocab_select_choice_word(
                                vc_esw)  # 词汇选择 选单词 游戏过程
                            vc_esw = vc_esw + 1

                elif self.game_title().text == "词汇运用(复习)":
                    if va == 0:
                        first_game.append(self.game_title().text)  #若为词汇运用单词

                        if vc_wse == 0:
                            vocab_recite.append(vc_esw)
                        else:
                            vocab_recite.append(vc_wse)
                        vc_wse = vc_esw = ws_r = 0

                    self.vchoose.vocab_apply(va)
                    va = va + 1

                elif self.game_title().text == "单词拼写(复习)":
                    if ws_r == 0:
                        word_spell.append(va)
                        va = 0
                    self.spell.dictation_pattern_recite(
                        ws_r, first_game)  # 单词拼写·默写模式 游戏过程
                    ws_r = ws_r + 1

                #单词详情
                elif self.game_title().text == "单词详情":
                    star_list = self.common.get_star_words()
                    familiar_list = self.common.get_familiar_words()

                    FlashCard().study_mine_word(m_fs, star_list, familiar_list,
                                                star_add, familiar_add)
                    m_fs = m_fs + 1

                elif self.game_title().text == "闪卡练习":
                    FlashCard().copy_mine_word(m_fc, star_add)
                    m_fc = m_fc + 1

                elif self.game_title().text == "单词拼写":
                    SpellingWord().dictation_pattern_mine(
                        m_ws, familiar_add)  # 单词拼写·默写模式 游戏过程
                    m_ws = m_ws + 1
                else:
                    print(self.game_title().text)
                    break
            else:
                print('=============== 一组单词练习完毕!===============\n')
                break
        print('词汇选择组数:', vocab_recite, '单词拼写组数:', word_spell)
        return fs, ws_r, len(vocab_recite), len(
            word_spell), first_game  #返回闪卡练习、单词拼写(复习)、词汇选择 的个数