测试用例:
import time import unittest from selenium import webdriver class TestLogin(unittest.TestCase): """ 对登录模块的功能进行测试 """ def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.implicitly_wait(10) self.driver.get("http://localhost/") # 点击首页的‘登录’链接,进入登录页面 self.driver.find_element_by_link_text("登录").click() def tearDown(self) -> None: self.driver.quit() def test01_login_success(self): """登录成功""" # 输入用户名、密码、验证码 self.driver.find_element_by_id("username").send_keys("13012345678") self.driver.find_element_by_id("password").send_keys("123456") self.driver.find_element_by_id("verify_code").send_keys("8888") # 点击‘登录’ self.driver.find_element_by_name("sbtbutton").click() # 断言提示信息 time.sleep(3) self.assertIn("我的账户", self.driver.title) def test02_login_username_is_not_exist(self): """账号不存在""" # 输入用户名、密码、验证码 self.driver.find_element_by_id("username").send_keys("13099999999") self.driver.find_element_by_id("password").send_keys("123456") self.driver.find_element_by_id("verify_code").send_keys("8888") # 点击‘登录’ self.driver.find_element_by_name("sbtbutton").click() # 断言提示信息 msg = self.driver.find_element_by_class_name("layui-layer-content").text print("msg=", msg) self.assertIn("账号不存在", msg) def test03_login_password_is_error(self): """密码错误""" # 输入用户名、密码、验证码 self.driver.find_element_by_id("username").send_keys("13012345678") self.driver.find_element_by_id("password").send_keys("error") self.driver.find_element_by_id("verify_code").send_keys("8888") # 点击‘登录’ self.driver.find_element_by_name("sbtbutton").click() # 断言提示信息 msg = self.driver.find_element_by_class_name("layui-layer-content").text print("msg=", msg) self.assertIn("密码错误", msg)
需求:针对TPshop项目的登录模块,实现接口测试
Postman实现截图:
需求:针对TPshop项目,模拟实现100个用户同时登录系统
JMeter实现截图: