【测试报告】个人博客系统自动化测试报告

news2024/10/7 2:20:36

文章目录

  • 项目背景
  • 项目功能
  • 测试计划
    • 功能测试
      • 测试用例
      • 执行测试的操作步骤
    • 自动化测试
      • 设计的模块、自动化运行的结果、问题定位的结果
      • 自动化测试优点

项目背景

        对于一个程序员来说,定期整理总结并写博客是不可或缺的步骤,不管是对近期新掌握的技术或者是遇到bug解决bug过程的记录等,都是非常有必要的。
        目前的博客网站有很多,比如CSDN、掘金、博客园等。本人在整个学习的阶段也都会经常在上面发布文章和见解等,最近学了一些开发所需要的主流框架,因此以做项目代学,做出了一个简易版的个人博客系统。

项目功能

        博客系统中最基本的用户管理、文章管理(增删改查等)都有涉及,此外在这个博客系统中不需要担心安全问题(因为用户密码采用了加盐加密处理,破解成本高,且在一些私人界面加入了拦截器等)、短时间内不需要重复登录(因为在redis中存储了用户的session信息并进行了持久化处理)、可以随时随地地更换自己喜欢的头像(因为上传的图片发送到服务器并使用Nginx存储起来,稍等一段时间后台刷新后即可看到换的头像)。

测试计划

功能测试

测试用例

在这里插入图片描述
        测试的第一步永远都是测试用例的编写,这里对这个项目中的功能使用脑图进行测试用例的编写。

执行测试的操作步骤

登录页:
(1)账号或密码为空:
在这里插入图片描述
(2)账号或密码填写错误:
在这里插入图片描述
(3)正确登录跳转到个人列表页:
在这里插入图片描述
个人列表页:
(1)正常登录状态下:
在这里插入图片描述
(2)未登录的状态下输入url - http://43.139.71.60:8081/myblog_list.html(跳转到登录页):
在这里插入图片描述
博客列表页:
(1)在未登录的情况下(只有登录按钮):
在这里插入图片描述
(2)在登录的状态下(有三个按钮选择):
在这里插入图片描述
博客详情页:
(1)在未登录的情况下(只读):
在这里插入图片描述
(2)在登录root账号下打开cxz的文章(只读):
在这里插入图片描述
(3)在cxz账户下打开自己的文章(可删除、修改):
在这里插入图片描述
博客编辑页:
(1)未登录的状态下(提示失败并跳转到登录页):
在这里插入图片描述
(2)登录的状态下(提示成功并跳转到个人列表页):
在这里插入图片描述
在这里插入图片描述

自动化测试

        重点还是自动化测试。编写自动化代码通常是需要根据编写的测试用例来进行的,但是由于时间关系,本自动化测试对部分主要功能进行编写,如分页、更换头像等没有在范围内,但是这些基本上都是类似的,这里就以部分为例。

设计的模块、自动化运行的结果、问题定位的结果

环境:
编译器:IDEA 2021.3.2
浏览器:Microsoft Edge 113.0.1774.57
驱动程序:msedgedriver.exe(具体在官网选择当前浏览器对应的版本的驱动即可)
自动化测试工具:selenium4
自动化测试框架:junit5
以上对应的依赖包:

        <!--    自动化测试    -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>

        <!--    保存屏幕截图文件    -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

        <!--    junit5     -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>

        由于驱动对象是在一开始就创建的,且全局只用这一个,所以我们可以将它封装起来并用static来修饰:

    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(10));
        }
        return driver;
    }

登录页:
        首先测试页面是否正常显示,此外需要测试两种情况:一是正常登录的情况;二是异常登录的情况。
        对于异常登录,这里简单测试一组数据,并将报错信息返回回来;对于正常登录,这里测试两组数据。测试登录都使用参数化,也就是以下两个注解:

    @ParameterizedTest
    @CsvSource({"root, 123"})

在这里插入图片描述

package com.blogWebAutoTest.Tests;

import com.blogWebAutoTest.common.autoTestUtils;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-05-30
 * Time: 15:16
 */
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class blogLoginTest extends autoTestUtils {
    public static EdgeDriver driver;

    @BeforeAll
    static private void baseControl(){
        driver = createDriver();
        driver.get("http://43.139.71.60:8081/login.html");
    }

    /*
    * 页面是否正确打开
    * 检查点:主页、注册元素是否存在
    * */
    @Test
    @Order(1)
    public void loginPageLoadRight() throws IOException {
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)"));
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
        getScreenShot(getClass().getName());
    }

    /*
    * 检查正常登录情况
    * */
    @ParameterizedTest
    @CsvSource({"root, 123456"})
    @Order(3)
    public void loginSuccess(String username, String password) throws InterruptedException, IOException {
        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(3000);
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
        getScreenShot(getClass().getName());
        driver.navigate().back();
//        Thread.sleep(3000);
    }

    /*
    * 检查异常的登录情况
    * */
    @ParameterizedTest
    @CsvSource({"root, 123"})
    @Order(2)
    public void loginFail(String username, String password) throws IOException, InterruptedException {
        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(3000);
        System.out.println(driver.switchTo().alert().getText());
        driver.switchTo().alert().accept();
        getScreenShot(getClass().getName());
//        Thread.sleep(3000);
    }
}

