Пример #1
0
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rowcount = self.data.get_case_rowCount()
        for i in range(1, rowcount):

            is_run = self.data.get_is_run(i)

            if is_run:
                modname = self.data.get_module(i)
                url = self.data.get_url(i)
                method = self.data.get_request_method(i)
                data = self.data.get_data_for_json(i)
                is_cookie = self.data.get_cookies(i)
                header = self.data.is_header(i)
                hoperesult = self.data.get_hopereval(i)
                is_depend = self.data.is_depend(i)
                # 是否需要依赖
                if is_depend != None:
                    self.depend_data = DependData(is_depend)
                    # 获取依赖的响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    data[depend_key] = depend_response_data

                # 是否保存cookies
                if is_cookie == 'write':
                    res = self.run_method.run_main(method, url, data)
                    op_headers = OperationHeader(res)
                    if modname == "登录":
                        op_headers.write_login_cookie()
                    else:
                        op_headers.write_cookie()

                elif is_cookie == 'yes':
                    op_json = OperationJson('../case/cookie.json')
                    header = {"Cookie": op_json.data}
                    res = self.run_method.run_main(method, url, data, header)
                else:
                    res = self.run_method.run_main(method, url, data)

                res = res.content.decode('utf-8')
                # print(res)

                if self.commonUtil.is_contain(hoperesult, res):
                    self.data.write_realresult(i, res)
                    self.data.write_result(i, "测试成功")
                    pass_count.append(i)

                else:
                    self.data.write_realresult(i, res)
                    self.data.write_result(i, "测试失败")
                    fail_count.append(i)

                res = json.loads(res)
                if (res['statusCode'] != "200"):
                    # print(res['errorMsg'])
                    pass
Пример #2
0
 def go_on_run(self):
     lines = self.data.get_case_lines()
     pass_count = []
     fail_count = []
     for i in range(1, lines):
         is_run = self.data.get_is_run(i)
         if is_run:
             res = None
             url = self.data.get_url(i)
             method = self.data.get_method_type(i)
             fix_request_key = self.data.get_fix_request_key(i)
             request_data = self.data.get_request_for_json(i)
             expected = self.data.get_expected_result(i)
             header = self.data.get_header(i)
             is_depend = self.data.is_depend(i)
             if is_depend is not None:
                 depend_case_id = self.data.get_depend_case_id(i)
                 depend_request = self.data.get_depend_request(i)
                 depend_data = DependData(depend_case_id)
                 depend_response = depend_data.get_data_for_key(i)  # 从依赖接口的返回结果中匹配需要的依赖字段
                 request_data[depend_request] = depend_response
             if header == 'yes':
                 self.oper_header.write_cookie()
                 cookies = self.oper_header.get_cookie()
                 header = {'Cookie': cookies}
                 # json.dump()
                 res = self.run.run_main(url, method, request_data, header)
             else:
                 res = self.run.run_main(url, method, request_data)
Пример #3
0
 def go_on_run(self, request_value, reponse_value):
     lines = self.data.get_case_lines()
     pass_count = []
     fail_count = []
     for i in range(1, lines):
         is_run = self.data.get_is_run(i)
         if is_run:
             res = None
             url = self.data.get_url(i)
             method = self.data.get_method_type(i)
             # request_data = self.data.get_request_for_json(i)
             # expected = self.data.get_expected_result(i)
             fix_request_key = self.data.get_fix_request_key(i)
             if fix_request_key is not None:
                 request_data = self.run_request_data(i, request_value)
                 expected = self.run_expected_data(i, reponse_value)
             else:
                 request_data = self.data.get_request_for_json(i)
                 expected = self.data.get_expected_result(i)
             header = self.data.get_header(i)
             is_depend = self.data.is_depend(i)
             if is_depend is not None:
                 depend_case_id = self.data.get_depend_case_id(i)
                 depend_request = self.data.get_depend_request(i)
                 depend_data = DependData(depend_case_id)
                 depend_response = depend_data.get_data_for_key(
                     i)  # 从依赖接口的返回结果中匹配需要的依赖字段
                 request_data[depend_request] = depend_response
             # if header == 'write':
             #     res = self.run.run_main(url, method, request_data)
             #     oper_header = OperationHeader()
             #     oper_header.write_cookie()
             if header == 'yes':
                 op_json = OperationJson('../dataconfig/esage_cookies.json')
                 cookie = op_json.get_data('Cookie')
                 cookies = {'Cookie': cookie}
                 res = self.run.run_main(url, method, request_data, cookies)
             else:
                 res = self.run.run_main(url, method, request_data)
             if self.comm.contrast(expected, res):
                 print("测试通过")
                 self.data.write_result(i, 'pass')
                 pass_count.append(i)
             else:
                 print("测试失败")
                 self.data.write_result(i, res)
                 fail_count.append(i)
