Exemplo n.º 1
0
 def write_xls(self, xls_name, sheet_name, row, result_text, result):
     self.xlsPath = os.path.join(getpath(), "Case_data", xls_name)
     wb = openpyxl.load_workbook(self.xlsPath)
     ws = wb[sheet_name]
     ws.cell(row=row, column=7).value = result_text
     ws.cell(row=row, column=8).value = result
     wb.save(self.xlsPath)
Exemplo n.º 2
0
 def __init__(self, level=yaml.log('level'), logger_name='hsc'):
     self.logger = logging.getLogger(
         logger_name)  # # 获取logger实例,如果参数为空则返回root logger、创建一个logger
     if not self.logger.handlers:
         formatter = logging.Formatter(  # 指定logger输出格式
             '时间:%(asctime)s '  # 时间,默认精确到毫秒
             # '文件名:%(filename)s ' # 日志文件名
             # '模块名:%(module)s ' #日志模块名
             # '方法:%(funcName)s '  # 日志函数名
             # '代码行:%(lineno)d ' # 日志模块代码行
             '级别:%(levelname) s '  # log级别
             # '路径:%(pathname)s ' # 完整路径
             '消息:%(message)s'  # 打印的消息
         )
         current_data = time.strftime('%Y-%m-%d',
                                      time.localtime(time.time()))  # 当前系统日期
         log_name = '{}.log'.format(current_data)  # 每天一份日志
         log_file = os.path.join(configpath.getpath(),
                                 'logs/{}'.format(log_name))  # log路径
         file_handler = logging.FileHandler(log_file,
                                            encoding='utf-8')  # 文件日志
         file_handler.setFormatter(formatter)  # 可以通过setFormatter指定输出格式
         self.console_handler = logging.StreamHandler(sys.stdout)  # 控制台日志
         self.console_handler.setFormatter(formatter)  # 也可以直接给formatter赋值
         self.logger.addHandler(self.console_handler)  # 为logger添加的日志处理器
         self.logger.addHandler(file_handler)  # 为logger添加的日志处理器
         self.logger.setLevel(
             level
         )  # log级别(NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL对应的值分别为:0,10,20,30,40,50)
Exemplo n.º 3
0
 def get_xls(self, xls_name, sheet_name):
     cls = []
     cls1 = []          #实验列表
     self.xlsPath = os.path.join(getpath(), "Case_data", xls_name)
     file = open_workbook(self.xlsPath, 'r')                  #打开工作簿
     sheet = file.sheet_by_name(sheet_name)              #通过名字打开工作簿
     rows = sheet.nrows
     for i in range(rows):
         if sheet.row_values(i)[0] != 'case_id':
             cls.append(sheet.row_values(i))
     return cls
Exemplo n.º 4
0
 def write_xls(self, xls_name, sheet_name):
     list = self.get_xls('case_xy_huawei.xlsx', 'Sheet5')
     self.xlsPath = os.path.join(getpath(), "Case_data", xls_name)
     wb = openpyxl.load_workbook(self.xlsPath)
     ws = wb[sheet_name]
     for i in list:
         ws.cell(row=int(i[0]), column=1).value = int(i[0])
         ws.cell(row=int(i[0]), column=2).value = i[1]
     wb.save(self.xlsPath)
     ws['A1'] = 24
     ws.cell(row=1, column=3).value = 123
     wb.save(self.xlsPath)
Exemplo n.º 5
0
 def __init__(self, **kwargs):
     self.kwargs = kwargs
     self.send_name_from = read_ini('EMAIL', 'cc_name')
     self.send_pwd_from = read_ini('EMAIL', 'cc_pwd')
     self.send_pd_from = read_ini('EMAIL', 'cc_pd')
     self.send_subject = read_ini('EMAIL', 'subject')
     self.send_name_to = read_ini('EMAIL', 'address')
     self.email_host = read_ini('EMAIL', 'mail_host')
     self.email_text = read_ini('EMAIL', 'TEXT')
     self.mail_body = open(
         os.path.join(configpath.getpath(), 'result', 'report.html'),
         'rb').read()
