当前位置: 首页 > news >正文

抽奖池项目测试

一、项目介绍

本项目采用前后端分离架构开发,通过数据库存储抽奖活动数据、用户信息及中奖记录,部署于云服务器以实现线上访问。前端包含登录页、注册页、活动列表页、抽奖页及中奖记录页五个核心页面,共同构成面向用户的抽奖互动系统。
                        

要点:

1、使用统⼀返回格式+全局错误信息定义处理前后端交互时的返回结果;
2、使用@ControllerAdvice+@ExceptionHandler实现全局异常处理;
3、使用拦截器实现用户登录校验;
4、集成Swagger实现⾃动⽣成API测试接口;

5、对密码进行加密处理。

 访问地址:管理员登录页面

自动化测试代码地址:JavaEE-Study: Java抽奖池测试

二、测试计划


1、功能测试


(1)测试环境:


操作系统:Windows 11家庭版
项目运行环境:IIntelliJ IDEA Community Edition 2022.1.4、JDK1.8、MySQL5.7
浏览器:Chorme、Edge、FireFox、QQ浏览器
自动化脚本环境:IIntelliJ IDEA Community Edition 2022.1.4
访问链接:管理员登录页面
测试技术: 主要手工进行单元测试和自动化测试
测试人员: 本人

(2)测试用例编写

  功能测试:

  非功能测试点:

 (3)部分功能测试


对注册页面进行的测试

场景1:输入邮箱已存在,密码,点击注册

预期结果:提示邮箱已经存在

实际结果:提示用户已经存在,与预期结果一致。

场景2:输入用户名不存在,点击注册

预期结果:注册成功,跳转回登录界面

实际结果:注册成功,跳转回登录界面,与预期结果一致。

对登录页面进行的测试

场景1:输入用户名存在,密码登录,点击登录

预期结果:登录成功,跳转到首页博客列表页面

实际结果:与预期结果一致。 

场景2:输入手机号不存在,密码登录,点击登录

预期结果:登录失败,给出错误提示

实际结果:登录失败,给出错误提示。

 ......

对首页进行的测试

场景1:未登录状态下,点击首页

预期结果:跳转回登录界面

实际结果:跳转回登录界面,与预期结果一致。

场景2:登录状态下,点击导航栏处的'活动列表'

预期结果:显示所有活动信息,以及活动是否结束

实际结果:与预期结果一致。

场景3:登录状态下,点击“创建活动”按钮,并未进行活动名称编写与活动描述

预期结果:对应文本框下报红提示

实际结果:与预期相符。

场景4:登录状态下,点击“活动中去抽奖”按钮进入抽奖页面

预期结果:进入抽奖页面

实际结果:与预期相符。

 ......

这里只给出部分测试,其他功能测试就不一一展示了。

2、自动化测试

注册页面测试


验证注册成功的情况


场景1:注册用户名在数据库不存在,邮箱格式正确,不重复,手机号格式正确,不重复,注册成功,跳转回登录界面。

  // 辅助方法:填写注册表单private void fillRegisterForm(String name, String phone, String email, String password) {// 清空并填写姓名(请替换为实际元素定位器)WebElement nameInput = driver.findElement(By.id("name"));nameInput.clear();if (name != null) nameInput.sendKeys(name);// 清空并填写手机号(请替换为实际元素定位器)WebElement phoneInput = driver.findElement(By.id("phone"));phoneInput.clear();if (phone != null) phoneInput.sendKeys(phone);// 清空并填写邮箱(请替换为实际元素定位器)WebElement emailInput = driver.findElement(By.id("email"));emailInput.clear();if (email != null) emailInput.sendKeys(email);// 清空并填写密码(请替换为实际元素定位器)WebElement passwordInput = driver.findElement(By.id("password"));passwordInput.clear();if (password != null) passwordInput.sendKeys(password);}// 辅助方法:点击注册按钮private void clickRegisterButton() {// 点击注册按钮(请替换为实际元素定位器)WebElement registerBtn = driver.findElement(By.id("registerBtn"));registerBtn.click();// 等待1秒让页面响应(实际项目建议用显式等待)try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }}// 测试1:正常注册(所有信息正确)@Test(priority = 1)public void testNormalRegistration() {// 打开注册页面driver.get(REGISTER_URL);// 填写正确的注册信息fillRegisterForm("测试用户",        // 姓名"13800138000",    // 正确手机号"test@example.com",// 正确邮箱"Test123456"      // 正确密码);// 点击注册按钮clickRegisterButton();// 验证注册成功(请根据实际成功标识修改)try {WebElement successMsg = driver.findElement(By.cssSelector(".success-message"));Assert.assertTrue(successMsg.isDisplayed(), "注册成功提示未显示");takeScreenshot("正常注册_成功"); // 截图成功场景} catch (NoSuchElementException e) {takeScreenshot("正常注册_失败"); // 截图失败场景Assert.fail("注册失败,未找到成功提示");}}

