Esempio n. 1
0
class Run_test:
    def __init__(self):
        self.data = GetData()
        self.runMethod = RunMethod()

    def run_case(self):
        rows = self.data.get_case_lines()
        #row = 0
        for row in range(1, rows):
            is_run = self.data.get_is_run(row)
            print(is_run)
            if is_run == True:
                url = self.data.get_url(row)
                print(url)
                method = self.data.get_request_method(row)
                print(method)
                #header = self.data.get_header(row)
                depend_case = self.data.is_depend(row)
                print(depend_case)
                #request_data = self.data.get_data_for_json(row)
                request_data = self.data.get_request_data(row)
                body = json.dumps(request_data)

                print(request_data)
                #method = 'post'
                #url = 'http://10.128.0.150:8002/backend/user/login'
                headers = {"Content-Type": "application/json;charset=UTF-8"}
                #headers = json.dumps(headerstring)

                '''bodystring = {"username" : "super", "password" : "Connext@0101"}
                body = json.dumps(bodystring)'''

                #res = self.runMethod.run_main(method, url, request_data, headers)
                print("==========")
                #print(res)
                if depend_case != None:
                    depend_data = DependentData(depend_case)
                    depend_res = depend_data.run_dependent(depend_data.case_id)
                    print(depend_res)
                    #self.depend_data = DependentData(depend_case)

                    # 获取依赖响应数据
                    depend_response_key = depend_data.get_data_for_key(row)
                    # 获取依赖的key(数据依赖字段excel)
                    depend_key = self.data.get_depend_field(row)
                    print(depend_key)
                    #request_data[depend_key] = depend_response_key
                    #op_json = OperrationJson('../dataconfig/user.json')
                    # header = OperrationJson.get_data('token')

                    #headers = {'Content-Type': 'application/json;charset=UTF-8'}
                    #body = {'username': '******', 'password': '******'}
                else:
                    res = self.runMethod.run_main(method, url, request_data, headers)
                    print(res)

            else:
                print("NO way")
Esempio n. 2
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):
        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)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    self.depend_data = DependdentData(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
                if header == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperetionJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    res = self.run_method.run_main(method, url, request_data,
                                                   cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)
                    # print(res)

                if self.com_util.is_equal_dict(expect, res) == 0:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)