Exemplo n.º 1
0
    def test_run(self, case):
        # run_list第1个用例,用例,key获取values
        url = ConfigYaml().get_conf_url() + case[data_key.url]

        case_id = case[data_key.case_id]
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        expect_result = case[data_key.expect_result]
        headers = case[data_key.headers]
        cookies = case[data_key.cookies]
        code = case[data_key.code]
        db_verify = case[data_key.db_verify]

        # 2.增加Headers
        # 3.增加cookies
        # 4.发送请求
        if pre_exec:
            # 前置测试用例
            pre_case = data_init.get_case_pre(pre_exec)
            print("前置条件信息为:%s" % pre_case)
            pre_res = self.run_pre(pre_case)
            headers, cookies = self.get_correlation(headers, cookies, pre_res)
        # 1.判断headers是否存在,json转义,无需
        header = Base.json_param(headers)
        cookie = Base.json_param(cookies)
        res = self.run_api(url,
                           method,
                           params=params,
                           header=header,
                           cookie=cookie)
        print("测试用例执行:%s" % res)

        # allure
        # sheet名称  feature 一级标签
        allure.dynamic.feature(sheet_name)
        # 模块   story 二级标签
        allure.dynamic.story(case_model)
        # 用例ID+接口名称  title
        allure.dynamic.title(case_id + case_name)
        # 请求URL  请求类型 期望结果 实际结果描述
        desc = "<font color='red'>请求URL111: </font> {}<Br/>" \
               "<font color='red'>请求类型222: </font>{}<Br/>" \
               "<font color='red'>期望结果: </font>{}<Br/>" \
               "<font color='red'>实际结果: </font>{}".format(url, method, expect_result, res)
        allure.dynamic.description(desc)

        # 断言验证
        # 状态码,返回结果内容,数据库相关的结果的验证
        assert_util = AssertUtil()
        assert_util.assert_code(int(res['code']), code)
        # 返回结果内容
        assert_util.assert_in_body(str(res["body"]), str(expect_result))
        Base.assert_db("db_1", res["body"], db_verify)
Exemplo n.º 2
0
    def run_pre(self, pre_case):
        url = ConfigYaml().get_conf_url() + pre_case[data_key.url]
        method = pre_case[data_key.method]
        params = pre_case[data_key.params]
        headers = pre_case[data_key.headers]
        cookies = pre_case[data_key.cookies]

        # 判断headers,cookies是否存在,json转义,无需
        header = Base.json_param(headers)
        cookie = Base.json_param(cookies)
        res = self.run_api(url, method, params, header)
        print("前置用例执行:%s" % res)
        return res