选了一圈还是用pytest 来做自动化测试,第一步安装,自己的电脑里用的是virtualenv 环境,先把环境安装好。
virtualenv -p python3 p3
在当前目录下生成了一个p3 目录,执行 source p3/bin/activate 进入Python3环境.
1.安装pytest
pip install --upgrade pip #先升级一下pip
pip install pytest
查看一下pytest –version 出来版本号 pytest 6.2.4
继续安装pytest 的插件
pip install pytest-progress
pip install pytest-sugar
pip install allure-pytest
2.安装allure
这是用来生成报告的
安装 allure
brew install allure #mac 下安装在
终端下 执行 allure --version 输出版本号 O
从GIT把 requests 给拉了一下来,里面有一个tests目录,执行一下
pytest requests/tests --alluredir=./results
再用generate 生成报告
allure generate results -o report --clean
还有另外一种
allure serve ./results
e服务器上用的Centos 也需要安装Chrome.
1.
1.vi /etc/yum.repos.d/google.repo
添加
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
2.yum update
3.yum install google-chrome-stable
2.
下一步下载
https://npm.taobao.org/mirrors/chromedriver/下到对应版本的liunx格式的chrome-driver 到指定目录,并将权限 chmod -R 755.
再执行 OK
最后一步配置Jenkins
1.在Jenkins 里安装插件
HTML Publisher plugin
Allure Jenkins Plugin
2.在全局配置里找到
输入allure 保存
3.建一个自由风格的项目
在Build 里选择Execute shell
#!/bin/bash
cd /data/pytest/mygoodreal/src
source ../../p3/bin/activate
pytest --driver Chrome -v --cache-clear --alluredir "${WORKSPACE}/target/allure-results" tests/
exit 0
用了Python 的 virtualenv 的,得用source 进入 python3 的环境
exit 0得有,不然会报错