コード例 #1
0
ファイル: run_test.py プロジェクト: testwhitebaby/cszxuexi
 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_except_data(i)
             header = self.data.is_header(i)
             depend_case = self.data.is_depend(i)
             if depend_case != None:
                 self.depend_data = DependdentData()
                 #响应数据
                 depend_respose_data = self.depend_data.get_data_for_key(i)
                 #获取依赖的key
                 depend_key = self.data.get_depend_key()
                 request_data[depend_key] = depend_respose_data
             res = self.run_method.run_main(method, url, request_data,
                                            header)
             if self.com_util.is_contain(expect, res):
                 self.data.write_result(i, "pass")
                 pass_count.append(i)
                 print("测试通过")
             else:
                 self.data.write_result(i, res)
                 fail_count.append(i)
                 print("测试失败")
     # print(len(pass_count))
     # print(len(fail_count))
     self.send_mail.send_main(pass_count, fail_count)
コード例 #2
0
    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)
                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 = 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)
                print(type(res))

                #if self.com_util.is_equal_dict(expect,res) == 0:
                #if self.com_util.is_contains_dict(expect,res):
                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    res = pass_count

                else:
                    #self.data.write_result(i,res)
                    self.data.write_result(i, 'fail')
                    fail_count.append(i)
                    res = fail_count
コード例 #3
0
ファイル: run_test.py プロジェクト: yanxianhui/pythonzdh
    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(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                case_name = self.data.get_case_name(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,
                                                   cookie)
                    self.logger.info("用例名称:" + case_name + "--->返回值:" + res)
                    #print(res)
                else:
                    res = self.run_method.run_main(method, url, request_data)
                    self.logger.info("用例名称:" + case_name + "--->返回值:" + res)
                    #print(res)
                if self.com_util.is_contain(expect, res) == True:
                    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)  #不带文件发送
        self.send_email.sendemail(pass_count, fail_count)  #带文件发送
コード例 #4
0
    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(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)
                    #print(request_data)
                    #request_data[depend_key] = depend_response_data
                    request_data = self.operation.deal_data(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('config/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, {'Content-Type': 'application/x-www-form-urlencoded'})


                if self.com_util.is_equal_dict(expect, res):
                    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_email(pass_count, fail_count)
コード例 #5
0
    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)
                expect = self.data.get_expcet_data(i)
                # sql_data = expect.strip("[]")
                sql_data1 = eval(expect)
                # sql_result = eval(sql_data1)
                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
                    # print(request_data[depend_key])
                    # res = self.run_method.run_main(method,url,request_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':
                    res = self.run_method.run_main(method, url, request_data)
                    # print(5,res)
                else:
                    res = self.run_method.run_main(method, url, request_data)
                    print(4, res)

                if self.com_util.is_equal_dict(res, sql_data1):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, str(res))
                    fail_count.append(i)
        #将运行结果通过钉钉发送
        dd_mes(pass_count, fail_count)
        exit()
コード例 #6
0
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        #10  0,1,2,3
        depend_data = ''
        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_request_data(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 = DependdentData(depend_case)
                    #获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    depend_data = depend_response_data
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    #数据依赖自动未填写,则不处理;请求自动无数据依赖字段,则不处理
                    if depend_key != None and request_data.haskey(depend_key):
                        request_data[depend_key] = depend_response_data
                if header == None:
                    res = self.run_method.run_main(method, url, request_data)
                elif header == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_header()
                #op_header.write_cookie()

                else:
                    res = self.run_method.run_main(method, url, request_data,
                                                   header)
                #函数判断
                if expect.find('${') >= 0:
                    self.data.find_def(expect)

                elif 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)
コード例 #7
0
ファイル: run_test.py プロジェクト: zlbkkk/test-api
    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)
                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 = 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["data"][2]["context"])
                    print(res)
                    # print(type(res))

                #自己写的:这个是判断字段是否在结果中
                if expect in res:
                    self.data.write_result(i, "pass")
                    pass_count.append(i)
                else:
                    self.data.write_result(i, "fail")
                    fail_count.append(i)