个人列表页:
        通过页面的共同元素看页面是否正常打开。

package com.blogWebAutoTest.Tests;

import com.blogWebAutoTest.common.autoTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-05-30
 * Time: 15:16
 */
public class blogListTest extends autoTestUtils {
//    public static EdgeDriver driver;

    @BeforeAll
    static private void baseControl(){
//        driver = createDriver();
        driver.get("http://43.139.71.60:8081/myblog_list.html");
    }

    /*
     * 页面是否正确打开
     * 检查点:创作数、访问量、写博客元素是否存在
     * */
    @Test
    public void loginPageLoadRight() throws IOException {
        driver.findElement(By.cssSelector("body > div.container > div.container-left > div > div:nth-child(5) > span:nth-child(1)"));
        driver.findElement(By.cssSelector("body > div.container > div.container-left > div > div:nth-child(5) > span:nth-child(2)"));
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
        getScreenShot(getClass().getName());
    }
}

博客编辑页:
        首先测试页面是否正常显示,此外需要测试写的博客能否正常提交,这里就可以使用到断言(无论结果显示的是否是“提交成功!”,都可以执行通过,不会出现报错的情况,这也是自动化测试的要求)。
在这里插入图片描述

package com.blogWebAutoTest.Tests;

import com.blogWebAutoTest.common.autoTestUtils;
import org.junit.jupiter.api.*;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-05-30
 * Time: 15:17
 */
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class blogEditTest extends autoTestUtils {
    //    public static EdgeDriver driver;

    @BeforeAll
    static private void baseControl(){
//        driver = createDriver();
        driver.get("http://43.139.71.60:8081/blog_edit.html");
    }

    /*
     * 页面是否正确打开
     * 检查点:主页、我的博客、退出登录元素是否存在
     * */
    @Test
    @Order(1)
    public void loginPageLoadRight() throws IOException {
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)"));
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)"));
        getScreenShot(getClass().getName());
    }

    @Test
    @Order(2)
    public void editAndSubmitBlog() throws IOException, InterruptedException {
        driver.findElement(By.cssSelector("#title")).sendKeys("测试执行自动化测试脚本");
        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(12) > a > i")).click();
        driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(12) > a > i")).click();
        driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(12) > a > i")).click();
        driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(12) > a > i")).click();
        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("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(13) > a > i")).click();
        driver.findElement(By.cssSelector("#editorDiv > div.editormd-toolbar > div > ul > li:nth-child(21) > a > i")).click();
        driver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();
        Thread.sleep(3000);
        Assertions.assertEquals("提交成功!", driver.switchTo().alert().getText());
        driver.switchTo().alert().accept();
        getScreenShot(getClass().getName());
    }
}

引入截图功能:
        由于自动化执行的速度是比较快的,所以中间过程是比较难看到的,因此我们可以使用截图并保存来看:
在这里插入图片描述
在这里插入图片描述
        图片不能单纯地命名为固定的,因为这样会造成覆盖的情况,也就是说之前截的图片会被覆盖掉,比较主流、合理的方法是使用时间戳来命名,更严谨的是按照日期来建文件夹,按照当前时间来取文件名的形式,避免重名的情况。

    //使用时间戳动态生成图片名
    public List<String> getTime(){
        //以天的维度按照文件夹进行保存
        List<String> list = new ArrayList<>();
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyyMMdd-HHmmssSS");
        String dirname = simpleDateFormat1.format(System.currentTimeMillis());
        String filename = simpleDateFormat2.format(System.currentTimeMillis());
        list.add(dirname);
        list.add(filename);
        return list;
    }

    //获取屏幕截图,把所有用例结果保存下来(非常适用于无头模式)
    public void getScreenShot(String s) throws IOException {
        List<String> list = getTime();
        String filename = "./src/test/java/com/blogWebAutoTest/" + list.get(0) + "/" + s + "_" + list.get(1) + ".png";
        File file = driver.getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file, new File(filename));
    }

博客详情页:
        博客详情页共同的元素是文章标题和发布时间,所以根据其来确定页面是否正常加载。
在这里插入图片描述

package com.blogWebAutoTest.Tests;

import com.blogWebAutoTest.common.autoTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-05-30
 * Time: 15:17
 */
public class blogDetailTest extends autoTestUtils {
    //    public static EdgeDriver driver;

