Ejemplo n.º 1
0
class RunTest:
	def __init__(self):
		self.run_method = RunMethod()
		self.data = GetData()
		self.asserts=Assert(self.data)
		self.od=OpenrationData()
		self.log=Log()
	def run_test_case(self):
		try:
			res = None
			rows_count = self.data.get_case_lines()
			for row in range(1, rows_count):
				is_run = self.data.get_is_run(row)
				if is_run:
					name = self.data.get_request_name(row)
					url = self.data.get_request_url(row)
					method = self.data.get_request_method(row)
					expect = self.data.get_expcet_data(row)
					is_update = self.data.get_is_update(row)
					header = self.data.get_is_header(row)
					depend_case = self.data.get_is_depend(row)
					if is_update:
						self.od.update_requests(row)
					if depend_case:
						self.od.replace_requests_data(depend_case,row)
					request_data = self.data.get_data_for_json(row)
					if header:
						res = self.run_method.run_main(method, url, request_data,header)
					else:
						res = self.run_method.run_main(method, url, request_data)
					self.asserts.assertIn(expect, res, row)
					self.log.test_log(name, method + '/' + url, request_data, res)
		except Exception as er:
			self.log.error_log(er)
Ejemplo n.º 2
0
 def __init__(self):
     self.run = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mail = SendEmail()
     self.log = UserLog()
     self.logger = UserLog.get_log()
Ejemplo n.º 3
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.common_util = CommonUtil()
     self.send_email = SendEmail()
     self.excel = OperationExcel()
     self.sheet_obj = self.excel.get_data()
Ejemplo n.º 4
0
	def run_dependent(self):
		run_method = RunMethod()
		row_num = self.opera_excel.get_row_num(self.case_id)
		request_data = self.data.get_data_for_json(row_num)
		#header = self.data.is_header(row_num)
		method = self.data.get_request_method(row_num)
		header = self.data.is_header(row_num)
		url = self.data.get_request_url(row_num)
		files = {'file': (
			'new1.xlsx', open("C:\\Users\\Aaron\\Desktop\\new1.xlsx", 'rb'), 'application/vnd.ms-excel')}

		if 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
			}
			res = run_method.run_main(method, url,request_data,headers,files,cookies)
		else:
			res = run_method.run_main(method,url,request_data)
		return json.loads(res)
Ejemplo n.º 5
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()  #不带文件发送
     self.send_email = Email()  #带文件发送
     get_user_log = UserLog()
     self.logger = get_user_log.get_log()
Ejemplo n.º 6
0
class RunTest():
	def __init__(self):
		self.run_method = RunMethod()
		self.data = GetData()
		self.com_util = CommonUtil()
		self.send_mai = SendEmail()  #不带文件发送
		self.send_email=Email()  #带文件发送
		get_user_log=UserLog()
		self.logger = get_user_log.get_log()
	#程序执行的
	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)  #不带文件发送
Ejemplo n.º 7
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.commonutil = Commonutil()
        self.sendmail = SendEmail()

    def go_on_run(self):  # 程序执行
        pass_count = []
        fail_count = []
        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)
                data = self.data.get_data_for_json(i)
                # expect = self.data.get_expect_data(i)  # Excel写入预期结果
                expect = self.data.get_expect_data_for_mysql(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                res = self.run_method.run_main(method, url, data, header)
                values = {"resultCode": res["resultCode"]}
                # print(res["resultData"]["access_id"])
                value = json.dumps(values)  # 字典转字符串匹配
                if depend_case is not None:
                    self.depend_data = DependentDate(depend_case)
                    # 依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    data = json.loads(data)
                    depend_key = self.data.get_depend_field(i)
                    data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(method, url, data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperationJson('../dataconfig/cooking.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {
                        'apsid': cookie
                    }
                    value = self.run_method.run_main(method, url, data, cookies)
                else:
                    value = self.run_method.run_main(method, url, data)
                if self.commonutil.is_equal_dict(expect, value):
                    self.data.write_result(i, '通过')
                    pass_count.append(i)
                    print('测试通过')
                else:
                    self.data.write_result(i, '失败')
                    fail_count.append(i)
                    print('测试失败')

                print(pass_count, fail_count)
        self.sendmail.send_main(pass_count, fail_count)
Ejemplo n.º 8
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)
                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)

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

                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    res = fail_count
        self.send_mai.send_main(pass_count, fail_count)
