Backend Development 8 min read

Common Issues and Solutions When Using HttpRunner for API Automation Testing

This article summarizes practical problems encountered with HttpRunner—such as YAML parsing errors, missing attributes, duplicate assertions, custom function parameter issues, and performance bottlenecks—and provides detailed debugging steps, code patches, multithreading enhancements, and report‑optimization techniques for large‑scale API test suites.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Common Issues and Solutions When Using HttpRunner for API Automation Testing

HttpRunner (v2.5.7) has been used in our project for nearly two years, handling over 2400 test cases with a 99.99% success rate; however, various issues arise during YAML‑based API automation.

Error: exception stage: parse tests – caused by undefined variables, missing $ prefixes, incorrect braces in debugtalk.py , inconsistent indentation, or wrong parameter definitions. The parser only accepts variables matching $[A-Za-z0-9_]+ , so a variable like $title-tup is reduced to $title , leading to lookup failures.

Error: ResponseObject does not have attribute: parsed_body – a bug in HttpRunner where self.parsed_body() should be replaced with self.json in response.py (line 62).

Issue: Assertions not executed – when multiple contains assertions share the same method and check values, HttpRunner merges them into a single dictionary key, overwriting earlier expectations and causing only the last assertion to run. The fix is to ensure unique check values or implement a custom assertion method in debugtalk.py for collection‑wide validation.

Error: Failed to extract attribute from response! – occurs when the expected variable is absent in the response or the first argument of an assertion does not contain the extracted value. Adjust the assertion parameters to include the extracted data.

Custom method parameter problem – custom assertion functions must accept exactly two parameters (check value, expect value) and should not wrap string arguments in quotes. The parser treats quoted strings as non‑function calls, skipping execution. Solutions: pass raw variables without quotes or define a variable and reference it.

Multithreading implementation – for large test suites, replace the original single‑process _run_suite in api.py with a thread‑pool version. Example code:

from concurrent.futures.thread import ThreadPoolExecutor
from concurrent import futures

Set max_workers to control thread count and keep test cases for the same interface in one YAML file to avoid coupling.

Improving report opening speed – when case numbers are huge, displaying all results slows down the report. Copy httprunner/report/template.html to template_fail.html and modify it to filter out successful cases, then run tests with --report-template=template_fail.html (preferably using an absolute path).

Overall, HttpRunner is a versatile HTTP(S) testing framework, but real‑world usage often requires debugging source code, customizing assertions, and optimizing execution and reporting for large‑scale test suites.

debuggingAutomationmultithreadingYAMLAPI testingHttpRunner
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.