Exemplo n.º 1
0
class StudyCircleList(BaseAction):
    """
    学习圈列表页面
    """
    conf = configread.ConfigRead('控件.ini')
    studycircle_loc = conf.get_elinfo('学习圈', '学习圈')
    praise_loc = conf.get_elinfo('学习圈', '点赞')
    praise_num_loc = conf.get_elinfo('学习圈', '点赞数')
    comment_btn_loc = conf.get_elinfo('学习圈', '评论')
    comment_loc = conf.get_elinfo('学习圈', '评论框')
    send_loc = conf.get_elinfo('学习圈', '发表评论')

    def __init__(self, driver):
        super().__init__(driver)
        self.click_find()
        self.click(*self.studycircle_loc)

    def click_comment(self):
        self.click(*self.comment_btn_loc)

    def input_comment(self, comment):
        self.send_keys(*self.comment_loc, value=comment)
        self.click(*self.send_loc)

    def click_praise(self):
        self.click(*self.praise_loc)

    def get_praisenum(self, index=0):
        """获取列表中某条数据的点赞数,默认第一条"""
        praise_num = int(
            self.get_attributes(*self.praise_num_loc,
                                index=index,
                                attribute='text'))
        return praise_num
Exemplo n.º 2
0
class Login(BaseAction):
    """
    登陆页面
    """
    conf = configread.ConfigRead('控件.ini')
    data = configread.ConfigRead('数据.ini')
    start_loc = conf.get_elinfo('启动', '马上体验')
    username_loc = conf.get_elinfo('登陆', '用户名')
    username_value = data.get_value('登陆', '用户名')
    pwd_loc = conf.get_elinfo('登陆', '密码')
    pwd_value = data.get_value('登陆', '密码')
    login_loc = conf.get_elinfo('登陆', '登陆')

    def __init__(self, driver):
        super().__init__(driver)

    def click_start(self):
        while True:
            self.swipe_left()
            if self.isexist(*self.start_loc):
                break
        self.click(*self.start_loc)

    def input_username(self):
        self.send_keys(*self.username_loc, value=self.username_value)

    def input_pwd(self):
        self.send_keys(*self.pwd_loc, value=self.pwd_value)

    def click_login(self):
        self.click(*self.login_loc)

    # 定义统一登陆入口
    def login(self):
        self.click_start()
        self.input_username()
        self.input_pwd()
        self.click_login()
Exemplo n.º 3
0
class ClassManage(BaseAction):
    """
    班级管理页面
    """
    conf = configread.ConfigRead('控件.ini')
    joinclass_loc = conf.get_elinfo('班级管理', '加入班级')
    createclass_loc = conf.get_elinfo('班级管理', '创建班级')

    def __init__(self, driver):
        super().__init__(driver)

    def click_joinclass(self):
        self.click(*self.joinclass_loc)

    def click_createclass(self):
        self.click(*self.createclass_loc)
Exemplo n.º 4
0
class XueTang(BaseAction):
    """
    学堂主页面
    """
    conf = configread.ConfigRead('控件.ini')
    sethomework_loc = conf.get_elinfo('学堂', '布置作业')
    checkhomework_loc = conf.get_elinfo('学堂', '批改作业')
    classmanage_loc = conf.get_elinfo('学堂', '班级管理')
    title_loc = conf.get_elinfo('学堂', '标题')

    def __init__(self, driver):
        super().__init__(driver)

    def click_sethomework(self):
        self.click(*self.sethomework_loc)

    def click_checkhomework(self):
        self.click(self.checkhomework_loc)

    def click_classmanage(self):
        self.click(*self.classmanage_loc)