Ejemplo n.º 9
0
 def run_dependent(self):
     run_method = RunMethod()
     row_num = self.opera_excel.get_row_num(self.case_id)
     request_data = self.data.get_data_for_json(row_num)
     url = self.data.get_request_url(row_num)
     header = self.data.is_header(row_num)
     method = self.data.get_request_method(row_num)
     res = run_method.run_main(method, url, request_data, header)
     return res
Ejemplo n.º 10
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()

    #程序执行的
    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()
Ejemplo n.º 11
0
class RunTest(object):
    def __init__(self):
        self.runmethod = RunMethod()
        self.getdata = GetData()
        self.commonutil = CommonUtil()
        self.sendmail = SendMail()

    def go_on_run(self):
        pass_count = []
        fail_count = []
        cookies = None
        rows = self.getdata.get_case_lines()
        for i in range(1, rows):
            is_run = self.getdata.get_is_run(i)
            if is_run:
                url = self.getdata.get_url(i)
                is_depend = self.getdata.is_depend(i)
                request_method = self.getdata.get_request_method(i)
                expect = self.getdata.get_expect(i)
                # print(expect)
                is_cookie = self.getdata.is_cookie(i)
                is_header = self.getdata.is_header(i)
                data = self.getdata.get_data_for_json(i)
                print(data)
                depend_case = self.getdata.is_depend(i)
                if is_depend:
                    self.depend_data = DependentData(depend_case)
                    field_depend = self.getdata.get_field_depend(i)
                    data_depend = self.depend_data.get_data_for_key(i)
                    data[field_depend] = data_depend

                if is_cookie == 'write':
                    res = self.runmethod.run_main(url, request_method, data)
                    op_cookie = OperationCookie(json.loads(res))
                    op_cookie.write_cookie()

                if is_cookie == 'yes':
                    op_json = OperationJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data("apsid")
                    cookies = {"apsid": cookie}

                res = self.runmethod.run_main(url, request_method, data,
                                              is_header, cookies)

                if self.commonutil.iscontain(expect, res):
                    print("测试通过")
                    self.getdata.write_result(i, "测试通过")
                    pass_count.append(i)
                else:
                    print(expect)
                    print(res)
                    print("测试失败")
                    self.getdata.write_result(i, res)
                    fail_count.append(i)
            else:
                return None
Ejemplo n.º 12
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
        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)
 def run_dependent(self):
     self.run_method = RunMethod()
     row_num = self.opera_excel.get_row_num(self.case_id)
     request_data = self.data.get_data_for_json(row_num)
     header = self.data.is_header(row_num)
     method = self.data.get_request_method(row_num)
     url = self.data.get_request_url(row_num)
     res = self.run_method.run_main(method,url,request_data,header)
     # print("there are res's data",res)
     return json.loads(res)
Ejemplo n.º 14
0
    def run_dependent(self):
        run_method = RunMethod()
        row_num = self.opera_excel.get_row_num(self.case_id)
        request_data = self.data.get_data_for_json(row_num)

        # header = self.data.is_header(row_num)
        method = self.data.get_request_method(row_num)
        url = self.data.get_request_url(row_num)
        res = run_method.run_main(method, url, request_data, {'Content-Type': 'application/x-www-form-urlencoded'})
        return json.loads(res)
Ejemplo n.º 15
0
 def run_dependnt(self):
     run_method = RunMethod()
     row_num = self.opera_excel.get_row_num(self.case_id)
     request_data = self.data.get_data_for_json(row_num)
     request_method = self.data.get_request_method(row_num)
     request_header = self.data.get_data_header_json(row_num)
     request_url = self.data.get_request_url(row_num)
     res = run_method.run_main(request_method, request_url, request_header,
                               request_data)
     return json.loads(res)
Ejemplo n.º 16
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)
                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)
Ejemplo n.º 17
0
 def run_dependent(self):
     """执行依赖测试,获取结果"""
     run_method = RunMethod()
     row_num = self.opera_excle.get_row_num(self.case_id)
     request_data = self.data.get_data_for_json(row_num)
     header = self.data.is_header(row_num)
     method = self.data.get_request_method(row_num)
     url = self.data.get_request_url(row_num)
     res = run_method.run_main(method, url, request_data, header)
     # 需要将数据更改为json格式
     return json.loads(res)