Exemplo n.º 6
0
 def get_xls(self, xls_name, sheet_name):
     cases = []
     xlspath = os.path.join(getpath(), "Case_data", xls_name)
     file = openpyxl.load_workbook(xlspath)
     sheet = file[sheet_name]
     rows = sheet.max_row
     for i in range(2, rows+1):
         case = Case()
         case_id = sheet.cell(row=i, column=1).value
         case_name = sheet.cell(row=i, column=2).value
         case_method = sheet.cell(row=i, column=3).value
         case_url = sheet.cell(row=i, column=4).value
         case_datas = sheet.cell(row=i, column=5).value
         case_expected = sheet.cell(row=i, column=6).value
         case.id = case_id
         case.name = case_name
         case.method = case_method
         case.url = case_url
         case.datas = case_datas
         case.expected = case_expected
         cases.append(case)
Exemplo n.º 7
0
import urllib.request
from configpath import getpath
import re
import chardet
import os
from read_writeyaml import MyYaml
path = os.path.join(getpath(), 'images')
page = urllib.request.urlopen(MyYaml().reptile('url'))
htmlCode = page.read() #获取网页源代码
print(chardet.detect(htmlCode)) #打印返回网页的编码方式
# print(htmlCode.decode('utf-8')) #打印网页源代码
data = htmlCode.decode('utf-8')
# pageFile = open('pageCode.txt', 'wb')#以写的方式打开pageCode.txt
# pageFile.write(htmlCode)#写入
# pageFile.close()#开了记得关
reg = MyYaml().reptile('matching')#正则表达式  ,,匹配以src="开头然后接一个或多个任意字符(非贪婪),以.jpg" 结尾的字符串

reg_img = re.compile(reg)#编译一下,运行更快
imglist = reg_img.findall(data)#进行匹配
x = 0
for img in imglist:
    print(img)
    urllib.request.urlretrieve('%s' % img, '%s\\%s.jpg' % (path, x))      #路径加文件名,保存在指定文件夹下
    x += 1
Exemplo n.º 8
0
 def __init__(self):
     self.url = MyYaml().reptile('url')
     self.url2 = MyYaml().reptile("url2")
     self.path = os.path.join(getpath(), 'my_reptile', 'result', MyYaml().reptile('file'))
     self.re = MyYaml().reptile("matching")
Exemplo n.º 9
0
import requests
import redis
from write_readini import write_ini
from write_readini import read_ini
from read_writeyaml import MyYaml
import os
from configpath import getpath
path = getpath()
projectName = MyYaml().config('projectName')
matching = MyYaml().config('matching')

# url = "http://twork.zhanye.wallet.openapi.youxin.info:42981"
# urladdress = "http://twork.zhanye.wallet.openapi.youxin.info:42981/v1/access_token"
# payload = {
#             'account': '637A5A9B-13B6-0C9A-D878-A33FE2D988CF',
#             'pass': '******'
#         }
# r = requests.post(urladdress, params=payload)
# result = r.json()
#print(result['token'])
#写入ini文件
# write_ini(node='session', child='tokennn', content=result['token'])

#读取ini文件
# tokk = read_ini(node='session', child='tokennn')
# print(tokk)
# a =  matching.split('_')
# print(a)

#
# moudleName = MyYaml().config('moudleName')
Exemplo n.º 10
0
import requests
import unittest
from models.Read_xls import readExcel
from myloging import Loging
import ddt
from read_writeyaml import MyYaml
from models import HTMLTestRunner3
from configpath import getpath
from models.myunit import mytest
import os
log = Loging()
report1 = os.path.join(getpath(), 'result', 'report.html')


@ddt.ddt
class TestGetNodeList_auth(unittest.TestCase):
    data = readExcel().get_xls('case_xy_huawei.xlsx', 'GetNodeList')

    @ddt.data(*data)
    def test_auth_GetNodeList(self, data):
        r = requests.post(MyYaml().config('url') + data.url, data.datas)
        self.result = r.json()
        time1 = r.elapsed.total_seconds()
        print('接口响应时间:' + str(time1))
        log.info('第{}条用例执行'.format(data.id))
        log.info('用例名称:{}'.format(data.name))
        log.info('接口响应时间为:{}'.format(time1))
        print(self.result)
        self.assertEqual(eval(data.expected)['status'], self.result['status'])

