由于我平常经常写博客,就想自己做一个“个人博客系统”,来存放自己的博客
Bug:
标题:账号密码输入错误时,页面无反应,易用性差
版本:谷歌版本 113.0.5672.64(正式版本) (64 位)
环境:Win11
操作步骤:通过登入页面,进行登入
预期结果:给用户提示用户名或密码错误
实际结果:页面无反应
Bug归属:前端
Bug级别:次要
BUG:
标题:作者信息展示失败
版本:谷歌版本 113.0.5672.64(正式版本) (64 位)
环境:Win11
操作步骤:通过主页点击查看全文
预期结果:给用户展示作者信息
实际结果:页面无展示
Bug归属:后端
Bug级别:一般
针对登入功能,博客列表页展示功能,文章详情页展示功能,博客编辑页发布功能,设计16个用例,全部通过。
设计了两个包,AutotestUtils包用来存放测试时使用的公共方法,Tests包是对各个功能设计测试用例,RunSuite是测试套件。
public class AutotestUtils {
public static EdgeDriver driver;
//创建驱动对象,单例模式
public static EdgeDriver getDriver() {
if(driver == null) {
EdgeOptions options = new EdgeOptions();
options.addArguments("--remote-allow-origins=*");
//options.addArguments("--window-size=1960,1080");
driver = new EdgeDriver(options);
//创建隐式等待
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
return driver;
}
//类外不可以实例化
private AutotestUtils() {
}
}
登入页面
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) //测试用例的执行顺序
public class BlogLoginTest {
public static EdgeDriver driver = AutotestUtils.getDriver();
//测试登入页面都要访问登入页面的url
@BeforeAll
public static void request() {
driver.get("http://101.133.141.74:8081/login.html");
}
/**
* 登入页面展示正确
*/
@Test
@Order(1)
void loginPageShowRight() {
driver.findElement(By.cssSelector("body > div.login-container > div > h3"));
driver.findElement(By.cssSelector("body > div.login-container"));
driver.findElement(By.cssSelector("body > div.nav"));
}
/**
* 正常登入
* 多参数,多次输入
* @param username
* @param password
*/
@ParameterizedTest //多参数
@CsvSource({ "lisi,lisi", "zhangsan,zhangsan"})
@Order(3)
void loginSuc(String username, String password) {
//多次测试需要清空输入框
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(5)"));
driver.findElement(By.cssSelector("body > div.nav"));
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1)"));
driver.navigate().back();
}
/**
* 异常登入
* @param username
* @param password
*/
@ParameterizedTest
@CsvSource({"'',''", "zhangsan,''", "'',zhangsan"})
@Order(2)
void loginFail(String username, String password) {
//多次测试需要清空输入框
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();
//处理弹窗
Alert alert = driver.switchTo().alert();
alert.accept();
}
}
博客列表页
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogListTest {
static EdgeDriver driver = AutotestUtils.getDriver();
@BeforeEach
void baseController() throws InterruptedException {
driver.get("http://101.133.141.74:8081/myblog_list.html");
}
/**
* 登入状态下
*/
@Test
@Order(1)
void ListShowRight() {
driver.findElement(By.cssSelector("body > div.container > div.container-left > div > div:nth-child(5)"));
driver.findElement(By.cssSelector("body > div.nav"));
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1)"));
}
/**
* 未登入状态,列表展示失败
*/
@Test
@Order(3)
void ListShowWrong() throws InterruptedException {
Thread.sleep(200);
Alert alert = driver.switchTo().alert();
alert.accept();
alert.accept();
driver.navigate().refresh();
}
//退出登入状态
@Test
@Order(2)
void out() throws InterruptedException {
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
//处理弹窗
Alert alert = driver.switchTo().alert();
alert.accept();
//返回登入页面
driver.findElement(By.cssSelector("body > div.login-container > div > h3"));
}
}
博客详情页
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogDetailTest {
static EdgeDriver driver = AutotestUtils.getDriver();
/**
* 未登入情况下,能正确展示
*/
@Test
@Order(1)
void BlogDetailNoLoad() {
driver.get("http://101.133.141.74:8081/blog_content.html?id=3");
driver.findElement(By.cssSelector("#username"));
driver.findElement(By.cssSelector("#title"));
driver.findElement(By.cssSelector("#editorDiv > p"));
}
/**
* 登入状态下
*/
@Test
@Order(2)
void BlogDetailLoad() throws InterruptedException {
driver.get("http://101.133.141.74:8081/login.html");
driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys("zhangsan");
driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("zhangsan");
driver.findElement(By.cssSelector("#submit")).click();
driver.findElement(By.cssSelector("#artDiv > div:nth-child(1) > a:nth-child(4)")).click();
driver.findElement(By.cssSelector("#username"));
driver.findElement(By.cssSelector("#title"));
driver.findElement(By.cssSelector("#editorDiv > p"));
}
}
博客编辑页
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogEditTest {
static EdgeDriver driver = AutotestUtils.getDriver();
@BeforeAll
static void get() {
driver.get("http://101.133.141.74:8081/blog_add.html");
}
/**
* 登入状态下,页面是否显示正常
*/
@Test
@Order(1)
void EditPageShowRight() {
driver.findElement(By.cssSelector("#title"));
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button"));
driver.findElement(By.cssSelector("#editorDiv > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll"));
}
/**
*正常填写博客能提交成功
*/
@Test
@Order(3)
void SubmitBlog() throws InterruptedException {
String expect = "测试1";
driver.findElement(By.cssSelector("#title")).sendKeys(expect);
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(21) > a > i")).click();
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(13) > a > i")).click();
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();
Thread.sleep(100);
Alert alert = driver.switchTo().alert();
alert.accept();
Thread.sleep(100);
alert.dismiss();
}
/**
* 不写标题不能提交成功
*/
@Test
@Order(2)
void SubmitBlogFail() {
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();
Alert alert = driver.switchTo().alert();
alert.accept();
alert.accept();
}
//退出登入
@Test
@Order(3)
void LoadOut() throws InterruptedException {
driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
Thread.sleep(200);
Alert alert = driver.switchTo().alert();
alert.accept();
}
/**
* 未登入去发布博客
*/
@Test
@Order(4)
void SubmitNotLoad() throws InterruptedException {
driver.get("http://101.133.141.74:8081/blog_add.html");
String expect = "测试1";
driver.findElement(By.cssSelector("#title")).sendKeys(expect);
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(21) > a > i")).click();
driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(13) > a > i")).click();
driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();
Thread.sleep(100);
Alert alert = driver.switchTo().alert();
alert.accept();
Thread.sleep(100);
alert.accept();
}
@AfterAll
public static void quit() throws InterruptedException {
driver.quit();
}
}
测试套件
@Suite
@SelectClasses({BlogLoginTest.class, BlogListTest.class, BlogDetailTest.class, BlogEditTest.class})
public class RunSuite {
}