introduction
Recently, some people did not have an interface to practice when learning interface automation testing. In fact, in terms of interfaces, they must either find a third party to provide them, or develop them by themselves. The third-party online API requires authentication, and there is a certain limit to the number of calls per day in general. If you develop it yourself, you can use it as long as you don’t power off it (to be honest, your company’s interface is enough for you to practice, and you may not be able to test it)
It just so happens that a certain platform master provides an e-commerce system under the Vue framework, and it is open source. If we only do interface testing (practice), we only need to download the back-end API service.
Download the through train: https://gitee.com/HUJIAFANGFUJIDDD/vue_api_server.git
Install Vue_Api_Server
1. The first step is to download the package. I won't talk about how to download it.
2. The second step: install the npm and node environment in advance (how to install these two, Baidu by yourself)
3. Step 3: Unzip the vue_api_server package, open the cmd command, enter the root directory of the package, and enter: npm install (install dependent packages)
As shown in the figure:
4. Step 4: Install mysql. If you already have it, ignore this step.
5. Step 5: Enter db and import mydb.sql into the mysql database.
6. Step 6: Go to the vue_api_server\config directory and open the file default.json
As shown in the figure:
copy{ "config_name" : "develop", "jwt_config" : { "secretKey":"itcast", "expiresIn":86400 }, "upload_config":{ "baseURL":"http://127.0.0.1:8888", "upload_ueditor":"uploads/ueditor", "simple_upload_redirect":"http://127.0.0.1/reload" }, "db_config" : { "protocol" : "mysql", "host" : "127.0.0.1", "database" : "mydb", "user" : "root", "password" : "1030", "port" : 3306 } }
Modify the database connection: (you can modify it according to your own situation, or you don’t need to modify it)
copy{ "config_name" : "develop", "jwt_config" : { "secretKey":"itcast", "expiresIn":86400 }, "upload_config":{ "baseURL":"http://127.0.0.1:8888", "upload_ueditor":"uploads/ueditor", "simple_upload_redirect":"http://127.0.0.1/reload" }, "db_config" : { "protocol" : "mysql", "host" : "127.0.0.1", "database" : "shop", "user" : "root", "password" : "123456", "port" : 3306 } }
7. Step 7: Open the cmd interface just now (under the project root directory), enter: node app.js command
The appearance of these API s proves that you have succeeded.
Api interface description and documentation
API V1 interface description
1. Interface reference address: http://127.0.0.1:8888/api/private/v1/ 2. The server has enabled CORS cross-domain support 3. Token authentication is uniformly used for API V1 authentication 4. API s that require authorization must use the Authorization field in the request header to provide a token token 5. Use HTTP Status Code to identify the status 6. The data return format uniformly uses JSON
Login verification interface
There are too many interfaces, please refer to the documentation for details, here is one, such as:
copy- Request path: login - Request method: post - request parameters | parameter name | Parameter Description | Remark | | -------- | -------- | -------- | | username | username | Can not be empty | | password | password | Can not be empty | - response parameter | parameter name | Parameter Description | Remark | | -------- | ----------- | --------------- | | id | user ID | | | rid | user role ID | | | username | username | | | mobile | phone number | | | email | Mail | | | token | token | based on jwt token of |
copy- response data
copy{ "data": { "id": 500, "rid": 0, "username": "admin", "mobile": "123", "email": "123@qq.com", "token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE1MTI1NDQyOTksImV4cCI6MTUxMjYzMDY5OX0.eGrsrvwHm-tPsO9r_pxHIQ5i5L1kX9RX444uwnRGaIM" }, "meta": { "msg": "login successful", "status": 200 } }
Api test
Now that the interface has been deployed, it is now for verification. I will not use python here, and I will directly postman to verify it:
It is consistent with the data returned by the interface document, which proves that there is no problem.
Summarize
The back-end interface of this project can fully satisfy your daily practice. Generally speaking, the interface in the project in the company is enough for you to be unable to test (the author). Of course, you can also develop a project background api yourself, such as what I wrote before Django API development case.
There is one more point that needs to be explained. The above is only that the interface has been adjusted. How to verify the specific interface, how to write a demo to test the api logic of this project, you still need to continue. The process of implementation is also a process of practice.
In addition, friends who are interested in test development, automated testing, and full-stack testing related technologies can join the group to learn, explore and communicate. To enter the group, scan the QR code below.