第一個接口
返回內容
headers : {'Access-Control-Allow-Headers': 'X-Requested-With, accept, content-type', 'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH', 'Access-Control-Allow-Creden
tials': 'true', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 16 Apr 2020 03:41:59 GMT'}
content_type : 'application/json;charset=UTF-8'
body : {'status': 200, 'msg': '操作成功!', 'timestamp': 1587008519540, 'execTime': 1587008519359, 'successData': {'AUTO_MYSQL_1587008056::sakila': ['actor', 'address', 'category', 'city', 'city_ta
rget', 'country', 'customer', 'film', 'film_actor', 'film_category', 'film_text', 'inventory', 'language', 'payment', 'rental', 'sms_code_10', 'sms_code_1000', 'sms_code_200', 'staff', 'store', 'actor_info', '
customer_list', 'film_list', 'nicer_but_slower_film_list', 'sales_by_film_category', 'sales_by_store', 'staff_list']}, 'errorData': None, 'errorMsg': None}
使用正則表達式提取
2020-04-16 11:34:33.955 | DEBUG | httprunner.response:extract_field:272 - extract: (\[.+\]) => ["actor","address","category","city","city_target","country","customer","film","film_actor","film_category","f
ilm_text","inventory","language","payment","rental","sms_code_10","sms_code_1000","sms_code_200","staff","store","actor_info","customer_list","film_list","nicer_but_slower_film_list","sales_by_film_category","
sales_by_store","staff_list"]
第二個接口
name: 刪除表 variables: dbName: sakila tableName: city dsName: AUTO_MYSQL request: headers: Content-Type: application/json;charset=UTF-8 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 json: $tableName method: DELETE url: /xdsfg/table/$dsName/$dbName/batchDelTab validate: - eq: - status_code - 200
2020-04-16 11:34:33.973 | INFO | httprunner.report.html.result:startTest:30 - 批量刪除表 2020-04-16 11:34:33.975 | INFO | httprunner.runner:_run_test:242 - DELETE http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008056/sakila/batchDelTab 2020-04-16 11:34:33.976 | DEBUG | httprunner.runner:_run_test:243 - request kwargs(raw): {'headers': {'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x6 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'HRUN-Request-ID': '191ce27d-3a9b-4b3b-9d49-ae6cbd01e20c'}, 'json': '["actor","address","category","city","city_target","country", "customer","film","film_actor","film_category","film_text","inventory","language","payment","rental","sms_code_10","sms_code_1000","sms_code_200","staff","store","actor_info","customer_list","film_list","nicer _but_slower_film_list","sales_by_film_category","sales_by_store","staff_list"]', 'verify': True} 2020-04-16 11:34:33.983 | DEBUG | httprunner.client:_send_request_safe_mode:238 - processed request: > DELETE http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008056/sakila/batchDelTab > kwargs: {'headers': {'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'HR UN-Request-ID': '191ce27d-3a9b-4b3b-9d49-ae6cbd01e20c'}, 'json': '["actor","address","category","city","city_target","country","customer","film","film_actor","film_category","film_text","inventory","language", "payment","rental","sms_code_10","sms_code_1000","sms_code_200","staff","store","actor_info","customer_list","film_list","nicer_but_slower_film_list","sales_by_film_category","sales_by_store","staff_list"]', ' verify': True, 'timeout': 120} 2020-04-16 11:34:40.991 | DEBUG | httprunner.client:log_print:25 - ================== request details ================== url : 'http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008056/sakila/batchDelTab' method : 'DELETE' headers : {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Co nnection': 'keep-alive', 'Content-Type': 'application/json;charset=UTF-8', 'HRUN-Request-ID': '191ce27d-3a9b-4b3b-9d49-ae6cbd01e20c', 'Cookie': 'JSESSIONID=646512509BDF8AAFB8AC46298676FC91', 'Content-Length': '404'} body : b'"[\\"actor\\",\\"address\\",\\"category\\",\\"city\\",\\"city_target\\",\\"country\\",\\"customer\\",\\"film\\",\\"film_actor\\",\\"film_category\\",\\"film_text\\",\\"inventory\\",\\"lang uage\\",\\"payment\\",\\"rental\\",\\"sms_code_10\\",\\"sms_code_1000\\",\\"sms_code_200\\",\\"staff\\",\\"store\\",\\"actor_info\\",\\"customer_list\\",\\"film_list\\",\\"nicer_but_slower_film_list\\",\\"sale s_by_film_category\\",\\"sales_by_store\\",\\"staff_list\\"]"' 2020-04-16 11:34:40.997 | DEBUG | httprunner.client:log_print:25 - ================== response details ================== ok : False url : 'http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008056/sakila/batchDelTab' status_code : 400 reason : '' cookies : {} encoding : 'UTF-8' headers : {'Access-Control-Allow-Headers': 'X-Requested-With, accept, content-type', 'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH', 'Access-Control-Allow-Creden tials': 'true', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 16 Apr 2020 03:42:06 GMT', 'Connection': 'close'} content_type : 'application/json;charset=UTF-8' body : {'timestamp': '2020-04-16T03:42:06.615+0000', 'status': 400, 'error': 'Bad Request', 'message': 'JSON parse error: Cannot deserialize instance of `java.lang.String[]` out of VALUE_STRING tok en; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String[]` out of VALUE_STRING token\n at [Source: (PushbackInputStream); line: 1, column: 1]', 'path': '/rest/meta2/table/AUTO_MYSQL_1587008056/sakila/batchDelTab'}
request details
body 中將 第一個接口提取的內容進行了轉義
運行成功,但是返回信息斷言與預期不一致,運行成功了,但是預期的功能並沒有實現
解決方案
接口步驟,使用自定義方法修改一下requests
def setup_request(request): print(request["json"]) json = (request["json"]) # 使用eval格式化內容,去掉字符串兩端的引號 request["json"] = eval(json) print(request["json"])
setup_hooks:
- ${setup_request($request)}
重新執行
2020-04-16 11:43:37.164 | DEBUG | httprunner.response:extract_field:272 - extract: (\[.+\]) => ["actor","address","category","city","city_target","country","customer","film","film_actor","film_category","film_text","inventory"," language","payment","rental","sms_code_10","sms_code_1000","sms_code_200","staff","store","actor_info","customer_list","film_list","nicer_but_slower_film_list","sales_by_film_category","sales_by_store","staff_list"] 2020-04-16 11:43:37.167 | DEBUG | httprunner.validator:validate:136 - start to validate. 2020-04-16 11:43:37.171 | DEBUG | httprunner.response:extract_field:272 - extract: status_code => 200 2020-04-16 11:43:37.173 | DEBUG | httprunner.validator:validate:182 - validate: status_code equals 200(int) ==> pass 2020-04-16 11:43:37.176 | DEBUG | httprunner.response:extract_field:272 - extract: content.status => 200 2020-04-16 11:43:37.180 | DEBUG | httprunner.validator:validate:182 - validate: content.status equals 200(int) ==> pass 2020-04-16 11:43:37.194 | DEBUG | httprunner.response:extract_field:272 - extract: content.msg => 操作成功! 2020-04-16 11:43:37.198 | DEBUG | httprunner.validator:validate:182 - validate: content.msg equals 操作成功!(str) ==> pass .
2020-04-16 11:43:37.201 | INFO | httprunner.report.html.result:startTest:30 - 批量刪除表 2020-04-16 11:43:37.202 | DEBUG | httprunner.runner:do_hook_actions:150 - call SETUP hook actions. 2020-04-16 11:43:37.204 | DEBUG | httprunner.runner:do_hook_actions:165 - call hook function: LazyString(${setup_request($request)}) ["actor","address","category","city","city_target","country","customer","film","film_actor","film_category","film_text","inventory","language","payment","rental","sms_code_10","sms_code_1000","sms_code_200","staff","store","actor_in fo","customer_list","film_list","nicer_but_slower_film_list","sales_by_film_category","sales_by_store","staff_list"] ['actor', 'address', 'category', 'city', 'city_target', 'country', 'customer', 'film', 'film_actor', 'film_category', 'film_text', 'inventory', 'language', 'payment', 'rental', 'sms_code_10', 'sms_code_1000', 'sms_code_200', 'staff' , 'store', 'actor_info', 'customer_list', 'film_list', 'nicer_but_slower_film_list', 'sales_by_film_category', 'sales_by_store', 'staff_list'] 2020-04-16 11:43:37.206 | INFO | httprunner.runner:_run_test:242 - DELETE http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008606/sakila/batchDelTab 2020-04-16 11:43:37.207 | DEBUG | httprunner.runner:_run_test:243 - request kwargs(raw): {'headers': {'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'HRUN-Request-ID': 'c6b014fb-28ae-471d-b316-1412965cbd5d'}, 'json': ['actor', 'address', 'category', 'city', 'city_target', 'country', 'customer', 'film', 'film_actor', 'film_c ategory', 'film_text', 'inventory', 'language', 'payment', 'rental', 'sms_code_10', 'sms_code_1000', 'sms_code_200', 'staff', 'store', 'actor_info', 'customer_list', 'film_list', 'nicer_but_slower_film_list', 'sales_by_film_category ', 'sales_by_store', 'staff_list'], 'verify': True} 2020-04-16 11:43:37.208 | DEBUG | httprunner.client:_send_request_safe_mode:238 - processed request: > DELETE http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008606/sakila/batchDelTab > kwargs: {'headers': {'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'HRUN-Request-ID': 'c6b014 fb-28ae-471d-b316-1412965cbd5d'}, 'json': ['actor', 'address', 'category', 'city', 'city_target', 'country', 'customer', 'film', 'film_actor', 'film_category', 'film_text', 'inventory', 'language', 'payment', 'rental', 'sms_code_10' , 'sms_code_1000', 'sms_code_200', 'staff', 'store', 'actor_info', 'customer_list', 'film_list', 'nicer_but_slower_film_list', 'sales_by_film_category', 'sales_by_store', 'staff_list'], 'verify': True, 'timeout': 120} 2020-04-16 11:43:41.516 | DEBUG | httprunner.client:log_print:25 - ================== request details ================== url : 'http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008606/sakila/batchDelTab' method : 'DELETE' headers : {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive' , 'Content-Type': 'application/json;charset=UTF-8', 'HRUN-Request-ID': 'c6b014fb-28ae-471d-b316-1412965cbd5d', 'Cookie': 'JSESSIONID=FC6197C57680BD347AC83A470A24D14B', 'Content-Length': '374'} body : b'["actor", "address", "category", "city", "city_target", "country", "customer", "film", "film_actor", "film_category", "film_text", "inventory", "language", "payment", "rental", "sms_code_10", "sms_code_1000", "s ms_code_200", "staff", "store", "actor_info", "customer_list", "film_list", "nicer_but_slower_film_list", "sales_by_film_category", "sales_by_store", "staff_list"]' 2020-04-16 11:43:41.520 | DEBUG | httprunner.client:log_print:25 - ================== response details ================== ok : True url : 'http://172.16.160.167:28080/rest/meta2/table/AUTO_MYSQL_1587008606/sakila/batchDelTab' status_code : 200 reason : '' cookies : {} encoding : 'UTF-8' headers : {'Access-Control-Allow-Headers': 'X-Requested-With, accept, content-type', 'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH', 'Access-Control-Allow-Credentials': 'true', 'Conten t-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 16 Apr 2020 03:51:07 GMT'} content_type : 'application/json;charset=UTF-8' body : {'status': 200, 'msg': '操作成功!', 'timestamp': 1587009067169, 'execTime': 1587009067060, 'successData': {'AUTO_MYSQL_1587008606::sakila::category': None, 'AUTO_MYSQL_1587008606::sakila::customer': None, 'AUTO_M YSQL_1587008606::sakila::sms_code_1000': None, 'AUTO_MYSQL_1587008606::sakila::film_actor': None, 'AUTO_MYSQL_1587008606::sakila::store': None, 'AUTO_MYSQL_1587008606::sakila::payment': None, 'AUTO_MYSQL_1587008606::sakila::city_tar get': None, 'AUTO_MYSQL_1587008606::sakila::language': None, 'AUTO_MYSQL_1587008606::sakila::staff': None, 'AUTO_MYSQL_1587008606::sakila::sms_code_200': None, 'AUTO_MYSQL_1587008606::sakila::sms_code_10': None, 'AUTO_MYSQL_15870086 06::sakila::actor': None, 'AUTO_MYSQL_1587008606::sakila::rental': None, 'AUTO_MYSQL_1587008606::sakila::inventory': None, 'AUTO_MYSQL_1587008606::sakila::sales_by_store': None, 'AUTO_MYSQL_1587008606::sakila::film_list': None, 'AUT O_MYSQL_1587008606::sakila::staff_list': None, 'AUTO_MYSQL_1587008606::sakila::address': None, 'AUTO_MYSQL_1587008606::sakila::actor_info': None, 'AUTO_MYSQL_1587008606::sakila::city': None, 'AUTO_MYSQL_1587008606::sakila::nicer_but _slower_film_list': None, 'AUTO_MYSQL_1587008606::sakila::customer_list': None, 'AUTO_MYSQL_1587008606::sakila::country': None, 'AUTO_MYSQL_1587008606::sakila::film_text': None, 'AUTO_MYSQL_1587008606::sakila::film': None, 'AUTO_MYS QL_1587008606::sakila::film_category': None, 'AUTO_MYSQL_1587008606::sakila::sales_by_film_category': None}, 'errorData': None, 'errorMsg': None}
失敗和成功的報告對比