验证注册失败的情况


场景2:注册邮箱在数据库存在,手机号不存在,注册失败,获取警告框信息。

代码同上。测试结果

登录界面测试


登录成功测试


场景1:测试手机号正确,密码正确,登录成功

   // 测试开始前创建截图目录@Override@BeforeClasspublic void setup() {super.setup(); // 调用父类的浏览器初始化方法File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图方法(复用注册测试类的逻辑,增加场景描述)private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("登录场景截图已保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("登录场景截图失败:" + e.getMessage());}}// 填写登录表单的通用方法private void fillLoginForm(String phone, String password) {// 定位手机号输入框(请根据实际页面元素修改)WebElement phoneInput = driver.findElement(By.id("phone"));phoneInput.clear();if (phone != null) {phoneInput.sendKeys(phone);}// 定位密码输入框(请根据实际页面元素修改)WebElement passwordInput = driver.findElement(By.id("password"));passwordInput.clear();if (password != null) {passwordInput.sendKeys(password);}}// 点击登录按钮private void clickLoginButton() {WebElement loginBtn = driver.findElement(By.id("loginBtn")); // 请修改为实际按钮IDloginBtn.click();// 等待页面响应(实际项目建议用显式等待)try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }}// 测试1:正常登录(手机号和密码正确)@Test(priority = 1)public void testNormalLogin() {driver.get(LOGIN_URL);// 输入正确的手机号和密码fillLoginForm("13800138000",  // 已注册的正确手机号"CorrectPass123" // 对应的正确密码);clickLoginButton();// 验证登录成功(通常会跳转到首页或个人中心,这里以首页标题为例)try {WebElement homeTitle = driver.findElement(By.cssSelector(".home-title"));Assert.assertTrue(homeTitle.isDisplayed(), "登录后未跳转到首页");takeScreenshot("正常登录_成功");} catch (NoSuchElementException e) {takeScreenshot("正常登录_失败");Assert.fail("正常登录失败,未找到首页标识");}}


登录失败测试


场景2:测试手机号正确,密码错误,登录失败

  // 测试4:异常场景 - 密码不正确@Test(priority = 4)public void testLoginWithIncorrectPassword() {driver.get(LOGIN_URL);// 手机号正确,密码错误fillLoginForm("13800138000",  // 正确手机号"WrongPass456"  // 错误密码);clickLoginButton();// 验证错误提示WebElement errorMsg = driver.findElement(By.cssSelector(".error-message"));Assert.assertTrue(errorMsg.getText().contains("密码不正确") ||errorMsg.getText().contains("账号或密码错误"),"未显示密码不正确的错误提示");takeScreenshot("异常登录_密码不正确");}

列表测试


未登录状态下测试


