Exemple #1
0
 def __init__(self, test_data_path, mode):
     data = Read_xls().read_data(test_data_path, 1)  #默认读取第一个表格
     self.keys_list = data[0]
     self.test_data = []
     if mode == 1:
         Logger().info("[mode:1],本次测试执行基本流测试用例")
         for i in range(1, len(data)):
             if data[i][1] == 1:
                 self.test_data.append(data[i])
                 i += 1
             else:
                 continue
     elif mode == 0:
         Logger().info("[mode:0],本次测试执行全部测试用例")
         self.test_data = data[1:]
     now = time.strftime('%Y-%m-%d-%H-%M-%S')
     global ruselt_path
     ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls"
     self.writedata = WriteExcel()
     self.writedata.creattable("result")
Exemple #2
0
keys_list = datas[0]
test_data=[]
if mode == 1:
    Logger().info("[mode:1],本次测试执行基本流测试用例")
    for i in range(len(datas)):
        if datas[i][2] == 1:
            test_data.append(datas[i])
            i += 1
        else:
            continue
elif mode == 0:
    Logger().info("[mode:0],本次测试执行全部测试用例")
    test_data = datas[1:]

#创建表格,建立表头
writedata = WriteExcel()
writedata.creattable("result")
header=["case_num","explain","result","data","code"]  #第四个开始设置你需要的值(要和报文字典的key值对应)
for n in range(len(header)):
    writedata.write_onlydata(0, n, header[n])