    @BeforeAll
    static private void baseControl(){
//        driver = createDriver();
        driver.get("http://43.139.71.60:8081/blog_content.html?id=18");
    }

    @Test
    public void blogDetailLoadRight() throws IOException {
        driver.findElement(By.cssSelector("#title"));
        driver.findElement(By.cssSelector("#data"));
        getScreenShot(getClass().getName());
    }

    @AfterAll
    private static void driverQuit(){
        driver.quit();
    }
}

        注意在最后需要使用@AfterAll注解来释放掉驱动对象,同样也是全局执行一次。


        实际上这个自动化涉及到的用例测试是非常少的,且很多功能都还没有测试全面,但其实也是大同小异。后面有时间会继续写完整后面的自动化代码,感兴趣的后面可以看完整代码:博客系统自动化测试代码(努力填坑中…)。

自动化测试优点

(1)使用了junit5框架中提供的注解,避免生成过多的对象,造成时间和资源的浪费,提高了自动化的执行效率。
(2)只创建一次驱动对象,避免每个用例重复创建驱动对象造成时间和资源的浪费。
(3)使用参数化,保持用例的简洁,提高代码的可读性,同时也方便存储大量数据的.csv文件导入。
(4)使用测试套件,降低自动化测试的工作量,因为通过套件就可以一次执行所有运行的测试用例。
(5)使用了隐式等待,提高了自动化的运行效率,提高了自动化的稳定性。
(6)加入了屏幕截图功能,方便在无头模式下追溯问题的位置。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/593330.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C# 读取json格式文件

读取json格式文件 安装 Newtonsoft.Json 程序集 1. 选择界面下方的【程序包管理器控制台】页面&#xff0c;输入安装指令 Install-Package Newtonsoft.Json 2. 安装完成后&#xff0c;请确保在代码文件的顶部包含以下 using 指令&#xff1a; using Newtonsoft.Json; 创建读…

GCC如何生成并调用静态库

一&#xff0c;简介 本文主要介绍如何使用gcc编译代码生成静态库&#xff0c;并调用静态库运行的操作步骤。 二&#xff0c;准备工作 使用add.c和main.c生成test可行性文件的流程图&#xff1a; add.c文件的内容&#xff1a; #include "add.h"int add(int a, i…

自学网络安全, 一般人我劝你还是算了吧

前言&#xff1a;自学我劝你还是算了&#xff0c;我为什么要劝你放弃我自己却不放弃呢&#xff1f;因为我不是一般人。。。 1.这是一条坚持的道路,三分钟的热情可以放弃往下看了. 2.多练多想,不要离开了教程什么都不会了.最好看完教程自己独立完成技术方面的开发. 3.有时多 …

【性能测试】Jenkins+Ant+Jmeter自动化框架的搭建思路

前言 前面讲了Jmeter在性能测试中的应用及扩展。随着测试的深入&#xff0c;我们发现在性能测试中也会遇到不少的重复工作。 比如某新兴业务处于上升阶段&#xff0c;需要在每个版本中&#xff0c;对某些新增接口进行性能测试&#xff0c;有时还需要在一天中的不同时段分别进行…

计算如何与实验结合发Science

理论计算与实验结合的研究已经成为TOP期刊中的主流方式。近日&#xff0c;上海交通大学种丽娜副教授一项关于质子交换膜水解槽阳极催化剂的研究成果在Science发表。该工作报道了一种由沸石甲基咪唑酯骨架&#xff08;Co-ZIF&#xff09;衍生并通过静电纺丝处理的镧和锰共掺杂的…

Python 修复共享内存问题和锁定共享资源问题

文章目录 使用 multiprocessing.Array() 在 Python 中使用共享内存解决多进程之间共享数据问题的解决方案 使用 multiprocessing.Lock() 锁定 Python 中的共享资源 本篇文章解释了多处理共享内存的不同方面&#xff0c;并演示了如何使用共享内存解决问题。 我们还将学习如何使用…

Axure教程—图片手风琴效果

本文将教大家如何用AXURE制作图片手风琴效果 一、效果介绍 如图&#xff1a; 预览地址&#xff1a;https://6nvnfm.axshare.com 下载地址&#xff1a;https://download.csdn.net/download/weixin_43516258/87847313?spm1001.2014.3001.5501 二、功能介绍 图片自动播放为手风…

MT4交易外汇平台有哪些优势?为何是外汇投资首选?

外汇市场上存在着各种各样的外汇交易商&#xff0c;但是很多的外汇交易商所选择的交易平台都是MT4交易外汇平台。作为全世界范围内使用最为广泛的交易平台&#xff0c;MT4交易外汇平台具有哪些优势&#xff0c;能够让外汇交易商和外汇投资者都选择使用。本文就来具体的聊聊&…

SQL中not in的一个坑

