Пример #1
0
    def go_on_run(self):
        """程序执行"""
        pass_count = []
        fail_count = []
        res = None
        # 获取用例数
        rows_count = self.data.get_case_lines()
        # 第一行索引为0
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)

                if depend_case != None:
                    self.depend_data = DependentData(depend_case)
                    # 获取依赖的响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    # 更新请求字段
                    request_data[depend_key] = depend_response_data
                # 如果header字段值为write则将该接口的返回的token写入到token.json文件,如果为yes则读取token.json文件
                if header == "write":
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_token()
                elif header == 'yes':
                    op_json = OperationJson("../dataconfig/token.json")
                    token = op_json.get_data('data')
                    request_data = dict(request_data,
                                        **token)  # 把请求数据与登录token合并,并作为请求数据

                    res = self.run_method.run_main(method, url, request_data)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                if expect != None:
                    if self.com_util.is_contain(expect, res):
                        self.data.write_result(i, "Pass")
                        pass_count.append(i)
                    else:
                        self.data.write_result(i, res)
                        fail_count.append(i)
                else:
                    print("用例ID:case-{i},预期结果不能为空")

        # 发送邮件
        # self.send_email.send_main(pass_count, fail_count)

        print("通过用例数:{len(pass_count)}")
        print("失败用例数:{len(fail_count)}")
Пример #2
0
    def go_on_run(self):
        """程序执行"""
        pass_count = []
        fail_count = []
        no_run_count = []
        res = None
        # 获取用例数
        rows_count = self.data.get_case_lines()
        print(rows_count)
        # 第一行索引为0
        for i in range(1, rows_count):
            print("i:", i)
            is_run = self.data.get_is_run(i)
            print(is_run)
            if is_run:
                url = self.data.get_request_url(i)
                print("url:", url)
                method = self.data.get_request_method(i)
                print("method:", method)
                request_data = self.data.get_data_for_json(i)
                print("request_data:", request_data)
                print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", type(request_data))
                expect = self.data.get_expect_data(i)
                print("expect:", expect)
                header = self.data.is_header(i)
                print("header:", header)
                token = self.data.is_token(i)
                print("token:", token)
                depend_case = self.data.is_depend(i)
                print("depend_case:", depend_case)

                if depend_case != None:
                    self.depend_data = DependentData(depend_case)
                    # 获取依赖的响应数据
                    print("#### i", i)
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    print("##################")
                    print("1depend_response_data:", depend_response_data)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    print("depend_key:", depend_key)
                    # 更新请求字段
                    request_data.get(
                        'params')[depend_key] = depend_response_data
                    #request_data = json.dumps(request_data, ensure_ascii=False)
                    print("request_data:", request_data)
                    print(type(request_data))
                # 如果header字段值为write则将该接口的返回的token写入到token.json文件,如果为yes则读取token.json文件
                if header == "write_token":
                    print("********************")
                    res = self.run_method.run_main(method, url,
                                                   request_data).json()
                    print("res:", res)
                    print("res type", type(res))
                    #print("res.json():", res.json())
                    op_header = OperationHeader(res)
                    op_header.write_token()
                elif header == 'write_cookie' and token == 'yes':
                    print("case22222222222222")
                    op_json = OperationJson("../dataconfig/token.json")
                    token = op_json.get_data('data')
                    request_data = dict(request_data,
                                        **token)  # 把请求数据与登录token合并,并作为请求数据
                    print("login_data", request_data)
                    res = self.run_method.run_main(method, url, request_data)
                    print("res_login:"******"@@@@@@@@@@@@@@@@@@@@@@@@@@")
                    op_json1 = OperationJson('../dataconfig/cookie.json')
                    op_json2 = OperationJson('../dataconfig/token.json')
                    cookies = op_json1.get_data('cookie')
                    token = op_json2.get_data('data')
                    request_data = dict(request_data, **token)
                    print("post_data:", request_data)
                    print("cookie:", cookies)
                    new_value = json.dumps(request_data.get("params"))
                    request_data["params"] = new_value
                    res = self.run_method.run_main(method,
                                                   url,
                                                   request_data,
                                                   cookies=cookies)
                    print("res:", type(res))
                else:
                    res = self.run_method.run_main(method, url, request_data)

                if expect != None:
                    if self.com_util.is_contain(expect, res):
                        self.data.write_result(i, "Pass")
                        pass_count.append(i)
                        if type(res) is dict:
                            self.data.write_real_res(i, json.dumps(res))
                        else:
                            self.data.write_real_res(i, json.dumps(res.json()))
                    else:
                        self.data.write_result(i, "Fail")
                        fail_count.append(i)
                        if type(res) is dict:
                            self.data.write_real_res(i, json.dumps(res))
                        else:
                            self.data.write_real_res(i, json.dumps(res.json()))
                else:
                    print(f"用例ID:case-{i},预期结果不能为空")
            else:
                self.data.write_result(i, "Not run")
                no_run_count.append(i)

        # 发送邮件

        print(f"通过用例数:{len(pass_count)}")
        print(f"失败用例数:{len(fail_count)}")
        print(f"未执行败用例数:{len(no_run_count)}")

        self.send_email.send_main(pass_count, fail_count, no_run_count)