Ejemplo n.º 18
0
 def run_dependent(self):
     run_method = RunMethod()
     #找到对应的行号,后续获取其他数据需要用到
     row_num = self.opera_excel.get_row_num(self.case_id)
     request_data = self.get_data_for_json(row_num)
     header = self.data.is_header(row_num)
     method = self.data.get_request_method(row_num)
     url = self.data.get_request_url(row_num)
     # 获取这些数据以便后续run_main 方法使用
     res = run_method.run_main(method, url, request_data, header)
     return json.loads(res)
Ejemplo n.º 19
0
 def run_dependent(self):
     run_method = RunMethod()
     row_num = self.opera_excel.get_row_num(self.id)
     # request_data = self.data.get_data_for_json(row_num)
     request_data = json.dumps(self.data.get_request_data(row_num))
     header = self.data.get_is_header(row_num)
     method = self.data.get_request_method(row_num)
     url = self.data.get_url(row_num)
     print('row_num:', row_num, 'request_data:', request_data, 'header:',
           header, 'method:', method, 'url:', url)
     res = run_method.run_main(method, url, request_data, header)  # order
     return json.loads(res.text)
Ejemplo n.º 20
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,4,5,6......  第一行不需要
        rows_count = self.data.get_case_lines()
        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)
            data = self.data.get_data_for_json(i)
            #不能调用get_request_data()方法
            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.sepend_data = DependentData()
                #获取的依赖相应数据
                depend_response_data = self.depend_data.get_data_for_key(i)
                #获取依赖的key
                depend_key = self.data.get_depend_filed(i)
                request_data[depend_key] = depend_response_data
            res = self.run_method.run_main(method, url, data, header)

            if is_run:
                #method,url,data=None,header=None  run_main里边变量的顺序不能错
                res = self.run_method.run_main(method, url, data, header)
                # print (type(res))
                if self.com_util.is_contain(expect, res):
                    # print ("测试通过")
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    print(pass_count)
                    print(len(pass_count))
                else:
                    # print ("测试失败")
                    self.data.write_result(i, 'fail')
                    fail_count.append(i)
                    # print (len(fail_count))
                    print(fail_count)
            return res
            self.send_mai.send_main([1, 2], [1])
        self.send_mai.send_main([1, 2], [1])
Ejemplo n.º 21
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)

                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)
Ejemplo n.º 22
0
class MainCase(unittest.TestCase):


    def setUp(self):
        self.run_method = RunMethod()
        self.com_util = CommonUtil()
    @data(*case_list)
    @unpack
    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)
Ejemplo n.º 23
0
 def run_depend(self):
     run_method = RunMethod()
     row_num = self.opera_excel.get_rows_num(self.case_id)
     request_data = {
         'Head':
         '{"UserID":3,"TimeStamp":"1516156123","Sign":"FC7B4D3405863A6D06DC4D6961B708BF"}',
         'Data': self.data.get_data_for_json(row_num)
     }
     header = self.data.is_header(row_num)
     url = self.data.get_request_url(row_num)
     method = self.data.get_request_method(row_num)
     res = run_method.runmain(method, url, request_data, header)
     return json.loads(res)
Ejemplo n.º 24
0
    def run_dependent(self):
        run_method = RunMethod()
#         拿到行号,获取get_data等需要行号获取
        row_num = self.opera_excel.get_row_num(self.case_id)
        request_data = self.data.get_data_for_json(row_num)
        # header = self.data.is_header(row_num)
        # if header == 'yes':

        method = self.data.get_request_method(row_num)
        url = self.data.get_request_url(row_num)
        res = run_method.run_main(method,url,request_data,header)
        # return res
        return json.loads(res)
Ejemplo n.º 25
0
class DependentData(object):
    def __init__(self, case_id):
        self.opexcel = OperationExcel()
        self.getdata = GetData()
        self.case_id = case_id
        self.runmethod = RunMethod()

    def get_case_line_data(self):
        row_data = self.opexcel.from_case_id_get_row_data(self.case_id)
        return row_data

    def rundependent(self):
        row_num = self.opexcel.from_case_id_get_row_num(self.case_id)
        request_data = self.getdata.get_data_for_json(row_num)
        url = self.getdata.get_url(row_num)
        method = self.getdata.get_request_method(row_num)
        header = self.getdata.is_header(row_num)
        res = self.runmethod.run_main(url, method, request_data, header)
        return res

    #在依赖response中查找依赖数据
    def get_data_for_key(self, row):
        depend_data = self.getdata.get_data_depend(row)
        response_data = self.rundependent()
        print(depend_data)
        print("************************")
        print(response_data)
        p_depend_data = parse(depend_data)
        madle = p_depend_data.find(response_data)
        return [math.value for math in madle][0]