コード例 #8
0
    def test_main(self, sheet_name, case_name, sheet_id, case_id):
        self.data = GetData(sheet_id)
        is_run = self.data.get_is_run(case_id)
        if is_run:
            url = self.data.get_request_url(case_id)
            method = self.data.get_request_method(case_id)

            #request_data = self.data.get_data_for_json(i)
            request_data = self.data.get_request_data(case_id)
            # expect = self.data.get_expcet_data_for_mysql(i)
            expect = self.data.get_expcet_data(case_id)
            header = self.data.is_header(case_id)
            depend_case = self.data.is_depend(case_id)
            if depend_case != None:
                self.depend_data = DependdentData(sheet_id, depend_case)
                # 获取的依赖响应数据
                depend_response_data = self.depend_data.get_data_for_key(case_id)
                # 获取依赖的key
                depend_key = self.data.get_depend_field(case_id)
                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_contain(expect, res):
                self.data.write_result(case_id,'pass')

            else:
                self.data.write_result(case_id, res)
            #self.assertIn(expect,res,"预期结果:{0} 未在实际返回结果:{1} 中! ".format(expect,res))
            #添加最后结果时间戳
            self.data.write_result(0,  '实际结果 {}'.format(time.strftime("%Y_%m_%d_%H_%M_%S")))
            self.assertIn(expect,res)
コード例 #9
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()
        i = 100
    #程序执行的
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        #10  0,1,2,3
        sheet_names=self.data.get_sheet_names()
        for sheet_id in range(len(sheet_names)):
            self.data = GetData(sheet_id)
            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)
                    request_data = self.data.get_request_data(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 != None:
                        self.depend_data = DependdentData(sheet_id,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)

                    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)
コード例 #10
0
ファイル: run_test.py プロジェクト: 2lusy/learndemo
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)

                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)
コード例 #11
0
    def go_on_run(self):
        oe = OperationExcel()
        res = None
        pass_count = []
        fail_count = []

        sheet_num = oe.get_sheets_number()
        for j in range(0, sheet_num):
            oe.sheet_no = j
            data = GetData(j)
            rows_count = data.get_case_lines()
            for i in range(1, rows_count):
                is_run = data.get_is_run(i)
                db_name = data.get_db_name(i)
                db_statement = data.get_db_statement(i)
                if db_name != None:
                    # print(db_name)
                    self.oper_db.get_db_connect(db_name, db_statement)
                    time.sleep(3)
                if is_run:
                    url = data.get_request_url(i)
                    method = data.get_request_method(i)
                    request_data = data.get_request_data(i)
                    #expect = self.data.get_expcet_data_for_mysql(i)
                    expect = str(int(data.get_expect_data(i)))
                    header = data.is_header(i)
                    depend_case = data.is_depend(i)
                    if depend_case != None:
                        depend_num = depend_case.count(",")
                        if depend_num == 0:
                            #获取依赖数据
                            depend_sheet_no = int(depend_case.split(":")[0])
                            depend_caseid = depend_case.split(":")[1]
                            depend_data = data.get_depend_key(i)
                            depend = DependdentData(depend_sheet_no,
                                                    depend_caseid)
                            depend_response_data = str(
                                depend.get_data_for_key(depend_data))
                            depend_key = data.get_depend_field(i)
                            request_data = json.loads(request_data)
                            #将依赖key的value赋给请求数据的key
                            request_data[depend_key] = depend_response_data
                            request_data = json.dumps(request_data)
                        else:
                            for n in range(0, depend_num):
                                depend_case1 = str(depend_case.split(",")[n])
                                depend_sheet_no1 = int(
                                    depend_case1.split(":")[n])
                                depend_caseid1 = depend_case1.split(":")[n]
                                #获取当前测试用例的依赖数据
                                depend_data = data.get_depend_key(i)
                                depend_data1 = str(depend_data.split(",")[n])
                                #实例化DependdentData类
                                depend1 = DependdentData(
                                    depend_sheet_no1, depend_caseid1)
                                #获取依赖key的value
                                depend_response_data1 = str(
                                    depend1.get_data_for_key(depend_data1))
                                #获取依赖的请求数据,对应excel表中依赖的请求数据字段
                                depend_key = data.get_depend_field(i)
                                depend_key1 = str(depend_key.split(",")[n])
                                # 把请求数据从json格式转换成字典
                                request_data = json.loads(request_data)
                                #将依赖key的value赋给请求数据的key
                                request_data[
                                    depend_key1] = depend_response_data
                                #把字典转换成json格式
                                request_data = json.dumps(request_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':
                        headers = \
                         {
                         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
                         "Content-Type": "application/json;charset=UTF-8"
                         }
                        res = self.run_method.run_main(method, url,
                                                       request_data, headers)
                    else:
                        res = self.run_method.run_main(method, url,
                                                       request_data)
                    if self.com_util.is_contain(expect, str(res["success"])):
                        data.write_result(i, 'pass')
                        data.write_return_result(i, str(res))
                        pass_count.append(i)
                    else:
                        data.write_result(i, 'fail')
                        data.write_return_result(i, str(res))
                        fail_count.append(i)
                    time.sleep(2)
コード例 #12
0
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        userName = "******"
        #10  0,1,2,3
        rows_count = self.data.get_case_lines()
        header = {"Content-Type": "application/json;charset=UTF-8"}
        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 = None
                if (method == "Post"):
                    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 != None:
                    self.depend_data = DependdentData(depend_case)
                    #获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(
                        i, header)
                    #获取依赖的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,
                                               header)
                if (i == 1):
                    header["X-Coolead-Token"] = json.loads(
                        res)["result"]["refreshToken"]
                    userName = request_data["userName"]


