Beispiel #1
0
class Run_case():
    def __init__(self, excelpath, file_path):
        self.data = Getdata(excelpath=excelpath)
        self.opexcel = oper_excel(filename=excelpath)
        self.file_path = file_path

    def banch_case(self):
        rows_count = self.data.get_case_lines()
        print("**********", rows_count)
        # print(rows_count)
        # 排除表头,从-1开始
        for i in range(1, rows_count):
            url = self.data.get_url(i)
            functionname = self.data.get_functionname(i)
            # method = self.data.get_method(i)
            isrun = self.data.get_is_run(i)
            # print("第", i, "条执行记录", isrun, functionname)
            # print("+++++++",url,isrun,functionname)
            # 查看运行状态是否运行
            if isrun:
                # print("第", i, "条执行记录", isrun, functionname)
                res = requests_batch(file_path=self.file_path + "/" +
                                     functionname + ".json",
                                     params_name=functionname,
                                     url=url)
                try:
                    print(res.json)
                except Exception as e:
                    print("未返回数据")
class exceltodb:
    def __init__(self):
        self.excelpath= "../Test_Case/Paper_Process.xls"
        self.db,self.connect  = DB_CONNECT(2).connect_db()
        self.excel = oper_excel(filename="../Test_Case/Paper_Process.xls")
        self.data = Getdata(excelpath=self.excelpath)
    def read_excel(self):
        print("开始")
        workbook =xlrd.open_workbook("../Test_Case/Paper_Process.xls")
        table = workbook.sheet_by_index(0)
            # 获取数据
        rows_count = self.data.get_case_lines()
        print("hangshu",rows_count)
        for i in range(30,rows_count):
            v1 = int(self.excel.get_cell_value(i,0))
            v2=str(self.excel.get_cell_value(i,1))
            v3 = int(self.excel.get_cell_value(i, 2))
            v4 = str(self.excel.get_cell_value(i, 3))
            v5= str(self.excel.get_cell_value(i, 4))
            v6 = str(self.excel.get_cell_value(i, 5))
            v7 = str(self.excel.get_cell_value(i,6))
            v8 = str(self.excel.get_cell_value(i, 7))
            v9 = self.excel.get_cell_value(i, 8)
            v10 = str(self.excel.get_cell_value(i, 9))
            v11 = self.excel.get_cell_value(i, 10)
            v12 = str(self.excel.get_cell_value(i, 11))
            v13 = str(self.excel.get_cell_value(i, 12))
            v14 = self.excel.get_cell_value(i, 13)
            v15 = self.excel.get_cell_value(i, 14)
            v16 = self.excel.get_cell_value(i, 15)
            v17 = self.excel.get_cell_value(i, 16)
            sql = "INSERT INTO Paper_Process VALUES(%s,'%s',%s,'%s','%s','%s','%s','%s',%s,'%s','%s','%s','%s','%s','%s','%s','%s')"%(v1,v2,v3,v4,v5,v6,v7,v8,v9,pymysql.escape_string(v10),v11,v12,v13,v14,v15,v16,v17)
            print(sql)
            # print(sql)
            # self.db.execute(sql)
            # self.connect.commit()
