网页聊天室-测试报告

发布时间:2026/5/27 7:58:15

网页聊天室-测试报告 一、项目介绍RoomChat 是一个基于Spring Boot 3.5.13 MyBatis MySQL后端和Next.js 16 React 19 Tailwind CSS 4前端的实时网页聊天室应用。采用 WebSocket 实现实时消息推送支持用户注册登录、好友管理、会话管理和实时消息收发等核心功能。二、测试计划本次测试主要从功能测试、界面测试、性能测试、易用性测试、兼容性测试、安全测试这六个方面来进行2.1 设计测试用例2.2 执行测试用例2.2.1 登录页面测试测试用例一输入正确的账号和密码预期结果和实际结果符合测试用例二输入正确的账号和错误的密码预期结果和实际结果符合测试用例三输入不存在的用户预期结果和实际结果符合测试用例四输入空的账号和密码预期结果和实际结果符合2.2.2 注册页面测试测试用例一输入正确的账号和密码预期结果和实际结果符合测试用例二输入已有的账号预期结果和实际结果符合测试用例三输入空的账号或密码预期结果和实际结果符合2.2.3 聊天页面测试测试用例一添加真实存在的好友预期结果和实际结果符合测试用例二搜索不存在的用户预期结果和实际结果符合测试用例三添加好友时输入空字符串预期结果和实际结果符合测试用例四添加自己为好友预期结果和实际结果符合测试用例五信息正常接收和发送预期结果和实际结果符合测试用例六输入空字符串无法发送预期结果和实际结果符合测试用例七发送超长信息自动滚动到最底部预期结果和实际结果符合测试用例九登出功能测试预期结果和实际结果符合测试用例十windows11使用不同浏览器进行测试预期结果和实际结果符合测试用例十一使用手机端进行测试预期结果和实际结果符合三、自动化测试自动化测试可以快速实际输出与预期结果是否一致。它可以大幅提升测试效率、降低重复劳动成本并支持持续集成与快速回归。本次自动化测试使用的是selenium。3.1 先引入所需要的依赖dependency groupIdorg.seleniumhq.selenium/groupId artifactIdselenium-java/artifactId version4.0.0/version /dependency dependency groupIdio.github.bonigarcia/groupId artifactIdwebdrivermanager/artifactId version5.8.0/version scopetest/scope /dependency3.2 创建Utils.java基类核心作用为所有测试类提供浏览器驱动和截图工具。关键设计public static WebDriver driver null; // 单例驱动public WebDriverWait wait null; // 显式等待public static String baseUrl http://1.14.186.164:8080;package common; import io.github.bonigarcia.wdm.WebDriverManager; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.WebDriverWait; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.time.Duration; public class Utils { public static WebDriver driver null; public WebDriverWait wait null; public static String baseUrl http://1.14.186.164:8080; public Utils(String url) { driver createDriver(); if (url ! null !url.isEmpty()) { driver.get(url); } wait new WebDriverWait(driver, Duration.ofSeconds(10)); } // 单例创建驱动对象 public static WebDriver createDriver() { if (driver null) { WebDriverManager.chromedriver().setup(); ChromeOptions options new ChromeOptions(); options.addArguments(--remote-allow-origins*); driver new ChromeDriver(options); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3)); } return driver; } // 截图保存到 images/日期/方法名-时间戳.png public void screenShot(String str) throws IOException { SimpleDateFormat sim1 new SimpleDateFormat(yyyy-MM-dd); SimpleDateFormat sim2 new SimpleDateFormat(HHmmssSS); String dirTime sim1.format(System.currentTimeMillis()); String fileTime sim2.format(System.currentTimeMillis()); String filename ./src/test/java/images/ dirTime / str - fileTime .png; File srcFile ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(srcFile, new File(filename)); } }3.3 LoginPage.java — 登录页测试继承关系LoginPage extends Utils构造函数 super(url) 导航到登录页。三个测试方法(1) checkPageRight() — 页面元素校验用 CSS Selector 定位三个关键元素能找到就说明页面渲染正常。(2) loginFail() — 登录失败场景(3) loginSuc() — 登录成功场景package tests; import common.Utils; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import java.io.IOException; public class LoginPage extends Utils { public static String url baseUrl /; public LoginPage() { super(url); } // 校验登录页元素是否正常显示用户名输入框、密码输入框、登录按钮 public void checkPageRight() throws IOException { driver.findElement(By.cssSelector(#username)); driver.findElement(By.cssSelector(#password)); driver.findElement(By.cssSelector(button[typesubmit])); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } // 异常的登录场景正确的用户名 错误的密码 public void loginFail() throws IOException { // driver.findElement(By.cssSelector(#username)).clear(); // driver.findElement(By.cssSelector(#password)).clear(); // React 受控组件用 CtrlA 全选覆盖 driver.findElement(By.cssSelector(#username)).sendKeys(Keys.chord(Keys.CONTROL, a), 张三); driver.findElement(By.cssSelector(#password)).sendKeys(Keys.chord(Keys.CONTROL, a), wrongpassword); driver.findElement(By.cssSelector(button[typesubmit])).click(); String errorMsg driver.findElement(By.cssSelector( body div.min-h-screen.grid.lg\\:grid-cols-2 div.flex.items-center.justify-center.p-8.bg-background div form div.p-3.text-sm.text-red-400.bg-red-950\\/20.border.border-red-900\\/30.rounded-lg)) .getText(); assert errorMsg.equals(用户名或密码错误); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } // 正确的用户名和密码登录, 验证跳转到 /chat public void loginSuc() throws IOException { // driver.findElement(By.cssSelector(#username)).clear(); // driver.findElement(By.cssSelector(#password)).clear(); // React 受控组件用 CtrlA 全选覆盖 driver.findElement(By.cssSelector(#username)).sendKeys(Keys.chord(Keys.CONTROL, a), 张三); driver.findElement(By.cssSelector(#password)).sendKeys(Keys.chord(Keys.CONTROL, a), 123); driver.findElement(By.cssSelector(button[typesubmit])).click(); // 登录成功会弹出 alert 登录成功, 接受后跳转到 /chat wait.until(ExpectedConditions.alertIsPresent()); driver.switchTo().alert().accept(); // 等待页面跳转到聊天页 wait.until(ExpectedConditions.urlContains(/chat)); assert driver.getCurrentUrl().contains(/chat); } }3.3.1 页面元素校验3.3.2 登陆失败场景3.3.3登陆成功场景3.4 ChatPage.java — 聊天页测试(1) checkPageRight() — 聊天页加载校验等 React 渲染出三个关键元素会话 Tab、好友 Tab、登出按钮。用 XPath 绝对路径定位从浏览器直接复制的。(2) checkSessionList() — 会话列表校验用 CSS 选择器定位左侧第一个会话按钮验证会话列表已加载。(3) checkFriendList() — 好友列表校验点击朋友Tab等待好友列表中的李四出现。(4) sendMessage() — 发送消息测试package tests; import common.Utils; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import java.io.IOException; import java.text.SimpleDateFormat; public class ChatPage extends Utils { public static String url baseUrl /chat; public ChatPage() { super(url); } // 校验聊天页已加载会话/朋友Tab、登出按钮 public void checkPageRight() throws IOException { //会话按钮 wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath(/html/body/div[2]/div[4]/div[1]/div[2]/button[1]/div) )); //好友列表 driver.findElement(By.xpath(/html/body/div[2]/div[4]/div[1]/div[2]/button[2]/div[1])); //登出按钮 driver.findElement(By.xpath(/html/body/div[2]/div[4]/div[1]/div[1]/div/button)); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } // 验证会话列表中包含至少一个会话 public void checkSessionList() throws IOException { WebElement sessionItem wait.until(ExpectedConditions.presenceOfElementLocated( By.cssSelector(body div.h-screen.bg-gradient-to-br.from-\\[\\#1a1a2e\\].via-\\[\\#16213e\\].to-\\[\\#0f3460\\].flex.flex-col div.relative.z-10.flex.flex-1.overflow-hidden div.w-80.flex-shrink-0.flex.flex-col.bg-white\\/5.backdrop-blur-sm.border-r.border-white\\/10 div.flex-1.overflow-y-auto.scrollbar-thin button) )); assert sessionItem.isDisplayed(); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } // 切换到朋友Tab, 验证好友列表包含李四 public void checkFriendList() throws IOException { driver.findElement(By.xpath(/html/body/div[2]/div[4]/div[1]/div[2]/button[2]/div[1])).click(); WebElement friendItem wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath(/html/body/div[2]/div[4]/div[1]/div[3]/div/div[2]/button) )); assert friendItem.isDisplayed(); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } // 发送消息给李四, 验证消息出现在聊天区域 public void sendMessage() throws IOException, InterruptedException { // 切回到会话Tab driver.findElement(By.xpath(/html/body/div[2]/div[4]/div[1]/div[2]/button[1]/div)).click(); // 点击李四的会话 WebElement sessionBtn wait.until(ExpectedConditions.elementToBeClickable( By.cssSelector(body div.h-screen.bg-gradient-to-br.from-\\[\\#1a1a2e\\].via-\\[\\#16213e\\].to-\\[\\#0f3460\\].flex.flex-col div.relative.z-10.flex.flex-1.overflow-hidden div.w-80.flex-shrink-0.flex.flex-col.bg-white\\/5.backdrop-blur-sm.border-r.border-white\\/10 div.flex-1.overflow-y-auto.scrollbar-thin button) )); sessionBtn.click(); // 等待聊天区域加载textarea出现 wait.until(ExpectedConditions.presenceOfElementLocated( By.tagName(textarea) )); // 等待 WebSocket 连接上聊天头部显示在线 wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath(//*[contains(text(), 在线)]) )); // 用时间戳生成唯一消息内容, 方便断言 SimpleDateFormat sim new SimpleDateFormat(HHmmssSS); String message AutoTest消息- sim.format(System.currentTimeMillis()); // 输入消息 WebElement textarea driver.findElement(By.tagName(textarea)); textarea.sendKeys(message); // 点击发送按钮textarea后面的兄弟button WebElement sendBtn textarea.findElement(By.xpath(./following-sibling::button)); sendBtn.click(); // 等待消息出现在聊天区域并截图 Thread.sleep(2000); wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath(//*[contains(text(), message )]) )); screenShot(Thread.currentThread().getStackTrace()[1].getMethodName()); } }3.4.1 聊天页正常加载3.4.2 会话列表检验3.4.3 好友列表检验3.4.4 发送消息测试3.5 测试入口main() 方法按顺序执行所有测试最后关闭浏览器[测试] 登录页元素校验...[测试] 登录失败场景...[测试] 登录成功场景...[测试] 聊天页元素校验...[测试] 会话列表...[测试] 好友列表...[测试] 发送消息...package tests; import common.Utils; import java.io.IOException; public class RunTests { public static void main(String[] args) throws IOException, InterruptedException { System.out.println( Roomchat AutoTest 开始 ); // 登录模块测试 System.out.println([测试] 登录页元素校验...); LoginPage login new LoginPage(); login.checkPageRight(); System.out.println([测试] 登录失败场景...); login.loginFail(); System.out.println([测试] 登录成功场景...); login.loginSuc(); // 聊天页模块测试 System.out.println([测试] 聊天页元素校验...); ChatPage chat new ChatPage(); chat.checkPageRight(); System.out.println([测试] 会话列表...); chat.checkSessionList(); System.out.println([测试] 好友列表...); chat.checkFriendList(); System.out.println([测试] 发送消息...); chat.sendMessage(); System.out.println( Roomchat AutoTest 结束 ); // 关闭浏览器 if (Utils.driver ! null) { Utils.driver.quit(); } } }四、项目bug总结4.1 密码没有设计加密存储(bug级别:严重)4.2 无登录防暴力破解(bug级别:严重)4.3 添加好友的时候可以搜索全部好友(bug级别:一般)五、性能测试5.1梯度压测线程组图解:00:00 ~ 01:15 0 → 200 阶梯式逐步加压每步约增加 10-20 线程01:15 ~ 01:45 保持 200 最大并发持续约 30 秒01:45 ~ 02:06 200 → 0 快速释放线程5.2线程的活跃数加压策略执行正常符合梯度测试预期5.3响应时间整体表现低并发阶段0-100 线程各接口响应时间基本在 50-200ms 之间表现良好中高并发阶段100-200 线程响应时间逐渐上升波动加大异常峰值约 01:28 时刻获取用户信息接口粉色 出现 ~1650ms 的尖峰同时其他接口也有明显抖动这个表现说明了在1:28时刻,系统达到过载,主要是由于获取用户信息的接口5.4 吞吐量(TPS 每秒处理的事务)各接口的 success/failure 曲线在 01:28 后混乱交织说明大量请求开始失败或超时系统可能出现了线程阻塞、连接池耗尽、数据库锁或服务崩溃01:28 时刻 TPS 先有一个冲顶~350随后立即崩盘5.5 聚合报告分析在线程数为达到最大值时未出现异常在时间为1:28左右开始出现异常六、性能测试报告综合上面分析来看,主要出现在获取用户信息这一接口该接口变慢 → 占用连接/线程不释放 → 其他接口受影响 → 整体雪崩崩溃临界点约 180-200 并发01:28 左右优化点:检查 SQL 执行计划、加索引、优化查询逻辑、增加缓存Redis七、测试总结本次测试通过 Selenium 编写自动化脚本 对登录、聊天页加载、好友列表、发送消息等核心功能进行了端到端验证通过 JMeter对主要 REST 接口进行了压力测试定位到 /userInfo 为性能瓶颈。测试结果表明现有系统在 180并发以下可正常运行超过该阈值需进行 SQL 优化和引入缓存来提升性能。附上gitee仓库网页聊天室:https://gitee.com/wuminzong/spring_boot_roomchat.git网页聊天室性能测试报告:https://gitee.com/wuminzong/spring_boot_roomchat_performance_test.git已部署到云服务器:http:1.14.186.164:8080

相关新闻