HttpRunner (hrp) Installation and Usage Guide

HttpRunner (hrp) Installation and Usage Guide

Table of Contents

  • 1. Introduction
  • 2. Installation on Windows
  • 3. Installation on macOS
  • 4. Basic Usage
  • 5. Detailed Parameters of hrp Command

1. Introduction

HttpRunner is an open-source API testing tool that supports various network protocols such as HTTP(S), HTTP2, WebSocket, and RPC.<span>hrp</span> is the command-line tool provided in HttpRunner v4, developed in Golang, offering better performance.

Main Features

  • • Supports multiple protocols: HTTP(S), HTTP2, WebSocket, RPC
  • • Various test case formats: YAML, JSON, pytest
  • • Rich assertion mechanisms
  • • Parameterized testing
  • • Support for custom functions
  • • Detailed test reports
  • • Cross-platform support

2. Installation on Windows

2.1 Download Precompiled Binary

Step 1: Download hrp.exe

  1. 1. Visit HttpRunner GitHub Releases:
    1. https://github.com/httprunner/httprunner/releases
  2. 2. Select the latest stable version
  3. 3. Download the <span>hrp-vx.x.x-windows-amd64.zip</span> file
  4. 4. Unzip the file to obtain <span>hrp.exe</span>

Step 2: Configure Environment Variables

  1. 1. Create a folder in the root of C drive: <span>C:\HttpRunner</span>
  2. 2. Place the <span>hrp.exe</span> file in this folder
  3. 3. Configure system environment variables:
  • • Right-click on “This PC” → “Properties”
  • • Click on “Advanced system settings”
  • • Click on “Environment Variables”
  • • In the “System variables” section, find the <span>Path</span> variable and click “Edit”
  • • Click “New” and enter <span>C:\HttpRunner</span>
  • • Click “OK” to save all settings

Step 3: Verify Installation

Open Command Prompt (CMD) and enter:

hrp --version
hrp -h

2.2 Install Using Package Manager

Using Chocolatey

choco install httprunner

Using Scoop

scoop install httprunner

3. Installation on macOS

3.1 One-Click Installation Script (Recommended)

Open Terminal and execute the following command:

bash -c "$(curl -ksSL https://httprunner.com/script/install.sh)"

3.2 Manual Installation

Step 1: Determine System Architecture

uname -m
# Intel Chip (x86_64): Download darwin-amd64 version
# Apple M1/M2 Chip (arm64): Download darwin-arm64 version

Step 2: Download and Install

# Download (using arm64 as an example, replace with amd64 for Intel chip)
wget https://github.com/httprunner/httprunner/releases/latest/download/hrp-v4.x.x-darwin-arm64.tar.gz

# Unzip
tar -xzf hrp-v4.x.x-darwin-arm64.tar.gz

# Move to system path
sudo mv hrp /usr/local/bin/

# Grant execute permission
sudo chmod +x /usr/local/bin/hrp

Step 3: Verify Installation

hrp --version
hrp -h

3.3 Using Homebrew

# Add tap
brew tap httprunner/tap

# Install
brew install httprunner

4. Basic Usage

4.1 Create a Project

# Create a project named demo
hrp startproject demo

# Enter project directory
cd demo

# View project structure
ls -la  # macOS/Linux
dir     # Windows

4.2 Project Structure

demo/
├── .env                    # Environment variable configuration file
├── .gitignore             # Git ignore file
├── debugtalk.py           # Custom function file
├── proj.json              # Project information file
├── har/                   # HAR file directory
│   └── .keep
├── reports/               # Test report directory
│   └── .keep
└── testcases/             # Test case directory
    ├── demo.json          # JSON format example
    ├── ref_testcase.yml   # YAML format example
    ├── requests.json      # Request example JSON
    └── requests.yml       # Request example YAML

4.3 Run Tests

# Run a single test case
hrp run testcases/requests.yml

# Run test case and generate HTML report
hrp run testcases/requests.yml --gen-html-report

# Run the entire test suite
hrp run testcases/

# View the generated report
open reports/      # macOS
explorer reports\  # Windows

5. Detailed Parameters of hrp Command

5.1 Basic Commands

# View version
hrp --version
hrp -V

# View help
hrp --help
hrp -h

