'''
=====================测试woniusales进销存系统的部分功能==============================
需求1(10分):正确账号可以登录系统
登录后跳转页面导航菜单右侧出现一个注销链接
需求2(20分):导航栏中每个菜单可以正确打开对应的页面, 点击菜单名,打开对应的页面的URL地址正确,页面标题正确
如:
点击“商品入库”页面URL为 http://localhost:端口/woniusales/store , 页面标题为 蜗牛进销存-商品入库
点击“批次管理”页面URL为 http://localhost:端口/woniusales/goods ,页面标题为 蜗牛进销存-批次管理
需求3(10分): 会员管理-添加会员, 输入新会员的信息 点击添加 可以保存会员的信息
需求4(10分): 会员管理-重得添加会员 输入已存在的会员手机号点击添加 不能重复添加
需求5(20分): 会员管理-修改会员基本信息 可以修改会员手机号,昵称,性别,出生日期
需求6(10分): 会员管理-修改会员积分 不能修改会员积分
需求7(20分): 会员管理-查询会员 输入手机号关键字,点查询显示包含手机号关键字的会员
请根据需求设计测试用例,写出测试用例的4大核心要素(未写测试用例要素,每个扣5分)
然后编写测试脚本,依据测试用例的期望结果 断言测试是否通过并打印输出测试报告
注意:每个测试用例编写完,还原测试环境,所有测试用例可以一次运行
'''
import pymysql
def select_many(sql):
#1.连接数据库,获取连接对象
db_con = pymysql.connect(host='localhost', port=3306, user='root', password='密码', database='librarydb',
charset='utf8')
#2.创建游标对象
mycur = db_con.cursor()
#3.用游标对象执行sql语句
mycur.execute(sql)
# 4.处理执行结果
data=mycur.fetchall()
# 5.关闭连接
db_con.close()
return data
def select_one(sql):
# 1.连接数据库,获取连接对象
db_con = pymysql.connect(host='localhost', port=3306, user='root', password='密码', database='librarydb',
charset='utf8')
# 2.创建游标对象
mycur = db_con.cursor()
# 3.用游标对象执行sql语句
mycur.execute(sql)
# 4.处理执行结果
data = mycur.fetchone()
# 5.关闭连接
db_con.close()
return data
def add_update_delete(sql):
# 1.连接数据库,获取连接对象
db_con = pymysql.connect(host='localhost', port=3306, user='root', password='密码', database='librarydb',
charset='utf8')
# 2.创建游标对象
mycur = db_con.cursor()
# 3.用游标对象执行sql语句
mycur.execute(sql)
# 4.处理执行结果
db_con.commit()
# 5.关闭连接
db_con.close()
import pymysql
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.select import Select
print("测试woniusales进销存系统的部分功能".center(60,"="))
class Test_Woniusales:
#创建链接对象
def __init__(self):
self.wb=webdriver.Chrome()
sleep(1)
self.wb.get("http://localhost:端口/woniusales")
sleep(1)
self.wb.maximize_window()
sleep(1)
#定位登录窗口输入框
def login(self,username,password,verifycode):
self.wb.find_element("id","username").send_keys(username)
sleep(1)
self.wb.find_element("id","password").send_keys(password)
sleep(1)
self.wb.find_element("id","verifycode").send_keys(verifycode)
sleep(1)
self.wb.find_element("class name","form-control.btn-primary").click()
sleep(1)
# 用例1 正确的账号登录成功
# 标题:正确的账号登录成功
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000
# 预期结果:输入正确的账号,点击登录后,成功登录系统,登录后跳转页面导航菜单右侧出现一个注销链接
def test_login(self,username,password,verifycode):
print("正确的账号登录成功".center(60, "="))
self.login(username,password,verifycode)
tet=self.wb.find_element("xpath","//*[@id='navbar']/ul[2]/li[2]/a").text
#================================断言===================================
#预期结果:输入正确的账号,点击登录后,成功登录系统,登录后跳转页面导航菜单右侧出现一个登录用户名和注销链接
if tet=="注销":
print("登录后跳转页面导航菜单右侧出现一个注销链接,测试通过")
else:
print("登录后跳转页面导航菜单右侧不出现一个注销链接,测试不通过")
sleep(1)
self.wb.find_element("link text", "注销").click()
# 用例2 导航栏中每个菜单对应的页面的URL地址正确,页面标题正确
# 标题:导航栏中每个菜单对应的页面的URL地址正确,页面标题正确
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000
# 预期结果:导航栏中每个菜单可以正确打开对应的页面,点击菜单名,打开对应的页面的URL地址正确,页面标题正确
def test_url(self,username, password, verifycode):
print("导航栏中菜单对应的页面的URL地址正确,页面标题正确".center(60, "="))
self.login(username, password, verifycode)
print("销售出库菜单".center(60, "-"))
self.wb.find_element("link text","销售出库").click()
sleep(1)
url=self.wb.current_url
url_name=self.wb.title
print(f"实际页面URL为:{url}",end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口/woniusales/sell",end=" ")
print("期望页面标题为:蜗牛进销存-销售出库")
# ================================断言1===================================
# 预期结果:点击销售出库菜单,打开对应的页面的URL地址正确,页面标题正确
if url=="http://localhost:8080/woniusales/sell" and url_name=="蜗牛进销存-销售出库":
print("点击销售出库菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击销售出库菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
#-------------------------------------------------------------------------
print("批次管理菜单".center(60, "-"))
self.wb.find_element("link text", "批次管理").click()
sleep(1)
url = self.wb.current_url
url_name = self.wb.title
print(f"实际页面URL为:{url}", end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口/woniusales/goods", end=" ")
print("期望页面标题为:蜗牛进销存-批次管理")
# ================================断言2===================================
# 预期结果:点击批次管理菜单,打开对应的页面的URL地址正确,页面标题正确
if url == "http://localhost:8080/woniusales/goods" and url_name == "蜗牛进销存-批次管理":
print("点击批次管理菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击批次管理菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
# -------------------------------------------------------------------------
print("商品入库菜单".center(60, "-"))
self.wb.find_element("link text", "商品入库").click()
sleep(1)
url = self.wb.current_url
url_name = self.wb.title
print(f"实际页面URL为:{url}", end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口号/woniusales/store", end=" ")
print("期望页面标题为:蜗牛进销存-商品入库")
# ================================断言3===================================
# 预期结果:点击商品入库菜单,打开对应的页面的URL地址正确,页面标题正确
if url == "http://localhost:8080/woniusales/store" and url_name == "蜗牛进销存-商品入库":
print("点击商品入库菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击商品入库菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
# -------------------------------------------------------------------------
print("库存查询菜单".center(60, "-"))
self.wb.find_element("link text", "库存查询").click()
sleep(1)
url = self.wb.current_url
url_name = self.wb.title
print(f"实际页面URL为:{url}", end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口号/woniusales/query", end=" ")
print("期望页面标题为:蜗牛进销存-库存查询")
# ================================断言4===================================
# 预期结果:点击库存查询菜单,打开对应的页面的URL地址正确,页面标题正确
if url == "http://localhost:8080/woniusales/query" and url_name == "蜗牛进销存-库存查询":
print("点击库存查询菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击库存查询菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
# -------------------------------------------------------------------------
print("会员管理菜单".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
url = self.wb.current_url
url_name = self.wb.title
print(f"实际页面URL为:{url}", end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口号/woniusales/customer", end=" ")
print("期望页面标题为:蜗牛进销存-会员管理")
# ================================断言5===================================
# 预期结果:点击会员管理菜单,打开对应的页面的URL地址正确,页面标题正确
if url == "http://localhost:8080/woniusales/customer" and url_name == "蜗牛进销存-会员管理":
print("点击会员管理菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击会员管理菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
# -------------------------------------------------------------------------
print("销售报表菜单".center(60, "-"))
self.wb.find_element("link text", "销售报表").click()
sleep(1)
url = self.wb.current_url
url_name = self.wb.title
print(f"实际页面URL为:{url}", end=" ")
print(f"实际页面标题为:{url_name}")
print("期望页面URL为:http://localhost:端口号/woniusales/report", end=" ")
print("期望页面标题为:蜗牛进销存-销售报表")
# ================================断言6===================================
# 预期结果:点击销售报表菜单,打开对应的页面的URL地址正确,页面标题正确
if url == "http://localhost:8080/woniusales/report" and url_name == "蜗牛进销存-销售报表":
print("点击销售报表菜单,打开对应的页面的URL地址正确,页面标题正确,测试通过")
else:
print("点击销售报表菜单,打开对应的页面的URL地址不正确或者页面标题正确,测试不通过")
sleep(1)
self.wb.find_element("link text", "注销").click()
# 用例3:会员管理-添加会员
# 标题:会员管理-添加会员成功
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000,新的正确的11位手机号码
# 预期结果:输入新会员的信息 点击添加,可以保存会员的信息
def test_addcustomer(self,username, password, verifycode,customerphone,customername,childsex,childdate,creditkids,creditcloth):
print("会员管理".center(60, "="))
self.login(username, password, verifycode)
print("添加会员".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
#定位手机号码框
self.wb.find_element("id","customerphone").send_keys(customerphone)
sleep(1)
#定位昵称输入框
self.wb.find_element("id", "customername").clear()
sleep(1)
self.wb.find_element("id","customername").send_keys(customername)
sleep(1)
#定位性别选择框
tsex=self.wb.find_element("id","childsex")
obj_tsex=Select(tsex)
obj_tsex.select_by_visible_text(childsex)
sleep(1)
#定位出生日期选择框
js ="document.getElementById('childdate').removeAttribute('readonly')"
self.wb.execute_script(js)
sleep(1)
self.wb.find_element("id", "childdate").clear()
sleep(1)
self.wb.find_element("id", "childdate").send_keys(childdate)
sleep(1)
self.wb.find_element("id", "childdate").click()
sleep(1)
#定位母婴积分框
self.wb.find_element("id", "creditkids").clear()
sleep(1)
self.wb.find_element("id","creditkids").send_keys(creditkids)
sleep(1)
#定位童装积分框
self.wb.find_element("id", "creditcloth").clear()
sleep(1)
self.wb.find_element("id", "creditcloth").send_keys(creditcloth)
sleep(1)
self.wb.find_element("xpath","/html/body/div[4]/div[1]/form[2]/div[2]/button[1]").click()
sleep(1)
self.wb.find_element("id", "customerphone").send_keys(customerphone) # 输入手机号
sleep(1)
self.wb.find_element("css selector","form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
# =======================================断言===================================
# 期望结果:输入新会员的信息 点击添加之后,可以保存会员的信息
list_tr = self.wb.find_elements("css selector", "#customerlist>tr")
row = len(list_tr) - 1
result_phone = self.wb.find_element("xpath", "//*[@id='customerlist']/tr[1]/td[2]").text
if row==1 and customerphone==result_phone:
print("新增会员成功,,可以保存会员的信息,测试通过")
else:
print("新增会员失败,无法保存会员的信息,测试不通过")
sleep(5)
self.wb.find_element("link text", "注销").click()
# 用例4:会员管理-重复添加会员
# 标题:重复添加会员失败
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000,账户中已经存在的11位手机号码
# 预期结果:已存在的手机号码不能重复添加
def test_repeatcustomer(self,username, password, verifycode,customerphone):
print("会员管理".center(60, "="))
self.login(username, password, verifycode)
print("重复添加会员".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
#定位手机号码框
self.wb.find_element("id","customerphone").send_keys(customerphone)
sleep(1)
self.wb.find_element("xpath","/html/body/div[4]/div[1]/form[2]/div[2]/button[1]").click() #点击新增按钮
# ================断言:操作的结果是否与预期结果一致====================
# 期望结果:账户中已经存在的会员,点击再次新增后,页面出现一个错误提示框,不能重复新增
try:
result_test3 = self.wb.find_element("xpath", "//*[text()='错误提示']").text
print("账户中已经存在的会员,点击再次新增后,页面中新增提示框,测试通过")
except:
print("账户中已经存在的会员,点击再次新增后,页面中无新增提示框,测试不通过")
sleep(1)
self.wb.find_element("xpath","/html/body/div[7]/div/div/div[3]/button").click()
sleep(1)
self.wb.find_element("link text", "注销").click()
# 用例5:会员管理-修改会员
# 标题:修改会员成功
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000,账户中已经存在的11位手机号码
# 预期结果:对账户中存在的会员,可以进行修改手机号,昵称,性别,出生日期
def test_updatecustomer(self,username, password, verifycode,customerphone,newphone, customername,childsex,childdate):
print("会员管理".center(60, "="))
self.login(username, password, verifycode)
print("修改会员".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
self.wb.find_element("id", "customerphone").send_keys(customerphone) # 定位手机号码输入框
sleep(1)
self.wb.find_element("css selector","form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
sleep(1)
self.wb.find_element("xpath","//*[@id='customerlist']/tr[1]/td[11]/a").click() #定位点击会员表中的修改按钮
sleep(1)
self.wb.find_element("id", "customerphone").clear() # 定位手机号码输入框清空
sleep(1)
self.wb.find_element("id", "customerphone").send_keys(newphone) # 定位手机号码输入框
sleep(1)
self.wb.find_element("id", "customername").clear() # 定位昵称输入框清空
sleep(1)
self.wb.find_element("id", "customername").send_keys(customername) # 定位昵称输入框
sleep(1)
# 定位性别选择框
tsex = self.wb.find_element("id", "childsex")
obj_tsex = Select(tsex)
obj_tsex.select_by_visible_text(childsex)
sleep(1)
# 定位出生日期选择框
js = "document.getElementById('childdate').removeAttribute('readonly')"
self.wb.execute_script(js)
sleep(1)
self.wb.find_element("id", "childdate").clear()
sleep(1)
self.wb.find_element("id", "childdate").send_keys(childdate)
sleep(1)
self.wb.find_element("id", "childdate").click()
sleep(1)
self.wb.find_element("id", "editBtn").click() #点击信息栏修改按钮
sleep(1)
self.wb.find_element("xpath","/html/body/div[7]/div/div/div[3]/button").click() #点击ok按钮
sleep(1)
# ==============================断言==========================
# 期望结果:对账户中存在的会员,可以进行修改手机号,昵称,性别,出生日期
self.wb.find_element("css selector","form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
sleep(1)
list_customer = self.wb.find_elements("xpath", "//*[@id='customerlist']/tr[1]/td") # 获取查询之后出现的会员信息
sleep(1)
list_custo=[custo.text for custo in list_customer[1:5]] #索引搜索,包头不包尾
list_cust=[newphone, customername, childsex, childdate]
if list_custo == list_cust:
print("对账户中存在的会员,可以进行修改手机号,昵称,性别,出生日期,测试通过")
else:
print("对账户中存在的会员,不可以进行修改手机号,昵称,性别,出生日期,测试不通过")
sleep(1)
self.wb.find_element("link text", "注销").click()
# 用例6:会员管理-修改会员积分
# 标题:修改会员积分失败
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000,账户中已经存在的11位手机号码
# 预期结果:对账户中存在的会员,不可以进行修改会员积分
def test_UpdateCustomerPoints(self, username, password, verifycode, customerphone,creditkids,creditcloth):
print("会员管理".center(60, "="))
self.login(username, password, verifycode)
print("修改会员积分".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
self.wb.find_element("id", "customerphone").send_keys(customerphone) # 定位手机号码输入框
sleep(1)
self.wb.find_element("css selector", "form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
sleep(1)
self.wb.find_element("xpath", "//*[@id='customerlist']/tr[1]/td[11]/a").click() # 定位点击会员表中的修改按钮
sleep(1)
# 定位母婴积分框
self.wb.find_element("id", "creditkids").clear()
sleep(1)
self.wb.find_element("id", "creditkids").send_keys(creditkids)
sleep(1)
# 定位童装积分框
self.wb.find_element("id", "creditcloth").clear()
sleep(1)
self.wb.find_element("id", "creditcloth").send_keys(creditcloth)
sleep(1)
self.wb.find_element("id", "editBtn").click() # 点击信息栏修改按钮
sleep(1)
self.wb.find_element("xpath", "/html/body/div[7]/div/div/div[3]/button").click() # 点击ok按钮
sleep(1)
self.wb.find_element("css selector","form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
sleep(1)
list_customer = self.wb.find_elements("xpath", "//*[@id='customerlist']/tr[1]/td") # 获取查询之后出现的会员信息
# ==============================断言==========================
# 期望结果:对账户中存在的会员,不可以进行修改会员积分
list_custo = [custo.text for custo in list_customer[5:7]] # 索引搜索,包头不包尾
list_cust = [creditkids, creditcloth]
if list_custo!=list_cust:
print("对账户中存在的会员,不可以进行修改积分,测试通过")
else:
print("对账户中存在的会员,可以进行修改积分,测试不通过")
sleep(1)
self.wb.find_element("link text", "注销").click()
# 用例7:会员管理-查询会员
# 标题:手机模糊查询会员正常
# 前置条件:打开登录页面
# 数据:admin/Milor123,验证码采用万能验证码0000,账户中已经存在的11位手机号码关键数字
# 预期结果:对账户中存在的会员,使用手机号关键数字可以正常查询会员信息
def test_coustomer_FuzzySearch(self,username,password,verifycode,phone):
global pho, i, j
print("会员管理".center(60, "="))
self.login(username, password, verifycode)
print("查询会员".center(60, "-"))
self.wb.find_element("link text", "会员管理").click()
sleep(1)
self.wb.find_element("id", "customerphone").send_keys(phone) # 定位手机号码输入框
sleep(1)
self.wb.find_element("css selector","form.form-inline>div:nth-child(2)>button:nth-child(3)").click() # 定位点击查询按钮
row = 0 # 会员列表初始行数
lst=[]
while True:
list_all = self.wb.find_elements("css selector", "tbody#customerlist>tr") # 点击查询之后页面显示的会员数量行
if len(list_all) == 1: # 当点击到最后一页的时候,会员表格中的数据行只有一行时结束循环
break
else:
row = row + len(list_all) - 1
list_phone = self.wb.find_elements("css selector", "#customerlist>tr>td:nth-child(2)")
for i in range(len(list_phone)):
pho=list_phone[i].text
lst.append(pho)
self.wb.find_element("xpath", "//*[@id='customerlist']/tr/td/a[2]").click() # 点击下一页
# 链接数据库,再从数据库中的会员表格数量进行对比,如果一致则为测试通过
sql = f"select customerphone from customer where customerphone like '%{phone}%'" # sql模糊查询含有该关键数字的手机号码会员
# 1.连接数据库,获取连接对象
db_con = pymysql.connect(host='localhost', port=3306, user='root', password='密码', database='woniusales',
charset='utf8')
# 2.创建游标对象
mycur = db_con.cursor()
# 3.用游标对象执行sql语句
mycur.execute(sql)
# 4.处理执行结果(游标对象提取查询的结果)
data = mycur.fetchall()
# 5.关闭连接
db_con.close()
# =============================断言==========================
# 期望结果:对账户中存在的会员,使用手机号关键数字可以正常查询会员信息
print("查询出会员表格中涵盖有该数字的手机号为:",end="")
for i in range(len(lst)):
print(lst[i],end=" ")
print()
print("查询出来数据表中涵盖有该数字的手机号为:",end="")
for j in range(len(list(data))):
print(list(data)[j][0],end=" ")
print()
if lst[i]==list(data)[j][0]:
print("对账户中存在的会员,使用手机号关键数字可以正常查询会员信息,测试通过")
else:
print("对账户中存在的会员,使用手机号关键数字不可以正常查询会员信息,测试不通过")
sleep(1)
self.wb.find_element("link text", "注销").click()
if __name__ == '__main__':
woniu=Test_Woniusales()
# woniu.login(username="admin",password="Milor123",verifycode="0000")
woniu.test_login(username="admin",password="Milor123",verifycode="0000")
woniu.test_url(username="admin",password="Milor123",verifycode="0000")
woniu.test_addcustomer(username="admin",password="Milor123",verifycode="0000",customerphone="手机号码", customername="小九",
childsex="女", childdate="2005-06-06", creditkids="50", creditcloth="50")
woniu.test_repeatcustomer(username="admin",password="Milor123",verifycode="0000",customerphone="手机号码")
woniu.test_updatecustomer(username="admin",password="Milor123",verifycode="0000", customerphone="13456789101", newphone="手机号码",
customername="小六",childsex="女", childdate="2005-06-06")
woniu.test_UpdateCustomerPoints(username="admin",password="Milor123",verifycode="0000",
customerphone="手机号码",creditkids="90",creditcloth="30")
woniu.test_coustomer_FuzzySearch(username="admin",password="Milor123",verifycode="0000",phone="15")
lua自动化测试脚本 自动化测试脚本实例
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ixchariot 自动化脚本测试案例 自动化测试脚本开发
通常对于一个稍具规模的系统,一些新的改动势必会带来一些额外的功能回归测试工作,而这个工作是非常繁杂的,人肉的方式一次又一次的重复将会非常的枯燥乏味。 而我们所希望的,是一种自动化回归脚本的方式,可以重复性的回归现有功能,并给出回归测试报告。 &n
ixchariot 自动化脚本测试案例 测试 python browser 浏览器