appium+jenkins自动化集成

时间:2021-02-23 14:07:27   收藏:0   阅读:0

1、linux 服务器上安装python、jdk、appium、nodejs、Android SDK 、Jenkins、Allure、Allure Commandline等

AndroidSDK安装:https://blog.csdn.net/qq_40308101/article/details/108578650

appium 安装:https://blog.csdn.net/vensers/article/details/105955197

allure 安装:https://blog.csdn.net/bang152101/article/details/108874136

Jenkins安装:https://blog.csdn.net/linkingfei/article/details/105309076

2、Jenkins 配置截图

技术图片

 

 

脚本执行代码:

技术图片
# -*- coding: utf-8 -*
import os
import shutil
import subprocess
import time
from pylib import Log
from pylib import commonlib
import pytest

PATH = os.path.split(os.path.realpath(__file__))[0]
xml_report_path = PATH + "/report/xml"
html_report_path = PATH + "/report/html"
commonlib.create_dir_not_exist(xml_report_path)
commonlib.create_dir_not_exist(html_report_path)

tm = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(time.time()))

def invoke(md):
    output, errors = subprocess.Popen(md,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()
    o = output.decode("utf-8")
    return o

if __name__ == __main__:

    log = Log.MyLog()
    log.info(
        f"---------------------------START: {tm}------------------------------")
    shutil.rmtree(xml_report_path)
    # 获取外部传参
    if os.environ[opt] == new:
        args = [-s, -q,-k,test_alipay_new_buyTicket_DES,--instafail, --tb=line, --alluredir, xml_report_path]
    elif os.environ[opt] == old_all:
        args = [-s, -q, -k, oldTicket, --instafail, --tb=line, --alluredir,xml_report_path]
    elif os.environ[opt] == other:
        args = [-s, -q, -k, test_other_applet_buyTicket, --instafail, --tb=line, --alluredir,xml_report_path]
    elif os.environ[opt] == old_des:
        args = [-s, -q, -k, test_buyTicket_DES, --instafail, --tb=line, --alluredir,xml_report_path]
    elif os.environ[opt] == old_sec:
        args = [-s, -q, -k, test_buyTicket_SEC, --instafail, --tb=line, --alluredir, xml_report_path]
    elif os.environ[opt] == old_appoint:
        args = [-s, -q, -k, test_appointTicketSec, --instafail, --tb=line, --alluredir, xml_report_path]
    else:
        args = [-s, -q, --instafail, --tb=line, --alluredir, xml_report_path]
    # 运行上次失败用例
    # args = [‘-s‘,‘-q‘,‘--lf‘,‘--alluredir‘, xml_report_path]
    pytest.main(args)
    cmd = allure generate %s -o %s --clean % (xml_report_path,
                                                html_report_path)
    invoke(cmd)
    log.info(
        f"-----------------------------END: {tm}-------------------------------")    
脚本执行代码

技术图片

 

 

技术图片

 

 技术图片

 

 构建命令代码:

echo ${opt}
HOME=/home/aut
source /etc/profile
source /home/aut/.bashrc
pyenv activate ${JOB_NAME}
pip install -r requirements_linux.txt -i https://mirrors.aliyun.com/pypi/simple
python run.py ${opt}
curl -H "Content-Type:application/json" -H "authorization:" -X POST --data { "job": "${JOB_NAME}", "build":${BUILD_NUMBER}} http://192.168.10.XX:5000/aut/sentReport

技术图片

 

 

 

 后台启动appium:

nohup appium > appium.log 2>&1 &

python 用例执行失败,触发Jenkins构建失败

链接:https://www.pythonheidong.com/blog/article/319258/5dd210e741d49e1fa45a/

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!