场景1:未登录状态下进入活动列表页,直接跳转回登录界面。测试通过。

  // 测试2:异常展示 - 未登录状态访问活动列表@Test(priority = 2)public void testActivityListWithoutLogin() {// 确保是未登录状态(清除缓存)driver.manage().deleteAllCookies();driver.get(ACTIVITY_MANAGE_URL);// 验证跳转至登录页new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains(LOGIN_URL));Assert.assertTrue(driver.getCurrentUrl().contains(LOGIN_URL), "未登录时未跳转至登录页");// 验证登录提示WebElement loginTip = driver.findElement(By.cssSelector(".login-tip"));Assert.assertTrue(loginTip.getText().contains("请先登录") ||loginTip.getText().contains("登录后查看"),"未显示未登录提示");takeScreenshot("异常展示_未登录访问");}

未登录,直接跳转回登录界面


登录状态下测试


场景2:登录后进入活动列表页,查看“首页”元素是否存在。

  // 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("活动列表截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();// 等待登录完成new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 测试1:正常展示 - 已登录状态下活动列表正确显示@Test(priority = 1)public void testActivityListNormalDisplay() {// 先登录系统login("13800138000", "CorrectPass123");// 访问活动管理页面driver.get(ACTIVITY_MANAGE_URL);// 验证页面标题WebElement pageTitle = driver.findElement(By.cssSelector(".page-title"));Assert.assertEquals(pageTitle.getText(), "活动管理", "页面标题不正确");// 验证活动列表存在WebElement activityTable = driver.findElement(By.id("activityTable"));Assert.assertTrue(activityTable.isDisplayed(), "活动列表表格未显示");// 验证至少有一条活动数据(根据实际业务调整)try {WebElement firstActivity = driver.findElement(By.cssSelector("#activityTable tbody tr:first-child"));Assert.assertTrue(firstActivity.isDisplayed(), "活动列表无数据");takeScreenshot("正常展示_活动列表有数据");} catch (NoSuchElementException e) {takeScreenshot("正常展示_活动列表无数据");System.out.println("提示:活动列表当前无数据,属于业务正常情况");}}

创建活动测试

未登录状态下测试

场景1:未登录状态下创建活动,直接跳转回登录界面。

// 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("新建抽奖活动截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 辅助方法:进入新建抽奖活动页面private void navigateToCreateActivityPage() {driver.get(ACTIVITY_MANAGE_URL);// 点击"新建抽奖活动"按钮(替换为实际元素定位)WebElement createBtn = driver.findElement(By.cssSelector(".btn-create-activity"));createBtn.click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("create"));}// 测试1:异常场景 - 登录信息已过期@Test(priority = 3)public void testCreateActivityWithExpiredLogin() {// 先正常登录并进入活动管理页login("13800138000", "CorrectPass123");driver.get(ACTIVITY_MANAGE_URL);// 模拟登录过期(删除认证Cookie)driver.manage().deleteCookieNamed("auth_token");// 尝试点击新建按钮driver.findElement(By.cssSelector(".btn-create-activity")).click();// 验证过期处理try {// 情况1:显示过期提示弹窗WebElement expiredDialog = new WebDriverWait(driver, Duration.ofSeconds(3)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".expired-dialog")));Assert.assertTrue(expiredDialog.getText().contains("登录信息已过期") &&expiredDialog.getText().contains("请重新登录"),"登录过期提示不正确");takeScreenshot("异常场景_登录过期_弹窗提示");} catch (TimeoutException e) {// 情况2:跳转至登录页new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains(LOGIN_URL));Assert.assertTrue(driver.getCurrentUrl().contains(LOGIN_URL), "未跳转至登录页");takeScreenshot("异常场景_登录过期_跳转登录页");}}

登录后测试