#				print   json.loads(res)
#	 			self.data.write_result(i,json.loads(res)["statusCode"])
                if self.com_util.is_equal_dict(
                        expect,
                        json.loads(res)["statusCode"]) == 0:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    bug_des ='<br/><span style="color:red">请求地址:</span>'+ str(self.data.get_request_url(i)) +\
                       '<br/><span style="color:red">请求数据:</span>' +str(self.data.get_data_for_json(i)) + \
                       '<br/><span style="color:red">返回结果:</span>'+ str(res)+\
                       '<br/><span style="color:red">测试帐户:</span>'+str(userName)
                    code = str(self.data.get_request_url(i)) + str(
                        self.data.get_data_for_json(i)) + str(userName)
                    bug_des = bug_des.replace("'", "\\'")
                    sql = '''
        insert into zt_bug(  `product`  ,
      `module` ,
      `project`,
      `plan`,
      `story` ,
      `storyVersion`,
      `task`,
      `toTask` ,
      `toStory`,
      `title` ,
      `keywords`,
      `severity`,
      `pri`,
      `type`,
      `os`,
      `browser`,
      `hardware`,
      `found`,
      `steps`,
      `status`,
      `confirmed` ,
      `activatedCount`,
      `mailto`,
      `openedBy`,
      `openedDate`,
      `openedBuild`,
      `assignedTo`,
      `assignedDate`,
      `resolvedBy`,
      `resolution`,
      `resolvedBuild`,
      `resolvedDate`,
      `closedBy`,
      `closedDate`,
      `duplicateBug`,
      `linkBug`,
      `case`,
      `caseVersion`,
      `result`,
      `testtask`,
      `lastEditedBy`,
      `lastEditedDate`,
      `deleted`)
    values('1', '0', '23', '0', '0', '1', '0', '0', '0',\
     '接口问题',\
      '', '3', '3', 'codeerror', 'win7', 'chrome', '', '', \

    '%s' , \

    'active', '1', '0', '', '', '', 'trunk', 'open', '', 'hezm', 'active', 'trunk', '', '', '', '0', '', '0', '0', '0', '0', '', '', '0')
        ''' % bug_des
                    #					print sql
                    add_bug = Add_bug()
                    query_sql = "select count(*) from zt_bug where steps = '%s'" % bug_des
                    count = add_bug.query_count(query_sql)['count(*)']
                    #					print query_sql
                    #					print count
                    if count == 0:
                        add_bug.insert_one(sql)

        self.send_mai.send_main(pass_count, fail_count)
