def draw_work(self):
        '''
        画几笔,用用橡皮擦
        录音,播放播音
        选择对错
        提交
        :return:
        '''
        # 定义driver
        res_driver = Driver().get_driver()
        # 定义对号
        right_button = res_driver.find_element_by_id(RES.ID_RIGHT)
        # 定义错号
        wrong_button = res_driver.find_element_by_id(RES.ID_WRONG)
        # 定义半对
        right_wrong_button = res_driver.find_element_by_id(RES.ID_RIGHT_WRONG)
        # 结果列表
        result = [right_button, wrong_button, right_wrong_button]

        # 定义提交按钮并点击
        submit_button = res_driver.find_element_by_id(RES.ID_SUBMIT)
        # 定义铅笔/橡皮按钮
        pen_erase_button = res_driver.find_element_by_id(RES.ID_PEN)
        # 定义录音/停止按钮
        record_button = res_driver.find_element_by_id(RES.ID_RECORD)
        # 定义播放按钮
        record_play_button = res_driver.find_element_by_id(RES.ID_RECORD_PLAY)
        # 定义查看题目按钮
        question_see_button = res_driver.find_element_by_id(RES.ID_QUESTION_SEE)

        # 定义标记按钮
        feedback_button = res_driver.find_element_by_id(RES.ID_IS_FEEDBACK)



        # 用笔画3笔
        res_driver.swipe(661, 473, 1821, 473)
        res_driver.swipe(661, 1358, 1821, 1358)
        res_driver.swipe(996, 318, 996, 1323)
        res_driver.swipe(1530, 318, 1530, 1323)
        # 点击铅笔按钮变为橡皮擦
        pen_erase_button.click()
        # 擦除一条线
        res_driver.swipe(1530, 318, 1530, 1323)
        # 录音按钮
        record_button.click()
        # 设置录音时间5s
        res_driver.implicitly_wait(5)
        # 再次点击停止录音
        record_button.click()
        # 点击录音播放按钮
        record_play_button.click()
        # 设置播放录音时间5s
        res_driver.implicitly_wait(5)
        # 点击查看题目
        question_see_button.click()
        if findsomething().find_by_message(res_driver, u'原题', 2, 1):
            print u'查看题目功能正常'
        else:
            print u'查看题目功能不正常'
        # 定义关闭查看题目按钮
        question_close_button = res_driver.find_element_by_id('com.xes.drawpanel:id/diss_window')
        # 关闭查看题目
        question_close_button.click()
        # 随机选择一个答题结果
        result[random.randint(0, 2)].click()
        # 点击标记按钮
        feedback_button.click()
        # 点击提交按钮
        submit_button.click()
                # 知识点出错
        show_submit1 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT1)
        # 分析能力弱
        show_submit2 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT2)
        # 基础概念模糊
        show_submit3 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT3)
        # 计算失误
        show_submit4 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT4)
        # 学习习惯较差
        show_submit5 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT5)
        # 马虎粗心
        show_submit6 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT6)
        # 态度不端正
        show_submit7 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT7)
        # 其它
        show_submit8 = res_driver.find_element_by_id(RES.ID_SHOW_SUBMIT8)
        # 1分
        show_score1 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE1)
        # 2分
        show_score2 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE2)
        # 3分
        show_score3 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE3)
        # 4分
        show_score4 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE4)
        # 5分
        show_score5 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE5)
        # 6分
        show_score6 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE6)
        # 7分
        show_score7 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE7)
        # 8分
        show_score8 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE8)
        # 9分
        show_score9 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE9)
        # 10分
        show_score10 = res_driver.find_element_by_id(RES.ID_SHOW_SCORE10)
        # 取消
        cancel_button = res_driver.find_element_by_id(RES.ID_CANCEl)
        # 确认
        yes_button = res_driver.find_element_by_id(RES.ID_YES)

        # 定义出错原因list
        wrong_button_list = [show_submit1, show_submit2, show_submit3, show_submit4, \
                             show_submit5, show_submit6, show_submit7, show_submit8]

        # 定义分数列表
        score_button_list = [show_score1, show_score2, show_score3, show_score4, show_score5, \
                             show_score6, show_score7, show_score8, show_score9, show_score10]
        # 随机选择一个错题原因
        wrong_button_list[random.randint(0, 7)].click()
        # 随机选择一个分数
        score_button_list[random.randint(0, 9)].click()
        # 取消关闭对话框
        cancel_button.click()
        # 再次点击提交按钮
        submit_button.click()
        # 随机选择一个错题原因
        wrong_button_list[random.randint(0, 7)].click()
        # 随机选择一个分数
        score_button_list[random.randint(0, 9)].click()
        # 点击确认提交作业
        yes_button.click()