场景2:登录后,输入活动标题,不输入活动描述,点击创建按钮,给出提示信息。

  // 测试4:异常场景 - 未填写活动描述@Test(priority = 4)public void testCreateActivityWithoutName() {login("13800138000", "CorrectPass123");navigateToCreateActivityPage();// 不填写活动名称,直接填写其他必填项driver.findElement(By.id("activityTime")).sendKeys("2025-09-01 00:00至2025-09-30 23:59");driver.findElement(By.cssSelector("#userSelection .checkbox:first-child")).click();driver.findElement(By.cssSelector("#prizeSelection .checkbox:first-child")).click();// 提交表单driver.findElement(By.id("submitBtn")).click();// 验证弹窗报错WebElement errorDialog = new WebDriverWait(driver, Duration.ofSeconds(3)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".error-dialog")));Assert.assertTrue(errorDialog.getText().contains("活动名称不能为空") ||errorDialog.getText().contains("请填写活动名称"),"未显示活动名称为空的错误提示");takeScreenshot("异常场景_未填写活动描述");}

场景2:登录后,未输入活动标题,点击创建按钮,给出提示信息。

 // 测试4:异常场景 - 未填写活动标题@Test(priority = 4)public void testCreateActivityWithoutName() {login("13800138000", "CorrectPass123");navigateToCreateActivityPage();// 不填写活动名称,直接填写其他必填项driver.findElement(By.id("activityTime")).sendKeys("2025-09-01 00:00至2025-09-30 23:59");driver.findElement(By.cssSelector("#userSelection .checkbox:first-child")).click();driver.findElement(By.cssSelector("#prizeSelection .checkbox:first-child")).click();// 提交表单driver.findElement(By.id("submitBtn")).click();// 验证弹窗报错WebElement errorDialog = new WebDriverWait(driver, Duration.ofSeconds(3)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".error-dialog")));Assert.assertTrue(errorDialog.getText().contains("活动名称不能为空") ||errorDialog.getText().contains("请填写活动名称"),"未显示活动名称为空的错误提示");takeScreenshot("异常场景_未填写活动名称");}

场景3:登录后,输入活动标题,输入活动描述,未圈选奖品,点击创建按钮,给出提示信息。

// 测试6:异常场景 - 未圈选奖品@Test(priority = 6)public void testCreateActivityWithoutPrizeSelection() {login("13800138000", "CorrectPass123");navigateToCreateActivityPage();// 填写活动名称和时间,选择人员,但不选择奖品driver.findElement(By.id("activityName")).sendKeys("测试活动_无奖品选择");driver.findElement(By.id("activityTime")).sendKeys("2025-09-01 00:00至2025-09-30 23:59");driver.findElement(By.cssSelector("#userSelection .checkbox:first-child")).click(); // 选择人员// 提交表单driver.findElement(By.id("submitBtn")).click();// 验证错误提示WebElement errorMsg = driver.findElement(By.cssSelector(".prize-selection-error"));Assert.assertTrue(errorMsg.getText().contains("请选择奖品") ||errorMsg.getText().contains("未圈选抽奖奖品"),"未显示未选择奖品的错误提示");takeScreenshot("异常场景_未圈选奖品");}

场景4:登录后,输入活动标题,输入活动描述,圈选奖品,未圈选人员,点击创建按钮,给出提示信息。

奖品列表页测试


未登录状态下


场景1:未登录状态下,进入奖品列表页,直接跳转回登录界面。

   // 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("奖品列表截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 辅助方法:导航到奖品列表页面private void navigateToPrizeList() {driver.get(ACTIVITY_MANAGE_URL);// 点击"奖品列表"按钮(替换为实际元素定位)WebElement prizeListBtn = driver.findElement(By.cssSelector(".menu-item-prizes"));prizeListBtn.click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("prizes"));}// 测试1:异常场景 - 未登录状态访问奖品列表@Test(priority = 2)public void testPrizeListWithoutLogin() {// 清除所有Cookie确保未登录状态driver.manage().deleteAllCookies();// 直接访问奖品列表页面driver.get(PRIZE_LIST_URL);// 验证跳转至登录页new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains(LOGIN_URL));Assert.assertTrue(driver.getCurrentUrl().contains(LOGIN_URL), "未登录访问奖品列表未跳转登录页");// 验证登录提示WebElement loginPrompt = driver.findElement(By.cssSelector(".login-prompt"));Assert.assertTrue(loginPrompt.getText().contains("请先登录") ||loginPrompt.getText().contains("登录后查看奖品"),"未登录访问奖品列表无提示信息");takeScreenshot("异常展示_未登录访问奖品列表");}