Пример #4
0
    def go_no_run(self, i):
        rows_conut = self.data.get_case_lines()  # 获取行数
        is_run = self.data.get_is_run(i)
        print(is_run)
        if is_run:
            url = self.data.get_url(i)
            method = self.data.get_request_way(i)  # 获取请求的方法
            request_data = self.data.get_json_data(i)  # 获取请求数据
            data_type = self.data.get_data_type(i)
            print(data_type)
            cookie = self.data.get_is_cookies(i)  # 获取cookies
            expect = self.data.get_expect(i)  # 获取预期结果
            result = self.data.get_result(i)
            depend_case = self.data.get_depend_case_id(i)  # 获取依赖的caseid
            if depend_case is not None:
                # 获取替换请求字段
                depend_key = self.data.get_depned_key(i)
                # 获取依赖的响应数据
                self.depend_data = DependData(depend_case)
                depend_response_data = self.depend_data.get_depned_value(i)
                split = len(depend_key.split(">"))  # 切割替换的字段
                # 根据请求字段的个数替换
                for y in range(0, split):
                    re = depend_key.split(">")
                    request_data[re[y]] = depend_response_data[y]
            if cookie == 'write':
                res = self.run_method.run_main(method, url, request_data)
                op_cookie = OperationCookie(res)  # 获取cookies
                op_cookie.write_cookie()  # 写入cookies
            elif cookie == 'yes':
                get_cookies = OperationJson('../data/scm-cookies.json')
                cooki = get_cookies.get_data('SESSION')
                cookies = {"SESSION": cooki}
                res = self.run_method.run_main(method, url, request_data,
                                               cookies, data_type)
            else:
                res = self.run_method.run_main(method, url, request_data)
            if self.is_contain.is_contain(expect, res):
                self.data.write_data(i, 'pass')
                print(res)

            else:
                self.data.write_data(i, 'fail')
                print(res)
Пример #5
0
    def go_on_run(self):
        row_count = self.data.getCaseCount()
        pass_count = []
        fail_count = []
        self.getToken()

        for i in range(1, row_count):
            test_name = self.data.getTestName(i)
            url = self.data.getURL(i)
            method = self.data.getRequstMethod(i)
            is_run = self.data.getIsRun(i)
            requestDataName = self.data.getRequestData(i)
            data = self.data.get_data_for_json(requestDataName)
            header = self.data.getHeader(i, self.token)
            expect = self.data.getExpectResult(i)
            case_depend = self.data.getCaseDepend(i)
            if is_run:
                if header != None:
                    header = self.data.getHeader(i, self.token)

                if case_depend != None:
                    # 获取依赖数据
                    data_depend = self.data.getDependData(i)
                    # 获取依赖的响应数据
                    depObj = DependData(case_depend)
                    depend_resonse_data = depObj.get_data_for_key(data_depend, self.token)
                    # 获取依赖的key
                    depend_key = self.data.getDependField(i)
                    # 将响应数据赋值给请求数据中的field项中
                    data[depend_key] = depend_resonse_data
                    if method == 'DELETE':
                        url = url + depend_resonse_data

                res = self.run_method.run_main(method, url, data, header)
                m = self.common.is_contain(expect, res)
                # 判断执行结果是否与预期结果一致,并将执行结果写入excel中
                if m:
                    self.data.writeResult(i+1, "pass")
                    pass_count.append(i)
                else:
                    print("接口执行错误-", test_name, ":", res)
                    self.data.writeResult(i+1, res)
                    fail_count.append(i)
Пример #6
0
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        flat = 1
        while(flat):
            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_form_json(i)
                    expect = self.data.get_expect_data(i)
                    header = self.data.is_header(i)
                    depend_case = self.data.is_depend(i)   #数据依赖
                    if depend_case != None:
                        self.depend_data = DependData()
                        #依赖的响应数据
                        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

                    # method,url,data=None,header=None  顺序不可以颠倒
                    try:
                        res = self.run_method.run_main(method,url,request_data,header)
                    except ConnectionError:
                        pass
                    if res == None:
                        time.sleep(600)
                    else:
                        if self.com_util.is_contain(expect,res):
                            log_pass('success!!!')
                            print(flat)
                            time.sleep(20)
                            flat += 1
                            # self.data.write_result(i,'pass')
                            # pass_count.append(i)
                        else:
                            log_error('fail!!!')
                            self.send_mai.send_main()
                            time.sleep(600)
