赞
踩
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
""" 1. 从Excel中读取接口的数据 2. 读取Sql命令 """ import xlrd import sys import os sys.path.append("..") from common.config import pro_path class Data(object): def \_\_init\_\_(self, filename): data_file_path = os.path.join(pro_path,"data",filename) self.wb = xlrd.open_workbook("../data/test\_user\_data.xlsx") def get\_case(self,sheet_name, case_name): sh = self.wb.sheet_by_name(sheet_name) for i in range(1, sh.nrows): if sh.cell(i,0).value == case_name: return sh.row_values(i) print("用例名未找到") return None def get\_sql(self, sql_name): sh = self.wb.sheet_by_name("SQL") for i in range(sh.nrows): if sh.cell(i,0).value == sql_name: return sh.cell(i,1).value print("sql未找到") return None if __name__ == "\_\_main\_\_": d = Data("test\_user\_data.xlsx") print(d.get_case("reg","test\_reg\_normal")) print(d.get_sql("checkUser"))
db.py: 数据层-数据库连接
""" 1. 从配置文件中读取数据库配置 2. 连接数据库 3. 执行sql并返回所有结果 """ import sys import pymysql sys.path.append("..") from common.config import Config class DB(object): def \_\_init\_\_(self): c = Config() self.conn = pymysql.connect(host=c.get_db_test("host"), port=int(c.get_db_test("port")), db=c.get_db_test("db"), user=c.get_db_test("user"), passwd=c.get_db_test("passwd"), charset="utf8") self.cur = self.conn.cursor() def do\_sql(self, sql): self.cur.execute(sql) return self.cur.fetchall() def \_\_del\_\_(self): self.cur.close() self.conn.close() if __name__ == "\_\_main\_\_": db = DB() print(db.do_sql("select \* from user"))
log.py: 数据层-log配置
""" 1. 配置log输出格式 time - loglevel - file - func - line - msg 2. 支持输出到log文件及屏幕 3. 支持返回一个logger,让其他模块调用 """ import sys sys.path.append("..") from common.config import Config, pro_path import time import logging import os class Log(): @classmethod def config\_log(cls): cf = Config() log_dir = os.path.join(pro_path, cf.get_runtime("log\_dir")) today = time.strftime("%Y%m%d", time.localtime(time.time())) log_file = os.path.join(log_dir, today+".log") # 获取一个标准的logger, 配置loglevel cls.logger = logging.getLogger() cls.logger.setLevel(eval("logging." + cf.get_runtime("log\_level").upper())) # 建立不同handler fh = logging.FileHandler(log_file, mode="a",encoding=‘utf-8’) ch = logging.StreamHandler() # 定义输出格式 ft = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s") fh.setFormatter(ft) ch.setFormatter(ft) # 把定制handler 添加到我们logger cls.logger.addHandler(fh) cls.logger.addHandler(ch) @classmethod def get\_logger(cls): cls.config_log() return cls.logger if __name__ == "\_\_main\_\_": l= Log.get_logger() l.info("abc") l.debug("hello, debug")
send_email.py: 数据层-邮件服务器连接
""" 1. 从配置文件中读取stmp配置 2. 从report文件夹下打开report.html,发送邮件 """ import smtplib from email.mime.text import MIMEText import os import sys sys.path.append("..") from common.config import Config, pro_path from common.log import Log def send\_email(report_name): cf = Config() logger = Log.get_logger() report_file = os.path.join(pro_path, cf.get_runtime("report\_dir"),report_name) with open(report_file, "rb") as f: body = f.read() # 格式化email正文 msg = MIMEText(body, "html", "utf-8") # 配置email头 msg["Subject"] = cf.get_email("subject") msg["From"] = cf.get_email("user") msg["To"] = cf.get_email("receiver") # 连接smtp服务器,发送邮件 smtp = smtplib.SMTP() smtp.connect(cf.get_email("server")) smtp.login(cf.get_email("user"),cf.get_email("pwd")) smtp.sendmail(cf.get_email("user"), cf.get_email("receiver"), msg.as_string()) print("邮件发送成功") if __name__ == "\_\_main\_\_": send_email("report.html")
case/case.py: 业务逻辑层, 为用例执行封装方法
""" 1. 加载数据 2. 发送接口 3. 为用例封装一些方法 """ import sys sys.path.append("..") from common.log import Log from common.config import Config from common.db import DB from common.data import Data import json import requests class Case(object): def \_\_init\_\_(self): self.logger = Log.get_logger() self.cf = Config() def load\_data(self, data_file): self.data = Data(data_file) def set\_env(self, env): self.env = env def run\_case(self, sheet_name, case_name, var={}): case_data = self.data.get_case(sheet_name, case_name) url = self.cf.get_server(self.env) + case_data[1] data = case_data[4].format(\*\*var) if case_data[3].lower() == "form": data = json.loads(data) headers = {} else: headers = {"content-type": "application/json"} if case_data[2].lower() == "get": resp = requests.get(url=url) else: resp = requests.post(url=url, headers=headers, data=data) return resp.text def check\_response(self): pass def check\_db(self, sql_name, vars={}): sql = self.data.get_sql(sql_name).format(\*\*vars) return self.db.exec_sql(sql) if __name__ == "\_\_main\_\_": c = Case() c.set_env("test") c.load_data("test\_user\_data.xlsx") r = c.run_case("login", "test\_login\_normal") print(r)
case/user/test_user.py: 表示层: 测试用例脚本
import sys import random import pytest sys.path.append("../..") from case.case import Case case = Case() def setup\_module(module): case.set_env('dev') case.load_data('test\_user\_data.xlsx') def test\_login\_normal(): result case.run("login", "test\_login\_normal") if __name__ == '\_\_main\_\_': pytest.main(["-q", "test\_user.py"]) run_all.py: 表示层: 执行所有用例入口# import os import time from util.config import Config from util.e_mail import send_email import pytest def main(): cf = Config() report_dir = cf.get_report_dir() now = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) report_name = os.path.join(report_dir, 'report\_' + now + '.html') pytest.main(["-q", "case", "--html=" + report_name]) send_email(report_name) if __name__ == '\_\_main\_\_': main()
下面是我整理的2023年最全的软件测试工程师学习知识架构体系图 |
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
转存中…(img-AXDwkRFX-1715394219021)]
[外链图片转存中…(img-SlCqqmHw-1715394219022)]
[外链图片转存中…(img-lEmIWiSo-1715394219022)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。