接口测试框架规划
Excel用例效果展示
测试报告效果
接口
excel编写用例(编写测试用例时参考的是接口文档)
Requests使用
Requests使用
方法封装
Yaml介绍与安装
Yaml基本操作
1.字典
#字典 #name: "test_yaml" #result: "sucess"
2.列表
#列表 #["a","b","c"] - "a" - "b" - "c"
3.字典嵌套字典
#字典嵌套字典
#{person1:{"name":"xiaoming","age":"18"},
#person2:{"name":"xiaohong","age":"20"}
#}
#person1:
# name: xiaoming
# age: 18
#person2:
# name: xiaohong
# age: 20
4.字典嵌套列表
#字典嵌套列表
#{person:["a","b","c"]}
#person:
# - "a"
# - "b"
# - "c"
5.列表嵌套列表
#列表嵌套列表
#[["a","b","c"],["1","2","3"]]
#-
# - "a"
# - "b"
# - "c"
#-
# - "1"
# - "2"
# - "3"
6.列表嵌套字典
#列表嵌套字典
#[{"username1":"test1"},{"password1":"111","username2":"test2"}]
- username1: "test1"
- password1: "111"
username2: "test2"
# test: "中文"
7.读取多个文档
#读取多个文档
---
"用户名称1": "test123"
"密码": "123456"
---
"用户名称1": "test456"
"密码": "123456"
8.Yaml读取文件
单个文档:r=yaml.safe_load(f)
多个文档:Yaml.safe_load_all()
配置文件
2-6日志文件
#1、导入Logging包
import logging
#2、设置配置信息
logging.basicConfig(level=logging.INFO,format='%(asctime)s-%(name)s-%(levelname)s-%(message)s')
#3、定义日志名称getlogger
logger = logging.getLogger("log_demo")
#4、info,debug
logger.info("info")
logger.debug("debug")
logger.warning("warning")
Pytest安装与入门
- 安装与入门
- 基础使用
函数级别的方法
类级别的方法
- 常用插件
- 数据参数化
数据参数化举例1
数据参数化示例1
传入多个参数,当传入多个参数时,是以元组的形式来使用的
- 应用接口用例
结果断言——断言之基本断言
结果断言——断言应用及封装
from utils.LogUtil import my_log
import pymysql
#1、创建封装类
class Mysql:
#2、初始化数据,连接数据库,光标对象
def __init__(self,host,user,password,database,charset="utf8",port=3306):
self.log = my_log()
self.conn = pymysql.connect(
host=host,
user=user,
password=password,
database=database,
charset=charset,
port=port
)
self.cursor = self.conn.cursor(cursor=pymysql.cursors.DictCursor)
#3、创建查询、执行方法
def fetchone(self,sql):
"""
单个查询
:param sql:
:return:
"""
self.cursor.execute(sql)
return self.cursor.fetchone()
def fetchall(self,sql):
"""
多个查询
:param sql:
:return:
"""
self.cursor.execute(sql)
return self.cursor.fetchall()
def exec(self,sql):
"""
执行
:return:
"""
try:
if self.conn and self.cursor:
self.cursor.execute(sql)
self.conn.commit()
except Exception as ex:
self.conn.rollback()
self.log.error("Mysql 执行失败")
self.log.error(ex)
return False
return True
#4、关闭对象
def __del__(self):
#关闭光标对象
if self.cursor is not None:
self.cursor.close()
#关闭连接对象
if self.conn is not None:
self.cursor.close()
if __name__ == "__main__":
mysql = Mysql("211.103.136.242",
"test",
"test123456","meiduo",
charset="utf8",
port=7090)
#res = mysql.fetchall("select username,password from tb_users")
res = mysql.exec("update tb_users set first_name='python' where username = 'python'")
print(res)
#1、创建db_conf.yml, db1,db2
#2、编写数据库基本信息
#3、重构Conf.py
#4、执行
"""
#1、导入pymysql包
import pymysql
#2、连接database
conn = pymysql.connect(
host = "211.103.136.242",
user = "test",
password = "test123456",
database = "meiduo",
charset = "utf8",
port =7090
)
#3、获取执行sql的光标对象
cursor = conn.cursor()
#4、执行sql
sql = "select username,password from tb_users"
cursor.execute(sql)
res = cursor.fetchone()
print(res)
#5、关闭对象
cursor.close()
conn.close()"""
结果断言——数据库断言之配置文件
#1.创建db_conf.yml,db1,db2
#2.编写数据库信息
#3.重构Conf.py
#4.执行