# Create project
hrp startproject <project_name>

# Run tests
hrp run <testcase_path>

5.2 Detailed Parameters for run Command

hrp run [OPTIONS] [TESTCASE_PATH]

Options:
  --gen-html-report              Generate HTML format test report
  --report-template string       Specify report template path
  --report-name string           Specify report name
  --log-level string             Set log level (debug|info|warn|error)
  --log-json                     Output logs in JSON format
  --continue-on-failure          Continue execution on failure
  --failfast                     Stop immediately on failure
  --save-tests                   Save test results to file
  --workers int                  Number of concurrent workers (default 1)
  --proxy-url string             Set proxy server URL
  --http2                        Enable HTTP/2 support
  --timeout int                  Set request timeout (seconds)
  --think-time float             Set think time between steps (seconds)
  --plugin string                Load plugin
  --env-file string              Specify environment variable file path

5.3 Common Command Combinations

# Basic run
hrp run testcases/demo.yml

# Generate HTML report
hrp run testcases/ --gen-html-report

# Set log level to debug
hrp run testcases/ --log-level debug

# Concurrent execution (4 workers)
rhp run testcases/ --workers 4

# Stop on failure
hrp run testcases/ --failfast

# Continue execution (even on failure)
rhp run testcases/ --continue-on-failure

# Set proxy
hrp run testcases/ --proxy-url http://127.0.0.1:8080

# Enable HTTP/2
hrp run testcases/ --http2

# Set timeout (30 seconds)
rhp run testcases/ --timeout 30

# Specify environment variable file
hrp run testcases/ --env-file .env.prod

# Custom report name
hrp run testcases/ --gen-html-report --report-name "API Automation Test Report"

# Combine multiple parameters
hrp run testcases/ \
  --gen-html-report \
  --report-name "Production Environment Test" \
  --workers 2 \
  --log-level info \
  --continue-on-failure

5.4 Other Useful Commands

# Convert test case format
hrp convert <source_file> <target_file>

# Generate performance test script
hrp boom <testcase_file>

# Start web interface
hrp startproject --web

# View project information
hrp info

# Validate test case syntax
hrp validate testcases/

# Clean project files
hrp clean

5.5 Environment Variable Settings

.env File Configuration

# Basic configuration
BASE_URL=https://api.example.com
API_VERSION=v1

# Authentication information
API_KEY=your_api_key_here
SECRET_KEY=your_secret_key_here

# Test configuration
TIMEOUT=30
RETRY_COUNT=3
THINK_TIME=1.0

# Environment identifier
ENV=test
DEBUG=true

Multi-Environment Configuration

# .env.dev - Development environment
BASE_URL=https://dev-api.example.com

# .env.test - Testing environment  
BASE_URL=https://test-api.example.com

# .env.prod - Production environment
BASE_URL=https://api.example.com

Use specified environment:

hrp run testcases/ --env-file .env.prod

5.6 Common Problem Solutions

Windows Issues

  • • Prompt “hrp is not an internal or external command”: Check the PATH configuration of environment variables
  • • Permission issues: Run Command Prompt as administrator

macOS Issues

  • • Prompt “permission denied”: Use <span>chmod +x</span> to grant execute permission
  • • Prompt “unable to verify developer”: Use <span>xattr -d com.apple.quarantine</span> to remove quarantine attribute

General Issues

  • • SSL certificate verification failed: Set <span>verify: false</span> in the test case
  • • Request timeout: Use <span>--timeout</span> parameter to increase timeout
  • • Chinese encoding issues: Ensure file encoding is UTF-8

Conclusion

This tutorial provides a complete installation and usage guide for HttpRunner (hrp) on Windows and macOS systems, including:

  1. 1. ✅ Multiple installation methods (precompiled binary, package manager, one-click script)
  2. 2. ✅ Detailed environment configuration steps
  3. 3. ✅ Basic usage process
  4. 4. ✅ Complete command parameter descriptions
  5. 5. ✅ Common problem solutions

Through this tutorial, you can quickly deploy and use HttpRunner for API testing on different operating systems.

Related Links

  • Official Websitehttps://httprunner.com/
  • GitHub Repositoryhttps://github.com/httprunner/httprunner
  • Official Documentationhttps://httprunner.com/docs/

Leave a Comment