Ejemplo n.º 26
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_uitl = CommonUitl()

    #程序执行的主入口
    def go_on_run(self):
        res = None
        #获取excel行数 即case个数
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            url = self.data.get_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_data_for_json(i)
            #预期结果值
            except_data = self.data.get_except_data(i)
            #header = self.data.is_header(i)
            if is_run:
                #method,url,data=None,header=None 顺序不能错
                res = self.run_method.run_main(method, url, data)
                print res
                if self.com_uitl.is_contain(except_data, res):
                    #print "测试通过"
                    self.data.write_data(i, "pass")
                else:
                    #print "测试失败"
                    self.data.write_data(i, "fail")
Ejemplo n.º 27
0
 def __init__(self, methodName='runTest', parame=None):
     super(ParameTestCase, self).__init__(methodName)
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
     self.operation = OperetionJson()
Ejemplo n.º 28
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()

    #程序执行的
    def go_on_run(self):
        res = None
        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)
                is_run = self.data.get_is_run(i)
                data = self.data.get_data_for_json(i)
                header = self.data.is_header(i)
                expect = self.data.get_expect_data(i)
                depend_case = self.data.is_depend(i)
                res = self.run_method.run_main(method, url, data, header)
                if depend_case != None:
                    self.depend_data = DependdentData()
                    #获取 响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_filed(i)

                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, "通过")
                else:
                    self.data.write_result(i, "失败")
                print(res)
Ejemplo n.º 29
0
class RunTest():
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()

    # 程序执行
    def go_on_run(self):
        res = None
        rows_count = self.data.get_case_line()
        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)
                res = self.run_method.run_main(method, url, data, header)
                if depend_case != None:
                    self.dependent_data = DependdentData()
                    depend_response_data = self.depend_data.get_data_for_key(i)

                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                else:
                    self.data.write_result(i, 'fail')
Ejemplo n.º 30
0
    def go_on_run(self):
        rows_count = GetData().get_case_lines()  #获取excel 有数据的行数
        # return rows_count

        for i in range(1, rows_count):
            # print(i)
            url = GetData().get_request_url(i)
            # print(url)
            method = GetData().get_request_method(i)
            is_run = GetData().get_is_run(i)
            data = GetData().get_request_data(i)  # 从excel表格中取数据
            # print(data)
            # print(type(data))
            expect = GetData().get_expcet_data(i)
            print(expect)
            # print(type(expect))
            headers = GetData().is_header(i)
            # print(headers)
            # print(type(headers))
            if is_run:
                res = RunMethod().run_main(method, url, data, headers)

                if CommonUtil().is_contain(expect, res):  #此处只是一个判断的封装类
                    # if expect in res:
                    GetData().write_result(i, '测试通过')
                    print('测试通过')
                    # return True      #这里放return True 只会执行一次就停止,针对于单个用例的方法判断有效,
                    #for 循环就会失效 所以建议封装一个类 判断放在类中
                else:
                    GetData().write_result(i, '测试失败')
                    print('测试失败')
                    # return False
                # print(type(res))
                print(res)
Ejemplo n.º 31
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common_util = CommonUtil()

    def go_on_run(self):
        rows_count = self.data.get_case_line()
        res_arr = []
        for i in range(1, rows_count):
            # print(i)
            url = self.data.get_request_url(i).strip()
            is_run = self.data.get_is_run(i)
            request_method = self.data.get_request_method(i)
            header = self.data.is_header(i)
            request_data = self.data.get_json_data(i)
            expect_data = self.data.get_expect_value(i)
            res = None
            if is_run:
                res = self.run_method.run_main(request_method, url, header,
                                               request_data)
                if self.common_util.is_contain(expect_data, res):
                    print('测试通过')
                else:
                    print('测试失败')
            res_arr.append(res)
        return res_arr
Ejemplo n.º 32
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()