Foreword
Before learning HttpRunner, we all use cases written in YAML/JSON
the maintenance, use is also very convenient. In fact, there are a lot of big brothers like to develop automated test platforms, such as we have today to build HttpRunnerManager
, which is developed based on HttpRunner good interface developed automated testing platform.
Github Address: https://github.com/HttpRunner/HttpRunnerManager
Although HttpRunnerManager author has stopped maintenance of the platform, but we can still learn more by building HttpRunnerManager, after the platform to build complete, we can write directly on the interface test automation platform.
Need to prepare in advance on Linux environment (The following is the environment when I set up):
1, Python 3.6.8 (refer to the article: Linux installation A Python 3 )
2, MySQL 5.7 (refer to article: install MySQL 5.7 Linux under )
Download Source HttpRunnerManager
First, we directly to Github
the download HttpRunnerManager
, download it to a local, or directly by the clone git. Here, I was a direct download archive.
The download is complete, unzip reached on a Linux server, or to spread through the Linux unzip
command to extract, finally, we get the following:
In the dependencies installed requirements.txt
Because the python3 and pip3 already installed on Linux, so there can be installed directly by pip3.
Installation command: PIP3 install -r requirements.txt
After entering the command to install, wait for the installation to complete. I encountered the following error when installing:
The above is an error in the installation mysqlclient
if a fault occurs, check in online, the reason is found to depend on the package when first installed Linux system installed mysql relevant packages mysql-devel
, so we need to install mysql-devel
the following command:
yum install mysql-devel
After the installation, re-installation requirements.txt
in dependencies, the error will not.
Creating the MySQL database HttpRunner
Next, we need to create the appropriate HttpRunner on MySQL database, set the appropriate user name, password, and start MySQL. Here is my pass under Windows Navicat
database connection MySQL created the name hrun
.
Created, you can not leave it behind will synchronize the database, and then get the data table structure.
Modify the configuration file
Modify HttpRunnerManager/settings.py
the configuration file DATABASES dictionary, we need to modify the place ( about settings.py in around line 120 ):
The only we modify the database configuration-related content, you can vim modify command, after amended as follows ( modify according to their actual situation ):
Database synchronization
Above, we just created a name for the hrun
database, but there is no data under the database table, now we will get the data synchronization database table. HttpRunnerManager need to return to the root directory, which is here in our HttpRunnerManager-master
directory.
生成数据迁移脚本:python3 manage.py makemigrations ApiManager
应用到db生成数据表:python3 manage.py migrate
同步数据库完成之后,我们再到 MySQL 中查看,可以发现 hrun
数据库下新增了很多数据表。
创建后台管理员用户
到这里,我们基本的搭建工作已差不多完成。现在,我们创建一个超级用户,并按提示输入相应用户名,密码,邮箱。该用户可用于管理后台数据。
创建后台用户:python3 manage.py createsuperuser
启动Django服务
我们还需要启动Django服务,Django默认端口一般是8000,启动服务的命令如下:
python3 manage.py runserver 0.0.0.0:8000
使用上面的命令,有一个不足的地方,那就是不能在后台运行,因此我们最好通过后台运行的方式来启动Django服务,命令如下:
nohup python3 manage.py runserver 0.0.0.0:8000 >hrun.log 2>&1 &
HttpRunnerManager在后台运行的日志,将输出到 hrun.log
下。
登录HttpRunnerManager
在Linux下启动服务之后,我们将在Windows下进行访问并登录HttpRunnerManager,我们需要检查一下 8000 等端口是否已开放,特别如果是在云服务器上搭建的环境,需要添加安全组规则,否则可能访问不到。
后台管理:http://ip地址:8000/admin/
注册界面:http://ip地址:8000/api/register/
Background operation and maintenance management login interface is as follows:
Enter the steps to create a background for background user can log on screen after login as follows:
HttpRunnerManager user registration interface is as follows:
After you create a normal user, switch to the login screen, as follows:
The main interface after the user logs on success:
Note: In the above main interface, we found the interface style seems to be something wrong, it is because we download the source code from Github some problems, here you need to manually change it up.
The above templates/base.html
document, line 23, you need to change it, will be http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css
replaced http://cdn.bootcss.com/amazeui/2.7.2/css/amazeui.min.css
, then replace, refresh the page again, the interface style to normal, the last display interface effects are as follows:
HttpRunnerManager, the asynchronous execution, scheduled tasks, task monitoring and other functions, need to build RabbitMQ messaging middleware, which we further study in the follow-up of it.
OK, now we HttpRunnerManager interface test platform has been basically set up success, in addition to the asynchronous execution, scheduled tasks, task monitoring, other functions can be used.