Ejemplo n.º 2
0
class TestMyWork(unittest.TestCase):
    # SetUp测试环境
    def setUp(self):
        '''获取driver对象,进入被测页面'''
        self._driver = Driver().get_driver()
        self.__init_Login_activity()

    # TearDown测试环境
    def tearDown(self):
        # 重置driver,清空driver累积状态,供同时运行多条case使用
        # Driver().reset_driver()
        # 关闭当前session,仅供单条case测试使用,多条的时候注释掉此行
        Driver().close_driver()

    # 初始化方法,登录账户
    def __init_Login_activity(self):
        _driver = LRES.login_account()

    # C-11: 验证试卷名字
    def test_11_PaperName(self):
        _exp_paper_name = RES.paper_name
        _act_paper_name = RES.find_all_work().find_element_by_id(RES.ID_PAPER_TITLE).text.encode('utf8')
        print _act_paper_name
        assert _exp_paper_name == _act_paper_name, \
            '试卷名字与期望不符,exp=%s, act=%s' % (_exp_paper_name, _act_paper_name)

    # C-12: 验证老师名字
    def test_12_TeacherName(self):
        _exp_teacher_name = RES.teacher_name
        _act_teacher_name = RES.find_all_work().find_element_by_id(RES.ID_TEACHER_NAME).text.encode('utf8')
        print _act_teacher_name
        assert _exp_teacher_name == _act_teacher_name, \
            '主讲老师名字与期望不符,exp=%s, act=%s' % (_exp_teacher_name, _act_teacher_name)

    # C-13: 验证班级名字
    def test_13_ClassName(self):
        _exp_class_name = RES.class_name
        # _act_class_name = self.__find_All_Work().find_element_by_
        _act_class_name = RES.find_all_work().find_element_by_id(RES.ID_CLASS).text.encode('utf8')
        print _act_class_name
        assert _exp_class_name == _act_class_name, \
            '班级名字与期望不符,exp=%s, act=%s' % (_exp_class_name, _act_class_name)

    # C-14: 验证发布时间
    def test_14_PubTime(self):
        _exp_pub_time = RES.pub_time
        _act_pub_time = RES.find_all_work().find_element_by_id(RES.ID_PUB_TIME).text.encode('utf8')
        print _act_pub_time
        assert _exp_pub_time == _act_pub_time, \
            '发布时间与期望不符,exp=%s, act=%s' % (_exp_pub_time, _act_pub_time)

    # C-15: 验证班级人数
    def test_15_Class_No(self):
        _exp_class_no = RES.class_no
        _act_class_no = RES.find_all_work().find_element_by_id(RES.ID_CLASS_NUM).text.encode('utf8')
        print _act_class_no
        assert _exp_class_no == _act_class_no[-1], \
            '班级人数与期望不符,exp=%s, act=%s' % (_exp_class_no, _act_class_no[-1])

    # C-16: 验证提交人数和未提交人数之和是否为班级总人数
    def test_16_Class_No(self):
        _submit_no = RES.find_all_work().find_element_by_id(RES.ID_SUBMIT_NUM).text.encode('utf8')
        # _submit_no.subString(-1)
        _not_submit_no = RES.find_all_work().find_element_by_id(RES.ID_NO_SUBMIT).text.encode('utf8')
        # 分别截取最后一个字符
        assert string.atoi(_submit_no[-1]) + string.atoi(_not_submit_no[-1]) == string.atoi(RES.class_no), \
            '提交人数与未提交人数之和和班级总人数不符,exp=%d, act=%d' % (
                string.atoi(_submit_no[-1]) + string.atoi(_not_submit_no[-1]), RES.class_no)

    #C-17: 验证批改按钮为批改(1)的时候试卷状态应该为待批改,批改(0)的时候试卷状态应该为已完成
    def test_17_Paper_Status_Pigai(self):
        RES.get_paper_status()

    # C-18: 验证待批作业数目
    def test_18_Ready_To_Pigai(self):
        _exp_ready_pigai = '0'
        _act_ready_pigai = self._driver.find_element_by_id(RES.ID_READY_TO_PIGAI).text.encode('utf-8')
        print '待批数量:' + _act_ready_pigai
        assert _exp_ready_pigai == _act_ready_pigai, \
            '待批数目与期望不符,exp=%s, act=%s' % (_exp_ready_pigai, _act_ready_pigai)

    #C-19: 点击作业原题与答案按钮
    def test_19_Question_Check(self):
        question = RES.find_all_work().find_element_by_id(RES.ID_QUESTION)
        question.click()
        play_button = self._driver.find_element_by_id(RES.ID_PLAY)
        play_button.click()
        # message = '无语音解析'.encode('utf-8')
        __driver = self._driver
        # RES.find_toast(u"无语音解析",5, 1, self._driver)
        print RES.wait_toast_by_message(self._driver, "无语音解析", 5, 0.00001)
        # RES().wait_activity(u"无语音解析",5, 1)
        # Find_Toast.wait_toast_by_message(u"无语音解析",5, 1)
        # Find_Toast.find_toast(u"无语音解析",5, 0.5, self._driver)
        # WebDriverWait(driver, 5, 0.5).until(expected_conditions.presence_of_element_located((By.PARTIAL_LINK_TEXT, message)))
        self._driver.swipe(2106, 1209, 240, 1209)
        play_button.click()

    #C-20: 找到发布按钮并发布作业
    def test_20_Publish_Work(self):
        RES.find_and_click_pub_button()

    #C-21: 找到批改按钮并批改作业
    def test_21_Draw_Work(self):
        '''
        没作业的时候打印没有待批改作业
        有作业的时候开始批改作业
        :return:
        '''
        RES.find_and_click_draw_button()
        student_name = self._driver.find_element_by_id(RES.ID_STUDENT_NAME).text.encode('utf-8')
        if student_name == u'无学生':
            print '现在没有待批改作业'
        else:
            #批改作业在testmywork中
            pass
            # RES_DrawPanel.draw_work()

    #C-22: 获取作业列表数目
    def test_22_Get_Work_No(self):
        list_panel_id = 'com.xes.drawpanel:id/live_ListView'
        # item_className = 'android.widget.LinearLayout'
        item_className = 'com.xes.drawpanel:id/rll'
        # a = Driver().get_driver().find_element_by_id(list_panel_id).find_elements_by_class_name(item_className)
        # print len(a)
        # b = a[0].find_elements_by_class_name('android.widget.TextView')
        # for tst in b:
        #     print tst.text.encode('utf-8')
        # stu_info = E.element_scroll(Driver().get_driver(), list_panel_id, item_className)
        stu_info = E.element_scroll_to_find_button(Driver().get_driver(), list_panel_id, item_className)
        stu_no = len(stu_info)
        # stu_no = len(E.element_scroll(Driver().get_driver(), list_panel_id, item_className))
        print '作业列表数量:' + str(stu_no)

    #C-23: 获取作业列表数目
    def test_23_Get_Work_No(self):
        list_panel_id = 'com.xes.drawpanel:id/live_ListView'
        item_className = 'com.xes.drawpanel:id/rll'
        a = Driver().get_driver().find_element_by_id(list_panel_id).find_elements_by_id(item_className)
        print FRES.find_all_button(a[0])