Exemplo n.º 5
0
class MicroCourse(BaseAction):
    """
    微课页面
    """
    conf = configread.ConfigRead('控件.ini')
    microcourse_loc = conf.get_elinfo('学堂', '微课')
    grade_loc = conf.get_elinfo('微课', '设置年级')
    grade_list_loc = conf.get_elinfo('微课', '年级列表')
    save_loc = conf.get_elinfo('微课', '保存')
    switch_loc = conf.get_elinfo('微课', '切换教材')
    version_list_loc = conf.get_elinfo('微课', '教材名')
    ok_loc = conf.get_elinfo('微课', '确定')
    version_loc = conf.get_elinfo('微课', '版本名称')
    subject_list_loc = conf.get_elinfo('微课', '学科列表')
    video_list_loc = conf.get_elinfo('微课', '视频列表')
    video_name_loc = conf.get_elinfo('微课', '视频标题')
    topic_list_loc = conf.get_elinfo('微课', '专题列表')
    topic_subject_loc = conf.get_elinfo('微课', '学科tab')

    def __init__(self, driver):
        super().__init__(driver)
        self.click(*self.microcourse_loc)

    def set_grade(self, grade):
        """
        设置年级
        :param grade: 3三年级,4四年级,5五年级,6六年级,7初一,8初二,9初三,10高一,11高二,12高三
        :return:
        """
        self.click(*self.grade_loc)
        grades = self.find_elements(*self.grade_list_loc)
        grade_dict = {
            3: grades[0],
            4: grades[1],
            5: grades[2],
            6: grades[3],
            7: grades[4],
            8: grades[5],
            9: grades[6],
            10: grades[7],
            11: grades[8],
            12: grades[9]
        }

        if grade in grade_dict.keys():
            grade_dict[grade].click()
        else:
            print('参数错误')
        self.click(*self.save_loc)

    def switch_version(self, version_index, switch_index=2):
        """
        切换教材版本
        :param version_index: 教材版本索引
        :param switch_index: 切换按钮索引
        :return:
        """
        self.clicks(*self.switch_loc, index=switch_index)
        version_list = self.find_elements(*self.version_list_loc)
        if version_index < len(version_list):
            version_list[version_index].click()
        else:
            print('版本不存在')
        self.click(*self.ok_loc)

    # 获取页面当前设置的年级名称
    def get_grade(self):
        grade = self.get_attribute(*self.grade_loc)
        return grade

    # 获取页面当前设置的教材版本名称
    def get_version_name(self, index):
        version_name = self.get_attributes(*self.version_loc, index=index)
        return version_name

    # 点击指定学科
    def click_subject(self, index):
        self.clicks(*self.subject_list_loc, index=index)

    # 点击随机专题
    def click_topic(self):
        self.random_ele(*self.topic_list_loc).click()

    # 点击随机视频
    def click_video(self):
        self.random_ele(*self.video_list_loc).click()

    # 切换专题的学科
    def switch_tab(self, value):
        eles = self.find_elements(*self.topic_subject_loc)
        for ele in eles:
            if ele.get_attribute('text') == value:
                ele.click()
                break
Exemplo n.º 6
0
def driver():
    appconf = configread.ConfigRead('appconf.ini')
    desired_caps = dict(appconf.get_items('desired_caps'))
    dr = webdriver.Remote(appconf.get_value('appium', 'base_url'), desired_caps)
    return dr
Exemplo n.º 7
0
class CloudClass(BaseAction):
    """
    云课堂页面
    """
    conf = configread.ConfigRead('控件.ini')
    cloudclass_loc = conf.get_elinfo('学堂', '云课堂')
    class_loc = conf.get_elinfo('云课堂', '班级列表')
    tab_loc = conf.get_elinfo('云课堂', '标签')
    join_loc = conf.get_elinfo('云课堂', '加入')
    schedule_loc = conf.get_elinfo('云课堂', '课表')
    play_loc = conf.get_elinfo('云课堂', '点击观看')
    vip_loc = conf.get_elinfo('云课堂', '开通会员')

    def __init__(self, driver):
        super().__init__(driver)
        self.click(*self.cloudclass_loc)

    # 点击班级列表
    def click_class(self, index):
        self.clicks(*self.class_loc, index=index)

    def switch_tab(self, index):
        """
        切换tab
        :param index: 0云课堂,1课堂回看
        :return:
        """
        if index == 0:
            self.clicks(*self.tab_loc, index=0)
        elif index == 1:
            self.clicks(*self.tab_loc, index=1)
        else:
            print('参数错误')

    # 加入云课堂
    def join_class(self):
        self.click(*self.join_loc)

    def set_schedule(self, day):
        """
        切换课程表
        :param day: 0第一列,1第二列,2第三列...6最后一列
        :return:
        """

        schedules = self.find_elements(*self.schedule_loc)
        schedule = {
            0: schedules[0],
            1: schedules[1],
            2: schedules[2],
            3: schedules[3],
            4: schedules[4],
            5: schedules[5],
            6: schedules[6]
        }

        if day in schedule.keys():
            schedules[day].click()
        else:
            print('参数错误')

    # 查找状态为可以观看的视频并点击
    def play(self):
        eles = self.find_elements(*self.play_loc)
        for ele in eles:
            if ele.get_attribute('text') == '点击观看':
                ele.click()
                break
            else:
                print('暂无可观看视频')

    # 点击开通会员按钮
    def click_openvip(self):
        self.click(self.vip_loc)
