个人博客系统测试报告

个人博客系统测试报告

1.项目背景

实现个人博客系统

采用前后端分离的方法来实现 , 同时使用了数据库存储相关信息 , 将其部署到云服务器上 ,

2.项目功能

博客系统最基本的文章管理 , 同时使用了 Redis 存储用户的 session 信息 , 用户密码使用了加盐处理更安全 .

  1. 注册功能 : 用户输入创建的账号和密码 , 点击注册按钮无误后显示注册成功
  2. 登录功能 : 用户输入正确的账号密码后 , 登录成功跳转到列表页面
  3. 我的博客页面 ; 可以在列表页查看当前登录用户发布的博客简介以及标题 , 时间 , 内容概要
  4. 博客详情页面 : 点击 “查看全文” 按钮就会跳转到当前博客详情页 , 此时就可以看到该篇博客的完整内容
  5. 写博客 : 在登录之后 点击 “写博客” 之后就会进入博客编辑页面 , 就可以进行博客的编写 , 点击
    “发布文章” 就可以成功的发布 .

3.测试计划

3.1功能测试

3.1.1 测试用例设计

在这里插入图片描述

3.1.2实际执行测试的部分操作步骤

注册测试 :

正常注册 :

  1. 打开浏览器 , 输入 http://47.95.4.180:8082/reg.html

  2. 用户名输入 : 张二 密码 : 222 点击提交

    在这里插入图片描述

  1. 注册成功

异常注册 :

  1. 打开浏览器 , 输入 http://47.95.4.180:8082/reg.html

  2. 用户名输入 : 张二 密码 : 222点击提交

    在这里插入图片描述

登录测试 :

正常登录 :

  1. 打开浏览器 , 输入 : http://47.95.4.180:8082/login.html

  2. 输入正确的账号 , 密码 用户名 : 王一 密码 : 111

    在这里插入图片描述

  1. 得到结果

    跳转到我的博客页

    在这里插入图片描述

异常登录 :

  1. 打开浏览器 , 输入 : http://47.95.4.180:8082/login.html

  2. 输入错误的账号 , 密码 用户名 : 王一 密码 : 123

    在这里插入图片描述

增加博客页面测试 :

已登录 :

正常增加 :

  1. 打开浏览器输入 http://47.95.4.180:8082/blog_add.html

  2. 输入标题 , 正文 , 点击发布

    在这里插入图片描述

在这里插入图片描述

异常增加 :

  1. 打开浏览器输入 http://47.95.4.180:8082/blog_add.html

  2. 不输入标题 / 不输入正文 , 点击发布

    在这里插入图片描述

在这里插入图片描述

未登录 :

  1. 打开浏览器输入 http://47.95.4.180:8082/blog_add.html
  2. 得到结果 : 跳转回登录页面

删除博客测试 :

已登录 :

  1. 打开浏览器 , 输入http://47.95.4.180:8082/myblog_list.html

  2. 点击删除

    在这里插入图片描述

修改博客测试 :

已登录 :

  1. 打开浏览器输入 , 输入http://47.95.4.180:8082/myblog_list.html

  2. 点击修改 , 进行文章的修改

    在这里插入图片描述

在这里插入图片描述

查看博客详情测试 :

已登录 :

  1. 打开浏览器 , 输入 http://47.95.4.180:8082/myblog_list.html

  2. 点击 查看全文 按钮

  3. 得到结果

    在这里插入图片描述

注销测试 :

  1. 打开浏览器 , 输入 http://47.95.4.180:8082/myblog_list.html

  2. 点击 右上角 注销按钮

  3. 得到结果

    在这里插入图片描述

跳转到登录页面

在这里插入图片描述

3.2自动化测试

3.2.1 脑图

在这里插入图片描述

3.2.2 代码
  1. 添加依赖

    <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>
    
  2. 代码

    登录功能 :

    	/**
         *
         * 输入正确的账号,密码登录成功
         */
        @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();
    
        }
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值