# if __name__ == '__main__':
#     a = exceltodb().read_excel()
Beispiel #3
0
class Run_case():
    # class执行前执行,且一个class只执行一次
    # @classmethod
    # def setupClass(cls):
    #     print('class执行前执行')
    # # 每个方法执行前执行一次
    # def setUp(self):
    #     print('test前执行')
    def __init__(self, excelpath=None, jsonpath=None):
        self.tablename = Case_Table().get_tablename()
        if excelpath:
            self.excelpath = excelpath
        else:
            self.excelpath = "../Test_Case/" + self.tablename + ".xls"
        if jsonpath:
            self.jsonpath = jsonpath
        else:
            self.jsonpath = "../data/" + self.tablename + ".json"
        self.run_method = inter()
        self.data = Getdata(self.excelpath, self.jsonpath)
        self.result = isequal()
        self.sendmail = sendmail()
        self.page_check = PageCheck()
        self.de_data = dependata(self.excelpath, self.jsonpath)
        self.caserun = Case(excelpath=self.excelpath, jsonpath=self.jsonpath)
        self.opexcel = oper_excel(filename=excelpath)
        self.DBCASE = Get_case()

    # 学生登陆cookies
    def student_cookies(self):
        cookies = Get_cookies(2)
        return cookies.getcookies_web()

    #admin登陆cookies
    def admin_cookies(self):
        cookies = Get_cookies(1)
        return cookies.get_cookies_admin()

    # 教师登陆cookies
    def teacher_cookies(self):
        cookies = Get_cookies(3)
        return cookies.getcookies_web()

    def go_run(self):
        # pass_count = []
        # fail_count = []
        res = None
        # 数据库中获取案例,写至表格中
        self.DBCASE.create_excel()
        # 获取需执行案例总数量
        rows_count = self.data.get_case_lines()
        # book = xlrd.open_workbook(filename=self.excelpath, formatting_info=True).sheet_by_index(0)
        # # 将上次的执行结果清除
        # for i in range(1, rows_count):
        #     self.opexcel.write_value(i, 13, "")
        #     self.opexcel.write_value(i, 16, "")
        # del book
        # print("清除原测试结果数据")
        # 排除表头,从-1开始
        for i in range(1, rows_count):
            caseid = self.data.get_case_id(i)
            url = self.data.get_url(i)
            functionname = self.data.get_functionname(i)
            web_admin = self.data.get_web_admin(i)
            method = self.data.get_method(i)
            isrun = self.data.get_is_run(i)
            data = self.data.get_data_json(i)
            file = self.data.get_files(i)
            return_value = self.data.get_return_value(i)
            # 若url为拼接方式
            if "+" in url:
                #     则获取到拼接参数
                url_data = self.de_data.depend_data(i)
                # print("表格里数据",url,url_data)
                url = url.split("+")[0] + str(url_data)
                # print("拼接后",url,type(url_data),type(str(url_data)))
            if file:
                files = {"logo1": ("aa.jpg", open(file, "rb"), "image/jpeg")}
            else:
                files = None
            # cookies = self.data.get_cookies(i)
            expect = self.data.get_expect(i)
            webexpect = self.data.get_web_expectvalu(i)
            depen_case = self.data.get_case_depen(i)
            depend_data = self.de_data.depend_data(i)
            # print("*****第",i,"个",data,depen_data,depen_filed)
            # 查看运行状态是否运行
            # 判断是否是后台案例
            if isrun and web_admin == 0:
                # 首先获取cookie,请求代入cookies
                cookies = self.admin_cookies()
                # 执行案例
                self.caserun.case_run(caseid, rows_count, depen_case,
                                      depend_data, url, method, data, cookies,
                                      expect, i, webexpect, functionname,
                                      files, return_value)
            # 判断是否是学生端案例
            elif isrun and web_admin == 1:
                cookies = self.student_cookies()
                self.caserun.case_run(caseid, rows_count, depen_case,
                                      depend_data, url, method, data, cookies,
                                      expect, i, webexpect, functionname,
                                      files, return_value)
            # 判断是否是教师端案例
            elif isrun and web_admin == 2:
                cookies = self.teacher_cookies()
                self.caserun.case_run(caseid, rows_count, depen_case,
                                      depend_data, url, method, data, cookies,
                                      expect, i, webexpect, functionname,
                                      files, return_value)
Beispiel #4
0
class report():
    def __init__(self, filename=None, new_filename=None, report_path=None):
        self.tablename = Case_Table().get_tablename()
        if filename:
            self.filename = filename
        else:
            self.filename = "../Test_Case/" + self.tablename + ".xls"
        if new_filename:
            self.new_filename = new_filename
        else:
            self.new_filename = "../Test_Case/" + self.tablename + "_bk.xls"
        if report_path:
            self.report_path = report_path
        else:
            self.report_path = "../Test_Case/TestCase.html"
        self.data = Getdata()

    def order_excel(self):
        read_excel = xlrd.open_workbook(self.filename)
        # 借助辅助数组,rows_mark
        rows_mark = []
        #遍历是否执行列数据
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            isrun = self.data.get_is_run(i)
            #如果不执行,则将该行数记录
            if isrun == False:
                rows_mark.append(i)
        return rows_mark

    #生成报告
    def creat_report(self):
        # 获取不执行案例所在行数
        rows = self.order_excel()
        #读取测试案例表格文件,跳过不执行的行数
        xd = pd.read_excel(self.filename,
                           skiprows=rows,
                           usecols=[0, 1, 4, 12, 13, 15, 16])  # 指定读取列
        # print(xd)
        #摘取所需要内容生成新的xls文件
        xd.to_excel(self.new_filename, index=False)
        #将excel转换为html
        to_html = pd.ExcelFile(self.new_filename)
        pd.set_option('display.max_colwidth', 1000)  # 设置列的宽度,以防止出现省略号
        df = to_html.parse()
        with codecs.open(self.report_path, 'w') as html_file:
            html_file.write(
                df.to_html(header=True, index=False, table_id="Test_Report"))
        # 将多余文件删除
        os.remove(self.new_filename)
        #自动打开报告文件
        # webbrowser.open(self.report_path)


# 案例表格、数据文件路径

# case_excelpath = "..//Test_Case//Paper_Process.xls"
# data_jsonpath="../data/Paper_Process.json"
# # # 定义报告文件
# excel_copy = "..//Test_Case//Paper_Process_bk.xls"
# html_path = "../Test_Case/Paper_Process.html"
# a = report(case_excelpath,excel_copy,html_path)
# a.creat_report()