Beispiel #1
0
    def test(self):
        # 2新建对象
        if self.method1 == "POST" and self.data_type == "Form":
            requests1 = Requests_Post1(self.url, self.params1,
                                       self.headers1)  # 传入实际参数
            # 3通过对象调方法
            result1 = requests1.requests_post2()
            print("post请求-form获取响应结果(python-字典类型)=",
                  result1)  # 5输出整个返回内容(字典类型)
        elif self.method1 == "POST" and self.data_type == "Json":
            requests1 = Requests_Post1(self.url, self.params1,
                                       self.headers1)  # 传入实际参数
            # 3通过对象调方法
            result1 = requests1.requests_post2()
            print("post请求-json获取响应结果(python-字典类型)=",
                  result1)  # 5输出整个返回内容(字典类型)
        elif self.method1 == "GET":
            requests1 = Requests_Get1(self.url, self.params1,
                                      self.headers1)  # 传入实际参数
            # 3通过对象调方法
            result1 = requests1.requests_get2()
            print("get请求获取响应结果(python-字典类型)=", result1)  # 5输出整个返回内容(字典类型)
        else:
            #记录日志文件,异常处理
            print("请求失败,请检查用例里的数据是否正确")

    #二,前面先做分支判断,得到响应数据,这里统一进行正则匹配
        print("错误码error_code是:", result1["error_code"])  # 6输出错误码error_code
        result2 = result1["error_code"]
        # print(result2)  #0
        # print(type(result2)) #<class 'str'>

        path1 = r"D:\PycharmProjects\xiaoqiang\base_181027\a1接口层框架设计1-0326\src5\testcase2.xlsx"
        wb1 = openpyxl.load_workbook(path1)
        sh1 = wb1.get_sheet_by_name("Sheet1")

        if result2 == self.check_point1["error_code"]:  #
            print("post请求返回的error_code是'0',测试通过")
            # sh1.cell(row=3, column=11).value = "通过"    #行号写死
            sh1.cell(row=self.row, column=11).value = "通过"
            wb1.save(path1)
        else:
            print("返回的error_code不是'0',测试不通过")