Getting Started with HttpRunner: Installation, Configuration, and Basic Usage
This guide introduces HttpRunner, covering supported operating systems, Python environment setup, installation via pip, key commands, parameter correlation, global configuration, variable handling, data‑driven testing, report generation, and a practical workflow using HAR files to create and run test cases.
HttpRunner First Experience
The article introduces HttpRunner, a Python‑based API testing framework, and outlines the environments it supports.
Runtime Environment
Supported systems: macOS, Linux, Windows. Development environment: Python (recommended Python 3.6 on macOS/Linux).
Installation Pip install httprunner After installation the following commands are available: hrun: alias for httprunner locusts: performance testing based on Locust har2case: converts HAR files to YAML/JSON test cases
Verify installation with hrun -V.
Quick Start
1. Parameter correlation – extract values (e.g., token) from earlier test cases and reference them in later requests using $var syntax.
2. Global configuration – extract common parts of test cases into a shared config section.
3. Variable declaration and usage – define variables in a variables block and reference them with $var.
4. Data parameterization – create a debugtalk.py file alongside test cases to define custom functions and variables.
5. Data‑driven testing – use the parameters keyword to specify parameter names and data sources for multiple test iterations.
Report Generation
Run tests with the hrun command; after execution an HTML report is generated in a reports folder within the working directory.
Practice
1. Capture API traffic with Charles and export it as a .har file.
2. Convert the HAR file to a test case using har2case path\test.har, which produces a JSON/YAML file.
3. Execute the generated test case with hrun path\test.json.
Result
The execution creates an HTML test report in the reports directory, providing a visual summary of the test outcomes.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