Пример #7
0
    def go_no_run(self):
        rows_conut = self.data.get_case_lines()  # 获取行数

        for i in range(1, rows_conut):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_url(i)
                case_name = self.data.get_case_name(i)
                method = self.data.get_request_way(i)  # 获取请求的方法
                request_data = self.data.get_json_data(i)  # 获取请求数据
                data_type = self.data.get_data_type(i)
                cookie = self.data.get_is_cookies(i)  # 获取cookies
                expect = self.data.get_expect(i)  # 获取预期结果
                depend_case = self.data.get_depend_case_id(i)  # 获取依赖的caseid
                if depend_case is not None:
                    # 获取替换请求字段
                    depend_key = self.data.get_depned_key(i)
                    # 获取依赖的响应数据
                    self.depend_data = DependData(depend_case)
                    depend_response_data = self.depend_data.get_depned_value(i)
                    split = len(depend_key.split(">"))  # 切割替换的字段
                    # 根据请求字段的个数替换
                    for y in range(0, split):
                        re = depend_key.split(">")
                        request_data[re[y]] = depend_response_data[y]
                if cookie == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_cookie = WriteCookies(res)  # 获取cookies
                    op_cookie.write_cookie()  # 写入cook ies
                elif cookie == 'yes':
                    get_cookies = OperationJson('../data/scm-cookies.json')
                    coo = get_cookies.get_data('SESSION')

                    cooki = {"SESSION": coo}
                    res = self.run_method.run_main(method, url, request_data,
                                                   cooki, data_type)

                else:
                    # get_cookies = OperationJson('../data/scm-cookies.json')
                    # cooki = get_cookies.get_data('accessToken')
                    # request_data['accessToken'] = cooki
                    res = self.run_method.run_main(method, url, request_data)

                if self.is_contain.is_contain(expect, res):
                    self.data.write_data(i, 'pass')
                    self.logger.info("第" + str(i) + "个case-->" + case_name +
                                     ": 测试通过")
                    self.logger.info("url--> " + url)
                    self.logger.info("request_data-->" + str(request_data))
                    self.logger.info("response_data-->" + res)
                    print("第" + str(i) + "个case-->" + case_name + ": 测试通过")
                    print(res)
                else:
                    self.data.write_data(i, res)
                    self.logger.info("第" + str(i) + "个case-->" + case_name +
                                     ": 测试失败")
                    self.logger.info("url--> " + url)
                    self.logger.info("request_data-->" + str(request_data))
                    self.logger.info("response_data-->" + res)
                    print("第" + str(i) + "个case-->" + "测试失败")
                    print(res)
Пример #8
0
    def go_on_run(self):
        res = None
        rows_count = self.data.get_case_lines()
        i = 0
        pass_ratelist_account = []
        pass_rateinfo_account = []
        fail_ratelist_account = []
        fail_rateinfo_account = []

        # 去除第一行
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            jsondata = self.data.get_data_for_json(i)
            print(jsondata)
            print(type(jsondata))
            reqdata = {
                'Head':
                '{"UserID":3,"TimeStamp":"1516156123","Sign":"FC7B4D3405863A6D06DC4D6961B708BF"}',
                'Data': jsondata
            }
            header = self.data.is_header(i)
            expect = self.data.get_expect_data(i)
            print(reqdata)
            print(type(reqdata))
            depend_case = self.data.is_depend(i)
            rescode = []
            if depend_case != None:
                self.depend_data = DependData(depend_case)
                #返回依赖的响应数据
                depend_response_data_list = self.depend_data.get_data_for_key(
                    i)
                print(depend_response_data_list)
                if depend_response_data_list == None:
                    self.data.write_result(i, '政策列表无政策返回')
                else:
                    ratecode_response_list = depend_response_data_list[0]
                    print(ratecode_response_list)
                    attachment_key_response_list = depend_response_data_list[1]
                    print(attachment_key_response_list)
                    '''
                    #获取依赖的字段
                    depend_key = self.data.get_depend_field(i)
                    print(depend_key)
                    #将配置在json文件中的dependkey的值更新一下
                    print(depend_key[0],depend_key[1])
                    '''
                    sessionidnew = depend_response_data_list[2]
                    for j in range(0, len(ratecode_response_list)):
                        jsondatadict = json.loads(jsondata)
                        #print(jsondatadict['RateCode'],jsondatadict['AttachmentKey'])
                        #从列表接口返回的ratecodelist赋值给请求参数RateCode
                        jsondatadict["RateCode"] = ratecode_response_list[j]
                        # 从列表接口返回的attachmentkeylist赋值给请求参数中的attachmentkey
                        jsondatadict[
                            "AttachmentKey"] = attachment_key_response_list[j]
                        jsondatadict["SessionId"] = sessionidnew
                        #将jsondatadict转为字符串
                        jsondatadict_to_str = json.dumps(jsondatadict)
                        reqdata['Data'] = jsondatadict_to_str
                        print(reqdata)
                        res = json.loads(
                            self.run_method.runmain(method, url, reqdata,
                                                    header))
                        print(res)
                        if self.comutil.is_contain(res, expect[:-1]):
                            rescode.append('Pass')
                            pass_rateinfo_account.append(j)
                            #self.data.write_result(i, rescode.append('Pass'))
                            print(rescode)
                        else:
                            rescode.append(res)
                            fail_rateinfo_account.append(j)
                            #self.data.write_result(i, rescode.append('Failed'))
                            print(rescode)
                        print(rescode)
                    self.data.write_result(i, rescode)
            else:
                if is_run:
                    res = json.loads(
                        self.run_method.runmain(method, url, reqdata, header))
                    print(res)
                if self.comutil.is_contain(res, expect[:-1]):
                    self.data.write_result(i, 'Pass')
                    pass_ratelist_account.append(i)
                    #print("测试通过")
                else:
                    self.data.write_result(i, res)
                    fail_ratelist_account.append(i)
                    #print("测试失败")
            print(len(pass_ratelist_account))
            print(len(fail_ratelist_account))
            print(len(pass_rateinfo_account))
            print(len(fail_rateinfo_account))