now = time.strftime('%Y-%m-%d-%H-%M-%S')
@ddt
@allure.feature('登录功能接口')
class TestLogin(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        Log=Logger()
        Logger().info("%s测试开始:" % __class__.__name__ )
        cls.Log=Log

    @classmethod
Exemple #3
0
from Common.list_dict import Change
from Common.conf import Read_conf
from Conf import Project_path
from Common.log import Logger
import time
import unittest
from ddt import ddt, data

test_data_path = Project_path.TestData_path + "Test_data.xls"
mode_path = Project_path.Conf_path + "interf_TestMode.conf"
http_conf_path = Project_path.Conf_path + "http.conf"
host = Read_conf(http_conf_path).get_value("HTTP", "host")
mode = Read_conf(mode_path).get_value("Mode", "login_mode")

booknames = Read_xls(test_data_path).get_workbook()
writedata = WriteExcel()
now = time.strftime('%Y-%m-%d-%H-%M')
row = 1


@ddt
class TestAll(unittest.TestCase):
    def setUp(self):
        self.Log = Logger()
        self.r = Read_xls(test_data_path)

    def tearDown(self):
        self.Log.close()

    @data(*booknames)
    def test_run(self, bookname):
Exemple #4
0
class MissionList():
    def __init__(self, test_data_path, mode):
        data = Read_xls().read_data(test_data_path, 1)  #默认读取第一个表格
        self.keys_list = data[0]
        self.test_data = []
        if mode == 1:
            Logger().info("[mode:1],本次测试执行基本流测试用例")
            for i in range(1, len(data)):
                if data[i][1] == 1:
                    self.test_data.append(data[i])
                    i += 1
                else:
                    continue
        elif mode == 0:
            Logger().info("[mode:0],本次测试执行全部测试用例")
            self.test_data = data[1:]
        now = time.strftime('%Y-%m-%d-%H-%M-%S')
        global ruselt_path
        ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls"
        self.writedata = WriteExcel()
        self.writedata.creattable("result")

    def run(self, host):
        header = ["case_num", "explain", "result", "data",
                  "code"]  #第五个开始设置你需要的值(要和报文字典的key值对应)
        for n in range(len(header)):
            self.writedata.write_onlydata(0, n, header[n])
        for i in range(len(self.test_data)):
            list_data = self.test_data[i]
            testcase_num = self.test_data[i][0]
            expalin = self.test_data[i][2]
            url = self.test_data[i][3]
            type = self.test_data[i][4]
            expectation = self.test_data[i][5]
            m = 6  #前面有几个非参数字段这里写几
            data = Change().list_dict(list_data, self.keys_list, m)
            result = Request(host).request(url, data, type)
            try:
                assert int(result["code"]) == expectation, "结果与期望不一致"
                test_result = "Pass"
            except Exception as e:
                Logger().error("第%s条用例[%s]测试失败【%s】" %
                               (testcase_num, expalin, e))
                test_result = "Falie"
            else:
                Logger().info("第%s条用例[%s]测试通过" % (testcase_num, expalin))

            finally:
                self.writedata.write_onlydata(i + 1, 0, testcase_num)
                self.writedata.write_onlydata(i + 1, 1, expalin)
                self.writedata.write_onlydata(i + 1, 2, test_result)
                self.writedata.write_onlydata(i + 1, 3, str(result))
                for h in range(len(header)):
                    if header[h] in list(result.keys()):
                        self.writedata.write_onlydata(i + 1, h,
                                                      str(result[header[h]]))
        self.writedata.save_excel(ruselt_path)
Exemple #5
0
 def __init__(self):
     self.Log=Logger()
     self.r = Read_xls(test_data_path)
     self.writedata = WriteExcel()
Exemple #6
0
class Interfere():
    def __init__(self):
        self.Log=Logger()
        self.r = Read_xls(test_data_path)
        self.writedata = WriteExcel()
    def sheet_books(self):
        self.books = self.r.get_workbook()
        return self.books
    def get_data(self,bookname):
        # self.r = Read_xls(test_data_path)
        # books = self.r.get_workbook()
        test_data=[]
        self.test_datas = self.r.read_data(bookname, 1)
        keys_list = self.r.read_data(bookname, 0)[0]
        if mode == 1:
            Logger().info("[mode:1],本次测试执行基本流测试用例")
            for i in range(len(self.test_datas)):
                if self.test_datas[i][1] == 1:
                    test_data.append(self.test_datas[i])
                    i += 1
                else:
                    continue
        elif mode == 0:
            Logger().info("[mode:0],本次测试执行全部测试用例")
            test_data = self.test_datas
        datas=[]
        datas.append(keys_list)
        datas.append(test_data)
        return datas
    def test_run( self,book_name,test_data,keys_list):
        # 创建表格,建立表头
        self.writedata.creattable(book_name)
        self.header = ["case_num", "explain", "result", "data", "code"]  # 第四个开始设置你需要的值(要和报文字典的key值对应)
        for n in range(len(self.header)):
            self.writedata.write_onlydata(0, n, self.header[n])
        for tdata in test_data:
            global row
            ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls"
            testcase_num = tdata[0]
            explain = tdata[2]
            url = tdata[3]
            type = tdata[4]
            expectation = tdata[5]
            m = 6  # 前面有几个非参数字段这里写几
            data = Change().list_dict(tdata, keys_list, m)
            result = Request(host).request(url, data, type)
            try:
                assert result["code"] == expectation, "与期望值不符"
                test_result = "Pass"
            except Exception as e:
                self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e))
                test_result = "Faile"
                raise e
            else:
                self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain))
            finally:
                self.writedata.write_onlydata(row, 0, testcase_num)
                self.writedata.write_onlydata(row, 1, explain)
                self.writedata.write_onlydata(row, 2, test_result)
                self.writedata.write_onlydata(row, 3, str(result))
                for h in range(len(self.header)):
                    if self.header[h] in list(result.keys()):
                        self.writedata.write_onlydata(row, h, str(result[self.header[h]]))
                row += 1
                self.writedata.save_excel(ruselt_path)
        row = 1
Exemple #7
0
from Common.read_txt import ReadDatadet
from Common.write_xls import WriteExcel

infile='E:\python_space\TestCase\yidian2.0.4页面事件埋点.txt'
data=ReadDatadet(infile)
xls_path='E:\yidian.xls'
sheet_name='埋点'
w=WriteExcel()
w.creattable(sheet_name)
for i in range(len(data)):
    w.write_linedata(i,data[i])
w.save_excel(xls_path)