Exemplo n.º 11
0
import requests
from models.myunit import mytest
from myloging import Loging
from read_writeyaml import MyYaml
import ddt
from models.Read_xls import readExcel
logg = Loging()
import unittest
from models import HTMLTestRunner
from configpath import getpath
import os
report1 = os.path.join(getpath(), 'result', 'GetRouteList.html')


@ddt.ddt
class GetRouteList_auth(unittest.TestCase):
    """获取游戏路由表接口"""
    data = readExcel().get_xls('case_xy_huawei.xlsx', 'GetRouteList')

    @ddt.data(*data)
    def test_auth_GetRouteList(self, data):
        """获取游戏路由表"""
        r = requests.post(MyYaml().config('url') + data.url,
                          data.datas,
                          stream=True)
        self.result = r.json()
        time1 = r.elapsed.total_seconds()
        print('接口响应时间:' + str(time1))
        logg.info('第{}条用例执行'.format(data.id))
        logg.info('用例名称:{}'.format(data.name))
        logg.info('接口响应时间为:{}'.format(time1))
Exemplo n.º 12
0
 def __init__(self):
     self.url = MyYaml().reptile('url')
     self.matching = MyYaml().reptile('matching')
     self.path_images = os.path.join(getpath(), 'images')
     self.path_file = os.path.join(getpath(), 'Py_file', 'test.txt')
     self.method = MyYaml().reptile('method')
Exemplo n.º 13
0
import unittest
from models.myunit import mytest
import os
from configpath import getpath

path = os.path.join(getpath(), 'Case\\XY')


class RunAllClass(object):
    def __init__(self):
        pass

    def run_module(self):
        """
        运行单个模块
        :param moduleName:
        :return:
        """

        # suite = unittest.TestSuite()
        # suite.addTest(mytest.parametrize(moudlename, param=None))
        # runner = unittest.TextTestRunner(verbosity=1)   #执行测试用例集 ,,verbosity 有 0 1 2 三个级别,verbosity=2 的输出最详细
        # result = runner.run(suite)           #失败用例列表
        # print(result)
        # print('sadf')
        discover = unittest.defaultTestLoader.discover(path, pattern="*_st.py")
        runner = unittest.TextTestRunner()
        runner.run(discover)


if __name__ == '__main__':
Exemplo n.º 14
0
import configparser
import os
import configpath

path = configpath.getpath()
pathload = os.path.join(path, 'confing.ini')


def write_ini(node='session', child='userKey', content=None):
    """写入ini文件"""
    config = configparser.ConfigParser()
    config.read(pathload, encoding='utf-8')

    try:
        #config.add_section("session") #增加节点
        config.set(node, child, content)
    except configparser.DuplicateSectionError:
        print("ini配置文件写入失败")

    f = open(pathload, "w", encoding='utf-8')
    config.write(f)
    f.close()


def read_ini(node='session', child='token'):
    '''读ini文件'''

    config = configparser.ConfigParser()
    config.read(pathload, encoding='utf-8')
    try:
        connect = config.get(node, child)
Exemplo n.º 15
0
import requests
from bs4 import BeautifulSoup
import re
from configpath import getpath
import os
path = os.path.join(getpath(), 'Py_file', 'test.txt')
print(path)

url = 'http://www.cntour.cn/'
strhtml = requests.get(url)

soup = BeautifulSoup(strhtml.text, 'lxml')

data = soup.select(
    '#main>div>div.mtop.firstMod.clearfix>div.centerBox>ul.newsList>li>a')

for item in data:
    result = {
        'title': item.get_text(),  #提取标签的正文用 get_text() 方法
        'link': item.get('href'),  #提取标签中的 href 属性用 get() 方法
        'ID': re.findall('\d+', item.get('href'))
    }
    write = str(result) + '\n'
    with open(path, 'a', encoding='utf-8') as e:
        e.write(write)
Exemplo n.º 16
0
import os
import platform
import unittest
import time
import json
import sys
import threading
from read_writeyaml import MyYaml
from myloging import Loging
from write_readini import write_ini, read_ini
from models.myunit import mytest
from models.myunit_per import ReadYaml
from models.MyRedis import Myredis as redis
from configpath import getpath

pathh = os.path.join(getpath(), 'result', 'report.html')

log = Loging()
redis = redis()
path = getpath()


class myThread(threading.Thread):  #继承父类threading.Thread
    def __init__(self, threadID, name, module, times):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.module = module
        self.time = times

    def run(self):