登陆状态下
 

场景1:登录后,点击奖品列表正常展示。

创建奖品测试


登录状态下测试


场景:登录后,进入创建奖品页,输入奖品名称、奖品图片、奖品价格,点击创建。

 // 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("创建奖品截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 辅助方法:导航到创建奖品页面private void navigateToCreatePrizePage() {driver.get(ACTIVITY_MANAGE_URL);// 先点击奖品列表driver.findElement(By.cssSelector(".menu-item-prizes")).click();new WebDriverWait(driver, Duration.ofSeconds(3)).until(ExpectedConditions.urlContains("prizes"));// 点击"创建奖品"按钮(替换为实际元素定位)WebElement createBtn = driver.findElement(By.cssSelector(".btn-create-prize"));createBtn.click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("create"));}// 测试1:正常展示 - 创建奖品页面正确加载@Test(priority = 1)public void testCreatePrizePageNormalDisplay() {// 登录系统login("13800138000", "CorrectPass123");// 导航到创建奖品页面navigateToCreatePrizePage();// 验证页面标题WebElement pageTitle = driver.findElement(By.cssSelector(".page-title"));Assert.assertEquals(pageTitle.getText(), "创建奖品", "创建奖品页面标题不正确");// 验证核心表单元素存在Assert.assertTrue(driver.findElement(By.id("prizeImageUpload")).isDisplayed(), "奖品图片上传区域未显示");Assert.assertTrue(driver.findElement(By.id("prizeName")).isDisplayed(), "奖品名称输入框未显示");Assert.assertTrue(driver.findElement(By.id("prizePrice")).isDisplayed(), "奖品价格输入框未显示");Assert.assertTrue(driver.findElement(By.id("prizeStock")).isDisplayed(), "奖品库存输入框未显示");Assert.assertTrue(driver.findElement(By.id("submitPrizeBtn")).isDisplayed(), "提交按钮未显示");takeScreenshot("正常展示_创建奖品页面加载成功");}// 测试2:正常场景 - 完整填写信息创建奖品成功@Test(priority = 2)public void testCreatePrizeSuccess() {login("13800138000", "CorrectPass123");navigateToCreatePrizePage();// 上传奖品图片(使用本地测试图片)WebElement imageUpload = driver.findElement(By.id("prizeImageUpload"));imageUpload.sendKeys("C:/test-images/prize-sample.png"); // 替换为实际测试图片路径// 填写奖品信息String prizeName = "测试奖品_" + System.currentTimeMillis();driver.findElement(By.id("prizeName")).sendKeys(prizeName);driver.findElement(By.id("prizePrice")).sendKeys("99.99");driver.findElement(By.id("prizeStock")).sendKeys("100");driver.findElement(By.id("prizeDesc")).sendKeys("这是一个测试奖品");// 提交表单driver.findElement(By.id("submitPrizeBtn")).click();// 验证创建成功WebElement successMsg = new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".success-message")));Assert.assertTrue(successMsg.getText().contains("创建成功"), "奖品创建成功提示未显示");takeScreenshot("正常场景_奖品创建成功");}

抽奖功能测试


登录状态下测试


