博客系统自动化测试

前言

针对个人博客项目进行了测试,个人博客系统主要由四个页面构成:登录页、博客列表页、博客详情页、博客编辑页;主要系统功能包括:用户的登录注销、查看全部博客、编辑发布博客、查看博客详情、强制功能。现在使用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是否一致
③获取登录页面的输入框内容是否为空
④设置执行顺序

3.代码测试结果

在这里插入图片描述

4.代码参考

个人博客系统自动化测试代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值