# API_Automated_Test **Repository Path**: hcguagua/API_Automated_Test ## Basic Information - **Project Name**: API_Automated_Test - **Description**: 基于Python+Requests+pytest+Allure+YMAL+Jenkins的接口自动化测试系统 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-07-21 - **Last Updated**: 2023-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API_Automated_Test #### 介绍 基于 开源接口(玩Android) 项目所有API接口搭建的一套接口自动化系统。 技术选型:Python+Requests+pytest+Allure+yaml+Jenkins 通过 Python+Requests 来发送和处理HTTP协议的请求接口,使用 Pytest 作为单元测试框架,使用 YAML 来管理测试数据,使用 Allure 来生成测试报告,并且通过Jenkins持续集成,发送邮件通知。 #### 目录结构 ``` |____api # 封装sdk和后台系统相关接口 |____case_script # 测试用例脚本 |____common # 通用工具类和函数 |____data # 测试数据 |____report # 存放生成的测试报告 |____config.py # 项目配置信息 |____install_req.py # 安装第三方库执行文件 |____pytest.ini # pytest配置文件 |____requirement.txt # 运行环境依赖的模块 |____run.py # 测试执行文件 ``` #### 安装教程 1. Python 3.9 2. Allure 3. 安装依赖: 1. 终端运行 pip install -r requirements.txt 2. 或 直接运行 install_req.py 文件 4. 安装java和jenkins ``` 1. 安装java环境 2. 安装Jenkins 安装最新的 LTS 版本: brew install jenkins-lts 启动詹金斯服务: brew services start jenkins-lts 关闭jenkins:brew services stop jenkins-lts 重新启动詹金斯服务: brew services restart jenkins-lts 更新詹金斯版本: brew upgrade jenkins-lts 再通过8080端口访问,例如本机访问Jenkins:http://localhost:8080 3. 修改配置: vi /opt/homebrew/Cellar/jenkins-lts/2.414.1/homebrew.mxcl.jenkins-lts.plist 将httpListenAddress修改为0.0.0.0就可以支持局域网IP访问 ``` 5. 配置项目 ``` 一. 插件安装: 1. Dashboard-->系统管理-->插件管理(jenkins安装的时候,把推荐的插件全部安装上) 2. Available plugins--> 安装 Allure Jenkins Plugin 二. 系统配置 1. Dashboard-->系统管理-->System 1. Jenkins Location Jenkins URL:http://:8080/ 系统管理员邮件地址: 你的邮箱地址 2. GitHub Credentials建议用Token 3. Extended E-mail Notification 配置SMTP server 4. 邮件通知 配置SMTP server Dashboard-->系统管理-->System 2. Dashboard-->系统管理-->System 1.Maven 配置 默认 2.JDK 安装 推荐使用本地JAVA_HOME,自动安装也可 3.Allure Commandline 安装 推荐使用本地安装目录,自动安装也可 4.其他设置全部自动安装就好,正常情况System全部自动安装都是欧克的,有问题再去看日志解决 三. 新建任务 1.GitHub项目 2.源码管理 1.Git Repositories 1.Repository URL 2.Credentials(建议Token凭证) Branches to build 1.指定分支 源码库浏览器(推荐githubweb) 1.URL 3.构建触发器 4.构建环境 Use secret text(s) or file(s) Secret text 5.Build Steps 执行 shell /bin/rm -rf ./report/* python3 install_req.py python3 run.py 6.构建后操作 1.Allure Report 1.Path:report 2.高级 Report path:allure-report 2.E-mail Notification 3.Editable Email Notification 1.Project Recipient List 2.其他邮件的样式配置自己配置一下就好 ``` 以上,完结,看能否正常构建并且发送邮件,有问题去看日志一个一个解决就好;项目实际情况有需要钉钉、lark通知的,和邮件通知配置类似的,jenkins都有对应的插件。 #### 测试报告效果展示 ![test_report.png](common%2Ftest_report.png)