コード例 #13
0
ファイル: run_test.py プロジェクト: star626/lh_autotest
    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)
                expect = self.data.get_expcet_data(i)
                # print("except data is %s" %expect)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                response_value = self.data.get_response_result_field(i)
                is_post_previous_case = self.data.get_post_result(i)
                depend_excel_file = self.data.is_excel(i)

                if depend_case == None:

                    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}
                        headers1 = op_json.get_data('Authorization')
                        headers = {'Authorization': headers1}
                        if depend_excel_file == 'Y':
                            files = {
                                'file':
                                ('new1.xlsx',
                                 open("C:\\Users\\Aaron\\Desktop\\new1.xlsx",
                                      'rb'), 'application/vnd.ms-excel')
                            }
                            res = self.run_method.run_main(
                                method, url, request_data, headers, files,
                                cookies)
                        else:
                            convert_data = json.dumps(request_data)
                            res = self.run_method.run_main(method,
                                                           url=url,
                                                           data=convert_data,
                                                           headers=headers,
                                                           cookies=cookies)
                    else:
                        res = self.run_method.run_main(method, url,
                                                       request_data)
                    # res = self.run_method.run_main(method, url, request_data)

                elif depend_case == "write":
                    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}
                        headers1 = op_json.get_data('Authorization')
                        headers = {'Authorization': headers1}
                        if depend_excel_file == 'Y':
                            files = {
                                'file':
                                ('new1.xlsx',
                                 open("C:\\Users\\Aaron\\Desktop\\new1.xlsx",
                                      'rb'), 'application/vnd.ms-excel')
                            }
                            res = self.run_method.run_main(
                                method, url, request_data, headers, files,
                                cookies)
                        else:
                            res = self.run_method.run_main(
                                method, url, request_data, headers, cookies)
                    else:
                        res = self.run_method.run_main(method, url,
                                                       request_data)

                    # res = self.run_method.run_main(method, url, request_data)
                    self.data.write_response_to_cell(
                        i, res.content.decode("utf-8"))

                else:
                    self.depend_data = DependdentData(depend_case)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)

                    if is_post_previous_case == 'N':

                        depend_response_data = self.depend_data.get_data_for_excel(
                            i)
                    else:
                        #获取的依赖响应数据
                        depend_response_data = self.depend_data.get_data_for_key(
                            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}
                        headers1 = op_json.get_data('Authorization')
                        headers = {'Authorization': headers1}

                        files = {
                            'file':
                            ('new1.xlsx',
                             open("C:\\Users\\Aaron\\Desktop\\new1.xlsx",
                                  'rb'), 'application/vnd.ms-excel')
                        }
                        request_data = json.dumps(request_data)
                        print(type(request_data))
                        res = self.run_method.run_main(method,
                                                       url=url,
                                                       data=request_data,
                                                       headers=headers,
                                                       cookies=cookies)

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

                # if depend_case == "write":
                # 	self.data.write_response_to_cell(i,res.decode("utf-8"))

                # if self.com_util.is_equal_dict(expect,json.dumps(res)) == 0:

                if self.com_util.is_contain(
                        expect, res.content.decode("utf-8")) == True:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    # self.data.write_result(i,json.dumps(res,ensure_ascii=False))
                    self.data.write_result(i, res.content.decode("utf-8"))
                    fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)