因not in 效率较低&#xff0c;在工作用一只用left join代替&#xff0c;在某一次查询使用了not in发现&#xff0c;结果为空&#xff0c;sql大致如下 select id from table1 where id not in (select id from table2)经过查询发现select id from table2里面的id有null值导致该…

司法大数据解决方案

2018年11月26日&#xff0c;司法部制定了《智慧监狱技术规范SFT0028-2018》并于2019年1月1日正式颁布实施&#xff0c;要求智慧监狱的建设应者眼于监狱工作实际&#xff0c;将物联网、云计算、大数据、人工智能等新一信息技术与监狱各项业务深度融合&#xff0c;形成标准规范科…

论文解读 | 基于改进点对特征的点云6D姿态估计

原创 | 文 BFT机器人 01 摘要 点对特征(PPF)方法已被证明是一种有效的杂波和遮挡下的姿态估计方法。 文章的改进方法主要包括: (1)一种基于奇偶规则求解封闭几何的法向的方法; (2)通过将体素网格划分为等效角度单元的有效降采样方法; (3)基于拟合点的验证步骤。在真实杂波数据集…

如何挖掘360下拉词,怎么删除360下拉负面词

大多数人的手机或者电脑上都安装了360浏览器&#xff0c;360搜索APP等&#xff0c;安装的用户量大&#xff0c;自然使用的用户也就多了&#xff0c;360下拉的优势就展现出来了&#xff0c;展示量大&#xff0c;全国各地均可见&#xff1b;能够引流来的都是相对精准的目标用户&a…

C#简单数据结构类和常用泛型结构类

文章目录 1.简单数据结构类&#xff08;1&#xff09;动态数组Arraylist&#xff08;2&#xff09;栈Stack&#xff08;3&#xff09;队列Queue&#xff08;4&#xff09;哈希表Hashtable 2.泛型3.常用泛型数据结构类&#xff08;1&#xff09;列表List&#xff08;2&#xff0…

高完整性系统:Fault Tolerant Design

目录 1. INTRODUCTION TO FAULT TOLERANCE 1.2 Definitions 1.3 Two Kinds of Faults 1.4 Hardware vs Software Faults 1.4.1 Failure Curve for Hardware 1.4.2 Hardware and Software Failures 1.5 Causes of Failures 1.6 3 Ways to Class Failures 1.6.1 Tempora…

Java 岗史上最全八股文面试真题汇总,堪称 2023 年面试天花板

前言 现如今&#xff0c;Java 面试的本质就是八股文&#xff0c;把八股文面试题背好&#xff0c;面试才有可能表现好。金九银十招聘黄金季已经来临&#xff01;大家在考研和找工作中纠结的时候&#xff0c;不妨先看一下面试题&#xff0c;毕竟我们的最终目标就是为了找一份心仪…

机器视觉怎么对陶瓷板外观尺寸进行自动检测?

随着陶瓷行业的发展&#xff0c;陶瓷板的生产和质量控制面临越来越高的要求。而机器视觉技术作为一种高精度、高效率、无损、可靠性高的自动化检测手段&#xff0c;已经成为陶瓷板外观尺寸自动化检测的首选方案。本文就如何利用机器视觉对陶瓷板外观尺寸进行自动检测进行分析和…

配电室的管理制度及综合监控系统的介绍

安科瑞虞佳豪 1、配电室全部机电设备&#xff0c;由配电室人员负责管理和值班&#xff0c;停送电由值班电工操作&#xff0c;非值班电工禁止操作&#xff0c;无关人员禁止进入配电室&#xff1b;公司内有关上级部门因检查工作&#xff0c;必须要进入这些场所时&#xff0c;应由…

【温故而知新】阶段总结!我在技术成长过程中的收获!

时间&#xff1a;2023年05月31日 作者&#xff1a;小蒋聊技术 邮箱&#xff1a;wei_wei10163.com 微信&#xff1a;wei_wei10 【20230531】【温故而知新】阶段总结&#xff01;我在技术成长过程中的收获&#xff01;_小蒋聊技术_免费在线阅读收听下载 - 喜马拉雅手机版欢迎…

第十八章行为性模式—观察者模式

文章目录 观察者模式解决的问题结构实例存在的问题使用场景 JDK 提供的实现 - Observable示例 行为型模式用于描述程序在运行时复杂的流程控制&#xff0c;即描述多个类或对象之间怎样相互协作共同完成单个对象无法单独完成的任务&#xff0c;它涉及算法与对象间职责的分配。行…

WMI系列--WMI订阅事件

前边对于WMI的基础内容进行简单的总结和整理&#xff0c;结下来的这篇内容主要针对WMI的永久订阅事件展开详细的阐述。 WMI事件订阅机制 WMI事件分为两类&#xff0c;分别是本地事件订阅和永久性事件订阅。 所谓本地事件是指运行在本地上下文环境当中的单个进程的事件&#x…