Beispiel #1
0
 def test_api(self,item):
     res=HttpRequest.http_request(item['method'],item['url'],eval(item['data']),getattr(GetCookie,'Cookie'))
     if res.cookies: #利用反射存储cookie值
         setattr(GetCookie,'Cookie',res.cookies)
     try:
         self.assertEqual(str(item['expected']),res.json()['resultcode'])
         TestResult='PASS'
     except AssertionError as e:
         TestResult='Failed'
         MyLog.error("执行用例出错:{0}".format(e))
         raise e
     finally:
         DoExcel.write_back(test_case_path,item['sheet_name'],item['case_id']+1,res.text,TestResult)
         MyLog.info("获取到的结果是:{0}".format(res.text))
    def http_request(method,url,data,cookie=None):
        try:
            if method.upper()=='GET':
                res=requests.get(url,data,cookies=cookie)
            elif method.upper() == 'POST':
                res=requests.post(url,data,cookies=cookie)
            else:
                MyLog.info("请求的方法不对")
        except Exception as e:
            MyLog.error("请求报错了:{0}".format(e))
            raise e
        return res