Пример #9
0
    def go_no_run(self):
        rows_conut = self.data.get_case_lines()  # 获取行数

        for i in range(1, rows_conut):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_url(i)
                case_name = self.data.get_case_name(i)
                method = self.data.get_request_way(i)  # 获取请求的方法
                request_data = self.data.get_json_data(i)  # 获取请求数据
                data_type = self.data.get_data_type(i)
                cookie = self.data.get_is_cookies(i)  # 获取cookies
                expect = self.data.get_expect(i)  # 获取预期结果
                depend_case = self.data.get_depend_case_id(i)  # 获取依赖的caseid
                if depend_case is not None:
                    # 获取替换请求字段
                    depend_key = self.data.get_depned_key(i)
                    # 获取依赖的响应数据
                    self.depend_data = DependData(depend_case)
                    depend_response_data = self.depend_data.get_depned_value(i)
                    split = len(depend_key.split(">"))  # 切割替换的字段
                    # 根据请求字段的个数替换
                    for y in range(0, split):
                        re = depend_key.split(">")
                        request_data[re[y]] = depend_response_data[y]
                if cookie == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_cookie = WriteCookies(res)  # 获取cookies
                    op_cookie.write_cookie()  # 写入cook ies
                elif cookie == 'yes':
                    father_path = os.path.join(
                        os.path.dirname(
                            os.path.dirname(os.path.abspath(__file__))),
                        'data')
                    file_path = os.path.join(father_path, '金城-cookies.json')
                    get_cookies = OperationJson(file_path)

                    cooki = get_cookies.get_data('accessToken')
                    request_data['accessToken'] = cooki
                    res = self.run_method.run_main(method, url, request_data,
                                                   data_type)

                else:
                    father_path = os.path.join(
                        os.path.dirname(
                            os.path.dirname(os.path.abspath(__file__))),
                        'data')
                    file_path = os.path.join(father_path, '金城-cookies.json')
                    get_cookies = OperationJson(file_path)
                    cooki = get_cookies.get_data('accessToken')
                    request_data['accessToken'] = cooki
                    res = self.run_method.run_main(method, url, request_data)

                if self.is_contain.is_contain(expect, res):
                    self.data.write_data(i, 'pass')
                    # self.logger.info("第" + str(i) + "个case-->" + case_name + ": \033[31m测试通过\033[0m")
                    self.logger.info("第%s 个case-->%s: 测试通过" %
                                     (str(i), case_name))
                    self.logger.info("url--> " + url)
                    self.logger.info("request_data-->" + str(request_data))
                    self.logger.info("response_data-->" + res)
                    print("第" + str(i) + "个case-->" + case_name + ": 测试通过")
                    # print("第" + str(i) + "个case-->" + case_name + ": \033[32m测试通过\033[0m")

                else:
                    self.data.write_data(i, res)
                    self.logger.info("第" + str(i) + "个case-->" + case_name +
                                     ": 测试失败")
                    self.logger.info("url--> " + url)
                    self.logger.info("request_data-->" + str(request_data))
                    self.logger.info("response_data-->" + res)
                    # print("第" + str(i) + "个case-->" + "\033[35m测试失败\033[0m")
                    print("第%s 个case-->%s: 测试失败" % (str(i), case_name))