场景1:登录状态下,进入活动列表页,点击"活动进行中,去抽奖",跳转到抽奖页面。

 // 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("活动抽奖流程截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 测试1:活动展示 - 验证"活动进行中"状态及跳转@Test(priority = 2)public void testActiveActivityDisplayAndRedirect() {login("13800138000", "CorrectPass123");driver.get(ACTIVITY_MANAGE_URL);// 定位进行中的活动(假设第二个活动为进行中状态)WebElement activeActivityRow = driver.findElement(By.cssSelector(".activity-row:nth-child(2)"));// 验证活动状态文本WebElement statusLabel = activeActivityRow.findElement(By.cssSelector(".activity-status"));Assert.assertEquals(statusLabel.getText(), "活动进行中", "进行中活动状态标识错误");// 验证操作按钮文本WebElement actionBtn = activeActivityRow.findElement(By.cssSelector(".activity-action-btn"));Assert.assertEquals(actionBtn.getText(), "去抽奖", "进行中活动操作按钮文本错误");// 点击按钮并验证跳转actionBtn.click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("lottery"));// 验证抽奖页面WebElement lotteryTitle = driver.findElement(By.cssSelector(".page-title"));Assert.assertTrue(lotteryTitle.getText().contains("抽奖"), "未跳转到抽奖页面");takeScreenshot("活动进行中_跳转抽奖页面");}


场景2:登录后点活动列表页,点击"活动已结束,查看中奖名单",跳转到获奖名单页面。

 // 初始化截图目录@Override@BeforeClasspublic void setup() {super.setup();File dir = new File(SCREENSHOT_DIR);if (!dir.exists()) {dir.mkdirs();}}// 截图工具方法private void takeScreenshot(String scenario) {try {String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String fileName = scenario + "_" + timestamp + ".png";File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);java.nio.file.Files.copy(screenshot.toPath(),new java.io.File(SCREENSHOT_DIR + fileName).toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING);System.out.println("活动抽奖流程截图保存:" + SCREENSHOT_DIR + fileName);} catch (Exception e) {System.err.println("截图失败:" + e.getMessage());}}// 辅助方法:登录系统private void login(String phone, String password) {driver.get(LOGIN_URL);driver.findElement(By.id("phone")).sendKeys(phone);driver.findElement(By.id("password")).sendKeys(password);driver.findElement(By.id("loginBtn")).click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("home"));}// 测试1:活动展示 - 验证"活动已结束"状态及跳转@Test(priority = 1)public void testEndedActivityDisplayAndRedirect() {// 登录系统并进入活动管理页login("13800138000", "CorrectPass123");driver.get(ACTIVITY_MANAGE_URL);// 定位已结束的活动(假设第一个活动为已结束状态)WebElement endedActivityRow = driver.findElement(By.cssSelector(".activity-row:nth-child(1)"));// 验证活动状态文本WebElement statusLabel = endedActivityRow.findElement(By.cssSelector(".activity-status"));Assert.assertEquals(statusLabel.getText(), "活动已结束", "已结束活动状态标识错误");// 验证操作按钮文本WebElement actionBtn = endedActivityRow.findElement(By.cssSelector(".activity-action-btn"));Assert.assertEquals(actionBtn.getText(), "查看中奖名单", "已结束活动操作按钮文本错误");// 点击按钮并验证跳转actionBtn.click();new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.urlContains("winners"));// 验证获奖名单页面WebElement winnersTitle = driver.findElement(By.cssSelector(".page-title"));Assert.assertTrue(winnersTitle.getText().contains("获奖名单"), "未跳转到获奖名单页面");takeScreenshot("活动已结束_跳转获奖名单");}

退出测试


场景:登录后,点击退出按钮,跳转回登录界面,退出成功。