Exemplo n.º 8
0
class StudyCircle(BaseAction):
    """
    学习圈页面
    """
    conf = configread.ConfigRead('控件.ini')
    studycircle_loc = conf.get_elinfo('学习圈', '学习圈')
    add_loc = conf.get_elinfo('学习圈', '添加')
    content_loc = conf.get_elinfo('学习圈', '内容')
    picture_loc = conf.get_elinfo('学习圈', '图片')
    takephoto_loc = conf.get_elinfo('学习圈', '拍照')
    shutter_loc = conf.get_elinfo('学习圈', '快门')
    done_loc = conf.get_elinfo('学习圈', '确定')
    picture_select_loc = conf.get_elinfo('学习圈', '复选框')
    save_picture_loc = conf.get_elinfo('学习圈', '确认图片')
    video_loc = conf.get_elinfo('学习圈', '视频')
    record_loc = conf.get_elinfo('学习圈', '开始录制')
    save_video_loc = conf.get_elinfo('学习圈', '保存视频')
    school_loc = conf.get_elinfo('学习圈', '选择学校')
    school_list_loc = conf.get_elinfo('学习圈', '学校列表')
    create_loc = conf.get_elinfo('学习圈', '发布')

    def __init__(self, driver):
        super().__init__(driver)
        self.click_find()
        self.click(*self.studycircle_loc)

    # 点发布学习圈按钮
    def click_add(self):
        self.click(*self.add_loc)

    def input_content(self, content):
        """
        输入学习圈内容
        :param content: str:学习圈内容
        :return:
        """
        self.send_keys(*self.content_loc, value=content)

    # 随机选择已加入学校
    def set_school(self):
        self.click(*self.school_loc)
        self.random_ele(*self.school_list_loc).click()

    def set_picture(self):
        """随机选择相册中9张图片,不足9张则选择全部"""
        self.click(*self.picture_loc)
        pictures = self.find_elements(*self.picture_select_loc)
        if len(pictures) >= 9:
            select_pictures = random.sample(pictures, 9)
            for select_picture in select_pictures:
                select_picture.click()
        else:
            for picture in pictures:
                picture.click()
            print('照片不足9张,自动选择相册中所有照片')
        self.click(*self.save_picture_loc)

    def take_photo(self):
        """拍照"""
        self.click(*self.picture_loc)
        time.sleep(2)
        self.click(*self.takephoto_loc)
        time.sleep(2)
        self.click(*self.shutter_loc)
        time.sleep(2)
        self.click(*self.done_loc)

    def set_video(self):
        self.click(*self.video_loc)
        self.long_press(*self.record_loc)
        self.click(*self.save_video_loc)

    # 点击发布
    def click_create(self):
        self.click(*self.create_loc)
