Esempio n. 1
0
 def __init__(self):
     excel_path = os.path.abspath('./Test_Case/ApiCase.xlsx')
     excel = ExcelUtil(excelPath=excel_path, sheetName='数据库')
     connect = excel.next()[0]
     self.host = connect['host']
     self.username = connect['username']
     self.password = connect['password']
     self.db = connect['db']
     self.charset = 'utf8'
     self.port = eval(connect['port'])
Esempio n. 2
0
 def setUpClass(cls):
     sql_data = ExcelUtil(path, sheetName='初始化').next()
     print('### 接口测试开始 ,向数据库中加载测试数据###')
     for i in sql_data:
         insert_sql = i['Insert_sql']
         insert_result = MysqlHelper().insert(sql=insert_sql)
         if insert_result == 1:
             print('Insert Success  -->> %s' % (insert_sql))
         else:
             print('Insert Fail -->> %s' % (insert_sql))
     print('### 数据加载完成 ###')
Esempio n. 3
0
 def tearDownClass(cls):
     sql_data2 = ExcelUtil(path, sheetName='初始化').next()
     print('### 接口测试结束,清理测试数据 ###')
     for j in sql_data2:
         delete_sql = j['Delete_sql']
         delete_result = MysqlHelper().delete(sql=delete_sql)
         if delete_result == 1:
             print('Delete Success  -->> %s' % (delete_sql))
         else:
             print('Delete Fail -->> %s' % (delete_sql))
     print('### 清理完成 ###')
def send_email(newfile):
    try:
        f=open(newfile,'rb')
        mail_body=f.read()
        f.close()
        #发送邮箱服务器
        smtpserver = 'smtp.163.com'
        user = '******'
        password='******' #授权码
        #发送&接收邮箱
        path = os.path.abspath('./Test_Case/ApiCase.xlsx')
        email_list = ExcelUtil(path, sheetName="execute").next()[0]
        sender = email_list['email_sender']
        receiver = email_list['email_receiver'].split('\n')

        # sender='*****@*****.**'
        # receiver=['*****@*****.**']
        #发送邮件主题
        subject = '接口自动化测试报告'

        #编写 HTML类型的邮件正文
        msg=MIMEMultipart('mixed')

        #注意:由于msg_html在msg_plain后面,所以msg_html以附件的形式出现
        #text = "Dear all!\n附件是最新的测试报告。\n麻烦下载下来看,用谷歌浏览器打开查看,附件包含所有案例执行详情。\n请知悉,谢谢。"
        #msg_plain = MIMEText(text,'plain', 'utf-8')
        #msg.attach(msg_plain)

        msg_html2 = MIMEText(mail_body,'html','utf-8')
        msg.attach(msg_html2)

        msg_html = MIMEText(mail_body,'html','utf-8')
        msg_html["Content-Disposition"] = 'attachment; filename="TestReport.html"'
        msg.attach(msg_html)

        #要加上msg['From']这句话,否则会报554的错误。
        msg['From'] = '[email protected] <*****@*****.**>'
        msg['To'] = ";".join(receiver)
        msg['Subject']=Header(subject,'utf-8')

        #连接发送邮件
        smtp=smtplib.SMTP()
        smtp.connect(smtpserver,25)
        smtp.login(user, password)
        smtp.sendmail(sender, receiver, msg.as_string())
        smtp.quit()
    except Exception as e:
        print("发送邮件失败:" + str(e))
Esempio n. 5
0
import unittest, ddt, time, os, json
import warnings
from API_Test.HwTestReport.HwTestReport import HTMLTestReport
from API_Test.Get_TestCase.read_excel import ExcelUtil
from API_Test.script.api_script import CaseScript

excel = ExcelUtil("G:\LocalGit\github\QiuW\API_Test\Test_Case\ApiCase.xlsx",
                  '汇总')


@ddt.ddt
class DataTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # warnings.simplefilter('ignore',ResourceWarning)
        print('### 接口测试开始 ###')

    @classmethod
    def tearDownClass(cls):
        time.sleep(1)
        print('### 接口测试结束 ###')

    @ddt.data(*excel.next())
    def test01(self, data):
        body_data = {}  # 每次遍历后将字典置为空
        ReqMethod = data['请求方式']
        url2 = data['接口地址']
        Except1 = data['状态码']
        Except2 = data['响应文本']

        if ReqMethod == 'get':
Esempio n. 6
0
import unittest, ddt, time, os, json, warnings
from API_Test.HwTestReport.HwTestReport import HTMLTestReport
from API_Test.Get_TestCase.read_excel import ExcelUtil
from API_Test.public_cls.my_unit import MyUnit
from API_Test.script.api_script import CaseScript
from jsonpath import jsonpath

path = os.path.abspath('./Test_Case/ApiCase.xlsx')
execute_sheet_name = ExcelUtil(path,
                               sheetName="execute").next()[0]['execute_sheet']
excel = ExcelUtil(path, sheetName=execute_sheet_name)


@ddt.ddt
class DataTest(MyUnit):
    @ddt.data(*excel.next())
    def test_TC(self, data):
        """测试%s""" % (data['用例标题'])
        body_data = {}  # 每次遍历后将字典置为空
        ReqMethod = data['请求方式']
        url2 = data['接口地址']
        Except1 = data['状态码']
        Except2 = data['响应包含']
        json_path = data['JsonPath_Assert']
        test_data = json.loads(data['参数'])
        sql = data['Sql_Assert']
        #处理有变量的参数
        if len(data['变量设置']) != 0:
            test_data = CaseScript().var_deal(var_set=data['变量设置'],
                                              deal_data=data['参数'])
        #log打印案例信息