コード例 #14
0
    def go_on_run(self):

        res = None
        pass_count = []
        fail_count = []
        #获取excel 文件的行数
        rows_count = self.data.get_case_lines()

        # 行数减1 即需要执行多少个用例
        for i in range(1, rows_count):
            # 判断该用例是否执行
            is_run = self.data.get_is_run(i)
            if is_run:

                url = self.data.get_request_domain(
                    i) + self.data.get_request_path(i)

                method = self.data.get_request_method(i)
                header = self.data.get_request_header(i)
                params = self.data.get_requestParams(i)
                body = self.data.get_body(i)
                cookies_1 = self.data.get_cookies(i)
                expectHTTPStatus = self.data.get_expectHttpStatus(i)

                if params != None:
                    params = self.paramOrBodyFollowDB(params)

                if body != None:
                    body = self.paramOrBodyFollowDB(body)

                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    # 所依赖的那条用例的数据对象
                    self.depend_data = DependdentData(depend_case,
                                                      fileName=fileName,
                                                      sheetid=sheetid)
                    #所依赖的那条用例的执行响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data = None

                    if params != None:
                        params[depend_key] = depend_response_data

                    if body != None:
                        body[depend_key] = depend_response_data

                cookies = {
                    "_qt": "zux5fyt9957zw9wyvausndkexpv00002",
                    "path": "/",
                    "domain": ".confucius.mobi"
                }
                res = self.run_method.run_main(url,
                                               method,
                                               cookies=cookies_1,
                                               body=body,
                                               headers=header,
                                               params=params)

                if expectHTTPStatus != res.status_code:
                    self.data.write_result(i, "fail")
                    self.data.write_actualStatusCode(i, res.status_code)
                    self.data.write_actualResponse(i, res.text)
                    continue

                self.data.write_actualStatusCode(i, res.status_code)

                print("res.text==", res.text)

                needCheckDict = self.data.get_expcet_response(i)
                if needCheckDict != None:
                    needCheckDict = self.paramOrBodyFollowDB(needCheckDict)

                checkListStr = []
                # 需要检查的字段集合
                checkListStr = [
                    str(i)
                    for i in self.getListFromDict(checkListStr, needCheckDict)
                ]

                flag = True
                for st in checkListStr:
                    if st not in res.text:
                        flag = False
                        self.data.write_result(i, "fail")
                        self.data.write_actualResponse(i, res.text)
                        fail_count.append(i)
                        break

                if flag == True:
                    self.data.write_result(i, "ok")
                    self.data.write_actualResponse(i, "")
                    pass_count.append(i)
        print("pass_count,fail_count===", pass_count, fail_count)