Exemplo n.º 9
0
class ResourcePage(BaseAction):
    """
    资源页面
    """
    # 定位器
    conf = configread.ConfigRead('控件.ini')
    resource_loc = conf.get_elinfo('学堂', '资源')
    filter_loc = conf.get_elinfo('资源', '筛选')
    period_loc = conf.get_elinfo('资源', '学段')
    subject_loc = conf.get_elinfo('资源', '选择学科')
    subject_list_loc = conf.get_elinfo('资源', '学科列表')
    version_loc = conf.get_elinfo('资源', '选择教材')
    version_list_loc = conf.get_elinfo('资源', '教材列表')
    book_loc = conf.get_elinfo('资源', '选择册别')
    book_list_loc = conf.get_elinfo('资源', '册别列表')
    chapter_loc = conf.get_elinfo('资源', '选择章节')
    chapter_list_loc = conf.get_elinfo('资源', '章节列表')
    save_loc = conf.get_elinfo('资源', '完成')

    def __init__(self, driver):
        super().__init__(driver)
        self.click(*self.resource_loc)

    def click_filter(self):
        self.click(*self.filter_loc)

    def set_period(self, period):
        """
        选择学段
        :param period: 3小学,2初中,1高中
        :return:
        """
        if period == 3:
            self.clicks(*self.period_loc, index=0)
        elif period == 2:
            self.clicks(*self.period_loc, index=1)
        elif period == 1:
            self.clicks(*self.period_loc, index=2)
        else:
            print('参数错误')

    def set_subject(self):
        """随机选择学科"""
        self.click(*self.subject_loc)
        self.random_ele(*self.subject_list_loc).click()

    def set_version(self):
        """随机选择教材版本"""
        self.click(*self.version_loc)
        self.random_ele(*self.version_list_loc).click()

    def set_book(self):
        """随机选择册别"""
        self.click(*self.book_loc)
        self.random_ele(*self.book_list_loc).click()

    def set_chapter(self):
        """随机选择册别"""
        self.click(*self.chapter_loc)
        self.random_ele(*self.chapter_list_loc).click()

    def click_save(self):
        self.click(*self.save_loc)
Exemplo n.º 10
0
class HomeWork(BaseAction):
    """
    布置作业页面
    """
    conf = configread.ConfigRead('控件.ini')
    sethomework_loc = conf.get_elinfo('学堂', '布置作业')
    subject_loc = conf.get_elinfo('布置作业', '选择学科')
    subject_list_loc = conf.get_elinfo('布置作业', '学科列表')
    class_loc = conf.get_elinfo('布置作业', '选择班级')
    grade_list_loc = conf.get_elinfo('布置作业', '年级列表')
    class_list_loc = conf.get_elinfo('布置作业', '班级列表')
    ok_loc = conf.get_elinfo('布置作业', '确定班级')
    version_loc = conf.get_elinfo('布置作业', '选择教材')
    version_list_loc = conf.get_elinfo('布置作业', '版本列表')
    book_list_loc = conf.get_elinfo('布置作业', '册别列表')
    save_version_loc = conf.get_elinfo('布置作业', '确定版本')
    practice_loc = conf.get_elinfo('布置作业', '同步练习')
    point_loc = conf.get_elinfo('布置作业', '知识点')
    chapter_loc = conf.get_elinfo('布置作业', '选择内容')
    chapter_list_loc = conf.get_elinfo('布置作业', '章节列表')
    add_loc = conf.get_elinfo('布置作业', '添加题目')
    preview_loc = conf.get_elinfo('布置作业', '预览')
    set_homework_loc = conf.get_elinfo('布置作业', '布置作业')
    sure_loc = conf.get_elinfo('布置作业', '确认布置')

    def __init__(self, driver):
        super().__init__(driver)
        self.click(*self.sethomework_loc)

    def set_homework_type(self, homework_type):
        """
        设置作业类型
        :param homework_type: 0同步练习1知识点
        :return:
        """
        if homework_type == 0:
            pass
        elif homework_type == 1:
            self.click(*self.point_loc)
        else:
            print('参数错误')

    def set_subject(self, subject):
        """
        设置学科
        :param subject: 0语文,1数学,3英语,4物理,5化学,6地理,7历史,8政治,9生物,10信息技术
        :return:
        """
        self.click(*self.subject_loc)
        try:
            self.clicks(*self.subject_list_loc, index=subject)
        except IndexError:
            print('参数错误')

    def set_class(self, index1, index2):
        """
        设置班级
        :param index1: 年级索引
        :param index2: 班级索引
        :return:
        """
        self.click(*self.class_loc)
        try:
            self.clicks(*self.grade_list_loc, index=index1)
            self.clicks(*self.class_list_loc, index=index2)
        except IndexError:
            print('参数错误')
        self.click(*self.ok_loc)

    def set_vertion(self, index1, index2):
        """
        设置教材版本和册别
        :param index1: 版本索引
        :param index2: 册别索引
        :return:
        """

        self.click(*self.version_loc)
        try:
            self.clicks(*self.version_list_loc, index=index1)
            self.clicks(*self.book_list_loc, index=index2)
        except IndexError:
            print('参数错误')
        self.click(*self.save_version_loc)

    # 选择随机章节的随机题目
    def set_question(self):
        self.click(*self.chapter_loc)
        for i in range(10):
            self.random_ele(*self.chapter_list_loc).click()
            time.sleep(10)
            # 随机选择章节,如果所选章节没有题目,返回选择章节页面
            if self.isexists(*self.add_loc):
                self.random_ele(*self.add_loc).click()
                break
            else:
                self.click_back()

    # 布置作业
    def set_homework(self):
        self.click(*self.set_homework_loc)
        self.click(*self.sure_loc)

    # 预览作业
    def preview(self):
        self.click(*self.preview_loc)
