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

博客学术汇测试报告

  Author:MTingle
major:人工智能


Build your hopes like a tower!


目录

一.项目简介

二.开发技术

三.测试用例设计

四.自动化测试代码

common包

博客编辑

博客列表

登录页面

未登录测试

主函数

五.性能测试

六.测试总结


一.项目简介

该项目是一款基于 SSM 框架搭建的个人博客系统。该系统依托 SSM 框架强大的稳定性和灵活性,实现了用户管理、文章发布等核心功能。用户可便捷注册登录,随心发布文章,分享生活感悟与专业见解。

二.开发技术

SpringBoot、SpringMVC、MyBatis、Token、MD5等。

三.测试用例设计


四.自动化测试代码

common包
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 java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Duration;public class Utils {public static WebDriver driver;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(2));}return driver;}public Utils(String url){//调用driver对象driver = createDriver();//访问urldriver.get(url);}public void getScreenShot(String str) throws IOException {//     ./src/test/image///                     /2024-07-17///                                /test01-17453010.png//                                /test02-17453020.png//                     /2024-07-18///                                /test01-17453030.png//                                /test02-17453034.png//屏幕截图SimpleDateFormat sim1 = new SimpleDateFormat("yyyy-MM-dd");SimpleDateFormat sim2 = new SimpleDateFormat("HHmmssSS");String dirTime = sim1.format(System.currentTimeMillis());String fileTime = sim2.format(System.currentTimeMillis());//./src/test/image/2024-07-17/test01-17453020.pngString filename ="./src/test/image/"+ dirTime +"/" + str + "-" + fileTime+".png";File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);//srcFile放到指定位置FileUtils.copyFile(srcFile,new File(filename));}
}
博客编辑
ackage tests;import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;import java.security.Key;
import java.time.Duration;public class EditPage extends Utils {public static String url = "http://8.137.19.140:9090/blog_edit.html";public EditPage() {super(url);}public void EditSuc() throws InterruptedException {String blogTile = "测试开发";driver.findElement(By.cssSelector("#title")).sendKeys(blogTile);WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));//第二种方法实现----下节课再讲
//        1.鼠标先挪动到博客内容区域
//        2.双击鼠标将内容删掉:鼠标双击内容+键盘DELETE
//        3.输入内容WebElement ele = driver.findElement(By.cssSelector("#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre > span > span"));Actions actions = new Actions(driver);//perform作用:为了在页面看到效果Thread.sleep(1000);actions.doubleClick(ele).perform();Thread.sleep(1000);actions.sendKeys(Keys.DELETE).perform();// 输入新内容actions.sendKeys("键盘输入测试开发").perform();Thread.sleep(1000);driver.findElement(By.cssSelector("#submit")).click();Thread.sleep(3000);driver.quit();}}
博客列表
package tests;import common.Utils;
import jdk.jshell.execution.Util;
import org.openqa.selenium.Alert;import java.util.List;public class ListPage extends Utils {public static String url = "http://8.137.19.140:9090/blog_list.htmlq";public ListPage() {super(url);}/*** 未登录状态下访问列表页*/public void listNoLogin(){// 处理警告弹窗Alert alert = driver.switchTo().alert();alert.accept();// 调整到登录页面String expect = driver.getTitle();assert expect.equals("登录页面");}}
登录页面
package tests;import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;import java.io.IOException;
import java.time.Duration;public class LoginPage extends Utils {public static String url = "http://8.137.19.140:9090/blog_login.html";public LoginPage() {super(url);}public void loginPageRight(){// 通过查找元素判断页面加载成功与否driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));driver.findElement(By.cssSelector("body > div.container-login > div"));}public void loginSuc() throws IOException {// 通过查找元素判断页面加载成功与否driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");driver.findElement(By.cssSelector("#password")).sendKeys("123456");driver.findElement(By.cssSelector("#submit")).click();// 检查是否登录成功: 通过检查是否存在 "查看全文" 按钮判断是否登录成功driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a"));// 页面标题判断是否登录成功String expect = driver.getTitle();assert expect.equals("博客列表页");
//        getScreenShot(getClass().getName());
//        assert expect.equals("博客列表111");//        driver.quit();}/*** 登录失败: 显示等待处理弹窗*/public void loginFail() throws IOException {driver.navigate().back();// 通过 clear 保证输入框没有文本信息driver.findElement(By.cssSelector("#username")).clear();driver.findElement(By.cssSelector("#password")).clear();// 通过查找元素判断页面加载成功与否driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan111");driver.findElement(By.cssSelector("#password")).sendKeys("123456");driver.findElement(By.cssSelector("#submit")).click();// 检查是否登录成功: 通过检查是否存在 "查看全文" 按钮判断是否登录成功
//        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a"));
//        getScreenShot(getClass().getName());WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));try {Alert alert = wait.until(ExpectedConditions.alertIsPresent());alert.accept();} catch (Exception e) {System.out.println("等待5秒后仍未检测到弹窗");}// 页面标题判断是否登录成功String expect = driver.getTitle();System.out.println(expect);
//        assert expect.equals("博客列表");
//        assert expect.equals("博客列表111");driver.quit();}}
未登录测试
package tests;import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;import java.io.IOException;public class PageByNoLogin extends Utils {public static String listurl = "http://8.137.19.140:9090/blog_list.html";public static String editurl = "http://8.137.19.140:9090/blog_edit.html";public static String detailurl = "http://8.137.19.140:9090/blog_detail.html";public PageByNoLogin() {super("");}// 列表页未登录处理public void listNoLogin() throws IOException {driver.get(listurl);Alert alert = driver.switchTo().alert();alert.accept();String expect = driver.getTitle();getScreenShot(getClass().getName());assert expect.equals("博客登录页");}public void detailNoLogin() throws IOException {driver.get(detailurl);Alert alert = driver.switchTo().alert();alert.accept();String expect = driver.getTitle();getScreenShot(getClass().getName());assert expect.equals("博客登录页");}public void editNoLogin() throws IOException {driver.get(editurl);Alert alert = driver.switchTo().alert();alert.accept();String expect = driver.getTitle();getScreenShot(getClass().getName());assert expect.equals("博客登录页");}}
主函数
package tests;import java.io.IOException;public class RunTests {public static void main(String[] args) throws IOException, InterruptedException {LoginPage login = new LoginPage();
//        login.loginPageRight();login.loginSuc();
//        login.loginFail();EditPage editPage = new EditPage();editPage.EditSuc();//        ListPage listPage = new ListPage();}
}

五.性能测试

Jmeter测试

性能测试报告

cmd参考运行命令: jmeter -n -t  博客登录请求.jmx -l blog.jtl -e  -o ./blog/.

六.测试总结

1) 主功能测试通过,项目可以上线
2) 项目上线后高优观察线上数据,查看线上用户操作日志,及时跟进用户反馈。


http://www.mrgr.cn/news/96664.html

相关文章:

  • Android:Dialog的使用详解
  • ffmpeg滤镜使用
  • 音频进阶学习二十四——IIR滤波器设计方法
  • VUE3+Mapbox-GL 实现鼠标绘制矩形功能的详细代码和讲解
  • NVR接入录像回放平台EasyCVR视频融合平台城市/乡镇污水处理厂解决方案
  • 蓝桥杯专项复习——二分查找、二分答案
  • Laravel APP_KEY 生成方法
  • 力扣每日一题:2712——使所有字符相等的最小成本
  • 苍穹外卖项目结构
  • 网络架构搭建中的 QinQ 与端口安全策略
  • DAY 32 leetcode 242--哈希表.有效的字母异位词
  • Oracle数据库数据编程SQL<3.5 PL/SQL 存储过程(Procedure)>
  • 魔改chromium——基础环境搭建
  • Open GL ES ->GLSurfaceView在正交投影下的图片旋转、缩放、位移
  • OpenCV图像输入输出模块imgcodecs
  • 什么是 CSSD?
  • OCCT(2)Windows平台编译OCCT
  • OpenCV图像输入输出模块imgcodecs(imwrite函数的用法)
  • Oracle数据库数据编程SQL<3.4 PL/SQL 自定义函数(Function)>
  • 初始ARM