# shop_mall **Repository Path**: wangkeyy2580/shop_mall ## Basic Information - **Project Name**: shop_mall - **Description**: 接口自动化——商城系统 shop_mall - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: wangke - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-09 - **Last Updated**: 2026-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 电商接口自动化测试框架 技术栈:Python + Pytest + Requests + YAML + Allure + GitHub Actions/Jenkins。 框架参考 `/Users/mac/Desktop/1/api_dl/` 的设计,支持: - YAML 数据驱动 - 单接口用例 `single_cases` - 多接口场景用例 `scenario_cases` - 按电商业务模块划分用例和测试脚本 - 全局变量提取和 `${变量}` 引用 - 按商城常见网关维护服务域名:认证、商城主站、后台、支付 - Allure 报告 - CI/CD ## 目录结构 ```text api_auto_framework/ ├── common/ # 公共封装:请求、断言、变量、解析器 ├── config/ # 环境和服务域名配置 ├── data/ # YAML 用例,按电商模块划分 │ ├── auth/ # 认证 │ ├── user/ # 用户 │ ├── product/ # 商品 │ ├── cart/ # 购物车 │ ├── order/ # 订单 │ ├── payment/ # 支付 │ └── scenario/ # 多接口业务流程 ├── tests/ # Pytest 测试脚本,按模块划分 ├── reports/ # Allure 报告 ├── logs/ # 运行日志 └── .github/workflows/ # GitHub Actions ``` ## 快速运行 ```bash cd /Users/mac/Desktop/api_auto_framework source .venv/bin/activate pytest ``` 也可以直接运行统一入口。不传参数时会让你选择运行单接口、多接口场景或全部: ```bash python run.py ``` 只跑单接口: ```bash python run.py --mode single ``` 只跑多接口场景: ```bash python run.py --mode scenario ``` 单接口和多接口都跑: ```bash python run.py --mode all ``` 只跑某个模块: ```bash python run.py --mode single --testcase data/product ``` ## 指定环境 ```bash pytest --env test pytest --env prod ``` 环境配置在 `config/config.yaml`。当前按商城项目常见方式维护,不是一个模块一个域名,而是按系统网关划分: ```yaml env: test: base_url: "https://dummyjson.com" service_domains: auth_service: https: default: "https://dummyjson.com" mall_service: https: default: "https://dummyjson.com" admin_service: https: default: "https://dummyjson.com" pay_service: https: default: "https://dummyjson.com" headers: Content-Type: "application/json" Accept: "application/json" timeout: http: 10 https: 10 ``` 后期接入公司测试环境时,通常这样改: ```yaml env: test: base_url: "https://test-api.yourshop.com" service_domains: auth_service: https: default: "https://test-auth.yourshop.com" mall_service: https: default: "https://test-mall.yourshop.com" admin_service: https: default: "https://test-admin.yourshop.com" pay_service: https: default: "https://test-pay.yourshop.com" ``` ## 指定 YAML 文件或目录 后期新增接口时,只需要在 `data/` 下面写 YAML,不需要新增 `.py` 文件。固定使用这个通用执行入口: ```bash pytest tests/test_yaml_dynamic --testcase data/auth/01_auth_api.yaml pytest tests/test_yaml_dynamic --testcase data pytest tests/test_yaml_dynamic --testcase data/auth --testcase data/product ``` 例如新增优惠券模块,只需要新建: ```text data/coupon/08_coupon_api.yaml ``` 然后运行: ```bash pytest tests/test_yaml_dynamic --testcase data/coupon ``` ## 生成 Allure 报告 ```bash pytest --alluredir=reports/allure-results --clean-alluredir allure generate reports/allure-results -o reports/allure-report --clean allure open reports/allure-report ``` ## 单接口 YAML 示例 ```yaml service_name: mall_service single_cases: - name: "商品模块-查询商品详情" id: "product_detail" module: "商品模块" service_name: mall_service protocol: "https" method: "GET" url: "/products/1" validate_rules: - check: "status_code" comparator: "eq" expected: 200 - check: "json.price" comparator: "gt" expected: 0 ``` ## 多接口场景 YAML 示例 ```yaml scenario_cases: - name: "电商核心流程-登录下单" id: "scenario_login_add_cart_order_check" module: "交易流程" protocol: "https" steps: - name: "用户登录" service_name: auth_service method: "POST" url: "/auth/login" json: username: "emilys" password: "emilyspass" extract: - name: "login_user_id" path: "json.id" global: true ```