コード例 #15
0
class RunTest:
    def __init__(self, fileName, sheetid):

        self.run_method = RunMethod()
        self.data = GetData(fileName=fileName, sheetid=sheetid)
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):

        res = None
        pass_count = []
        fail_count = []
        #获取excel 文件的行数
        rows_count = self.data.get_case_lines()

        # 行数减1 即需要执行多少个用例
        for i in range(1, rows_count):
            # 判断该用例是否执行
            is_run = self.data.get_is_run(i)
            if is_run:

                url = self.data.get_request_domain(
                    i) + self.data.get_request_path(i)

                method = self.data.get_request_method(i)
                header = self.data.get_request_header(i)
                params = self.data.get_requestParams(i)
                body = self.data.get_body(i)
                cookies_1 = self.data.get_cookies(i)
                expectHTTPStatus = self.data.get_expectHttpStatus(i)

                if params != None:
                    params = self.paramOrBodyFollowDB(params)

                if body != None:
                    body = self.paramOrBodyFollowDB(body)

                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    # 所依赖的那条用例的数据对象
                    self.depend_data = DependdentData(depend_case,
                                                      fileName=fileName,
                                                      sheetid=sheetid)
                    #所依赖的那条用例的执行响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data = None

                    if params != None:
                        params[depend_key] = depend_response_data

                    if body != None:
                        body[depend_key] = depend_response_data

                cookies = {
                    "_qt": "zux5fyt9957zw9wyvausndkexpv00002",
                    "path": "/",
                    "domain": ".confucius.mobi"
                }
                res = self.run_method.run_main(url,
                                               method,
                                               cookies=cookies_1,
                                               body=body,
                                               headers=header,
                                               params=params)

                if expectHTTPStatus != res.status_code:
                    self.data.write_result(i, "fail")
                    self.data.write_actualStatusCode(i, res.status_code)
                    self.data.write_actualResponse(i, res.text)
                    continue

                self.data.write_actualStatusCode(i, res.status_code)

                print("res.text==", res.text)

                needCheckDict = self.data.get_expcet_response(i)
                if needCheckDict != None:
                    needCheckDict = self.paramOrBodyFollowDB(needCheckDict)

                checkListStr = []
                # 需要检查的字段集合
                checkListStr = [
                    str(i)
                    for i in self.getListFromDict(checkListStr, needCheckDict)
                ]

                flag = True
                for st in checkListStr:
                    if st not in res.text:
                        flag = False
                        self.data.write_result(i, "fail")
                        self.data.write_actualResponse(i, res.text)
                        fail_count.append(i)
                        break

                if flag == True:
                    self.data.write_result(i, "ok")
                    self.data.write_actualResponse(i, "")
                    pass_count.append(i)
        print("pass_count,fail_count===", pass_count, fail_count)

    # params  body 期望的response 字段的值从数据库中拿取
    def paramOrBodyFollowDB(self, dic_data):
        if isinstance(dic_data, dict):

            for p in dic_data:
                if str(dic_data[p]).startswith("sql_"):
                    sql = str(dic_data[p])[4:]
                    dic = operation_mysql.search_one(sql=sql)
                    result_db = None
                    for x in dic:
                        result_db = dic[x]
                        break
                    dic_data[p] = result_db

            return dic_data

    # 递归获取 expectResponse 字段的 字典value值
    def getListFromDict(self, list, dic):
        for i in dic:
            if isinstance(dic[i], dict):
                self.getListFromDict(list, dic[i])
            else:
                list.append(dic[i])
        return list
