jenkins調用禪道提交測試用例python腳本

#coding=utf-8
import hashlib
import re
import requests
import datetime
import os
import sys
import io

print(sys.getdefaultencoding())
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding=‘utf-8’)

account = sys.argv[1]
password = sys.argv[2]
product = sys.argv[3]
project = sys.argv[4]
bulid = sys.argv[5]
name = sys.argv[6]

print(account)
print(password)
print(product)
print(project)
print(bulid)
print(name)

#创建session
session = requests.Session()

#设置表单参数
passwordStrength = ‘1’
referer = ‘/zentao/’
keepLogin = ‘0’
frame = ‘pytest’
pri = ‘0’
status = ‘done’

#构建登陆请求头
login_url = ‘http://10.175.94.181:8080/zentao/user-login.html’
response = session.get(login_url)
html = response.text

#正则表达式,获取服务器端发来的随机数
pattern = r"<input\s+type=‘hidden’\s+name=‘verifyRand’\s+id=‘verifyRand’\s+value=‘(\d+)’.*>"
match = re.search(pattern, html)
rand = verifyRand = match.group(1)
passwordmd5 = hashlib.md5((hashlib.md5(password.encode(‘utf-8’)).hexdigest() + rand).encode(‘utf-8’)).hexdigest()

#构建参数
payload = {
‘account’:account,
‘password’:passwordmd5,
‘passwordStrength’:passwordStrength,
‘referer’:referer,
‘verifyRand’:rand,
‘keepLogin’:keepLogin,
}

response = session.post (login_url,data=payload)
print(response.status_code)
print(response.content)

#構建提交請求頭
send_url = ‘http://10.175.94.181:8080/zentao/testtask-importUnitResult-’+product+‘.html’
response = session.get(send_url)
html = response.text
#print(html)

#正則表達式,獲取bulidID,project,uid
#a = ‘NPI部门组织结构和人员信息接口_第三轮测试’
#pattern = r"<option\s+value=‘(\d+)’\s+title=‘“+bulid+”’.*>"
#match = re.search(pattern, html)
#bulid = match.group(1)
print(bulid)

#b = ‘NPI部门组织结构和人员信息接口’
#pattern = r"<option\s+value=‘(\d+)’\s+title=‘“+project+”’.*>"
#match = re.search(pattern, html)
#project = match.group(1)
print(project)

pattern = r"var\s+kuid\s+=\s+‘(.*)’"
match = re.search(pattern, html)
uid = verifyRand = match.group(1)
print(uid)

#獲取當前時間和前一天時間
now = datetime.datetime.now()
one_day = datetime.timedelta(days=-1)
one_day_before = now + one_day
begin = one_day_before.strftime(‘%Y-%m-%d’)
end = now.strftime(‘%Y-%m-%d’)
print(begin)
print(end)

#构建参数
payload = {
‘project’:project,
‘build’:bulid,
‘frame’:frame,
‘owner’:account,
‘pri’:pri,
‘begin’:begin,
‘end’:end,
‘name’:name,
‘desc’:‘’,
‘mailto[]’:‘’,
‘contactListMenu’:‘’,
‘uid’:uid,
‘product’:product,
‘status’:status,
}

headers = {
‘Content-Type’:‘application/xml’
}

#發送請求
#獲取文件
filename = ‘.\testresult.xml’
if not os.path.isfile(filename):
print(f’Error:{filename} does not exist’)
exit()
with open(filename,‘rb’) as f:
resultFile = {‘resultFile’:f}
response = session.post(send_url,data=payload,files=resultFile)

print(response.status_code)
print(response.content)

session.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值