python 项目目录结构
MobileAutomation 项目结构
MobileAutomation
├─ Basefunctest
│ │ __init__.py
│ │
│ ├─ iOS
│ │ │ conftest.py
│ │ │ main.py
│ │ │ test_create_blank_pdf.py
│ │ │ test_file_to_pdf.py
│ │ │ test_merge_pdf.py
│ │ │ test_scan.py
│ │ │ test_web_to_pdf.py
│ │ │ __init__.py
│ │ │
│ │ ├─ common
│ │ │ data_operator.py
│ │ │ func_operator.py
│ │ │ web_operator.py
│ │ │ __init__.py
│ │ │
│ │ └─ page
│ │ │ base_page.py
│ │ │ blank_pdf_page.py
│ │ │ file_content_page.py
│ │ │ locator.py
│ │ │ main_page.py
│ │ │ page_operator.py
│ │ │ scan_page.py
│ │ │ web_to_pdf_page.py
│ │ │ __init__.py
│ │ │
│ │ └─ report
│ │ │ allure_report
│ │ │ allure_result_file
│ │ │
│ └─ tools
│ └─ allure-2.13.9
│ ├─ bin
│ │ allure
│ │ allure.bat
│ │
│ ├─ config
│ │ allure-cucumber.yml
│ │ allure-junit.yml
│ │ allure.yml
│ │
测试入口的 main.py
import os
import shutil
from common import data_operator
from common import func_operator
if __name__ == '__main__':
report_path = os.path.join(data_operator.WORK_SPACE, 'Basefunctest', 'iOS', 'report')
print(f"report_path:{report_path}")
if os.path.exists(report_path):
shutil.rmtree(report_path)
os.mkdir(report_path)
allure_result_file = './report/allure_result_file'
allure_report = './report/allure_report'
execute_str = f"python3 -m pytest --alluredir {allure_result_file}"
environ_dict = os.environ
build_url = environ_dict.get('BUILD_URL')
print(f"jenkins build url:{build_url}")
if build_url:
allure_url = ''.join([build_url, 'allure'])
print(f"jenkins allure url:{allure_url}")
os.system(execute_str)
else:
ip = func_operator.get_host_ip()
port = func_operator.get_free_port(8000, 9000)
print(f"allure server port:{port}")
allure_path = '../tools/allure-2.13.9/bin/allure'
os.system(execute_str)
os.system(f"{allure_path} generate {allure_result_file} -o {allure_report} --clean")
os.system(f"{allure_path} open -h {ip} -p {port} {allure_report}")
jenkins 配置
新建一个节点
当前测试的 iOS 工程需要在 mac 电脑上跑,所以需要在 mac 上搭建一个节点。  ![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-44rSUFFy-1625570438320)(mdpic\jenkins+pytest+allure2.png)]](https://img-blog.csdnimg.cn/20210706192305977.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70) 
启动节点
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-htBLzLGp-1625570438325)(mdpic\jenkins+pytest+allure5.png)]](https://img-blog.csdnimg.cn/2021070619234222.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70)
新建一个项目
配置要运行的节点标签
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uBlwdCKC-1625570438326)(mdpic\jenkins+pytest+allure7.png)]](https://img-blog.csdnimg.cn/20210706192451974.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70)
配置git
添加密码,创建子目录(名字为git的项目名)。其中有一些配置是需要安装jenkins 插件的。 ![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uzV4CctW-1625570438326)(mdpic\jenkins+pytest+allure8.png)]](https://img-blog.csdnimg.cn/20210706192506623.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70) 
配置build
选择了用shell脚本的方式触发测试 ![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zl9JmQSL-1625570438327)(mdpic\jenkins+pytest+allure10.png)]](https://img-blog.csdnimg.cn/20210706192528209.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70)
配置allure插件
和项目中的 main.py 文件中的代码相匹配:测试产生的 allure 文件存在路径、生成报告的路径 ![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OeNCdpgr-1625570438328)(mdpic\jenkins+pytest+allure11.png)]](https://img-blog.csdnimg.cn/20210706192542405.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMzYyNzY3,size_16,color_FFFFFF,t_70) 
展示
  
|