コード例 #1
0
ファイル: a1_interface.py プロジェクト: cn5036518/xq_py
    def test(self):
        #调接口类,新建接口类的对象,传入参数 前提:先导入接口类文件
        h1 = Http_request1(self.url, self.params1, self.headers1)
        if self.method1 == "POST" and self.data_type1 == "Json":
            result1 = h1.post_request1()
            print(result1)
        elif self.method1 == "POST" and self.data_type1 == "Form":
            result1 = h1.post_request1()
            print(result1)
        elif self.method1 == "GET":
            result1 = h1.get_request2()
            print(result1)

        ret1 = result1["error_code"]
        ret2 = self.check_point1["error_code"]
        if ret1 == ret2:
            print("测试通过")
            #写入测试通过和响应数据
            sh1.cell(
                i + 2,
                11).value = "通过"  #这里是=,而不是==  注意  #这里的i+2就可以保障读取的行和写入的行是同一行
            # #写入响应数据到excel前,先把响应数据(http请求类的return是字典),从字典转换成json字符串才行
            # result1 = json.dumps(result1,ensure_ascii=False)  #参数2是用来解决中文乱码
            # sh1.cell(2,12).value = result1
        else:
            print("测试不通过")
            # 写入测试通过和响应数据
            sh1.cell(i + 2, 11).value = "不通过"  # 这里是=,而不是==  注意
            # 写入响应数据到excel前,先把响应数据(http请求类的return是字典),从字典转换成json字符串才行
        result1 = json.dumps(result1, ensure_ascii=False)  # 参数2是用来解决中文乱码
        sh1.cell(i + 2, 12).value = result1
        wb1.save(path1)
コード例 #2
0
    def test(self):
        h1 = Http_request1(self.url, self.params1, self.headers1)
        if self.method1 == "POST" and self.data_type1 == "Json":
            result1 = h1.post_request1()  #小括号要加上
            print(result1)
        elif self.method1 == "POST" and self.data_type1 == "Form":
            result1 = h1.post_request1()
            print(result1)
        elif self.method1 == "GET":
            result1 = h1.get_request2()
            print(result1)
        else:
            print("请检查测试用例的数据")

        ret1 = result1["error_code"]
        ret2 = self.check_point1["error_code"]

        if ret1 == ret2:
            print("测试通过")
            #写入通过和响应数据(需要将响应数据从字典转换衬json字符串才能写入)
            sh1.cell(i + 2, 11).value = "通过"  #通过i+2 保证读取的行和写入的行是同一行
            print(i)
        else:
            print("测试不通过")
            sh1.cell(i + 2, 11).value = "不通过"
        result1 = json.dumps(result1,
                             ensure_ascii=False)  #字典转换成json字符串,参数2是显示中文的
        sh1.cell(i + 2, 12).value = result1
        wb1.save(path1)
コード例 #3
0
ファイル: a1_interface2.py プロジェクト: cn5036518/xq_py
    def test(self, url, params1, headers1, method1, data_type1, check_point1,
             yes_no1, i):
        #这里的i是形参,确保读取行和写入行是同一行
        h1 = Http_request1(url, params1, headers1)
        if method1 == "POST" and data_type1 == "Json":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.post_request1()  #小括号要加上
            print(result1)
        elif method1 == "POST" and data_type1 == "Form":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.post_request1()
            print(result1)
        elif method1 == "GET":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.get_request2()
            print(result1)
        else:
            print("请检查测试用例的数据")

        ret1 = result1["error_code"]
        ret2 = check_point1["error_code"]

        if ret1 == ret2:
            print("测试通过")
            #写入通过和响应数据(需要将响应数据从字典转换衬json字符串才能写入)
            sh1.cell(i, 11).value = "通过"  #通过i+2 保证读取的行和写入的行是同一行
        else:
            print("测试不通过")
            sh1.cell(i, 11).value = "不通过"
        result1 = json.dumps(result1,
                             ensure_ascii=False)  #字典转换成json字符串,参数2是显示中文的
        sh1.cell(i, 12).value = result1
        # wb1.save(path1)  #path1是用例文件
        wb1.save(path2)  #另存为到path1--就是一个测试报告的性质(填写了测试结果和响应数据后)
