def run(self): try: # 调用set_case_suite获取test_suite suit = self.set_case_suite() print("suit:", suit) # 判断test_suite是否为空 if suit is not None: # 打开result/report.html测试报告文件,如果不存在就创建 fp = open(resultPath, 'wb') # 调用HTMLTestRunner 这个文件不用管 网上有可以直接下载的 runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title="测试报告", description="测试说明") runner.run(suit) else: print("没有案例可以测试") finally: on_off = readConfig.ReadConfig().get_email('on_off') if on_off == 'on': #configEmail.Email().send_email() print("发送邮件") elif on_off == 'off': print('发送邮件已关闭') fp.close()
def testgetOwnerid(self): # if self.case_name == "gzhlogincase": method = readConfig.ReadConfig().get_http("method") path = readConfig.ReadConfig().get_http("path") data = readConfig.ReadConfig().get_http("data") url = readConfig.ReadConfig().get_http("gzhbaseurl") datajson = json.loads(data) print(datajson) print(url + path) info = RunMain().run_main(method, url + path, datajson) res = json.loads(info) print("----", res) if res['Code'] == "000000": global ShipOwnerId ShipOwnerId = res['Data']['ShipOwnerId'] else: print("ShipOwnerId值错误") return ShipOwnerId
import os import smtplib import threading import zipfile import glob import getPath from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from datetime import datetime from read import readConfig localReadConfig = readConfig.ReadConfig() #SMTP 服务器主机 mail_host = localReadConfig.get_email('mail_host') #指定 SMTP 服务使用的端口号 mail_port = localReadConfig.get_email('mail_port') #用户名 mail_user = localReadConfig.get_email('mail_user') #邮件密码 授权码 mail_pass = localReadConfig.get_email('mail_pass') #邮件发送方邮箱地址 sender = localReadConfig.get_email('sender') #接受邮件放邮箱地址 value = localReadConfig.get_email('receiver') title = localReadConfig.get_email('subject') content = localReadConfig.get_email('content') class Email(): def __init__(self): self.receiver = []
#author:zwx import json import unittest import paramunittest import requests import urllib.parse import read.readExcel as readExcel from common.configHttp import RunMain import read.readConfig as readConfig push_xls = readExcel.ReadExcel().get_xls("login.xls", "push") url = readConfig.ReadConfig().get_http("xcxbaserurl") #获取配置文件中的url地址 gzhurl = readConfig.ReadConfig().get_http("gzhbaseurl") @paramunittest.parametrized(*push_xls) class testpush(unittest.TestCase): def setParameters(self, case_name, path, data, method, isTest): self.case_name = str(case_name) self.path = str(path) self.data = str(data) self.method = str(method) self.isTest = str(isTest) #调用测试方法 def testuserOrder(self): self.pushlog() self.shareposter() #添加推送记录 def pushlog(self):
import requests import read.readConfig as readConfig import json from common.configHttp import RunMain import unittest url = readConfig.ReadConfig().get_http("gzhonlineurl") #获取配置文件中的url地址 response = requests.get( url + '/api/login/detail?token=gzhlogin:0f289302-3cbd-4a5a-8e47-edd071a0a1d0') versionInfo = response.text versionInfoPython = json.loads(versionInfo) dataList = versionInfoPython.get('Data') shipOwnerId = dataList.get('ShipOwnerId') goods = requests.get(url + '/api/ware/' + shipOwnerId + '/shipowner/alllist') goodsInfo = goods.text goodsList = json.loads(goodsInfo).get('Data') WareDTOs = goodsList.get('WareDTOs') wareId = WareDTOs[0].get('Id') xcxtoken = 'xcxlogin%3A16e265ff-ff1f-4ab1-a998-1f6325c8a357&AppInfoCode=code001&MerchantId=645d5071-1c22-4161-a093-7566f5cca058'
import json import unittest import paramunittest import urllib.parse import read.readExcel as readExcel from common.configHttp import RunMain import read.readConfig as readConfig login_xls = readExcel.ReadExcel().get_xls("login.xls", "shagnhu") url = readConfig.ReadConfig().get_http("baseurl") #获取配置文件中的url地址 #@paramunittest.parametrized(*变量名)-----变量名为excel文件, #setParameters方法里面的参数为excel文件中的列的变量名,必须与之完全一样,不能多加和少减 @paramunittest.parametrized(*login_xls) class testUserLogin(unittest.TestCase): def setParameters(self, case_name, path, data, method, isTest): self.case_name = str(case_name) self.path = str(path) self.data = str(data) self.method = str(method) self.isTest = str(isTest) def description(self): self.case_name def setUp(self): print(self.case_name + "------------测试开始------------------") #调用测试方法 def testShanghu(self):
import json import paramunittest import write.WriteExcel as WriteExcel from common.configHttp import RunMain import unittest import read.readConfig as readConfig import read.readExcel as readExcel import getPath book = WriteExcel.writeExcel() basepath = getPath.get_basepath() EnterShop = readExcel.ReadExcel().get_xls("EnterShop.xlsx", "shop") url = readConfig.ReadConfig().get_http("baseurl") @paramunittest.parametrized(*EnterShop) class testEnterShop(unittest.TestCase): def setParameters(self, case_name, path, data, method): self.case_name = case_name self.path = path self.data = data self.method = method def description(self): self.case_name def setUp(self): print("测试开始") def testGetEnterShop(self): self.GetEnterShop()
import json import unittest import paramunittest import urllib.parse import read.readExcel as readExcel from common.configHttp import RunMain import read.readConfig as readConfig login_xls = readExcel.ReadExcel().get_xls("login.xls", "login") url = readConfig.ReadConfig().get_http("loginurl") @paramunittest.parametrized(*login_xls) class testUserLogin(unittest.TestCase): def setParameters(self, case_name, path, data, method): self.case_name = str(case_name) self.path = str(path) self.data = str(data) self.method = str(method) def description(self): self.case_name def setUp(self): print(self.case_name + "测试开始前准备") #调用测试方法 def testLogin(self): self.checkResult() def tearDown(self):