diff --git a/README.md b/README.md index f99df3440ed97588c916b0afc41185144a3fc3f1..94fc0cc02c6cfef061c753ce315a82befee72a61 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ path为当前请求返回结果的jsonpath 根据path的值更换后置处理参 ``` # 三、文件展示 -## 3.1yaml文件展示 +### 3.1yaml文件展示 > !!!***所有case的id 务必唯一***!!! @@ -363,7 +363,7 @@ login: # caseID **请务必唯一** code: 200 # HTTP响应码断言 ``` -## 3.2 config.ini配置文件格式 +### 3.2 config.ini配置文件格式 > 重点为[directory] 中的test_name 所有程序都围绕test_name 进行执行 > 根据testname来生成测试用例执行测试等 @@ -440,6 +440,141 @@ login.yml ![登录接口yaml文件](https://img-blog.csdnimg.cn/37a61e07520d4e2388a28e9a8bd45f60.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6bq76L6j54Or5YS_,size_20,color_FFFFFF,t_70,g_se,x_16) conftest.py ![conftests中使用cookie的登录前置](https://img-blog.csdnimg.cn/1a8fe3e670ac48699ac92a11960a6bc1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6bq76L6j54Or5YS_,size_20,color_FFFFFF,t_70,g_se,x_16) +# 八、jenkins集成 +### 8.1 docker环境搭建: +1 安装docker(不会请百度) +2 新建任意文件夹 +3 新建文件 Dockerfile +4 新建文件docker-compose.yml +5 复制python安装包![img_3.png](pic/img_3.png) +文件内容如下: +_**docker-compose.yml**_ +```yaml +version: '3' +services: + jenkins: + image: "jenkins_python" + build: . + depends_on: + - redis + container_name: jenkins + volumes: + - "/home/jenkins:/var/jenkins_home" + ports: + - "10240:8080" + - "10241:50000" + user: root + links: + - redis + redis: + image: "redis:alpine" + container_name: redis + restart: always + volumes: + - ../redis/redis.conf:/usr/local/etc/redis/redis.conf:rw + - ../redis/data:/data:rw + command: --requirepass "123456" + ports: + - "6379:6379" + expose: + - 6379 +``` +_**Dockerfile**_ +```dockerfile +FROM jenkins/jenkins +USER root +ADD ./Python-3.9.7.tgz /var/python +RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list +RUN sed -i s@/security.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list +WORKDIR /var/python3 +RUN apt-get update \ +&& apt-get install -y vim\ +&& apt-get -y install gcc automake autoconf libtool make \ +&& apt-get -y install zlib* \ +&& apt-get -y install openssl libssl-dev \ +&& apt-get -y install sudo \ +&& apt-get install libffi-dev \ +&& apt-get install -y nodejs \ +&& /var/python/Python-3.9.7/configure --prefix=/var/python3 --with-ssl \ +&& make \ +&& make install \ +&& ln -sf /var/python3/bin/python3.9 /usr/bin/python \ +&& ln -sf /var/python3/bin/pip3 /usr/bin/pip \ +&& apt install npm -y \ +&& npm install -g allure-commandline --save-dev \ +&& /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone +WORKDIR / +``` +在文件目录内执行命令 +`docker-compose up` +这样生成了两个容器 一个是包含allure和python的jenkins容器和一个redis容器 + +### 8.2jenkins配置 + +`Javahome路径 查询echo $JAVA_HOME 输出 /opt/java/openjdk` + +1 安装allure 和gitee插件 + +![](pic/img_4.png) + +![](pic/img_5.png) + +2 配置全局变量 + +![img_6.png](pic/img_6.png) + +3.新建autotest任务 + +![img_7.png](pic/img_7.png) + +![img_8.png](pic/img_8.png) + +![img_9.png](pic/img_9.png) + +![img_10.png](pic/img_10.png) + +![img_11.png](pic/img_11.png) + +![img_12.png](pic/img_12.png) +4 增加构建步骤 + +![img_13.png](pic/img_13.png) + +```shell + +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --default-timeout=1000 -r requirements.txt + +python setupMain.py + +``` + +5 增加构建后操作allure报告 + +![img_14.png](pic/img_14.png) + +`report/xml` + +点击高级 + +![img_15.png](pic/img_15.png) + +`report/html +` + +**注意路径 相对workspace内任务的路径 前面没有斜线** + +###8.3注意事项 +**注意路径 相对workspace内任务的路径 前面没有斜线** +**Ubuntu文件编码有坑 项目yaml文档必须用utf-8编码** + +### 8.4脚本代码更改 +找到`setipMain.py` +![img.png](pic/img_16.png) +红框内注意为当前jenkins建立的任务名称 +修改config.ini内redis配置 配置内容与docker容器保持一致 如密码 +![img.png](pic/img_17.png) + +**_注意 host 为dockercompose内link名称 内部链接采用redis:6379_** --- diff --git a/common/basePage.py b/common/basePage.py index 344a0f997bccd613d2f35b59237fbf6c90915893..1a63e19cf247377dd52c473a477e082f61ecf2f2 100644 --- a/common/basePage.py +++ b/common/basePage.py @@ -315,21 +315,22 @@ class apiSend(object): apisend = apiSend() if __name__ == '__main__': - h = { - "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjE2OTRmYjlmLTUzNjYtNGZjZS1hODg4LTBlY2UxOThmZThhZSJ9.5_mD4abE-5iHsSr6RB9R8qaIRV7zidUFkpytyyd2cjSiQcrdJvAE_6GjU9Q_Xsr0JmTkSCTiefpFySguyk2E8Q", - "Content-Type": "multipart/form-data" - - } - d = { - "param": "updateSupport=0", - "urlparam": None - } - p = {'address': '/v1/enter/trade/', 'assert': {'jsonpath': None, 'sqlassert': None, 'time': 2, 'code': 201}, - 'data': {'param': {'name': '行业名称$RandomString($RandomPosInt(2,6)$)$', - 'desc': '备注$RandomString($RandomPosInt(2,8)$)$'}, 'urlparam': None}, - 'headers': {'Content-Type': 'application/json', - 'Authorization': 'GREEN eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMiwiZXhwIjoxNjUxODMzNjY4LCJ1c2VybmFtZSI6ImRsMDAxIn0.Dbk1ddEXdmW1tRzxZLvFgJwsh0hek6HJjzCabStdnz0'}, - 'host': 'host_HB', 'info': '新建行业', 'method': 'POST', 'cache': None, 'relevance': None} - ress = apisend(address=p['address'], data=p['data'], method=p['method'], headers=p['headers'], - caches=p['cache'], host=p['host'], ) - print(ress) + # h = { + # "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjE2OTRmYjlmLTUzNjYtNGZjZS1hODg4LTBlY2UxOThmZThhZSJ9.5_mD4abE-5iHsSr6RB9R8qaIRV7zidUFkpytyyd2cjSiQcrdJvAE_6GjU9Q_Xsr0JmTkSCTiefpFySguyk2E8Q", + # "Content-Type": "multipart/form-data" + # + # } + # d = { + # "param": "updateSupport=0", + # "urlparam": None + # } + # p = {'address': '/v1/enter/trade/', 'assert': {'jsonpath': None, 'sqlassert': None, 'time': 2, 'code': 201}, + # 'data': {'param': {'name': '行业名称$RandomString($RandomPosInt(2,6)$)$', + # 'desc': '备注$RandomString($RandomPosInt(2,8)$)$'}, 'urlparam': None}, + # 'headers': {'Content-Type': 'application/json', + # 'Authorization': 'GREEN eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMiwiZXhwIjoxNjUxODMzNjY4LCJ1c2VybmFtZSI6ImRsMDAxIn0.Dbk1ddEXdmW1tRzxZLvFgJwsh0hek6HJjzCabStdnz0'}, + # 'host': 'host_HB', 'info': '新建行业', 'method': 'POST', 'cache': None, 'relevance': None} + # ress = apisend(address=p['address'], data=p['data'], method=p['method'], headers=p['headers'], + # caches=p['cache'], host=p['host'], ) + # print(ress) + d =pymysql \ No newline at end of file diff --git a/config/config.ini b/config/config.ini index 8e04794df10ab3c4f678ab56d3d3401811131498..26de895ee3d4530efbc59f1a7cb642ddfe626ca6 100644 --- a/config/config.ini +++ b/config/config.ini @@ -31,14 +31,15 @@ receivers = 529548204@qq.com host = 127.0.0.1 port = 3306 user = root -password = test@123 -database = test +password = 123456 +database = new charset = utf8 [redis] host = 127.0.0.1 +;host = redis port = 6379 db = 2 -password = 123456 +password = charset = UTF-8 [dingding] webhook = https://oapi.dingtalk.com/robot/send?access_token=2e7987d965c9ce0fd3d7a703d9653f9f12237dd9b5f07a21a2e1cb84cc2bbb7e diff --git a/pic/img_10.png b/pic/img_10.png new file mode 100644 index 0000000000000000000000000000000000000000..23addaf2e37d50b641ecb1b5740d3ce9b73a4ee2 Binary files /dev/null and b/pic/img_10.png differ diff --git a/pic/img_11.png b/pic/img_11.png new file mode 100644 index 0000000000000000000000000000000000000000..372de912139e6b5bf7230390876450e668704d17 Binary files /dev/null and b/pic/img_11.png differ diff --git a/pic/img_12.png b/pic/img_12.png new file mode 100644 index 0000000000000000000000000000000000000000..6e13b46512ca095afcb4477cd6064f303de331d3 Binary files /dev/null and b/pic/img_12.png differ diff --git a/pic/img_13.png b/pic/img_13.png new file mode 100644 index 0000000000000000000000000000000000000000..ddca6b77748542bbd949ab3b9edf57c40e5e891d Binary files /dev/null and b/pic/img_13.png differ diff --git a/pic/img_14.png b/pic/img_14.png new file mode 100644 index 0000000000000000000000000000000000000000..24d7f9857b256d5cc87ee8c55b85a5346549cceb Binary files /dev/null and b/pic/img_14.png differ diff --git a/pic/img_15.png b/pic/img_15.png new file mode 100644 index 0000000000000000000000000000000000000000..d78bdbffd0b235216458643e44ef6f34e4de4472 Binary files /dev/null and b/pic/img_15.png differ diff --git a/pic/img_16.png b/pic/img_16.png new file mode 100644 index 0000000000000000000000000000000000000000..49ac455bb628f0e8df21a309a2ce2d3c059f81e2 Binary files /dev/null and b/pic/img_16.png differ diff --git a/pic/img_17.png b/pic/img_17.png new file mode 100644 index 0000000000000000000000000000000000000000..16a4ee46f9f4a881b18ca1adbe47f6c87c22fa6c Binary files /dev/null and b/pic/img_17.png differ diff --git a/pic/img_3.png b/pic/img_3.png new file mode 100644 index 0000000000000000000000000000000000000000..80914f9005bfeb1154296b258fb8e0f3bbd3ccd6 Binary files /dev/null and b/pic/img_3.png differ diff --git a/pic/img_4.png b/pic/img_4.png new file mode 100644 index 0000000000000000000000000000000000000000..ea07b179514f2a029b899c74bb729f37db4170bc Binary files /dev/null and b/pic/img_4.png differ diff --git a/pic/img_5.png b/pic/img_5.png new file mode 100644 index 0000000000000000000000000000000000000000..e3e6f3c31fcd1c419b7d3672892d19d08806da24 Binary files /dev/null and b/pic/img_5.png differ diff --git a/pic/img_6.png b/pic/img_6.png new file mode 100644 index 0000000000000000000000000000000000000000..6d530d53f551727959e31a7630582d940e5d1aa9 Binary files /dev/null and b/pic/img_6.png differ diff --git a/pic/img_7.png b/pic/img_7.png new file mode 100644 index 0000000000000000000000000000000000000000..920983543f63756b7a3fc00b971f2f871bc482d6 Binary files /dev/null and b/pic/img_7.png differ diff --git a/pic/img_8.png b/pic/img_8.png new file mode 100644 index 0000000000000000000000000000000000000000..d1d3b8771d7fc6e1f6e56bb20ed7a441e2813254 Binary files /dev/null and b/pic/img_8.png differ diff --git a/pic/img_9.png b/pic/img_9.png new file mode 100644 index 0000000000000000000000000000000000000000..018eca22babfc4d4ee5041cdb668685dbdb5e31b Binary files /dev/null and b/pic/img_9.png differ diff --git a/setupMain.py b/setupMain.py index 8256da372730c0a1c595f132df607f1561a402a9..08f175cd9c2a76b36d31ec840af37b48985ad48a 100644 --- a/setupMain.py +++ b/setupMain.py @@ -38,7 +38,7 @@ def run(): # args = ['-s', '-q', test_case_path,] # args = ['-s', '-q', test_case_path, '--alluredir', - # '/var/jenkins_home/workspace/js/report/xml'] # docker中 jenkins工作空间项目根路径 + # '/var/jenkins_home/workspace/autotest/report/xml',"--clean-alluredir", '-n', '3'] # docker中 jenkins工作空间项目根路径 pytest.main(args) @@ -47,12 +47,12 @@ def run(): # 发送报告 # send_email(localtime + "测试报告", "http://192.168.1.3:9999") # 钉钉发送 - ding = DingTalkSendMsg() - ding.send_text("点击链接打开测试报告 http://192.168.1.3:9999") + # ding = DingTalkSendMsg() + # ding.send_text("点击链接打开测试报告 http://192.168.1.3:9999") # 生成html报告 - os.system(r'allure generate {0} -o {1} --clean'.format(temp_path, html_path)) + # os.system(r'allure generate {0} -o {1} --clean'.format(temp_path, html_path)) # 打开报告服务 并指定端口 - os.system(r'allure serve {0} -p 9999'.format(temp_path)) + # os.system(r'allure serve {0} -p 9999'.format(temp_path)) if __name__ == '__main__': diff --git a/test_suite/datas/demo/biaodan.yml b/test_suite/datas/demo/biaodan.yml index 2cf9d7fad6f0bd72e7a1827cf069b6581e5f2c47..d8a3cbd865fddd0aedf7e0c038c1a625a981a819 100644 --- a/test_suite/datas/demo/biaodan.yml +++ b/test_suite/datas/demo/biaodan.yml @@ -1,5 +1,5 @@ shoucang: - name: ղ + name: shoucang order: 1 token: Cookies file: false @@ -9,7 +9,7 @@ shoucang: jsonpath: sqlassert: null time: 2 - code: 200 + code: 400 data: file: param: 'title=2&author=2&link=2' @@ -18,7 +18,7 @@ shoucang: Content-Type: multipart/form-data Cookie: 'JSESSIONID=99B88CEE3899FE3CFA18F16D8178F6DD; Hm_lvt_90501e13a75bb5eb3d067166e8d2cad8=1649643332,1649654094; loginUserName=13688400244; token_pass=31af42ab609241621eab384a93c8188e; loginUserName_wanandroid_com=13688400244; token_pass_wanandroid_com=31af42ab609241621eab384a93c8188e; Hm_lpvt_90501e13a75bb5eb3d067166e8d2cad8=1649654312' host: demo - info: + info: method: POST cache: relevance: diff --git a/test_suite/datas/demo/login.yml b/test_suite/datas/demo/login.yml index d64bbc202301a439dadac0ebfc2e5b4895417f18..c88ee3f006817a21f96d7a35192d8dd530704b27 100644 --- a/test_suite/datas/demo/login.yml +++ b/test_suite/datas/demo/login.yml @@ -1,5 +1,5 @@ login: - name: ¼ + name: 登录 order: 1 token: false file: false @@ -21,8 +21,8 @@ login: method: POST cookie: true cache: - - cachefrom: 'cookie' # response : ӽлȡ body : Ӳлȡ - path: # body "id=2&path=haha" תֵ Ȼpathʹjsonpathȡֵ + - cachefrom: 'cookie' # response : 从结果中获取 body : 从参数中获取 + path: # body如果是 "id=2&path=haha" 会转换成字典 然后根据path使用jsonpath取值 name: 'cookie' relevance: teardown: diff --git a/util/tools/encryption.py b/util/tools/encryption.py index 57ef12ab53fb4430235a1599f2fc32657c2949e7..3ba568ad48112d591b28195052465e608a48d7b1 100644 --- a/util/tools/encryption.py +++ b/util/tools/encryption.py @@ -21,8 +21,7 @@ class Encryption(object): def __call__(self, func): @wraps(func) def wrapped_function(*args, **kwargs): - # 打开logfile并写入 - # print(kwargs["casedata"]["data"]) + # 处理pytest数据驱动的加密数据 self.data = kwargs["casedata"]["data"] kwargs["casedata"]["data"]["param"] = self.custom_encryption() return func(*args, **kwargs) diff --git a/util/tools/sendEmail.py b/util/tools/sendEmail.py index 2a291712ba8401ffed700621066e0d592b07ec60..d790298edcad5074cacc5c91e5252fb6a4860c99 100644 --- a/util/tools/sendEmail.py +++ b/util/tools/sendEmail.py @@ -5,7 +5,7 @@ from email.header import Header from email.mime.text import MIMEText from config.confManage import mail_manage -from scripts.log import Log +from util.tools.log import Log Log()