コード例 #4
0
ファイル: a1_interface.py プロジェクト: cn5036518/xq_py
    def test(self):
        request1 = Http_request1(self.url, self.param1, self.headers1)
        # 1调http请求类,新建请求类对象 传入成员变量,方便方法间使用
        if self.method1 == "POST" and data_type1 == "Json":
            result1 = request1.post_method1()  #2对象调请求类中的post方法,前提先导入http请求类
            print(result1)
            # print(type(result1))
            # print("----")
        elif self.method1 == "POST" and data_type1 == "Form":
            result1 = request1.post_method1()  # 2对象调请求类中的post方法
            print(result1)
            # print(type(result1))
            # print("----2")
        elif self.method1 == "GET":
            result1 = request1.get_method2()  # 2对象调请求类中的get方法
            print(result1)  #该请求类本身不支持get方法
            print(type(result1))
            print("----3")
        else:
            print("请求失败,请检查用例里的数据是否正确")
        result2 = result1["error_code"]
        # print(result2)  #0
        # print(type(result2))  #int
        check_point2 = check_point1["error_code"]
        #这里的check_point1刚刚读取的时候是json,必须先转换成python字典使用
        # print(check_point2)

        if result2 == check_point2:
            print("错误码是%s,测试通过" % result2)
            #写入单元格
            sh1.cell(row=i + 2, column=11).value = "通过"  #注意:将循环遍历中的行号i+2传到这里
            # sh1.cell(row=2, column=12).value = result1
            # 这里的result1是字典,要写入excel,需要先将字典转换成json字符串才行,否则报错
            # result1 = json.dumps(result1,ensure_ascii=False)
            # # ensure_ascii=False  这个参数默认是True,表示只显示ascii,
            # # 如果这个参数改成False,就可以显示non-ascii(包含汉字)
            # sh1.cell(row=i+2, column=12).value = result1
            # wb1.save(path1)
            # 注意:写入单元格后,必须save后,才能生效,没有save的话,写入是没有生效的
            # save的时候,当前的excel文件必须是关闭的,如果是打开的,会出现报错
            # PermissionError: [Errno 13] Permission denied:
            #  'D:\\PycharmProjects\\xiaoqiang\\02base_181027\\001\\lianxi.xlsx'
        else:
            print("错误码是%s,测试不通过" % result2)
            sh1.cell(row=i + 2, column=11).value = "不通过"  #注意:将循环遍历中的行号i+2传到这里
        result1 = json.dumps(result1, ensure_ascii=False)
        sh1.cell(row=i + 2, column=12).value = result1
        wb1.save(path1)
コード例 #5
0
ファイル: a1_interface2.py プロジェクト: cn5036518/xq_py
    def test(self, url, params1, headers1, method1, data_type1, check_point1,
             yes_no1, i, path1_report, sh1, wb1):
        # 将读取字段,行号、测试报告路径、工作簿wb1,工作表sh1作为形式参数
        #这里的i是形参,确保读取行和写入行是同一行
        # # 2 获取工作簿
        # wb1 = openpyxl.load_workbook(path2_case)
        #
        # # 3 获取工作表
        # sh1 = wb1.get_sheet_by_name("Sheet1")

        # # 3 最大行数
        # max_row1 = sh1.max_row  # 没有小括号,属性

        h1 = Http_request1(url, params1, headers1)
        if method1 == "POST" and data_type1 == "Json":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.post_request1()  #小括号要加上
            print(result1)
        elif method1 == "POST" and data_type1 == "Form":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.post_request1()
            print(result1)
        elif method1 == "GET":  #注意:这里的字母大小写必须和excel保持一致
            result1 = h1.get_request2()
            print(result1)
        else:
            print("请检查测试用例的数据")

        ret1 = result1["error_code"]
        ret2 = check_point1["error_code"]

        if ret1 == ret2:
            print("测试通过")
            #写入通过和响应数据(需要将响应数据从字典转换衬json字符串才能写入)
            sh1.cell(i, 11).value = "通过"  #通过i+2 保证读取的行和写入的行是同一行
        else:
            print("测试不通过")
            sh1.cell(i, 11).value = "不通过"
        result1 = json.dumps(result1,
                             ensure_ascii=False)  #字典转换成json字符串,参数2是显示中文的
        sh1.cell(i, 12).value = result1
        # wb1.save(path1)  #path1是用例文件
        wb1.save(path1_report)  #另存为到path1_report--就是一个测试报告的性质(填写了测试结果和响应数据后)
コード例 #6
0
ファイル: a1_interface.py プロジェクト: cn5036518/xq_py
    def test(self):
        request1 = Http_request1(self.url, self.param1, self.headers1)
        # 1调http请求类,新建请求类对象 传入成员变量,方便方法间使用
        if self.method1 == "POST" and data_type1 == "Json":
            result1 = request1.post_method1()  #2对象调请求类中的post方法,前提先导入http请求类
            print(result1)
            # print(type(result1))
            # print("----")
        elif self.method1 == "POST" and data_type1 == "Form":
            result1 = request1.post_method1()  # 2对象调请求类中的post方法
            print(result1)
            # print(type(result1))
            # print("----2")
        elif self.method1 == "GET":
            result1 = request1.get_method2()  # 2对象调请求类中的get方法
            print(result1)  #该请求类本身不支持get方法
            print(type(result1))
            print("----3")
        else:
            print("请求失败,请检查用例里的数据是否正确")
        result2 = result1["error_code"]
        # print(result2)  #0
        # print(type(result2))  #int
        check_point2 = check_point1["error_code"]
        #这里的check_point1刚刚读取的时候是json,必须先转换成python字典使用
        # print(check_point2)

        if result2 == check_point2:
            print("错误码是%s,测试通过" % result2)
            #写入单元格
            sh1.cell(row=i + 2, column=11).value = "通过"  #注意:将循环遍历中的行号i+2传到这里
        else:
            print("错误码是%s,测试不通过" % result2)
            sh1.cell(row=i + 2, column=11).value = "不通过"  #注意:将循环遍历中的行号i+2传到这里
        result1 = json.dumps(result1, ensure_ascii=False)
        sh1.cell(row=i + 2, column=12).value = result1
        wb1.save(path1)