文章目录
前言
针对个人博客项目进行了测试,个人博客系统主要由四个页面构成:登录页、博客列表页、博客详情页、博客编辑页;主要系统功能包括:用户的登录注销、查看全部博客、编辑发布博客、查看博客详情、强制功能。现在使用selenium3和junit5以及WebDriver驱动器来完成博客系统的部分自动化测试。
一、手工测试用例
二、代码编写
1.在pom.xml文件中引入相关依赖
代码如下:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<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>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<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>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
2.新建包并建立测试类和公共类
InitAndClose类
存放驱动的创建和关闭代码
代码如下:
public class InitAndClose {
static WebDriver webDriver;
/*创建驱动*/
@BeforeAll
static void SetInit() {
webDriver = new ChromeDriver();
}
/*关闭浏览器*/
@AfterAll
static void SetClose() {
webDriver.quit();
}
}
BlogCase测试类
(1)登录页面测试
①打开博客系统
②测试正常登录:单参数测试
③测试异常登录:用户名、密码错误
④点击登录按钮,页面能否跳转到博客列表页
⑤博客列表页的用户信息和登录的用户信息是否一致
⑥设置执行顺序
(2)博客列表页测试
①打开博客列表页
②获取页面的所有标题
③该页面的标题是否为0
④设置执行顺序
(3)查看全文测试
以点击第一条博客为测试
①点击“查看全文”按钮页面是否发生跳转
②获取当前页面URL是否和博客详情页的URL匹配
③获取当前页面的标题是否和博客详情页的标题匹配
④获取第一条博客的标题和博客详情页的博客标题是否匹配
⑤当发布新的文章,该测试是否能继续通过
⑥设置执行顺序
(4)博客编辑页测试
①点击写博客的按钮是否发生跳转
②获取当前页面的URL和页面的标题是否与博客编辑页的URL和标题一致
③能否对输入框输入相应的内容
④点击发布按钮是否发生跳转
⑤获取当前页面的URL和页面的标题是否与列表页的URL一致
⑥获取第一篇文章的标题和时间是否与发布的文章表和时间一致
⑦设置执行顺序
(5)注销功能测试
①点击注销按钮是否发生跳转
②获取当前页面的URL与登录页面的URL是否一致
③获取登录页面的输入框内容是否为空
④设置执行顺序