{"id":14978770,"url":"https://github.com/yanchunhuo/automationtest","last_synced_at":"2025-05-14T20:07:10.748Z","repository":{"id":37140017,"uuid":"208973239","full_name":"yanchunhuo/AutomationTest","owner":"yanchunhuo","description":"自动化测试框架，支持接口自动化、WEB UI自动化、APP UI自动化、性能测试；支持多系统相互调用；支持接口与UI相互调用；支持dubbo接口调用","archived":false,"fork":false,"pushed_at":"2025-02-17T01:05:31.000Z","size":45470,"stargazers_count":944,"open_issues_count":0,"forks_count":346,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-06T13:05:11.404Z","etag":null,"topics":["appium","automated-testing","autotesting","dubbo","selenium"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanchunhuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-17T06:13:58.000Z","updated_at":"2025-04-03T08:43:34.000Z","dependencies_parsed_at":"2024-08-21T12:28:07.006Z","dependency_job_id":"8de915c8-c73b-4dbe-8770-27e169abf571","html_url":"https://github.com/yanchunhuo/AutomationTest","commit_stats":{"total_commits":286,"total_committers":5,"mean_commits":57.2,"dds":0.5384615384615384,"last_synced_commit":"6d2c6870a09c723e05fba53ed077e0e7b6693148"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanchunhuo%2FAutomationTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanchunhuo%2FAutomationTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanchunhuo%2FAutomationTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanchunhuo%2FAutomationTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanchunhuo","download_url":"https://codeload.github.com/yanchunhuo/AutomationTest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741197,"owners_count":21154252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appium","automated-testing","autotesting","dubbo","selenium"],"created_at":"2024-09-24T13:58:21.562Z","updated_at":"2025-04-13T15:58:14.399Z","avatar_url":"https://github.com/yanchunhuo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![avatar](https://github.com/yanchunhuo/resources/blob/master/APIAutomationTest/report.png)\n\n# [自动化测试]()\n\n# [概况]()\n* 本项目支持接口自动化测试、app ui自动化测试、web ui自动化测试、性能测试\n* 本项目由以下工具组成\n    * pytest：python的一个单元测试框架,https://docs.pytest.org/en/latest/\n    * pytest-xdist：pytest的一个插件,可多进程同时执行测试用例,https://github.com/pytest-dev/pytest-xdist\n    * allure-pytest：用于生成测试报告,http://allure.qatools.ru/\n    * PyHamcrest：一个匹配器对象的框架，用于断言，https://github.com/hamcrest/PyHamcrest\n    * requests：http请求框架,http://docs.python-requests.org/en/master/\n    * Appium：移动端的自动化测试框架,https://github.com/appium/appium/tree/v1.15.1\n    * selenium：web ui自动化测试框架,https://www.seleniumhq.org/\n    * cx_Oracle：oracle操作库,https://cx-oracle.readthedocs.io/en/latest/index.html\n    * JPype1：用于执行java代码,https://github.com/jpype-project/jpype\n    * paramiko：ssh客户端,https://docs.paramiko.org/en/stable/\n    * Pillow：用于图片处理,https://pillow.readthedocs.io/en/latest/\n    * PyMySQL：用于操作MySQL数据库,https://github.com/PyMySQL/PyMySQL\n    * redis：redis客户端,https://pypi.org/project/redis/\n    * tess4j：java的图片识别工具,https://github.com/nguyenq/tess4j/\n    * allpairspy: 用于将参数列表进行正交分析，实现正交分析法用例覆盖，https://pypi.org/project/allpairspy/\n    * python-binary-memcached：用于操作memcached，https://github.com/jaysonsantos/python-binary-memcached\n    * kazoo：用于操作zookeeper，https://github.com/python-zk/kazoo\n    * websockets：用于websocket请求，https://github.com/aaugustin/websockets\n    * Js2Py：用于执行js代码，https://github.com/PiotrDabkowski/Js2Py\n    * sqlacodegen：用于根据数据库表结构生成python对象，https://github.com/agronholm/sqlacodegen\n    * SQLAlchemy：SQL工具包及对象关系映射（ORM）工具，https://github.com/sqlalchemy/sqlalchemy\n* 当前仅支持Python\u003e=3.6，建议安装Python V3.6.8版本\n* 项目如需执行java代码(即使用jpype1)，则项目目录所在的路径不可包含中文\n    \n# [使用]()\n## 一、环境准备\n### 1、脚本运行环境准备\n#### 1.1、安装系统依赖\n* Linux-Ubuntu:\n    * apt-get install libpq-dev python3-dev 【用于psycopg2-binary所需依赖】\n    * apt-get install g++ libgraphicsmagick++1-dev libboost-python-dev 【用于pgmagick所需依赖】\n    * apt-get install python-pgmagick 【pgmagick所需依赖】\n* Linux-CentOS:\n    * yum install python3-devel postgresql-devel 【用于psycopg2-binary所需依赖】\n    * yum install GraphicsMagick-c++-devel boost boost-devel【用于pgmagick所需依赖】\n* Windows:\n    * 安装Microsoft Visual C++ 2019 Redistributable，下载地址：https://visualstudio.microsoft.com/zh-hans/downloads/ 【jpype1、图像识别字库所需依赖】\n\n#### 1.2、安装python依赖模块\n* pip3 install -r requirements.txt\n* 安装pgmagick\n    * Linux:\n        * pip3 install pgmagick==0.7.6\n    * Windows:\n        * 下载安装对应版本：https://www.lfd.uci.edu/~gohlke/pythonlibs/#pgmagick\n* 安装xmind-sdk-python\n    * 下载地址:https://github.com/xmindltd/xmind-sdk-python\n\n#### 1.3、安装allure\n* 源安装\n    * sudo apt-add-repository ppa:qameta/allure\n    * sudo apt-get update \n    * sudo apt-get install allure\n    * 其他安装方式：https://github.com/allure-framework/allure2\n* 手动安装\n    * 下载2.7.0版本:https://github.com/allure-framework/allure2/releases\n    * 解压allure-2.7.0.zip\n    * 加入系统环境变量:export PATH=/home/john/allure-2.7.0/bin:$PATH\n\n#### 1.4、安装openjdk8或jdk8\n* sudo add-apt-repository ppa:openjdk-r/ppa\n* sudo apt-get update\n* sudo apt-get install openjdk-8-jdk\n\n#### 1.5、安装maven\n* 完成maven的安装配置\n\n#### 1.6、安装Oracle Instant Client\n* Linux\n    * 安装libaio包\n        * Linux-CentOS:yum install libaio\n        * Linux-Ubuntu:apt-get install libaio1\n    * 配置Oracle Instant Client\n        * 下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html\n        * 下载安装包instantclient-basic-linux.x64-18.3.0.0.0dbru.zip\n        * 解压zip包,并配置/etc/profile\n            * unzip instantclient-basic-linux.x64-18.3.0.0.0dbru.zip\n            * export LD_LIBRARY_PATH=/home/john/oracle_instant_client/instantclient_18_3:$LD_LIBRARY_PATH\n        * 中文编码设置\n        \n            ```python \n            import os\n            os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'\n            ```\n* Windows\n    * 下载地址:http://www.oracle.com/technetwork/topics/winx64soft-089540.html\n    * 下载安装包instantclient-basic-windows.x64-11.2.0.4.0.zip\n    * 解压zip包,并配置环境变量\n        * 系统环境变量加入D:\\instantclient-basic-windows.x64-11.2.0.4.0\\instantclient_11_2\n        * 配置中文编码,环境变量创建NLS_LANG=SIMPLIFIED CHINESE_CHINA.UTF8  \n    * 注意:如果使用64位,python和instantclient都需要使用64位\n\n#### 1.7、图像识别字库准备\n* 下载对应字库:https://github.com/tesseract-ocr/tessdata\n* 将下载的字库放到common/java/lib/tess4j/tessdata/\n* Linux\n    * 安装依赖\n        * Linux-Ubuntu:sudo apt install pkg-config aclocal libtool automake libleptonica-dev\n        * Linux-CentOS:yum install autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel\n    * 安装leptonica，下载leptonica-1.78.0.tar.gz，下载地址：https://github.com/DanBloomberg/leptonica/releases\n        * 安装步骤同tesseract-ocr的安装\n        * 修改/etc/profile添加如下内容，然后source\n        ```\n        export LD_LIBRARY_PATH=$LD_LIBRARY_PAYT:/usr/local/lib\n        export LIBLEPT_HEADERSDIR=/usr/local/include\n        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig\n        ```\n    * 安装tesseract-ocr，下载tesseract-4.1.1.tar.gz，下载地址：https://github.com/tesseract-ocr/tesseract/releases\n        * ./autogen.sh\n        * ./configure\n        * sudo make\n        * sudo make install\n        * sudo ldconfig\n* Windows\n    * 安装Microsoft Visual C++ 2019 Redistributable，下载地址：https://visualstudio.microsoft.com/zh-hans/downloads/\n\n### 2、selenium server运行环境准备\n#### 2.1、安装jdk1.8,并配置环境变量\n* export JAVA_HOME=/usr/lib/jvm/jdk8\n* export JRE_HOME=${JAVA_HOME}/jre \n* export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib\n* export PATH=${JAVA_HOME}/bin:$PATH\n\n#### 2.2、安装配置selenium\n* 配置selenium server\n    * 下载selenium-server-standalone-3.141.0.jar\n    * 下载地址:http://selenium-release.storage.googleapis.com/index.html\n    * 以管理员身份启动服务:java -jar selenium-server-standalone-3.141.0.jar -log selenium.log\n* 下载浏览器驱动\n    * 谷歌浏览器：https://chromedriver.storage.googleapis.com/index.html\n        * 驱动支持的最低浏览器版本：https://raw.githubusercontent.com/appium/appium-chromedriver/master/config/mapping.json\n    * 火狐浏览器：https://github.com/mozilla/geckodriver/\n        * 驱动支持的浏览器版本：https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html\n    * IE浏览器(建议使用32位,64位操作极慢)：http://selenium-release.storage.googleapis.com/index.html\n    * 将驱动所在目录加入到selenium server服务器系统环境变量:export PATH=/home/john/selenium/:$PATH\n* IE浏览器设置\n    * 在Windows Vista、Windows7系统上的IE浏览器在IE7及以上版本中，需要设置四个区域的保护模式为一样，设置开启或者关闭都可以。\n        * 工具--\u003eInternet选项--\u003e安全\n    * IE10及以上版本增强保护模式需要关闭。\n        * 工具--\u003eInternet选项--\u003e高级\n    * 浏览器缩放级别必须设置为100%，以便本地鼠标事件可以设置为正确的坐标。\n    * 针对IE11需要设置注册表以便于浏览器驱动与浏览器建立连接\n        * Windows 64位：HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BFCACHE\n        * Windows 32位：HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BFCACHE\n        * 如果FEATRUE_BFCACHE项不存在，需要创建一个，然后在里面创建一个DWORD(32位)，命名为iexplore.exe，值为0\n        * Windows 64位两个注册表建议都设置\n    * IE8及以上版本设置支持inprivate模式，以便多开IE窗口时cookies能够独享\n        * HKKY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main 下建一个名为TabProcGrowth的DWORD(32位)，值为0\n    * 重启系统\n    * 注:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration\n\n### 3、appium server运行环境准备\n#### 3.1、安装jdk1.8,并配置环境变量\n* export JAVA_HOME=/usr/lib/jvm/jdk8\n* export JRE_HOME=${JAVA_HOME}/jre \n* export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib\n* export PATH=${JAVA_HOME}/bin:$PATH\n\n#### 3.2、安装配置appium server\n* 安装appium desktop server\n    * 下载Appium-windows-1.15.1.exe\n    * 下载地址:https://github.com/appium/appium-desktop/releases\n    * 以管理员身份启动服务\n\n* Android环境准备\n    * 安装java(JDK),并配置JAVA_HOME=/usr/lib/jvm/jdk8\n    * 安装Android SDK,并配置ANDROID_HOME=\"/usr/local/adt/sdk\"\n    * 使用SDK manager安装需要进行自动化的Android API版本\n    \n* IOS环境准备\n    * 由于测试IOS真实设备没办法直接操作web view，需要通过usb，实现通过usb创建连接需要安装ios-webkit-debug-proxy\n    * 下载安装地址：https://github.com/google/ios-webkit-debug-proxy/tree/v1.8.5\n\n* 手机chrome环境准备\n    * 确保手机已安装chrome浏览器\n    * 下载chrome浏览器驱动：https://chromedriver.storage.googleapis.com/index.html\n    * 驱动支持的最低浏览器版本：https://raw.githubusercontent.com/appium/appium-chromedriver/master/config/mapping.json\n    * 在appium desktop上设置驱动的路径\n\n* 混合应用环境准备\n    * 方法一：安装TBS Studio工具查看webview内核版本：https://x5.tencent.com/tbs/guide/debug/season1.html\n    * 方法二：打开地址（该地址在uc开发工具中可查到）查看webview内核版本：https://liulanmi.com/labs/core.html\n    * 下载webview内核对应的chromedriver版本：https://chromedriver.storage.googleapis.com/index.html\n    * 配置文件进行驱动路径的配置\n    * 注：webview需要开启debug模式\n\n* Windows环境准备\n    * 支持Windows10及以上版本\n    * 设置Windows处于开发者模式\n    * 下载WinAppDriver并安装(V1.1版本),https://github.com/Microsoft/WinAppDriver/releases\n    * \\[可选\\]下载安装WindowsSDK,在Windows Kits\\10\\bin\\10.0.17763.0\\x64内包含有inspect.exe用于定位Windows程序的元素信息\n\n* 其他更多配置：https://github.com/appium/appium/tree/v1.15.1/docs/en/drivers\n\n## 二、修改配置\n* vim config/app_ui_config.conf 配置app ui自动化的测试信息\n* vim config/web_ui_config.conf 配置web ui自动化的测试信息\n* vim config/projectName/projectName.conf 配置测试项目的信息\n* 修改性能测试负载机的系统最大打开文件数,避免并发用户数大于最大打开文件数\n\n## 三、运行测试\n### 1、API测试\n* cd AutomationTest/\n* python3 -u run_api_test.py --help\n* python3 -u run_api_test.py 运行cases/api/目录所有的用例\n* python3 -u run_api_test.py -k keyword 运行匹配关键字的用例，会匹配文件名、类名、方法名\n* python3 -u run_api_test.py -d dir     运行指定目录的用例，默认运行cases/api/目录\n* python3 -u run_api_test.py -m mark    运行指定标记的用例\n\n### 2、web ui测试\n* cd AutomationTest/\n* python3 -u run_web_ui_test.py --help\n* python3 -u run_web_ui_test.py 运行cases/web_ui/目录所有的用例\n* python3 -u run_web_ui_test.py -k keyword 运行匹配关键字的用例，会匹配文件名、类名、方法名\n* python3 -u run_web_ui_test.py -d dir     运行指定目录的用例，默认运行cases/web_ui/目录\n* python3 -u run_web_ui_test.py -m mark    运行指定标记的用例\n\n### 3、app ui测试\n* cd AutomationTest/\n* python3 -u run_app_ui_test.py --help\n* python3 -u run_app_ui_test.py 运行cases/app_ui/目录所有的用例\n* python3 -u run_app_ui_test.py -tt phone -k keyword 运行匹配关键字的用例，会匹配文件名、类名、方法名\n* python3 -u run_app_ui_test.py -tt phone -d dir     运行指定目录的用例，默认运行cases/app_ui/目录\n* python3 -u run_app_ui_test.py -m mark              运行指定标记的用例\n\n### 4、性能测试\n* cd AutomationTest/\n* ./start_locust_master.sh\n* ./start_locust_slave.sh\n\n## 四、生成测试报告\n### 1、API测试\n* cd AutomationTest/\n* python3 -u generate_api_test_report.py -p 9080 \n* 访问地址http://ip:9080\n* 在使用Ubuntu进行报告生成时，请勿使用sudo权限，否则无法生成，allure不支持\n\n### 2、web ui测试\n* cd AutomationTest/\n* python3 -u generateReport_web_ui_test_report.py -ieport 9081 -chromeport 9082 -firefoxport 9083\n* 访问地址http://ip:908[1-3]\n* 在使用Ubuntu进行报告生成时，请勿使用sudo权限，否则无法生成，allure不支持\n\n### 3、app ui测试\n* cd AutomationTest/\n* python3 -u generateReport_app_ui_test_report.py -sp 9084\n* 访问地址http://ip:9084\n\n### 注：在使用Ubuntu进行报告生成时，请勿使用sudo权限，否则无法生成，allure不支持\n\n## 五、项目说明\n### 1、API测试\n* 项目\n    * demoProject 例子项目\n        \n### 2、web ui测试\n* 元素的显式等待时间默认为30s\n* 封装的显式等待类型支持:page_objects/web_ui/wait_type.py\n* 封装的定位类型支持:page_objects/web_ui/locator_type.py\n* 默认使用4个worker进行并行测试\n* 文件下载处理暂不支持ie浏览器\n* 无头浏览器暂不支持ie浏览器\n* 项目\n    * demoProject 例子项目\n        \n### 3、app ui测试\n* 元素的显式等待时间默认为30s\n* 封装的显式等待类型支持:page_objects/app_ui/wait_type.py\n* 封装的定位类型支持:page_objects/app_ui/locator_type.py\n* 项目\n    * android \n        * demoProject 例子项目\n\n# [项目结构]()\n* base 基础请求类\n* cases 测试用例目录\n* common 公共模块\n* common_projects 每个项目的公共模块\n* config　配置文件\n* init 初始化\n* logs 日志目录\n* output 测试结果输出目录 \n* packages app ui测试的安装包\n* page_objects 页面映射对象\n* pojo 存放自定义类对象\n* test_data 测试所需的测试数据目录\n* run_api_test.py 运行api测试脚本\n* run_web_ui_test.py 运行web ui测试脚本\n* run_app_ui_test.py 运行app ui测试脚本\n* generate_api_test_report.py 生成api测试报告\n* generateReport_web_ui_test_report.py 生成web ui测试报告\n* generateReport_app_ui_test_report.py 生成app ui测试报告\n* start_locust_master.sh 启动locust主节点\n* start_locust_slave.sh 启动locust从节点\n\n# [编码规范]()\n* 统一使用python 3.6.8\n* 编码使用-\\*- coding:utf8 -\\*-,且不指定解释器\n* 类/方法的注释均写在class/def下一行，并且用三个双引号形式注释\n* 局部代码注释使用#号\n* 所有中文都直接使用字符串，不转换成Unicode，即不是用【u'中文'】编写\n* 所有的测试模块文件都以test_projectName_moduleName.py命名\n* 所有的测试类都以Test开头，类中方法(用例)都以test_开头\n* 每个测试项目都在cases目录里创建一个目录，且目录都包含有api、scenrarios两个目录\n* case对应setup/teardown的fixture统一命名成fixture_[test_case_method_name]\n* 每一个模块中测试用例如果有顺序要求【主要针对ui自动化测试】，则自上而下排序，pytest在单个模块里会自上而下按顺序执行\n\n# [pytest常用]()\n* @pytest.mark.skip(reason='该功能已废弃')\n* @pytest.mark.parametrize('key1,key2',[(key1_value1,key2_value2),(key1_value2,key2_value2)])\n* @pytest.mark.usefixtures('func_name')\n\n# [注意点]()\n* 运行pytest时指定的目录内应当有conftest.py，方能在其他模块中使用。@allure.step会影响fixture，故在脚本中不使用@allure.step\n* 由于web ui配置的驱动是直接设置在系统环境变量，app ui指定了混合应用的浏览器驱动，在运行app ui时appium有可能会读取到系统的环境变量的配置，故运行时请排查此情况\n* 数据库操作，所有表操作均进行单表操作，如需多表查询，使用代码进行聚合\n* web ui测试\n    * 统一使用Firefox浏览器进行元素定位\n    * 能用id、name、link(不常变化的链接)定位的，不使用css定位，能使用css定位，不使用xpath定位\n    * 项目使用并发运行，故编写测试用例时，应该避免模块与模块直接的用例会相互影响测试结果\n* app ui测试\n    * 能用id、name、link(不常变化的链接)定位的，不使用css定位，能使用css定位，不使用xpath定位\n    * 如需要上传文件到手机或者从手机下载文件，请确保有手机对应目录的读写权限\n    * 视频录制统一对单个单个case进行，保证录制时间不超过3分钟，且录制文件不要过大，否则会引起手机内存无法存储视频\n            * 确认手机是否能进行视频录制执行命令adb shell screenrecord /sdcard/test.mp4，能正常执行即可\n    * 设备屏幕坐标系原点都在最左上角，往右x轴递增，往下y轴递增\n\n# [进交流群]()\n![avatar](https://github.com/yanchunhuo/resources/blob/master/wechat.png =200x)\n\n\n[![Stargazers over time](https://starchart.cc/yanchunhuo/AutomationTest.svg)](https://starchart.cc/yanchunhuo/AutomationTest)\n\n[![Top Langs](https://profile-counter.glitch.me/yanchunhuo/count.svg)](https://github.com/yanchunhuo)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanchunhuo%2Fautomationtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanchunhuo%2Fautomationtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanchunhuo%2Fautomationtest/lists"}