コード例 #16
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)
コード例 #17
0
    def go_on_run(self):
        count_all_case = 0
        count_all_case_detail = []
        count_yes_case = 0
        count_yes_case_detail = []
        count_no_case = 0
        count_no_case_detail = []
        pass_count = []
        fail_count = []
        #通过data_json_of_excel来获取json文件里面保存的excel文件名,然后根据字典里面的value值是否为yes来确定执行相应的excel
        get_json_of_excel = self.data_json_of_excel.get_json_of_excel()
        #这里的for循环是为了控制遍历执行json文件中的所有需执行的excel文件
        for jsonOfExcelDict in get_json_of_excel:
            if get_json_of_excel[jsonOfExcelDict].lower() == 'yes':
                excel_path = '../dataconfig/' + jsonOfExcelDict + '.xls'
                self.data = GetData(excel_path, 0)
                self.run_method.setExcelPathName(excel_path)
            else:
                continue
            res = None

            #10  0,1,2,3
            rows_count = self.data.get_case_lines()
            #置空上次接口测试的结果
            # for i in range(1, rows_count):
            # 	self.data.write_void_to_output_cell(i, " ")
            # 	print(self.data.get_case_name(i))
            #开始接口测试
            for i in range(1, rows_count):
                count_all_case += 1
                is_run = self.data.get_is_run(i)
                if is_run:
                    count_yes_case += 1
                    case_id = self.data.get_case_id(i)
                    case_name = self.data.get_case_name(i)
                    # 显示当前正在执行的case的id和name,用来在报错的时候定位是那一条case出问题了
                    print("ID:\n{}\n接口名称:{}\n调用表路径:{}".format(
                        case_id, case_name, excel_path))
                    url = self.data.get_request_url(i)
                    method = self.data.get_request_method(i)
                    request_data = self.data.get_data_for_json(i)
                    #这是mss老师当时把预期结果里面的sql语111句查询出来,然后返回到expect里面的写法
                    # expect = self.data.get_one_sql_data(i, self.data.get_expcet_data)
                    expect = self.data.get_expcet_data(i)
                    # RunTestPrint
                    # print(expect)
                    # print(type(expect))
                    header = self.data.is_header(i)
                    depend_case = self.data.is_depend(i)
                    depend_case_sql = self.data.is_depend_sql(i)
                    if depend_case != None:
                        self.depend_data = DependdentData(
                            depend_case, excel_path, 0)
                        #获取的依赖响应数据
                        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 depend_case_sql != None:
                        #获取的sql查询依赖数据
                        depend_sql_results = self.data.get_one_sql_data(
                            i, self.data.get_sql_rely_result_data)
                        #如果depend_sql_results的值为null说明这段sql语句没有查询出结果,比如我在做某个用户新增之前我需要先删除,
                        #但是如果该用户根本都没有的话,那么就删除不了,这时候就需要这里的if来判断
                        if depend_sql_results != "null":
                            #把unicode格式的字典改为json格式
                            depend_sql_results = json.loads(depend_sql_results)
                            #通过循环把字典数据里面的value取出来
                            for key in depend_sql_results:
                                depend_sql_result = depend_sql_results[key]

                            #获取依赖的key
                            depend_key = self.data.get_depend_field(i)
                            request_data[depend_key] = depend_sql_result

                    if header == 'write':
                        res = self.run_method.run_main(method, url,
                                                       request_data)
                        op_header = OperationHeader(res)
                        op_header.write_header()

                    elif header == 'yes':
                        op_json = OperetionJson('../dataconfig/cookie.json')
                        cookie = op_json.get_data('token')
                        cookies = {"Authorization": cookie}
                        try:
                            res = self.run_method.run_main(
                                method, url, request_data, cookies)
                        except json.decoder.JSONDecodeError:
                            # 如果出现json.decoder.JSONDecodeError的报错的话,就走到这里,然后把响应的模块清空
                            # 这样子的话我就知道哪些模块出错了,或者说知道哪些模块没有执行
                            self.data.write_void_to_output_cell(i, " ")
                            print(self.data.get_case_name(i))
                            continue

                    else:
                        try:
                            res = self.run_method.run_main(
                                method, url, request_data)
                        except json.decoder.JSONDecodeError:
                            # 如果出现json.decoder.JSONDecodeError的报错的话,就走到这里,然后把响应的模块清空
                            # 这样子的话我就知道哪些模块出错了,或者说知道哪些模块没有执行
                            self.data.write_void_to_output_cell(i, " ")
                            print(self.data.get_case_name(i))
                            continue

                    #写响应结果返回值到返回状态列
                    self.data.write_code_responde_result(
                        i,
                        json.loads(res)['code'])
                    #写请求数据内容到请求数据内容列
                    self.data.write_request_data_result(
                        i, json.dumps(request_data, ensure_ascii=False))

                    #判断预期结果和实际结果是否一致,并将结果填入excel
                    if self.com_util.is_equal_dict2(expect, res) == True:
                        self.data.write_result_status(i, 'pass')
                        self.data.write_result(i, res)
                        pass_count.append(i)
                    else:
                        self.data.write_result_status(i, 'fail')
                        self.data.write_result(i, res)
                        fail_count.append(i)

                    sql_result = self.data.get_all_sql_data(
                        i, self.data.get_sql_result_data)
                    self.data.write_sql_result(i, sql_result)
                else:
                    count_no_case_detail.append(self.data.get_case_name(i))
        self.send_mai.send_main(pass_count, fail_count, "OA项目所有空参数测试点")
        print('所有case条数为:{}条;\n运行了的case条数为{}条;\n没有运行的case条数为{}条.'.format(
            count_all_case, count_yes_case, count_all_case - count_yes_case))
        print('(因为登录模块多执行了9次,所以所有case真是条数条数应该为{}-9={})'.format(
            count_all_case, count_all_case - 9))
        print('没有运行的case是:')
        for case_detail in count_no_case_detail:
            print(case_detail)