예제 #1
0
class login():
    def __init__(self):
        self.Opexl = OperationExcle('../dataCase/login.xls', 0)
        self.data = GetData()
        self.com_util = CommonUtil()
        self.run_method = RunMethod()

    def test_Login(self):
        rownums = self.data.get_case_line()
        for i in range(1, rownums):
            is_run = self.data.get_is_run(i)
            # print(is_run)
            url = self.data.get_url(i)
            # print(url)
            method = self.data.get_request_method(i)
            request_data = self.data.request_data_type_change(i)
            # print(request_data)
            expect = self.data.get_expect_data(i)
            # print(expect)
            header = self.data.is_header(i)
            select_str = 'select'
            insert_str = 'INSERT'
            update_str = 'UPDATE'
            delete_str = 'DELETE'
            for except_num in select_str, insert_str, update_str, delete_str:
                except_str = self.com_util.is_contain(except_num, expect)
                if except_str is True:
                    expect = self.data.get_sql_expect_data(i)
                else:
                    expect = self.data.get_expect_data(i)
            # print(expect)

            if is_run is True:
                res = self.run_method.run_main(method, url, request_data,
                                               header)
                if except_str is False:
                    if self.com_util.is_contain(expect, res) == True:
                        self.data.write_result(i, 'pass')
                        print("测试通过")
                    else:
                        self.data.write_result(i, 'Filed')
                        print('测试失败')
                # print(res)

                if except_str is True:
                    if self.com_util.is_equal_dict(expect,
                                                   res) == True:  # 判断字典是否相等
                        self.data.write_result(i, 'pass')
                        print('测试通过')
                    else:
                        self.data.write_result(i, res)
                        print('测试失败')
                print(res)
            else:
                pass
예제 #2
0
class TypeChange:
    def __init__(self):
        self.Cu = CommonUtil()

    def data_change(self, data):
        datas = self.Cu.is_contain("{", data)
        if datas == True:
            return eval(data)
        else:
            return data
예제 #3
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)
예제 #4
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mail = SendEmail()
     self.op_testReport = Write_testReport_excle()
예제 #5
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()
        self.op_testReport = Write_testReport_excle()

    # 程序执行
    def go_on_run(self):
        global pass_count, fail_count
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_line()
        # print(rows_count)
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            # print(is_run)
            url = self.data.get_url(i)
            # print(url)
            method = self.data.get_request_method(i)
            request_data = self.data.request_data_type_change(i)
            # print(request_data)
            expect = self.data.get_expect_data(i)
            # print(expect)
            header = self.data.is_header(i)
            select_str = 'select'
            insert_str = 'INSERT'
            update_str = 'UPDATE'
            delete_str = 'DELETE'
            for except_num in select_str, insert_str, update_str, delete_str:
                except_str = self.com_util.is_contain(except_num, expect)
                if except_str is True:
                    expect = self.data.get_sql_expect_data(i)
                else:
                    expect = self.data.get_expect_data(i)
            # print(expect)
            errorNum = 0
            if is_run is True:
                while errorNum <= Config_Try_Num:  # 判段失败次数是否小于等于配置失败重试次数
                    res = self.run_method.run_main(method, url, request_data,
                                                   header)
                    if except_str is False:
                        if self.com_util.is_contain(expect, res) == True:
                            self.data.write_result(i, 'pass')
                            print("测试通过")
                            pass_count.append(i)
                            errorNum = 0
                            break
                        else:
                            self.data.write_result(i, 'Filed')
                            # print('测试失败,重试中')

                            if errorNum < Config_Try_Num:
                                errorNum += 1
                                print("测试失败,重试中,当前重试次数为第%s次" % (errorNum))
                            else:
                                print("重试次数已用完,测试失败")
                                fail_count.append(i)
                                break
                    # print(res)

                    if except_str is True:
                        if self.com_util.is_equal_dict(
                                expect, res) == True:  # 判断字典是否相等
                            self.data.write_result(i, 'pass')
                            pass_count.append(i)
                            print('测试通过')
                        else:
                            self.data.write_result(i, 'Filed')
                            # print('测试失败,重试中')
                            if errorNum < Config_Try_Num:
                                errorNum += 1
                                print("测试失败,重试中,当前重试次数为第%s次" % (errorNum))
                            else:
                                print("重试次数已用完,测试失败")
                                fail_count.append(i)
                                break

                else:
                    pass
                print(res)
                # print(self.com_util.is_contain(expect,res)==True)

    # 发送邮件、生成测试报告
    def create_test_report(self):
        self.op_testReport.write_TestReport(pass_count,
                                            fail_count)  # 生成excel表格测试报告
        self.op_testReport.excle_to_html()  # 将测试报告转换为html输出
        self.send_mail.send_main(pass_count, fail_count)  # 发送测试报告邮件
예제 #6
0
 def __init__(self):
     self.Opexl = OperationExcle('../dataCase/login.xls', 0)
     self.data = GetData()
     self.com_util = CommonUtil()
     self.run_method = RunMethod()
예제 #7
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
예제 #8
0
 def __init__(self):
     self.Cu = CommonUtil()