HttpRunner-01:Linux上安装httprunner环境


1.环境准备

我的本地主机系统是Window11,自行安装ubuntu20.04系统,通过Linux环境搭建一个HttpRunner。

ubuntu20.04环境:

  • Python=3.8.2

1.1 替换源

  • 使用pip3安装httprunner(报错)
rosaany@Rosefinch:~$ sudo apt install python3-pip

执行完发现报错:E: Package 'python3-pip' has no installation candidate,想到本地源需要替换一下

  • 备份原有的源
rosaany@Rosefinch:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  • 在网上找到对应版本的源,我这里是ubuntu20.04版本

以阿里源为例

rosaany@Rosefinch:~$ sudo vim /etc/apt/sources.list

# 替换为如下的源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

# 替换保存退出后 更新 源
sudo apt update
  • 再次安装pip3(这回成功了)

rosaany@Rosefinch:~$ sudo apt install python3-pip

1.2 安装HttpRunner

rosaany@Rosefinch:~$ pip3 install httprunner

安装 HttpRunner 后,系统中将添加 5 个命令:

  • httprunner: 主命令,用于所有功能
  • hrun: 别名httprunner run,用于运行 YAML/JSON/pytest 测试用例
  • hmake: 别名httprunner make,用于将 YAML/JSON 测试用例转换为 pytest 文件
  • har2case: 别名httprunner har2case,用于将 HAR 转换为 YAML/JSON 测试用例
  • locusts: 用于运行locust 的负载测试

1.3 测试HttpRunner命令

rosaany@Rosefinch:~$ httprunner
httprunner: command not found

出现上面报错是因为相关指令没找到,默认会到/usr/bin目录下寻找命令
利用find命令查找httprunner目录所在

  • 测试httprunner命令

  • 添加软链接

rosaany@Rosefinch:~$ httprunner -V
3.1.6

同理的,其它命令如果也报类似的错误,通过find和ln命令建立一个软链接