Exemplo n.º 11
0
class CreateSchool(BaseAction):
    """
    创建学校页面
    """
    conf = configread.ConfigRead('控件.ini')
    school_loc = conf.get_elinfo('班级管理', '类型学校')
    institution_loc = conf.get_elinfo('班级管理', '类型机构')
    name_loc = conf.get_elinfo('班级管理', '学校名称')
    primary_loc = conf.get_elinfo('班级管理', '学段小学')
    junior_loc = conf.get_elinfo('班级管理', '学段初中')
    high_loc = conf.get_elinfo('班级管理', '学段高中')
    area_loc = conf.get_elinfo('班级管理', '所在区域')
    pca_loc = conf.get_elinfo('班级管理', '选择省市')
    address_loc = conf.get_elinfo('班级管理', '地址')
    save_loc = conf.get_elinfo('班级管理', '保存')
    # 进入页面前置操作元素
    classmanage_loc = conf.get_elinfo('学堂', '班级管理')
    createclass_loc = conf.get_elinfo('班级管理', '创建班级')
    chooseschool_loc = conf.get_elinfo('班级管理', '选择学校')
    add_loc = conf.get_elinfo('班级管理', '创建学校')

    def __init__(self, driver):
        super().__init__(driver)
        self.click(*self.classmanage_loc)
        self.click(*self.createclass_loc)
        self.click(*self.chooseschool_loc)
        self.click(*self.add_loc)

    def set_school_type(self, type):
        """
        选择创建类型:机构或学校
        :param type: 1学校,2机构
        :return:
        """
        if type == 1:
            pass
        elif type == 2:
            self.click(*self.institution_loc)
        else:
            print('参数错误')

    def input_name(self, name):
        now = time.strftime('%Y%m%d%H%M%S')
        fname = name + now
        self.send_keys(*self.name_loc, value=fname)

    def set_period(self, period):
        """
        选择学段
        :param period: 1高中,2初中,3小学
        :return:
        """
        if period == 1:
            pass
        elif period == 2:
            self.click(*self.junior_loc)
        elif period == 3:
            self.click(*self.primary_loc)
        else:
            print('参数错误')

    def set_pca(self):
        """
        随机选择学校所在省市区
        """
        self.click(*self.area_loc)
        while True:
            self.random_ele(*self.pca_loc).click()
            # print(self.get_activity())
            if self.get_activity() == '.school.classmanager.AddSchoolActivity':
                break

    def input_address(self, address):
        self.send_keys(*self.address_loc, value=address)

    def click_save(self):
        self.click(*self.save_loc)
