个人博客系统测试报告
1.项目背景
实现个人博客系统
采用前后端分离的方法来实现 , 同时使用了数据库存储相关信息 , 将其部署到云服务器上 ,
2.项目功能
博客系统最基本的文章管理 , 同时使用了 Redis 存储用户的 session 信息 , 用户密码使用了加盐处理更安全 .
- 注册功能 : 用户输入创建的账号和密码 , 点击注册按钮无误后显示注册成功
- 登录功能 : 用户输入正确的账号密码后 , 登录成功跳转到列表页面
- 我的博客页面 ; 可以在列表页查看当前登录用户发布的博客简介以及标题 , 时间 , 内容概要
- 博客详情页面 : 点击 “查看全文” 按钮就会跳转到当前博客详情页 , 此时就可以看到该篇博客的完整内容
- 写博客 : 在登录之后 点击 “写博客” 之后就会进入博客编辑页面 , 就可以进行博客的编写 , 点击
“发布文章” 就可以成功的发布 .
3.测试计划
3.1功能测试
3.1.1 测试用例设计
3.1.2实际执行测试的部分操作步骤
注册测试 :
正常注册 :
打开浏览器 , 输入 http://47.95.4.180:8082/reg.html
用户名输入 : 张二 密码 : 222 点击提交
- 注册成功
异常注册 :
打开浏览器 , 输入 http://47.95.4.180:8082/reg.html
用户名输入 : 张二 密码 : 222点击提交
登录测试 :
正常登录 :
打开浏览器 , 输入 : http://47.95.4.180:8082/login.html
输入正确的账号 , 密码 用户名 : 王一 密码 : 111
得到结果
跳转到我的博客页
异常登录 :
打开浏览器 , 输入 : http://47.95.4.180:8082/login.html
输入错误的账号 , 密码 用户名 : 王一 密码 : 123
增加博客页面测试 :
已登录 :
正常增加 :
打开浏览器输入 http://47.95.4.180:8082/blog_add.html
输入标题 , 正文 , 点击发布
异常增加 :
打开浏览器输入 http://47.95.4.180:8082/blog_add.html
不输入标题 / 不输入正文 , 点击发布
未登录 :
- 打开浏览器输入 http://47.95.4.180:8082/blog_add.html
- 得到结果 : 跳转回登录页面
删除博客测试 :
已登录 :
打开浏览器 , 输入http://47.95.4.180:8082/myblog_list.html
点击删除
修改博客测试 :
已登录 :
打开浏览器输入 , 输入http://47.95.4.180:8082/myblog_list.html
点击修改 , 进行文章的修改
查看博客详情测试 :
已登录 :
打开浏览器 , 输入 http://47.95.4.180:8082/myblog_list.html
点击 查看全文 按钮
得到结果
注销测试 :
打开浏览器 , 输入 http://47.95.4.180:8082/myblog_list.html
点击 右上角 注销按钮
得到结果
跳转到登录页面
3.2自动化测试
3.2.1 脑图
3.2.2 代码
-
添加依赖
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.11.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.9.1</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-params</artifactId> <version>5.9.1</version> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-suite</artifactId> <version>1.9.1</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.9.1</version> <scope>test</scope> </dependency>
-
代码
登录功能 :
/** * * 输入正确的账号,密码登录成功 */ @Order(1) @ParameterizedTest @CsvFileSource(resources = "LoginSuccess.csv") void LoginSuccess(String username, String password, String blog_list_url) { System.out.println(username + password + blog_list_url); // 打开博客登录页面 webDriver.get("http://47.95.4.180:8082/login.html"); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 输入账号admin webDriver.findElement(By.cssSelector("#username")).sendKeys(username); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 输入密码123 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.SECONDS); // 跳转到列表页 // 获取到当前页面url String cur_url = webDriver.getCurrentUrl(); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 如果url=http://47.95.4.180:8082/blog_list.html,测试通过,否则测试不通过 Assertions.assertEquals(blog_list_url, cur_url); // 列表页展示用户信息是admin // 用户名是admin测试通过,否则测试不通过 webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.left > div > h3")).getText(); Assertions.assertEquals(username, cur_admin); }
博客列表页数量不为0 :
@Order(2) @Test void BlogList() { // 打开博客列表页 webDriver.get("http://47.95.4.180:8082/blog_list.html"); // 获取页面上所有博客标题对应的元素 webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); int title_num = webDriver.findElements(By.cssSelector(".title")).size(); // 如果元素数量不为0,测试通过 Assertions.assertNotEquals(0 ,title_num); }
博客详情页校验 :
@Order(4) @ParameterizedTest @MethodSource("Generator") void BlogDetail(String expected_url, String expected_title, String expected_blog_title) { // 找到第一篇博客对应的产看全文按钮 webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/a")).click(); // 获取当前页面url webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); String cur_url = webDriver.getCurrentUrl(); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 获取当前页面title String cur_title = webDriver.getTitle(); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 获取博客标题 String cur_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.right > div > h3")).getText(); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); Assertions.assertEquals(expected_title ,cur_title); Assertions.assertEquals(expected_blog_title, cur_blog_title); if(cur_url.contains(expected_blog_title)) { System.out.println("测试通过"); } else { System.out.println("测试不通过"); } }
写博客:
@Order(3) @Test void EditBlog() throws InterruptedException { // 找到写博客按钮,点击 webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click(); webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // 通过Js讲鼻涕进行输入 ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试\""); sleep(3000); // 点击发布 webDriver.findElement(By.cssSelector("#submit")).click(); sleep(3000); // 获取当前页面url String cur_url = webDriver.getCurrentUrl(); Assertions.assertEquals("http://47.95.4.180:8082/blog_list.html", cur_url); }
校验已发布博客标题以及时间 :
void BlogInfoChecked() { webDriver.get("http://47.95.4.180:8082/blog_list.html"); // 获取第一篇博客标题 String first_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > div.title")).getText(); // 获取第一篇博客发布时间 String first_blog_time = webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[2]")).getText(); // 校验博客标题是不是自动化测试 Assertions.assertEquals("自动化测试", first_blog_title); // 如果时间是2023-9-05年发布的,测试通过 if(first_blog_title.contains("2023-9-05")) { System.out.println("测试通过"); } else { //System.out.println(cur_url); System.out.println("当前时间是:" + first_blog_time); System.out.println("测试不通过"); } }
删除刚才发布的博客 :
@Order(6) @Test void DeleteBlog() throws InterruptedException { // 打开博客列表页面 webDriver.get("http://47.95.4.180:8082/blog_list.html"); // 点击全文按钮 webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); webDriver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a")).click(); // 点击删除按钮 webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(7)")).click(); sleep(3000); // 博客列表页第一篇博客标题不是“自动化测试” String first_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.right > div > h3")).getText(); // 校验当前博客标题不等于“自动化测试” webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); Assertions.assertNotEquals(first_blog_title, "自动测试"); }
注销用户 :
@Order(7) @Test void Logout() { webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS); webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click(); webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS); // 校验url(登录URL) String cur_url = webDriver.findElement(By.cssSelector("body > div.container > div.right > div > h3")).getText(); }