目录
1、测试概述
1.1、项目名称
1.2、测试时间
1.3、编写目的
1.4、测试范围
2、测试计划
2.1、测试用例
2.1.1、注册/登录模块
2.1.2、个人中心模块
2.1.3、找回密码模块
2.1.4、博客主列表模块
2.1.5、个人博客列表模块
2.1.6、个人草稿列表模块
2.1.7、博客详情模块
2.1.8、博客编辑页
2.2、bug等级划分
2.3、测试环境与配置
3、测试执行
4、自动化测试
4.1、准备工作
4.2、注册自动化测试
4.3、登录自动化测试
4.4、找回密码自动化测试
4.5、个人中心自动化测试
4.6、博客列表页自动化测试
4.7、个人博客列表页自动化测试
4.8、草稿列表页自动化测试
4.9、博客详情页自动化测试
4.10、博客编辑页自动化测试
3、bug汇总
3.1、功能测试中发现的bug
3.2、兼容性测试中发现的bug
4、总结
4.1、缺陷和限制
4.2、综合评价
博客系统测试
2023年4月13日——2023年4月。。。。
对自己所编写的博客系统项目中所有的软件测试活动中,包括测试进度、资源问题、风险进行评估,总结测试活动的成功经验与不足,以便今后更好的开展测试工作
主体模块 | 测试内容 |
用户 | 注册新用户、登录系统、修改密码、找回密码、个人详细信息 |
博客 | 博客主列表页、个人博客列表页、个人博客草稿页、博客全文 |
界面测试:使用手工测试,部分使用自动化测试
安全测试:使用手工测试
易用性测试:使用手工测试
兼容性测试:也是使用手工测试,由于本人只有一部手机、一台电脑,所以除了在电脑上使用Chrome进行自动化测试以外,安卓的兼容性测试、电脑的不同浏览器:Edge、Firefox都是用手工测试
功能测试:部分使用自动化测试,详情继续往下看~
所有的手工测试,在没有bug的情况下,我就不写在这上面了~
创建一个maven项目,目录:
引入依赖:
org.seleniumhq.selenium
selenium-java
4.2.2
org.junit.jupiter
junit-jupiter
5.8.2
test
org.junit.platform
junit-platform-suite
1.8.2
test
commons-io
commons-io
2.6
org.seleniumhq.selenium
selenium-edge-driver
4.2.2
test
commom包下AutoTestUtils类【封装一些公共方法,方便调用】:
package com.BlogAutoTest.commom;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:13:02
*/
public class AutoTestUtils {
public static EdgeDriver driver;
//创建驱动对象
public static EdgeDriver createDriver() {
if(driver == null) {
EdgeOptions options = new EdgeOptions();
options.addArguments("--remote-allow-origins=*");
driver = new EdgeDriver(options);
//创建隐式等待
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
}
return driver;
}
//保存屏幕截图
public static void getScreenShot(String str) throws IOException {
List list = getTime();
//dir+filename
//./指的是当前的项目路径下,也就是BlogAutoTest下
//./src/test...相对路径
String filename = "./src/test/java/com/BlogAutoTest/"+list.get(0)+"/" + str + "_" + list.get(1)+".png";
File srcFile = driver.getScreenshotAs(OutputType.FILE);
//放到指定位置
FileUtils.copyFile(srcFile,new File(filename));
}
public static List getTime() {
//文件按照天的维度按文件进行保存
//文件格式 20230302-123244毫秒
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd-HHmmssSSS");
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyyMMdd");
String filename = simpleDateFormat1.format(System.currentTimeMillis());
String dirname = simpleDateFormat2.format(System.currentTimeMillis());
List list = new ArrayList<>();
list.add(dirname);
list.add(filename);
return list;
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import java.awt.*;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.*;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:55
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class RegTest {
public static EdgeDriver driver = createDriver();
//进入页面
@BeforeAll
public static void baseControl() throws InterruptedException {
driver.get("http://43.139.193.116:8085/blog/reg.html");
}
//1------检查注册页面是否正常打开
@Test
@Order(1)
void regPageLoadRight() throws InterruptedException {
driver.findElement(By.cssSelector("body > div.login-container > div > h3"));
driver.findElement(By.xpath("//*[@id=\"password2\"]"));
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
}
//2------用户名/密码为空是否有提示信息
@Test
@Order(2)
void RegFail() throws IOException, InterruptedException, AWTException {
//1、直接注册
driver.findElement(By.cssSelector("#username")).clear();
driver.findElement(By.cssSelector("#password")).clear();
driver.findElement(By.cssSelector("#password2")).clear();
//2、输入用户名
driver.findElement(By.cssSelector("#username")).sendKeys("cl");
//3、输入密码
driver.findElement(By.cssSelector("#password")).sendKeys("123");
//4、输入确认密码
driver.findElement(By.cssSelector("#password2")).sendKeys("123");
getScreenShot(getClass().getName());
driver.findElement(By.cssSelector("#submit")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
}
//3-----正确注册
@Test
@Order(3)
void RegRight() throws IOException, InterruptedException, AWTException {
driver.findElement(By.cssSelector("#username")).clear();
driver.findElement(By.cssSelector("#password")).clear();
driver.findElement(By.cssSelector("#password2")).clear();
String username = String.valueOf(System.currentTimeMillis());
String password = "123";
driver.findElement(By.cssSelector("#username")).sendKeys(username);
driver.findElement(By.cssSelector("#password")).sendKeys(password);
driver.findElement(By.cssSelector("#password2")).sendKeys(password);
getScreenShot(getClass().getName());
driver.findElement(By.cssSelector("#submit")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.awt.*;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.*;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:55
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class LoginTest {
public static EdgeDriver driver = createDriver();
//打开页面
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/login.html");
}
//1-------检查页面是否正常打开
@Test
@Order(1)
void loginPageLoadRight() {
driver.findElement(By.cssSelector("body > div.login-container > div > div.msg > a.m"));
driver.findElement(By.cssSelector("body > div.login-container > div > div.msg > a.ms"));
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)"));
}
//2-------登陆失败
@Order(2)
@ParameterizedTest
@CsvSource({"zhangsan,789","lisi,789"})
void loginFail(String username,String password) throws InterruptedException, IOException, AWTException {
driver.findElement(By.cssSelector("#username")).clear();
driver.findElement(By.cssSelector("#password")).clear();
driver.findElement(By.cssSelector("#username")).sendKeys(username);
driver.findElement(By.cssSelector("#password")).sendKeys(password);
driver.findElement(By.cssSelector("#submit")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
getScreenShot(getClass().getName());
}
//3--------登陆成功
@Order(3)
@ParameterizedTest
@CsvSource({"cl,1118","zhangsan,123"})
void loginSuc(String username,String password) throws IOException, InterruptedException, AWTException {
driver.findElement(By.cssSelector("#username")).clear();
driver.findElement(By.cssSelector("#password")).clear();
driver.findElement(By.cssSelector("#username")).sendKeys(username);
driver.findElement(By.cssSelector("#password")).sendKeys(password);
driver.findElement(By.cssSelector("#submit")).click();
//检测是否到个人列表页
driver.findElement(By.cssSelector("body > div.container > div.container-left > div > div:nth-child(4) > span:nth-child(1)"));
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(7)"));
getScreenShot(getClass().getName());
driver.navigate().back();
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:13:00
*/
public class FindPasswordTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/find_password.html");
}
@Test
void FPSWPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("body > div.login-container > div > div:nth-child(4) > span"));
driver.findElement(By.cssSelector("body > div.login-container > div > div:nth-child(3)"));
getScreenShot(getClass().getName());
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:58
*/
public class MyCenterTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/mycenter.html");
}
@Test
void MCPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("body > div.login-container > div > div:nth-child(5) > span"));
driver.findElement(By.cssSelector("body > div.login-container > div > div:nth-child(3)"));
getScreenShot(getClass().getName());
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:58
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogListTest {
//未登录状态 + 登录状态
//登录状态下
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/blog_list.html");
}
@Test
void BLPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(1)"));
driver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(2)"));
getScreenShot(getClass().getName());
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.awt.*;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:58
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MyBlogListTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/myblog_list.html");
}
//1------检查页面加载
@Test
@Order(1)
void mListPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("body > div.container > div.container-left > div > div:nth-child(4) > span:nth-child(1)"));
driver.findElement(By.cssSelector("#username"));
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(7)"));
getScreenShot(getClass().getName());
}
//2------检查文章内容是否显示过长
@Test
@Order(2)
void lengthMore() {
String artCount = driver.findElement(By.cssSelector("#artCount")).getText();
if(artCount.equals("0")) {
String expect = "暂无文章";
String actual = driver.findElement(By.cssSelector("#artDiv > h3:nth-child(1)")).getText();
Assertions.assertEquals(expect,actual);
}else {
String content = driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > div.desc")).getText();
if(content.length() > 200) {
Assertions.assertEquals(200,content.length());
}
}
}
//3------删除博客操作
@Test
@Order(3)
void delRight() throws InterruptedException, AWTException {
String artCount = driver.findElement(By.cssSelector("#artCount")).getText();
if(artCount.equals("0")) {
//删除
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > a:nth-child(6)")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
//检查页面是否还存在当前文章
Thread.sleep(500);
String artCount1 = driver.findElement(By.cssSelector("#artCount")).getText();
if(Integer.parseInt(artCount1) == (Integer.parseInt(artCount)-1)) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
}
}
//4------修改博客
@Test
@Order(4)
void ModRight() {
String artCount = driver.findElement(By.cssSelector("#artCount")).getText();
if(artCount.equals("0")) {
String artTitleFirst = driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > div.title")).getText();
//修改
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > a:nth-child(5)")).click();
//检查当前修改页面是否为当前文章
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button:nth-child(4)"));
// String title = driver.findElement(By.cssSelector("#title")).getAttribute("value");
Assertions.assertEquals(title,artTitleFirst);
// if(title.equals(artTitleFirst)) {
// Assertions.assertTrue(true);
// } else {
// Assertions.assertTrue(false);
// }
driver.navigate().back();
}
}
//5-------查看全文
@Test
@Order(5)
void lookArt() {
String artCount = driver.findElement(By.cssSelector("#artCount")).getText();
if(artCount.equals("0")) {
// String artTitleFirst = driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > div.title")).getText();
//查看全文
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > a:nth-child(4)")).click();
//检查文章详情页是否是当前文章
//先检查页面是否加载出来了
driver.findElement(By.cssSelector("body > div.container > div.container-right > div.upvote > button"));
driver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(3) > div.textarea-comment > button"));
// String title = driver.findElement(By.cssSelector("#title")).getText();
// Assertions.assertEquals(title,artTitleFirst);
}
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:12:57
*/
public class DraftListTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/mydraft_list.html");
}
@Test
void BDraftPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("#username"));
driver.findElement(By.cssSelector("body > div.container > div.container-left > div > a"));
getScreenShot(getClass().getName());
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.awt.*;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:13:01
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogDetailTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/blog_content.html?id=1");
}
@Order(1)
@Test
void BDetailPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("body > div.container > div.container-right > div.upvote > button"));
driver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(3) > div.textarea-comment > button"));
getScreenShot(getClass().getName());
}
//点赞
@Order(2)
@Test
void VoteRight() throws InterruptedException, AWTException {
String voteCount = "0";
String NewVote = "0";
try {
voteCount = driver.findElement(By.cssSelector("#tag")).getText();//原始点赞数
} catch (NumberFormatException e) {
e.printStackTrace();
}
//点赞
driver.findElement(By.cssSelector("body > div.container > div.container-right > div.upvote > button")).click();
Thread.sleep(2500);
driver.switchTo().alert().accept();
try {
NewVote = driver.findElement(By.cssSelector("#tag")).getText();//当前点赞数
if(Integer.parseInt(voteCount) >= 0 && Integer.parseInt(NewVote) >= 0) {
if ((Integer.parseInt(NewVote) + 1) == Integer.parseInt(voteCount) ||
(Integer.parseInt(NewVote) - 1) == Integer.parseInt(voteCount)) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
} else {
Assertions.assertTrue(false);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
//评论
@Order(3)
@Test
void CommentRight() throws InterruptedException, AWTException {
String comment = "很棒!";
//评论
driver.findElement(By.cssSelector("#text-comment")).sendKeys(comment);
driver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(3) > div.textarea-comment > button")).click();
Thread.sleep(2000);
Alert alert = driver.switchTo().alert();
alert.accept();
//检查
String comment1 = driver.findElement(By.cssSelector("#comment-list > div > div.comment-content")).getText();
if(comment.equals(comment1)) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
}
}
package com.BlogAutoTest.Tests;
import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;
import java.awt.*;
import java.io.IOException;
import static com.BlogAutoTest.commom.AutoTestUtils.createDriver;
import static com.BlogAutoTest.commom.AutoTestUtils.getScreenShot;
/**
* Created with IntelliJ IDEA.
* Description:
* User:龙宝
* Date:2023-04-15
* Time:13:01
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogEditTest {
public static EdgeDriver driver = createDriver();
@BeforeAll
static void baseControl() {
driver.get("http://43.139.193.116:8085/blog/blog_add.html");
}
@Test
@Order(1)
void BEditPageLoadRight() throws IOException {
driver.findElement(By.cssSelector("#day"));
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button:nth-child(4)"));
getScreenShot(getClass().getName());
}
@Test
@Order(2)
void addArt() throws InterruptedException, AWTException {
String title = "周一";
driver.findElement(By.cssSelector("#title")).sendKeys(title);
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(21) > a")).click();
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(5) > a")).click();
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button:nth-child(6)")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
String t = driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > div.title")).getText();
if(t.equals(title)) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
}
}
结论:界面设计不兼容移动端,但功能支持
该博客系统只满足了最基本的功能,吸引用户量,还需要拓展更多的功能,例如:登陆的验证码、用户头像、关注、粉丝、用户周排名、月排名、总排名、主页皮肤等等;另外性能方面也存在不足,还需要继续优化~
可以上线~