Пример #3
0
    def go_on_run(self):
        global expect
        expect = True
        res = None
        pass_count = []
        fail_count = []
        # 10  0,1,2,3
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                # expect = self.data.get_expcet_data_for_mysql(i)
                expect = self.data.get_expcet_data(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                if depend_case is not None:
                    self.depend_data = DependdentData(depend_case)
                    # 获取的依赖响应数据
                    # for depend_response_data_list in
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    if len(depend_response_data) == 1:
                        request_data_result = "".join(depend_response_data)
                    else:
                        request_data_result = ",".join(
                            [str(i) for i in depend_response_data])
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    depend_key_list = depend_key.split(",")
                    print(type(depend_key_list))
                    for (key_list, key) in zip(request_data_result.split(","),
                                               depend_key_list):
                        print(key_list, key)
                        if method == "Post" or method == "Get" or method == "Put_Add" or method == "Put":
                            # print(key)
                            request_data[key] = key_list
                        else:
                            request_data = depend_response_data
                            break

                contentType = "application/json"

                if header == 'write':
                    header = {'Content-Type': contentType}
                    res = self.run_method.run_main(method,
                                                   url,
                                                   data=request_data,
                                                   header=header)
                    op_header = OperationHeader(res)
                    op_header.write_token()

                elif header == 'yes':
                    op_json = OperetionJson('../dataconfig/token.json')
                    token = op_json.get_data('token')
                    header = {
                        'Content-Type': contentType,
                        'Authorization': token
                    }
                    # print("request_data=======%s" % request_data)
                    res = self.run_method.run_main(method,
                                                   url,
                                                   request_data,
                                                   header=header)
                elif header == 'write_user':
                    header = {
                        'Content-Type': contentType,
                    }
                    res = self.run_method.run_main(method,
                                                   url,
                                                   request_data,
                                                   header=header)
                    op_header = OperationHeader(res)
                    op_header.write_user_token()
                elif header == 'weChat':
                    op_json = OperetionJson('../dataconfig/weChatToken')
                    token = op_json.get_data('token')
                    header = {
                        'Content-Type': contentType,
                        'Authorization': token
                    }
                    res = self.run_method.run_main(method,
                                                   url,
                                                   request_data,
                                                   header=header)
                else:
                    res = self.run_method.run_main(method, url, request_data)

            if self.com_util.is_contain(expect, res) == 0:
                self.data.write_result(i, 'pass')
                pass_count.append(i)
            else:
                self.data.write_result(i, res)
                fail_count.append(i)
Пример #4
0
    def go_on_run(self):
        """程序执行"""
        pass_count = []
        fail_count = []
        request_data_file = ''
        res = None
        # 获取用例数
        rows_count = self.data.get_case_lines()

        # 第一行索引为0
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                #request_data = json.load(self.data.get_request_data(i))
                expect = self.data.get_expcet_data(i)
                token = self.data.is_token(i)
                depend_case = self.data.is_depend(i)
                headers = self.data.get_headers(i)
                r = self.data.get_request_data(i)

                # 上传文件处理
                if r != None:
                    if r.endswith('jpg') | r.endswith('png') | r.endswith(
                            'docx') | r.endswith('doc') | r.endswith(
                                'ppt') | r.endswith('pptx'):  #其他文件暂不考虑
                        file_payload = {
                            'file': (r, open('../' + r, 'rb'))
                        }  #, "image/jpg"
                        m = MultipartEncoder(file_payload)
                        headers['Content-Type'] = m.content_type
                        request_data = m
                    #处理依赖
                    elif depend_case != None:
                        self.depend_data = DependentData(depend_case)
                        # 获取依赖key和value [id1:3]
                        depend_response_data = self.depend_data.get_data_for_key(
                            i)  # {caseid:{id1:1,id2:2}}
                        for caseid in depend_response_data:
                            for k in depend_response_data[caseid]:
                                y = '${' + caseid + ',' + k + '}'
                                if r.find(y):
                                    t = r.replace(
                                        y,
                                        str(depend_response_data[caseid][k]))
                                    r = t
                        request_data = json.loads(r, encoding='utf-8')

                    else:  # 没有依赖直接转换输出
                        request_data = json.loads(r, encoding='utf-8')

                else:
                    request_data = {}

                # 如果token字段值为write则将该接口的返回的token写入到token.json文件,如果为yes则读取token.json文件
                if token == "write":

                    res = self.run_method.run_main(method, url, request_data,
                                                   headers)
                    op_header = OperationHeader(res)
                    op_header.write_token()
                elif token == 'yes':
                    op_json = OperationJson("../dataconfig/token.json")
                    token = op_json.get_data('data')
                    headers.update(token)

                    #request_data = dict(request_data, **token)  # 把请求数据与登录token合并,并作为请求数据
                    res = self.run_method.run_main(method, url, request_data,
                                                   headers)

                else:

                    res = self.run_method.run_main(method, url, request_data,
                                                   headers)

                #将响应数据写入excel
                log().info("响应结果\n%s", res)
                self.data.write_respond_data(i, res)
                if expect != None:
                    if self.com_util.is_contain(expect, res):
                        self.data.write_result(i, "Pass")
                        pass_count.append(i)
                    else:
                        self.data.write_result(i, "failed")
                        fail_count.append(i)
                else:
                    print(f"用例ID:case-{i},预期结果不能为空")

        # 发送邮件
        # self.send_email.send_main(pass_count, fail_count)

        print(f"通过用例数:{len(pass_count)}")
        print(f"失败用例数:{len(fail_count)}")
Пример #5
0
    def go_on_run(self,i):
        pass_count = []
        fail_count = []
        request_data_file = ''
        res = None
        # 获取用例数
        rows_count = self.data.get_case_lines()
        # 第一行索引为0
        # for i in range(1, rows_count):
        is_run = self.data.get_is_run(i)
        if is_run:
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            #request_data = json.load(self.data.get_request_data(i))
            expect = self.data.get_expcet_data(i)
            token = self.data.is_token(i)
            depend_case = self.data.is_depend(i)
            headers= self.data.get_headers(i)
            r = self.data.get_request_data(i)
            self.data.write_respond_data(i, '')#清空响应信息


            # 上传文件处理
            if r!=None:
                if r.endswith('jpg')| r.endswith('png')| r.endswith('docx')| r.endswith('doc')| r.endswith('ppt')| r.endswith('pptx'):#其他文件暂不考虑
                    log().info('读取上传文件')
                    file_payload = {'file': (r, open('../' + r, 'rb'))}#, "image/jpg"
                    m = MultipartEncoder(file_payload)
                    headers['Content-Type'] = m.content_type
                    request_data = m
                    log().info('生成上传文件Multipart')
                #处理依赖
                elif depend_case != None:
                    self.depend_data = DependentData(depend_case)
                    # 获取依赖key和value [id1:3]
                    depend_response_data = self.depend_data.get_data_for_key(i)  # {caseid:{id1:1,id2:2}}
                    for caseid in depend_response_data:
                        for k in depend_response_data[caseid]:
                            y = '${' + caseid + ',' + k + '}'
                            if r.find(y):
                                t = r.replace(y, str(depend_response_data[caseid][k]))
                                r = t
                    log().info('依赖(最终)请求拼接完成\n%s', r)
                    request_data = json.loads(r, encoding='utf-8')

                else:# 没有依赖直接转换输出
                        log().info('获取没有依赖的请求参数\n%s',r)
                        request_data =json.loads(r,encoding='utf-8')

            else:
                request_data={}

            # 如果token字段值为write则将该接口的返回的token写入到token.json文件,如果为yes则读取token.json文件
            if token == "write":
                log().info('写入token')
                res = self.run_method.run_main(method, url,request_data,headers)
                op_header = OperationHeader(res)
                op_header.write_token()
            elif token == 'yes':
                op_json = OperationJson("../dataconfig/token.json")
                token = op_json.get_data('data')
                log().info("获取token\n%s",token)
                headers.update(token)
                #request_data = dict(request_data, **token)  # 把请求数据与登录token合并,并作为请求数据
                res = self.run_method.run_main(method, url,request_data,headers)

            else:

                res = self.run_method.run_main(method, url,request_data,headers)
            log().info("响应结果\n%s", res)
            self.data.write_respond_data(i, res)

            if expect != None:
                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, "Pass")
                    pass_count.append(i)

                else:
                    self.data.write_result(i, "failed")
                    fail_count.append(i)

            else:

                log().error('用例ID:case-%s,预期结果不能为空',i)

            return res