校园幸运抽(抽奖系统)测试报告
校园幸运抽(抽奖系统)
- 项目介绍
- 测试用例设计
- 部分测试示例
- 自动化测试
- 编写自动化脚本
- (1)引入相关的脚本依赖
- (2) 创建对应的类和文件夹
- 自动化部分功能实战结果(视频)
- 部分源码展示:
- 测试总结:
- 接口测试
项目介绍
"校园幸运抽"是一款基于SSM(Spring+SpringMVC+MyBatis)框架构建的智能抽奖平台,专为校园场景设计,集活动运营、数据安全和高并发处理于一体。系统采用Spring Boot3现代化架构,融合多种前沿技术,为师生提供趣味性强、公平透明的抽奖体验,同时为运营者提供高效的管理工具。
测试用例设计
部分测试示例
注册信息不填直接点击注册,出现提示词
正常注册
密码错误登录
正常登录跳转到活动中心页面
自动化测试
编写自动化脚本
(1)引入相关的脚本依赖
(2) 创建对应的类和文件夹
自动化部分功能实战结果(视频)
屏幕录制 2025-07-12 223510
部分源码展示:
public class Utils {private static WebDriver driver;public Utils() {}public static WebDriver getDriver() {if(driver == null) {WebDriverManager.firefoxdriver().setup();FirefoxOptions options = new FirefoxOptions();options.addArguments("--headless");driver = new FirefoxDriver();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));}return driver;}public static void openUrl(String url) {getDriver().get(url);}public static void quitDriver() {if (driver != null) {driver.quit();driver = null;}}public static void waitForElementVisible(By locator, Duration timeout) {new WebDriverWait(getDriver(), timeout).until(ExpectedConditions.visibilityOfElementLocated(locator));}public static void waitForElementClickable(By locator, Duration timeout) {new WebDriverWait(getDriver(), timeout).until(ExpectedConditions.elementToBeClickable(locator));}public static void ScreenShot(String name) {//年月日SimpleDateFormat sim1 = new SimpleDateFormat("yyyy-MM-dd");//时分秒SimpleDateFormat sim2 = new SimpleDateFormat("HHmmssSS");String dirTime = sim1.format(System.currentTimeMillis());String fileTime = sim2.format(System.currentTimeMillis());File srcFile= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);String fileName = "./src/test/java/images/" + dirTime + "/" + name +"/"+ "-" + fileTime + ".png";try {FileUtils.copyFile(srcFile,new File(fileName));} catch (IOException e) {System.out.println("截图失败:"+e.getMessage());}}public static WebDriverWait Wait() {return new WebDriverWait(getDriver(), Duration.ofSeconds(10));}public static void captureFullScreen(String picName) {//年月日SimpleDateFormat sim1 = new SimpleDateFormat("yyyy-MM-dd");//时分秒SimpleDateFormat sim2 = new SimpleDateFormat("HHmmssSS");String dirTime = sim1.format(System.currentTimeMillis());String fileTime = sim2.format(System.currentTimeMillis());File srcFile= ((TakesScreenshot)getDriver()).getScreenshotAs(OutputType.FILE);String fileName = "./src/test/java/images/" + dirTime + "/" +picName+"/"+ "-" + fileTime ;try {// 创建 Robot 类实例Robot robot = new Robot();// 获取屏幕尺寸Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());// 捕获整个屏幕BufferedImage screenFullImage = robot.createScreenCapture(screenRect);// 将截图保存为文件ImageIO.write(screenFullImage, "png", new File(fileName));} catch (AWTException | IOException e) {e.printStackTrace();}}}private Alert alert ;private WebDriver driver ;{Utils.openUrl("http://101.201.58.216:8080/blogin.html");driver = Utils.getDriver();}public void loginInformation(String username, String password,String picName) {driver.findElement(By.xpath("//*[@id=\"phoneNumber\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).clear(); // 清空密码输入框driver.findElement(By.xpath("//*[@id=\"phoneNumber\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("/html/body/div/div[2]/form[1]/button")).click();}//正确登录public void Normallogin(String username, String password,String picName) {loginInformation(username, password,picName);String title = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/span")).getText();assert title.equals("退出");Utils.ScreenShot(picName);// 输入密码}public void userCorrectPasswordError(String username, String password,String picName) {loginInformation(username, password,picName);Utils.Wait().until(ExpectedConditions.alertIsPresent());alert=driver.switchTo().alert();String title = alert.getText();assert title.equals("登录失败!密码错误");// Utils.captureFullScreen(picName);// 输入密码alert.accept();Utils.ScreenShot(picName);}public void userErrorPasswordCorrect(String username, String password,String picName) {loginInformation(username, password,picName);alert=driver.switchTo().alert();String title = alert.getText();assert title.equals("登录失败!登录方式不存在");// Utils.ScreenShot(picName);// 输入密码alert.accept();Utils.ScreenShot(picName);}public void userEmptyPasswordCorrect(String username, String password,String picName) {loginInformation(username, password,picName);String textPhone=driver.findElement(By.xpath("//*[@id=\"phoneNumber-error\"]")).getText();assert textPhone.equals("请输入您的手机号");// Utils.ScreenShot(picName);// 输入密码Utils.ScreenShot(picName);}public void userCorrectPasswordEmpty(String username, String password,String picName) {loginInformation(username, password,picName);String text=driver.findElement(By.xpath("//*[@id=\"password-error\"]")).getText();assert text.equals("请输入密码");// Utils.ScreenShot(picName);// 输入密码Utils.ScreenShot(picName);}public void userErrorPasswordError(String username, String password,String picName) {loginInformation(username, password,picName);alert=driver.switchTo().alert();String title = alert.getText();assert title.equals("登录失败!登录方式不存在");// Utils.ScreenShot(picName);// 输入密码alert.accept();Utils.ScreenShot(picName);}public void userEmptyPasswordEmpty(String username, String password,String picName) {loginInformation(username, password,picName);String textPhone=driver.findElement(By.xpath("//*[@id=\"phoneNumber-error\"]")).getText();String textPassword=driver.findElement(By.xpath("//*[@id=\"password-error\"]")).getText();assert textPhone.equals("请输入您的手机号");assert textPassword.equals("请输入密码");Utils.ScreenShot(picName);}
源码仓库:https://gitee.com/daiyang-200332/automated-testing-source-code
测试结果:自动化正常结束,用例通过
测试总结:
该项目在功能方面表现良好,测试过程中发现的问题均已修复,但由于云服务器资源不足,链接不够稳定,以及项目逻辑中设置了多开限制,因此暂时未能进行完整的压力测试
接口测试
利用postman对于登录,注册,创建奖品,创造抽奖人员,抽奖等接口进行测试,保证接口返回值正确
测试结果:符合预期结果