コード例 #1
0
class RunTest:
    def __init__(self):
        """
        初始化RunTest类
        """
        self.run_method = RunMain()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.send_email = SendEmail()

    def go_on_run(self):
        """
        执行测试用例
        :return: 通过用例和失败用例
        """
        pass_list = []
        fail_list = []
        rows_count = self.data.get_case_num()
        for i in range(1, rows_count):
            is_run = self.data.is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_method(i)
                data = self.data.get_data_for_json(i)
                cookie = self.data.is_cookie(i)
                header = self.data.is_header(i)
                expect = self.data.get_expect_data(i)
                if isinstance(expect, float):
                    expect = str(int(expect))
                depend_case = self.data.is_depend(i)
                if depend_case is not None:
                    depend_data = DependentData(depend_case)
                    # 获取依赖响应的返回数据
                    depend_response_data = depend_data.get_data_for_key(i)
                    # # 使用mock-test模拟请求
                    # depend_response_data = mock_test(self.run_method.run_main, data, url, "POST", order)
                    # 获取依赖的字段
                    depend_field = self.data.get_depend_field(i)
                    # 更新
                    data[depend_field] = depend_response_data
                if cookie == 'write':
                    res = self.run_method.run_main(method, url, data, header)
                    opera_cookie = OperationCookie(res)
                    opera_cookie.write_cookie()
                elif cookie == 'yes':
                    op_json = OperationJson('../data_config/cookie.json')
                    cookie = op_json.get_data('ASP.NET_SessionId')
                    cookies = {'ASP.NET_SessionId': cookie}
                    res = self.run_method.run_main(method, url, data, cookies)
                else:
                    res = self.run_method.run_main(method, url, data)
                if self.common_util.is_contain(expect, res.text):
                    # print("PASS")
                    pass_list.append(i)
                    self.data.write_result(i, 'PASS')
                else:
                    # print("FAILED")
                    fail_list.append(i)
                    self.data.write_result(i, 'FAILED')
        self.send_email.send_main(pass_list, fail_list)
コード例 #2
0
class RunTest(object):
    def __init__(self):
        self.common_util = CommonUtil()
        self.send_email = SendEmail()
        self.connect_db = OperationMySQL()
        self.run_method = RunMethod()
        self.op_json = OperationJson()

    def run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.connect_db.get_count()
        print(rows_count)
        for i in range(0, rows_count):
            run = self.connect_db.search('run', i)
            if run:
                url = self.connect_db.search('url', i)
                request_method = self.connect_db.search('request_method', i)
                request_data = self.op_json.get_data(
                    self.connect_db.search('request_data', i))
                expect = self.connect_db.search('expect', i)
                print(expect)
                res = self.run_method.run_main(request_method, url,
                                               request_data)
                print(res)
                if self.common_util.is_contain(expect, res) == 1:
                    self.connect_db.write('pass', i + 1)
                    pass_count.append(i + 1)
                    print(pass_count)
                else:
                    self.connect_db.write(res, i + 1)
                    fail_count.append(i + 1)
                    print(fail_count)
        self.send_email.send_main(pass_count, fail_count)
