Exemple #1
0
def work_fixture():
    #   登录测试账号
    driver = login_success_fixture()
    #   获取课程页面
    index_page = PageIndex(driver)
    #   点击加入课程
    index_page.click_join_course()
    #   输入课程验证码
    index_page.input_course_code(config.get("test_data", "code"))
    #   点击加入按钮
    index_page.add()
    #   点击进入班级
    index_page.click_course()
    #   获取班级页面
    class_page = PageClass(driver)
    #   点击进入班级_作业页面
    class_page.click_get_work()
    #   获取作业页面
    work_page = PageWork(driver)
    yield class_page, work_page
    #   点击课程更多按钮
    index_page.click_course_more()
    #   点击课程退课按钮
    index_page.click_course_drop()
    #   输入登录密码
    index_page.input_drop_course_pwd(config.get("test_data", "pwd"))
    #   点击退课按钮
    index_page.click_drop_course()
    driver.quit()
Exemple #2
0
def login_success_fixture():
    """测试账号登录"""
    driver = webdriver.Chrome(options=get_option())
    #   获取登录页面
    login_page = PageLogin(driver)
    login_page.login(name=config.get("test_data", "name"),
                     pwd=config.get("test_data", "pwd"))
    return driver
class PageLogin(BasePage):
    url = config.get("env", "base_url") + config.get("url", "login_url")

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

    def login(self, name, pwd):
        """输入账号密码登录"""
        self.input_text(LoginLocator.name_ele, name, "登录_输入账号")
        self.input_text(LoginLocator.pwd_ele, pwd, "登录_输入密码")
        self.click_element(LoginLocator.login_btn, "登录_点击登录")
Exemple #4
0
def get_option():
    """浏览器模式配置"""
    if config.get("env", "headless") == "True":
        """设置浏览启动的选项:无头模式"""
        opt = webdriver.ChromeOptions()
        opt.add_argument("--headless")
        return opt
    else:
        return None
Exemple #5
0
class Course_data:
    """课程测试数据"""

    #   加入课程成功
    join_course_success_case = [{
        "title": "加入课堂成功",
        "data": config.get("test_data", "code"),
        "expected": "加入课堂成功"
    }]

    #   加入课程失败
    join_course_error_case = [{
        "title": "加课码不存在",
        "data": "1111111",
        "expected": "该加课码不存在或者已经失效"
    }, {
        "title": "加课码不足6位",
        "data": "111",
        "expected": "加课验证码必须是6位字符"
    }, {
        "title": "已经选过此课程",
        "data": config.get("test_data", "code"),
        "expected": "你已经选过此课程"
    }]

    #   退出课程成功
    drop_course_success_case = [{
        "title": "退出课堂成功",
        "data": config.get("test_data", "pwd"),
        "expected": "课程退课成功"
    }]

    #   退出课程失败
    drop_course_error_case = [{
        "title": "退出课堂失败",
        "data": "123456",
        "expected": "密码错误"
    }]

    #   进入班级成功
    ender_class_success_case = [{
        "title": "进入班级成功",
        "expected": "python-web项目实战- 考核项目"
    }]
Exemple #6
0
class Work_data:
    """作业测试用例"""

    #   上传作业成功
    update_work_success_case = [{
        "title": "上传作业成功",
        "data": config.get("test_data", "filename"),
        "expected": "作业提交成功"
    }]

    #   作业留言成功
    massage_success_case = [{
        "title": "作业留言成功",
        "data": "自动化留言测试",
        "expected": "自动化留言测试"
    }]

    #   作业提交成功查看状态
    view_work_success_case = [{"title": "作业已提交状态", "expected": "已提交"}]
Exemple #7
0
    # 创建一个日志收集器
    log = logging.getLogger(name)
    # 设置日志收集器等级
    log.setLevel(level)
    # 创建日志输出渠道
    s_h = logging.StreamHandler()
    f_h = logging.FileHandler(filename, encoding='utf-8')
    # 为日志输出渠道设置等级
    s_h.setLevel(sh_level)
    f_h.setLevel(fh_level)
    # 绑定日志输出渠道到日志收集器上
    log.addHandler(s_h)
    log.addHandler(f_h)
    # 设置日志输出格式
    log_format = logging.Formatter('%(asctime)s-【%(filename)s】-->line:%(lineno)d-%(levelname)s:%(message)s')
    # 为日志输出渠道设置日志格式
    s_h.setFormatter(log_format)
    f_h.setFormatter(log_format)
    # 返回一个日志收集器
    return log


log = create_log(
    name=config.get('logging', 'name'),
    level=config.get('logging', 'level'),
    filename=os.path.join(LOG_DIR, config.get('logging', 'filename')),
    sh_level=config.get('logging', 'sh_level'),
    fh_level=config.get('logging', 'fh_level')

)
Exemple #8
0
class HandleLog():
    def __init__(self, filename):
        self.filename = filename

    def write_log(self):
        log = logging.getLogger("logs")
        log.setLevel("DEBUG")
        sh = logging.StreamHandler()
        sh.setLevel("DEBUG")
        log.addHandler(sh)
        fh = logging.FileHandler(self.filename, encoding="utf8")
        fh.setLevel("DEBUG")
        log.addHandler(fh)
        formats = '%(asctime)s -- [%(filename)s-->line:%(lineno)d] - %(levelname)s: %(message)s'
        form = logging.Formatter(formats)
        sh.setFormatter(form)
        fh.setFormatter(form)
        return log


log = HandleLog(os.path.join(LOGS_PATH, config.get("log", "filename")))
log = log.write_log()

if __name__ == '__main__':
    log.error("error")
    log.info("info")
    log.debug("debug")
    log.warning("warning")
    log.critical("critical")