@Order(1)@ParameterizedTest@CsvSource(value = "cherry, 321")void LoginOut1(String username, String password) throws InterruptedException, IOException {//1-登录// 打开登录页面webDriver.get("http://59.110.23.211:9090/blogin.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);// 输入用户名webDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);// 输入密码webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);// 点击提交webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);//2-点击我的帖子webDriver.findElement(By.cssSelector("#index_nav_avatar")).click();Thread.sleep(1000);//点击退出按钮webDriver.findElement(By.cssSelector("#index_user_logout")).click();Thread.sleep(1000);//获取当前的url地址String expect = "http://59.110.23.211:9090/blogin.html";String actual = webDriver.getCurrentUrl();//判断是否跳转到登录界面webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(expect, actual);//截图File srcFile =  ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);String fileName = "LoginOutSuccess.png";FileUtils.copyFile(srcFile, new File(fileName));}

3、性能测试


对登录界面进行性能测试

使用 JMeter 对 管理员密码登录接口、获取人员列表接口、获取奖品列表接口 以及 获取活动列表接口 进行性能测试:

聚合报告:

结果分析: 

1. 所有接口的异常率为0%,且响应时间较为稳定,说明系统在当前并发场景下具有良好的稳定性和可靠性

2. 总体吞吐量达到361.4/sec,单个接口的吞吐量也都在90次/秒以上,表明系统在当前并发场景下具备较强的处理能力

响应时间:

结果分析: 

1. 管理员密码登录接口的响应时间波动较大,平均在75 ms左右

2. 获取人员列表、奖品列表和活动列表接口的响应时间相对稳定,平均在43 ms左右

 每秒处理事务数:

结果分析:

1. 在测试过程中,每秒处理事务数基本保持在90次左右,说明系统在当前并发情况下仍能保持较高的处理能力

 2. 接近测试结束时,TPS有明显下降趋势,这是由于线程数量逐渐减少导致的

活跃线程数:

结果分析:

1. 测试开始后,线程数量迅速上升至20个,并在大部分时间内保持稳定

2. 接近测试结束时,线程数量逐渐减少,最终降至0,表明所有线程任务完成并退出

总结


功能测试:

1. 在线抽奖系统的基本功能正常运行,正常流程能够正确执行

2. 用户进行抽奖时响应及时,能够对抽奖过程中的异常情况进行处理

3. 在进行抽奖通知时,仅使用 qq 邮箱进行通知,可对其进行优化,使系统支持多种邮箱通知以及验证码通知

界面测试:

1. 所有按钮点击响应及时,页面显示良好,无错别字,无遮挡或显示错误情况

2. 对于异常情况都使用弹窗进行提示,对用户体验不友好,可使用自定义模态框、表单验证反馈等进行提示

性能测试:

1. 该系统的性能测试结果表明其在当前并发场景下表现优秀,能够满足需求

2. 后续可调整测试配置,增加线程数或调整循环次数,以测试更高并发用户数下性能

http://www.dtcms.com/a/348763.html

相关文章:

  • 【信息安全】英飞凌TC3xx安全调试口功能实现(调试口保护)
  • 解决Ubuntu22.04 安装vmware tools之后,不能实现文件复制粘贴和拖拽问题
  • AIStarter安装与调试:一键启动与收益中心教程
  • 为什么hive在处理数据时,有的累加是半累加数据
  • Codejock Suite ProActiveX COM Crack
  • C++如何将多个静态库编译成一个动态库
  • 【C++】 9. vector
  • golang3变量常量
  • 【golang长途旅行第30站】channel管道------解决线程竞争的好手
  • 在WSL2-Ubuntu中安装Anaconda、CUDA13.0、cuDNN9.12及PyTorch(含完整环境验证)
  • 深度学习与自动驾驶中的一些技术
  • 51c自动驾驶~合集18
  • 点评《JMeter核心技术、性能测试与性能分析》一书
  • 使用单个连接进行数据转发的设计
  • 大数据毕业设计选题推荐-基于大数据的北京市医保药品数据分析系统-Spark-Hadoop-Bigdata
  • 1688拍立淘接口数据全面解析详细说明(item_search_img)
  • Highcharts Maps/地图 :高性能的地理数据可视化方案
  • 打工人日报#20250824
  • CTFHub技能树 git泄露3道题练习--遇到没有master如何解决!!!
  • 一文掌握 Java 键盘输入:从入门到高阶(含完整示例与避坑指南)
  • 【大模型LLM学习】Research Agent学习笔记
  • c++随笔二
  • CI/CD企业案例详解
  • 从零开始学习概念物理(第13版)(1)
  • 问卷管理系统测试报告
  • 极验demo(float)(二)
  • JAVA快速学习(一)
  • 30分钟通关二分查找:C语言实现+LeetCode真题
  • 【通识】大模型
  • AI工具:开启开发实践的新纪元