コード例 #3
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)  #不带文件发送
コード例 #4
0
ファイル: run_test.py プロジェクト: shouhuqingtian/Test
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)
コード例 #5
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)
コード例 #6
0
class RunText:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.sendmail = SendEmail()
        # 执行程序的主入口

    def go_on_run(self, pr=None):
        res = None
        pass_count = []
        fail_count = []
        row_count = self.data.get_case_lines()
        for i in range(1, row_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            data = self.data.get_data_for_json(i)
            is_run = self.data.get_is_run(i)
            header = self.data.get_data_header_json(i)
            expect = self.data.get_expect_data(i)
            depend_case = self.data.is_depend(i)
            # if depend_case != None:
            #     self.depend_data = DependdentData(depend_case)
            #     #获取相应数据的依赖
            #     depend_response_data = self.data.get_depend_key(i)
            #     #获取依赖的key
            #     depend_key = self.data.get_depend_field(i)
            #     data[depend_key] = depend_response_data
            # res = self.run_method.run_main(method,url,header,data)
            # print res'''
            '''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 is_run:
                res = self.run_method.run_main(method, url, header, data)
                if self.common_util.is_contain(expect, res):
                    # print "测试通过"
                    print self.data.write_value(i, "pass")
                    pass_count.append(i)
                else:
                    # print "测试失败"
                    print self.data.write_value(i, res)
                    fail_count.append(i)

        self.sendmail.send_main(pass_count, fail_count)
コード例 #7
0
class RunTest:
    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()

    # 程序执行的主入口
    def go_on_run(self):
        res = None
        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)
                # if i == 7:
                #     print("已经成年")
                # url = 'http://192.168.2.81:10003/shop/goods/new-list'
                method = self.data.get_request_method(i)
                is_run = self.data.get_is_run(i)
                data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data(i)
                # expect = self.data.get_expcet_data_for_mysql(i)
                # data = {'pageNum': 1, 'pageSize': 10}
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                # header = {'Content-Type': 'application/json'}
                if depend_case != None:
                    self.depend_data = DependentData(depend_case)
                    # 获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    print("this is dependResponseData = ",depend_response_data)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_fileld(i)
                    print("*************this is depend_key = ",depend_key)
                    # 根据获取的依赖key,将depend_kay更新成depend_response_data
                    data[depend_key] = depend_response_data
                    print("*************this is data[depend_key]",data[depend_key])

                res = self.run.run_main(method, url, data, header)
                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)
            else:
                self.data.write_result(i, 'N/A')
                continue
            # print(res)
            #     print(len(pass_count))
            #     print(len(fail_count))
        self.send_mail.send_main(pass_count,fail_count)
コード例 #8
0
ファイル: run_test.py プロジェクト: tany-92/auto_test_mac
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_email = SendEmail()

    # 程序执行的主入口
    def go_on_run(self):
        #rows_count = self.data.get_case_lines()
        rows_count = 2
        pass_count = []
        fail_count = []
        res = None
        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)
            request_data = self.data.get_data_for_json(i)
            header = self.data.get_is_header(i)
            expect = self.data.get_expect_data_for_sql(i)
            print(expect)
            print(type(expect))
            depend_case = self.data.is_depend(i)
            '''if depend_case != '':
                self.depend_data = DependentData(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
                res = self.run_method.run_main(method,url,request_data,header)'''
            #res = self.run_method.run_main(method, url, request_data, header)
            request_data1 = {
                "id": 1,
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
                "age": 18
            }
            ress = mock_test(
                self.run_method.run_main(method, url, request_data, header),
                request_data, url, method, request_data1)
            print(ress)
            print(type(ress))
            if is_run:
                if self.com_util.is_equal_dict(expect, ress):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, ress)
                    fail_count.append(i)
        self.send_email.send_main(pass_count, fail_count)
コード例 #9
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])
コード例 #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
ファイル: run_test.py プロジェクト: Huangping1830/AutoTest
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 = []
        rows_count = self.data.get_case_lines()
        flat = 1
        while(flat):
            for i in range(1,rows_count):
                is_run = self.data.get_is_run(i)
                if is_run:
                    url = self.data.get_request_url(i)
                    method = self.data.get_request_method(i)
                    request_data = self.data.get_data_form_json(i)
                    expect = self.data.get_expect_data(i)
                    header = self.data.is_header(i)
                    depend_case = self.data.is_depend(i)   #数据依赖
                    if depend_case != None:
                        self.depend_data = DependData()
                        #依赖的响应数据
                        depend_response_data =self.depend_data.get_data_for_key(i)
                        #获取依赖的key
                        depend_key = self.data.get_depend_field(i)
                        request_data[depend_key] = depend_response_data

                    # method,url,data=None,header=None  顺序不可以颠倒
                    try:
                        res = self.run_method.run_main(method,url,request_data,header)
                    except ConnectionError:
                        pass
                    if res == None:
                        time.sleep(600)
                    else:
                        if self.com_util.is_contain(expect,res):
                            log_pass('success!!!')
                            print(flat)
                            time.sleep(20)
                            flat += 1
                            # self.data.write_result(i,'pass')
                            # pass_count.append(i)
                        else:
                            log_error('fail!!!')
                            self.send_mai.send_main()
                            time.sleep(600)
コード例 #12
0
class RunTest(object):
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.send_email = SendEmail()

    def run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            run = self.data.get_run(i)
            if run:
                url = self.data.get_url(i)
                request_method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expect(i)
                print(expect)
                header = self.data.get_header(i)
                # case_depend = self.data.get_case_depend(i)
                # if case_depend != None:
                #     self.depend_data = DependentData(case_depend)
                #     depend_response_data = self.depend_data.get_data_for_key(i)
                #     depend_key = self.data.get_depend_response_data(i)
                #     request_data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(request_method, url,
                                                   request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()
                elif header == 'yes':
                    op_json = OperationJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    res = self.run_method.run_main(request_method, url,
                                                   request_data, cookies)
                else:
                    res = self.run_method.run_main(request_method, url,
                                                   request_data)
                    print(res)
                if self.common_util.is_contain(expect, res) == 1:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    print(pass_count)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    print(fail_count)
        self.send_email.send_main(pass_count, fail_count)
コード例 #13
0
ファイル: run.py プロジェクト: niuqun1/api_qequeset
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 = []
        # 获取所有行
        roes_count = self.data.get_case_lines()
        # 跳过1在行里循环
        for i in range(1, roes_count):
            is_run = self.data.get_is_run(i)
            if is_run:  #执行
                urls = self.data.get_url(i)  #接口地址
                url = host_api + urls
                method = self.data.git_method_way(i)  #请求方
                former = self.data.get_api_data(i)  #请求数据
                expect = self.data.get_expcet_data(i)  #预期结果
                header = operation_header.gain_herder()  #获取header
                depend_case = self.data.is_depend(i)  #获取是否有数据依赖
                if depend_case != None:  #判断数据依赖不是空
                    self.depend_data = DependdentData(
                        depend_case)  #实列化depend_data
                    data = self.depend_data.get_data_for_key(
                        i, former)  #获取依赖返回data
                    print(type(data), i)
                res = self.run_method
                if is_run:  #判断是否执行
                    if method != 'Post' and data != None:
                        datas = eval(data)
                    else:
                        datas = data
                    res = self.run_method.run_main(method, url, datas, header)
                    self.data.write_api_return_data(i, res)
                    if self.com_util.is_contain(expect, res):  #判断预期结果
                        self.data.write_resuit(i, "测试通过")
                        pass_count.append(i)
                    else:
                        self.data.write_resuit(i, "测试失败")
                        fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)
コード例 #14
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()

    #程序入口
    def go_on_run(self):
        res = None
        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)
                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 = DependentData()
                    #获取的依赖响应数据
                    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
                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:
                    #print("测试失败")
                    self.data.write_result(i, res)
                    fail_count.append(i)
        print(len(pass_count))
        print(len(fail_count))
        self.send_mail.send_main(pass_count, fail_count)
コード例 #15
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()

    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        print(rows_count)
        for i in range(1, rows_count):
            #获取excel表格中的数据
            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_request_data(i)
            header = self.data.is_header(i)
            expect = self.data.get_expcet_data(i)
            print(url, method, is_run, data, header, expect)
            #判断是否执行
            if is_run:
                res = self.run_method.run_main(method, url, data, header)
                info(res)
                #print(res)
                #判断预期结果和实际结果
                if self.com_util.is_contain(expect, res['data']):
                    #如果通过就把行号写入定义的列表中
                    pass_count.append(i)
                    #在excel表中的实际结果中输入测试结果
                    self.data.write_result(i, "pass")
                    print("测试通过")
                else:
                    print("测试失败")
                    #把执行失败的行号写入定义的列表中
                    fail_count.append(i)

        print(len(pass_count))
        print(len(fail_count))
        self.send_mail.send_main(pass_count, fail_count)
コード例 #16
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.dataexcel = OpertionExcel
        self.commonutil = CommonUtil
        self.sendemail = SendEmail()
    #程序执行主入口
    def go_on_run(self):
        pass_count = []
        fail_count = []
        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_way(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_expcet_data(i)
            depend_case = self.data.is_depend(i)
            if depend_case != None:
                 # print("`````11`")
                 self.depend_data = DependentData(depend_case)
                 #获取返回结果里面的依赖
                 depend_respones_data = self.depend_data.get_data_for_key(i)
                 #获取依赖的key
                 depend_data = self.data.get_depend_field(i)
                 #将返回结果里面的依赖赋值给依赖数据
                 data[depend_data] = depend_respones_data

            if is_run == True:
                run_main = self.run_method.run_main(method,url,data,header)
                # print(type(run_main))
                # print(type(expect))
                print(run_main)
                if expect in run_main:
                     self.data.write_result(i,"pass")
                     pass_count.append(i)
                else:
                     self.data.write_result(i,run_main)
                     fail_count.append(i)
        self.sendemail.send_main(pass_count,fail_count)
コード例 #17
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):

        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        #遍历case按行和列取
        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(i)
            expect = self.data.get_expect_data(i)
            header = self.data.is_header(i)
            name = self.data.get_name(i)
            # print name,'接口测试结果为:'
            if is_run:
                res = self.run_method.run_main(method, url, header, data)
                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    # print "测试通过"
                    # print type(expect)
                    # print type(res)
                    # print res
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    # print "测试失败"
                    # print type(res)
                    # print res
        print len(pass_count)
        print len(fail_count)
        self.send_mai.send_main(pass_count, fail_count)
コード例 #18
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common = CommonUtil()
        self.send_email = SendEmail()

    #程序执行入口:
    def go_on_run(self):
        #统计通过用例数
        pass_count = []
        #统计失败用例数
        fail_count = []
        #取出Excel用例的总行数
        rows_count = self.data.get_case_line()
        #循环读取Excel表里各行列数据
        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_request_data_for_json_keyword(i)
            headers = self.data.get_is_header(i)
            expect = self.data.get_expect_data(i)
            #如果该条用例需要执行,就执行接口方法
            if is_run:
                res = self.run_method.run_main(method, url, data, headers)
                #判断如果期望结果在实际结果中
                if self.common.is_contains(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_email.send_main(pass_count, fail_count)
コード例 #19
0
ファイル: run_test.py プロジェクト: lzx20121123/python-
class RunTest(object):
    def __init__(self):
        self.runmethod = RunMethod()
        self.getdata = Getdata()
        self.common = commonutil()
        self.sd_Email = SendEmail()
        self.Msql = OperationMysql()

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

        logname = "loger%s.txt" % time.strftime('%Y%m%d%H%M%S',
                                                time.localtime())  #日志名称
        testlog = Logger(logname, 'DEBUG', "loger")

        errorname = "errorlog%s.txt" % time.strftime('%Y%m%d%H%M%S',
                                                     time.localtime())  #异常日志
        ferror = open(errorname, 'w')

        _timeformat = '%Y-%m-%d %H:%M:%S'
        pass_count = []
        fail_count = []
        address = "http://192.168.1.102:3000"

        rows_count = self.getdata.get_caselines()  #行数
        for i in range(1, rows_count):  #
            url = address + self.getdata.get_Url(i)  #url
            #print (url)
            method = self.getdata.get_request_method(i)  #请求方式
            is_run = self.getdata.get_isrun(i)  #是否执行
            data = self.getdata.get_data_for_json(i)  #请求数据
            expect = self.getdata.get_expect_data(i)  #获得预期结果
            #res
            #print (expect)
            header = self.getdata.is_header(i)  #是否携带heaers
            if is_run:
                sql = self.getdata.get_mysql_data(i)  #是否有数据库命令
                #print (sql)
                try:
                    if sql == None:
                        res = self.runmethod.run_main(method, url, data,
                                                      header)
                        #print (res)
                    else:
                        self.Msql.run_sql(sql)
                        res = self.runmethod.run_main(method, url, data,
                                                      header)
                        print(22)
                    com = self.common.is_contain(expect, res)

                    testlog.info(
                        "url:%s,  method:%s,  data:%s, expect:%s, sql:%s, result:%s"
                        % (url, method, data, expect, sql, com))  #日志
                    if com is True:
                        self.getdata.write_result(i, 'pass')  #测试结果写入excel
                        print('测试通过')
                        pass_count.append(com)
                    else:
                        self.getdata.write_result(i, res)  #测试结果写入excel
                        fail_count.append(com)
                        print(res)
                        print('测试失败')
                except Exception as e:

                    ferror.write(
                        "[%s]  port:%s, error: %s \n" % (time.strftime(
                            _timeformat, time.localtime()), url, e))  #异常日志
                    self.getdata.write_result(i, '-----run fail---------')
                    com = False
                    print("-----run fail---------")
                    fail_count.append(com)
        #ferror.close()
        cont = self.sd_Email.send_main(pass_count, fail_count)  #邮件内容
        send_result = self.sd_Email.send_Email(cont)  #发送邮件
        return send_result
コード例 #20
0
ファイル: run_test.py プロジェクト: star626/lh_autotest
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)
                # 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)
コード例 #21
0
ファイル: run_test.py プロジェクト: cwx727/interface_frame
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommondUtil()
        self.email = SendEmail()

    def go_on_run(self):
        '''主运行程序'''
        res = None
        pass_count = []
        fail_count = []
        row_count = self.data.get_case_lines()
        for i in range(1, row_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            data = self.data.get_data_from_json(i)
            header = self.data.is_header(i)
            is_run = self.data.get_is_run(i)
            #expect_result = self.data.get_expect_data(i)
            expect_result, expect_result_type = self.data.get_expect_data_for_mysql(
                i)
            #expect_result_type = self.data.get_expect_data_for_mysql(i)[1]
            #print('-------expect_result',expect_result)
            #print('-------expect_result_type',expect_result_type)
            depend_case = self.data.get_field_depend_value(i)
            if is_run:
                if depend_case:
                    #print('1111---------depend_case',depend_case)
                    case_id = self.data.get_case_depend_value(i)  #允许数据依赖逻辑
                    #print('1111---------case_id',case_id)
                    value = DependentData(case_id).get_data_for_key(i)
                    #print('1111------------value',value)
                    #判断是否为post请求,如果是,将data中的值刷新,如果为get,将依赖值,赋值给url
                    if method == 'POST':
                        data[depend_case] = value
                    else:
                        url = url + '?' + depend_case + '=' + value
                        #print('-------------url', url)
                #print('-------data',data)
                '''
				if header == 'write':
					res = self.run_method.run_main(method,url,data)
					OperationHeader(res).write_cookie()
				elif header == 'yes':
					cookie = OperationJson('../dataconfig/cookie.json').get_data('apsid')
					cookies = {'apsid':cookie}
					res = self.run_method.run_main(method,url,data,cookies)
				else:
					res = self.run_method.run_main(method,url,data)
				'''
                #res = OperationHeader().header_main(header,method,url,data)
                res = OperationHeader().header_main(header, method, url,
                                                    data)  #head判断和处理

                #print('---------',expect_result)
                #print('----res',res,type(res))
                #if self.com_util.is_contain(expect_result,res):#字符串判断
                if self.com_util.is_equal(expect_result, res,
                                          expect_result_type):  #测试结果写入excel
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, str(res))
                    fail_count.append(i)
        self.email.send_main(pass_count, fail_count)  #发送邮件
コード例 #22
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data_json_of_excel = GetExcelDataOfJson()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    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)
コード例 #23
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_email = SendEmail()

    # 程序执行的主入口
    def go_on_run(self):
        # 10  0,1,2,3,
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        print(rows_count)
        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)
                print(i, url)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expect_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 is_run:
                # method,url,data=None,header=None
                if depend_case != None:
                    # self.depend_data = DependentData(depend_case)
                    print("depend_case is" + " --- " + depend_case)
                    self.depend_data = DependentData(depend_case)
                    # 获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #     获取依赖的key
                    print(depend_response_data)
                    depend_key = self.data.get_depend_field(i)
                    print(depend_key)
                    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 = OperationJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    # cookie = op_header.get_data()
                    # cookie = ../dataconfig/cookie.json ../dataconfig/cookie.json
                    res = self.run_method.run_main(method, url, request_data,
                                                   cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                # res = self.run_method.run_main(method,url,request_data,header)
                # print(res)
                if self.com_util.is_contain(expect, res):
                    # print("测试通过")
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    # print("测试失败")
                    # self.data.write_result(i, 'fail')
                    self.data.write_result(i, res)
                    fail_count.append(i)
        self.send_email.send_main(pass_count, fail_count)
コード例 #24
0
import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
import datetime
import HTMLTestRunner
import unittest
from util.send_email import SendEmail
'''添加用例集'''
# 获取test目录路径
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
case_path = os.path.join(rootPath, "zyt_test")

suite = unittest.defaultTestLoader.discover(case_path, pattern="test*.py")
'''生成HTML的报告'''
time = datetime.datetime.now().date()
filepath = r"{}\report\report{}.html".format(rootPath, time)
fp = open(filepath, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
                                       verbosity=2,
                                       title="ZTY Interface Testing")
runner.run(suite)
fp.close()
'''发送邮件'''
report_name = "report2{}".format(filepath.split("report2")[1])
send_email = SendEmail()
send_email.send_main(filepath, report_name)
コード例 #25
0
ファイル: run_test.py プロジェクト: fan1992619/at_api
class RunTest:
    global pass_count
    global fail_count
    global message_list
    pass_count = []
    fail_count = []
    message_list = []

    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommontUtil()
        self.article = SendArticles()
        self.send_mai = SendEmail()

    #num表示循环次数或者case数量,id_list:case id,expect,res:表示需要判断是否包含的两个预期结果
    def is_write(self, num, id_list, expect, res):
        if self.com_util.is_contain(expect, res):
            self.data.write_result(num, 'pass')
            print('第%d次' % num, id_list, 'pass')
            pass_count.append(num)
        else:
            self.data.write_result(num, res)
            print('第%d次' % num, id_list, res)
            fail_count.append(num)
            m = ('第%d次' % num, id_list)
            message_list.append(m)

    #程序执行的
    def go_on_run(self):
        res = None
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            # if i<1:
            # 	continue
            is_run = self.data.get_is_run(i)
            #判断程序是否执行
            if is_run:
                url = self.data.get_request_url(i)
                request_name = self.data.get_request_name(i)

                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                header = self.data.is_header(i)
                id = self.data.get_number_id(i)
                expect = self.data.get_expcet_data(i)
                #判断except的值是否为字符串
                if type(expect) != str:
                    expect = int(expect)
                    expect = str(expect)
                else:
                    pass
                if i == 39 or i == 40 or i == 71 or i == 72:
                    #判断该链接是否为发布文章主题之列的
                    if self.com_util.is_contain("发布项目文章", request_name):
                        res = self.article.send_article_project()
                        self.is_write(i, id, expect, res)
                    elif self.com_util.is_contain("发布主题文章", request_name):
                        res = self.article.send_article_subject()
                        self.is_write(i, id, expect, res)
                    elif self.com_util.is_contain("发布项目问题", request_name):
                        res = self.article.send_question_project()
                        self.is_write(i, id, expect, res)
                    elif self.com_util.is_contain("发布主题问题", request_name):
                        res = self.article.send_question_subject()
                        self.is_write(i, id, expect, res)
                else:
                    if header == 'no':
                        res = self.run_method.run_main(method, url, header,
                                                       request_data)
                        # print(type(res))
                        if self.com_util.is_contain(expect, res):
                            self.data.write_result(i, 'pass')
                            print('第%d次' % i, id, 'pass')
                            pass_count.append(i)
                        else:
                            # print('第%d次' % i, id)
                            self.data.write_result(i, res)
                            print('第%d次' % i, id, res)
                            fail_count.append(i)
                            m = ('第%d次' % num, id)
                            message_list.append(m)
                    else:
                        res = self.run_method.run_main(method, url, header,
                                                       request_data)
                        if self.com_util.is_contain(expect, res):
                            self.data.write_result(i, 'pass')
                            print('第%d次' % i, id, 'pass')
                            pass_count.append(i)
                        else:
                            self.data.write_result(i, res)
                            print('第%d次' % i, id, res)
                            fail_count.append(i)
                            m = ('第%d次' % num, id)
                            message_list.append(m)
            else:
                continue
        self.send_mai.send_main(pass_count, fail_count, message_list)
コード例 #26
0
class Runtest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_email = SendEmail()

    #程序执行过程

    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        no_run_count = []
        rows_count = self.data.get_case_lines()
        #每次执行时清楚log文件
        log_file = '../log/log.txt'
        with open(log_file, 'w') as f:
            f.seek(0, 0)  #定位光标位置
            f.truncate()  #删除文件

        for i in range(1, rows_count):
            try:
                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_value(i)
                    #获取excel文件的关键字
                    header_key = self.data.get_request_header(i)

                    #获取json文件中header对应的文件数据

                    header = self.data.get_header_value(i)
                    expect = self.data.get_expect_data(i)
                    depend_case = self.data.is_depend(i)

                    if depend_case != None:
                        self.depend_data = DependentData(depend_case)
                        #获取依赖字段的响应数据
                        depend_response_data = self.depend_data.get_value_for_key(
                            i)
                        #获取请求依赖的key
                        depend_key = self.data.get_depend_field(i)
                        #将依赖case的响应返回某个字段value赋值给接口请求
                        data[depend_key] = depend_response_data

                    if header_key == 'write_Cookies':
                        res = self.run_method.run_main(method,
                                                       url,
                                                       data,
                                                       header,
                                                       params=data)
                        op_header = OperationHeader(res)
                        op_header.write_cookie()

                    elif header_key == 'get_Cookies':
                        op_json = OperationJson('../dataconfig/cookie.json')
                        cookie = op_json.get_data('apsid')
                        cookies = {'apsid': cookie}
                        res = self.run_method.run_main(method,
                                                       url,
                                                       data,
                                                       header=cookies,
                                                       params=data)

                    else:
                        res = self.run_method.run_main(method,
                                                       url,
                                                       data,
                                                       header,
                                                       params=data)

                    #get请求参数是params:request.get(url='',params={}),post请求数据是data:request.post(url='',data={})
                    #excel文件中没有区分直接用请求数据表示,则data = self.data.get_data_value(i)拿到的数据,post请求就是data=data,get请就是params=data

                    #excel拿到的expect数据时str类型,返回的是res是dic类型

                    if self.com_util.is_contain(expect, json.dumps(res)):
                        self.data.write_result(i, 'pass')
                        pass_count.append(i)

                    else:
                        #返回res是dic类型,res数据写入excel中,需要dict转换为str
                        self.data.write_result(i, json.dumps(res))
                        with open(log_file, 'a', encoding='utf-8') as f:
                            f.write('\n第%s条用例不相同\n' % i)
                            f.write('expect:%s\n Actual:%s\n' % (expect, res))
                        fail_count.append(i)

                else:
                    no_run_count.append(i)

            except Exception as e:
                #异常写入测试结果
                self.data.write_result(i, str(e))
                #报错写入指定路径文件
                with open(log_file, 'a', encoding='utf-8') as f:
                    f.write('\n第%s条测试用例' % i)

                initlogging(log_file, e)
                fail_count.append(i)
        self.send_email.send_main(pass_count, fail_count, no_run_count)
コード例 #27
0
        print("添加成功的行数:", pass_count)
        self.addmerchantfun.activeweb.printredword()
        print("添加失败的行数:", fail_count)
        self.addmerchantfun.activeweb.printnormalword()
        self.send_mai.send_main(pass_count, fail_count)  # 调用发送邮件


if __name__ == '__main__':
    run = RunTest()  #实例化
    print('---------------------------')
    stdout_backup = sys.stdout
    gettime = GetTimeStr()
    timestr = gettime.getTimeStr()
    logpath = "../log/%s_message.txt" % timestr
    print("Now all print info will be written to log文件:", logpath)
    # define the log file that receives your log info
    log_file = open(logpath, "w", encoding="utf-8")
    # redirect print output to log file
    sys.stdout = log_file
    print('----------开始打印日志-----------------\n')
    run.go_on_run()
    print('\n----------日志打印结束-----------------')
    log_file.close()
    # restore the output to initial pattern
    sys.stdout = stdout_backup
    print("Now this will be presented on screen")

    #发送log至邮箱
    send_e = SendEmail()
    send_e.send_main([1], [2], logpath)
コード例 #28
0
class RunTest:
    def __init__(self):
        # self.addmerchantfun = AddMerchantFun()   #实例化
        self.data = GetData()  #实例化
        self.send_mai = SendEmail()  #实例化

    #程序执行
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        global flag

        rows_count = self.data.get_case_lines()
        print("需要添加%d个商户" % (rows_count - 1))
        for i in range(1, rows_count):  #循环,但去掉第一个

            try:
                print("添加第%d个商户" % i)
                self.writebrandname = self.data.get_brandname(i)
                self.writeremail = self.data.get_email(i)
                self.writercontactnumber = self.data.get_contactnumber(i)
                self.writermerchanttype = self.data.get_merchanttype(i)
                self.writercategory = self.data.get_category(i)
                self.writercriteria = self.data.get_criteria(i)
                self.writersiup = self.data.get_siup(i)
                self.writerprovince = self.data.get_province(i)
                self.writercity = self.data.get_city(i)
                self.writerdistrict = self.data.get_district(i)
                self.writervillage = self.data.get_village(i)
                self.writerpostcode = self.data.get_postcode(i)
                self.writeraddress = self.data.get_address(i)
                self.writercompany = self.data.get_company(i)
                self.writernpwptaxid = self.data.get_npwptaxid(i)
                self.writerofficialwebsite = self.data.get_officialwebsite(i)
                self.writerphotosiup = self.data.get_photosiup(i)
                self.writerphotonpwpcompany = self.data.get_photonpwpcompany(i)
                self.writerphototdp = self.data.get_phototdp(i)

                self.writername = self.data.get_name(i)
                self.writertypeid = self.data.get_typeid(i)
                self.writeridentitynumber = self.data.get_identitynumber(i)
                self.writernpwp = self.data.get_npwp(i)
                self.writeraddresstwo = self.data.get_addresstwo(i)
                self.writernationality = self.data.get_nationality(i)
                self.writerposition = self.data.get_position(i)
                self.writerphone = self.data.get_phone(i)
                self.writeremailtwo = self.data.get_emailtwo(i)
                self.writerphotofullfacebust = self.data.get_photofullfacebust(
                    i)

                self.writerlocationphoto = self.data.get_locationphoto(i)
                self.writerphotoofthecashiersdesk = self.data.get_photoofthecashiersdesk(
                    i)
                self.writerotherphoto = self.data.get_otherphoto(i)

                self.writerbank = self.data.get_bank(i)
                self.writeraccountname = self.data.get_accountname(i)
                self.writeraccountnumber = self.data.get_accountnumber(i)

                self.writerqrindoamount = self.data.get_qrindoamount(i)

                self.addmerchantfun = AddMerchantFun(
                    self.writebrandname, self.writeremail,
                    self.writercontactnumber, self.writermerchanttype,
                    self.writercategory, self.writercriteria, self.writersiup,
                    self.writerprovince, self.writercity, self.writerdistrict,
                    self.writervillage, self.writerpostcode,
                    self.writeraddress, self.writercompany,
                    self.writernpwptaxid, self.writerofficialwebsite,
                    self.writerphotosiup, self.writerphotonpwpcompany,
                    self.writerphototdp, self.writername, self.writertypeid,
                    self.writeridentitynumber, self.writernpwp,
                    self.writeraddresstwo, self.writernationality,
                    self.writerposition, self.writerphone, self.writeremailtwo,
                    self.writerphotofullfacebust, self.writerlocationphoto,
                    self.writerphotoofthecashiersdesk, self.writerotherphoto,
                    self.writerbank, self.writeraccountname,
                    self.writeraccountnumber, self.writerqrindoamount)  # 实例化

                flag = False
                flagadd = self.addmerchantfun.addMerchant()
                # print("flagadd标志为",flagadd)
                if flagadd:
                    flag = True
            except Exception as e:
                self.addmerchantfun.activeweb.printredword()
                print('异常现象打印:', e)
                self.addmerchantfun.activeweb.printnormalword()
            finally:
                # print('第%d次循环执行完毕'%i)
                # print("flag标志:",flag)
                if flag:
                    pass_count.append(i + 1)  # 通过的加到集合里
                else:
                    fail_count.append(i + 1)  # 失败的加到集合里
                assertresult = [0, 0]
                i = i + 1
        self.addmerchantfun.activeweb.printgreenword()
        print("添加成功的行数:", pass_count)
        self.addmerchantfun.activeweb.printredword()
        print("添加失败的行数:", fail_count)
        self.addmerchantfun.activeweb.printnormalword()
        self.send_mai.send_main(pass_count, fail_count)  # 调用发送邮件
コード例 #29
0
class GuestCase:
    def __init__(self):
        self.json_file = "/Users/mac/Desktop/测试资料/蜗牛家产品线/woniujia_cc_jiekou/woniujia_cc_jiekou_git/woniujia_cc_project/dataconfig/request_pram.json"
        self.sheet_name = "客户模块"
        self.sheet_id = 5
        self.data = GetData(self.json_file, self.sheet_name, self.sheet_id)
        self.run_method = RunMethod()
        self.util = CommonUtil()
        self.email = SendEmail()

    def go_to_guest(self):
        # self.run_comm = RunCommon(self.excel_file, self.json_file)
        # self.run_comm.go_run_case()
        # 获取用例行数
        row_count = self.data.get_case_line()
        pass_count = []
        fail_count = []
        for i in range(1, row_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_url(i)
                request_type = self.data.get_request_type(i)
                data = self.data.get_data_for_json(i)
                if i == 1:
                    header = self.data.get_header(i)
                    response = self.run_method.run_main(
                        request_type, url, data, header)
                    res = json.loads(response)
                    # 获取token、operid并写入文件中
                    with open(self.util.base_dir(), 'w') as f:
                        f.write(res["data"]["token"] + "," + res["data"]["id"])
                else:
                    token = self.util.getToken(0)
                    token_header = self.data.get_token_header(i, token)
                    depend_morecase = self.data.is_more_depend(i, 0)
                    # 判断是否存在依赖
                    if depend_morecase != None:
                        self.depend_data = DependentData(
                            depend_morecase, self.excel_file, self.json_file)
                        dependent_response_data = self.depend_data.get_data_for_key(
                            i, 0)
                        depend_key = self.data.get_dependent_key(i, 0)
                        print("depend_key", depend_key)
                        if url == "http://182.61.33.241:8089/app/api/private/1.0/client/":
                            request_url = url + dependent_response_data
                            response = self.run_method.run_main(
                                request_type, request_url, data, token_header)
                        if url == "http://182.61.33.241:8089/app/api/private/1.0/reporting/addorupdate":
                            depend_param2 = self.data.is_more_depend(i, 1)
                            self.depend_data2 = DependentData(
                                depend_param2, self.excel_file, self.json_file)
                            dependent_response_data2 = self.depend_data2.get_data_for_key(
                                i, 1)
                            depend_key2 = self.data.get_dependent_key(i, 1)
                            jsonData = json.loads(data)
                            jsonData[depend_key] = dependent_response_data
                            jsonData[depend_key2] = dependent_response_data2
                            requestData = json.dumps(jsonData)
                            response = self.run_method.run_main(
                                request_type, url, requestData, token_header)
                        else:
                            jsonData = json.loads(data)
                            print("data:", data)
                            jsonData[depend_key] = dependent_response_data
                            requestData = json.dumps(jsonData)
                            response = self.run_method.run_main(
                                request_type, url, requestData, token_header)
                    else:
                        if url == "http://182.61.33.241:8089/app/api/private/1.0/follow/clientpage":
                            oper_id = self.util.getToken(1)
                            json_data = json.loads(data)
                            json_data["operId"] = oper_id
                            request_data = json.dumps(json_data)
                            response = self.run_method.run_main(
                                request_type, url, request_data, token_header)
                        else:
                            response = self.run_method.run_main(
                                request_type, url, data, token_header)

                expect_res = self.data.get_except(i)
                print("期望结果:", expect_res)
                if self.util.is_contain(expect_res, response):
                    self.data.write_result(i, "测试通过", self.sheet_id)
                    pass_count.append(i)
                    print("测试通过")
                else:
                    self.data.write_result(i, "测试失败", self.sheet_id)
                    fail_count.append(i)
                    print("测试失败")
                self.data.write_response(i, response, self.sheet_id)
        self.email.send_main(pass_count, fail_count)
        return response
コード例 #30
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 = []
        file_count = []
        skip_count = []
        rows_count = self.data.get_case_lines()

        for i in range(1,rows_count):
            print('第',i,'条case')
            id = self.data.get_id(i)
            print('id:',id)
            url = self.data.get_url(i)
            print('url:',url)
            method = self.data.get_request_method(i)
            print('method:',method)
            is_run = self.data.get_is_run(i)
            print('is_run:',is_run)
            # data = self.data.get_data_for_json(i)
            # print('data:',data)
            data = self.data.get_request_data(i)
            data = json.dumps(data)
            print('data:', data,type(data))
            expect = self.data.get_expect_data(i)
            print('expect:',expect)
            header = self.data.get_is_header(i)
            print('header:',header,type(header))
            depend_case = self.data.is_depend(i)
            depend_to = self.data.get_to_depend(i)
            print('depend_to:',depend_to,type(depend_to))


            if is_run:

                if depend_case != None:
                    self.depend_data = DependdentData(depend_case)
                    # 获取响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)     # <class 'str'>   order

                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)     # text

                    # 拼接进去
                    if depend_to == 'H':
                        header[depend_key] = depend_response_data
                        # print('header[depend_key]:',header[depend_key],type(header[depend_key]))
                    elif depend_to == 'B':
                        data = json.loads(data)
                        data[depend_key] = depend_response_data
                        data = json.dumps(data)
                    else:
                        pass


                res = self.run_method.run_main(method, url, data, header)
                print(res.text,'----------')


                # if self.com_util.is_contain(self,expect,res):

                if expect in res.text:
                    # print(i,"测试通过",expect,res.text)
                    self.data.write_result(i,'pass')
                    pass_count.append(i)
                else:
                    # print(res.status_code)
                    # print(i,"测试失败",expect,res.text)
                    self.data.write_result(i, res.text)
                    file_count.append(i)

            else:
                skip_count.append(i)

            i += 1


        print('通过:',len(pass_count),'失败:',len(file_count),'跳过:',len(skip_count))
        self.send_mai.send_main(pass_count,file_count,skip_count)
コード例 #31
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 = []
        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)