Exemplo n.º 12
0
class BaseAction:
    """基础操作类"""
    conf = configread.ConfigRead('控件.ini')
    study_loc = conf.get_elinfo('导航', '学堂')
    communicate_loc = conf.get_elinfo('导航', '沟通')
    find_loc = conf.get_elinfo('导航', '发现')
    my_loc = conf.get_elinfo('导航', '我的')

    def __init__(self, driver):
        self.driver = driver

    def find_element(self, *loc):
        """
        元素定位
        :return: element
        """
        # ele = None
        try:
            # 显示等待
            WebDriverWait(self.driver, 15).until(lambda driver: self.driver.find_element(*loc))
            ele = self.driver.find_element(*loc)
        # except NoSuchElementException:
            # print('找不到元素')
        except TimeoutException:
            print('查找元素超时')
        else:
            return ele

    def find_elements(self, *loc):
        """
        定位一组元素
        :return: element
        """
        try:
            WebDriverWait(self.driver, 15).until(lambda driver: self.driver.find_elements(*loc))
            eles = self.driver.find_elements(*loc)
        except TimeoutException:
            print('查找元素超时')
        else:
            return eles

    def isexist(self, *loc):
        """
        判断元素是否存在
        :param loc:
        :return:Boolean
        """
        flag = None
        try:
            # 显示等待
            WebDriverWait(self.driver, 5).until(lambda driver: self.driver.find_element(*loc))
            flag = True
        except TimeoutException:
            flag = False
            print('查找元素超时')
        finally:
            return flag

    def isexists(self, *loc):
        """
        判断元素是否存在
        :param loc:
        :return:Boolean
        """
        flag = None
        try:
            # 显示等待
            WebDriverWait(self.driver, 5).until(lambda driver: self.driver.find_elements(*loc))
            flag = True
        except TimeoutException:
            flag = False
            print('查找元素超时')
        finally:
            return flag

    def click(self, *loc):
        ele = self.find_element(*loc)
        ele.click()

    def clicks(self, *loc, index=None):
        eles = self.find_elements(*loc)
        eles[index].click()

    def long_press(self, *loc, duration=10000):
        ele = self.find_element(*loc)
        elx = ele.location.get('x')
        ely = ele.location.get('y')
        self.driver.swipe(elx, ely, elx, ely, duration=duration)

    def getsize(self):
        """
        获取屏幕尺寸
        :return: tuple
        """
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        return [x, y]

    def swipe_left(self, during=None):
        """
        左滑
        :param during:
        :return:
        """
        l = self.getsize()
        x1 = l[0] * 0.75
        y = l[1] * 0.5
        x2 = l[0] * 0.25
        self.driver.swipe(x1, y, x2, y, during)

    def swipe_right(self, during=None):
        """
        右滑
        :param during:
        :return:
        """
        l = self.getsize()
        x1 = l[0] * 0.25
        y = l[1] * 0.5
        x2 = l[0] * 0.75
        self.driver.swipe(x1, y, x2, y, during)

    def swipe_up(self, during=None):
        """
        上滑
        :param during:
        :return:
        """
        l = self.getsize()
        x = l[0] * 0.5
        y1 = l[1] * 0.75
        y2 = l[1] * 0.25
        self.driver.swipe(x, y1, x, y2, during)

    def swipe_down(self, during=None):
        """
        下滑
        :param during:
        :return:
        """
        l = self.getsize()
        x = l[0] * 0.5
        y1 = l[1] * 0.25
        y2 = l[1] * 0.75
        self.driver.swipe(x, y1, x, y2, during)

    def swipe_bottom(self, *loc):
        """滑到一组元素底部"""
        while True:
            text = self.get_attributes(*loc, index=-1)
            self.swipe_up()
            current_text = self.get_attributes(*loc, index=-1)
            if text == current_text:
                break

    def send_keys(self, *loc, value):
        ele = self.find_element(*loc)
        ele.clear()
        ele.send_keys(value)

    def get_attribute(self, *loc, attribute='text'):
        """
        获取一个控件的属性
        :param loc:
        :param attribute:属性类型
        :return: str
        """
        ele = self.find_element(*loc)
        value = ele.get_attribute(attribute)
        return value

    def get_attributes(self, *loc, index=None, attribute='text'):
        """
        获取一组元素中某一个元素的属性
        :param loc:
        :param index: 元素索引
        :param attribute: 属性类型
        :return: str
        """
        eles = self.find_elements(*loc)
        value = eles[index].get_attribute(attribute)
        return value

    def get_title(self, *loc):
        """
        获取页面标题
        :param loc: 页面控件信息
        :return: str
        """
        title = self.get_attribute(*loc, attribute='text')
        return title

    def get_activity(self):
        activity = self.driver.current_activity
        return activity

    def click_back(self):
        """点击系统返回按钮"""
        self.driver.keyevent(4)

    def random_ele(self, *loc):
        """获取一组元素中随机一个元素"""
        eles = self.find_elements(*loc)
        randele = random.choice(eles)
        return randele

    def click_study(self):
        self.click(*self.study_loc)

    def click_communicate(self):
        self.click(*self.communicate_loc)

    def click_find(self):
        self.click(*self.find_loc)

    def click_my(self):
        self.click(*self.my_loc)