【项目日记(五)】搜索引擎-测试报告

❣博主主页: 33的博客

▶️文章专栏分类:项目日记◀️

🚚我的代码仓库: 33的代码仓库🚚

🫵🫵🫵关注我带你了解更多项目内容

这里写目录标题

1.项目背景

搜索引擎主要采用了前后端分离的方式来实现,把整个项目分成前端模块,索引模块,搜索模块,同时将其布置到云服务器中。该搜索引擎只是基于java API的站内搜索,根据用户输入的关键词按权重检索出对应的结果。

2.测试环境

软件:Google Chrome

开发工具:IDEA

测试工具:自动化测试工具Selenium

操作系统:Windows 10家庭中文版

浏览器版本:Google Chrome126.0.6478.115(正式版本) (64 位)

3.测试计划

测试用例:

3.1功能测试

执行过程部分截图:



3.2自动化测试

java 复制代码
package docsearcher;

import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.openqa.selenium.By;

import static java.lang.Thread.sleep;

public class docSearcher extends InitAndEnd{
    @Order(1)
    @Test
    public void search() throws InterruptedException {
        webDriver.get("http://119.91.235.248:8080/index.html");
        sleep(3000);
        webDriver.findElement(By.cssSelector("body > div > div.header > input[type=text]")).sendKeys("array");
        sleep(3000);
        webDriver.findElement(By.cssSelector("#search-btn")).click();
        sleep(3000);
        String s=webDriver.findElement(By.cssSelector("body > div > div.result > div.count")).getText();
        StringBuilder ret=new StringBuilder();
        for (char c:s.toCharArray()){
            if(Character.isDigit(c)){
                ret.append(c);
            }
        }
        if(ret.equals("0")){
            System.out.println("测试失败");
        }else {
            System.out.println("测试通过");
        }
    }
    @Order(2)
    @Test
    public void search2() throws InterruptedException {
        webDriver.get("http://119.91.235.248:8080/index.html");
        sleep(3000);
        webDriver.findElement(By.cssSelector("body > div > div.header > input[type=text]")).clear();
        webDriver.findElement(By.cssSelector("body > div > div.header > input[type=text]")).sendKeys(" ");
        sleep(3000);
        webDriver.findElement(By.cssSelector("#search-btn")).click();
        sleep(3000);
        String s=webDriver.findElement(By.cssSelector("body > div > div.result > div.count")).getText();
        StringBuilder ret=new StringBuilder();
        for (char c:s.toCharArray()){
            if(Character.isDigit(c)){
                ret.append(c);
            }
        }
        System.out.println(ret);
        String SS=ret.toString();
        if(SS.equals("0")){
            System.out.println("测试通过");
        }
    }
}

亮点:

使用Selenium与Junit结合来测试:

①使用了JUnit5中提供的注解:避免生成过多的对象,造成资源和时间的浪费,提高了自动化的执行

效率。

②只创建一次驱动对象,避免每 个用例重复创建驱动对象造成时间和资源的浪费。

③使用参数化:保持用例的简洁,提高代码的可读性

④使用测试套件:降低了测试人员的工作量,通过套件一次执行所有要运行的测试用例。

⑤使用了等待:提高了自动化的运行效率,提高了自动化的稳定性,减小误报的可能性。

⑥使用了屏幕截图:方便问题的追溯以及问题的解决

相关推荐
Elastic 中国社区官方博客2 小时前
Elasticsearch:如何在 Elastic AI Builder 里使用 DSL 来查询 Elasticsearch
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
LaughingZhu5 小时前
Product Hunt 每日热榜 | 2026-03-30
大数据·数据库·人工智能·经验分享·搜索引擎
蒸蒸yyyyzwd6 小时前
后端学习笔记day5-搜索引擎相关
搜索引擎
Elastic 中国社区官方博客7 小时前
Elasticsearch:如何在 workflow 里调用一个 agent
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
老陈头聊SEO8 小时前
生成引擎优化(GEO)引领内容创作与用户体验优化整合的新路径
其他·搜索引擎·seo优化
老陈头聊SEO9 小时前
生成引擎优化(GEO)推动内容创作效率与用户体验提升的最佳实践
其他·搜索引擎·seo优化
看山还是山,看水还是。9 小时前
消控室五方对讲接听操作流程
经验分享·笔记·搜索引擎·pdf·百度云·印象笔记·有道云笔记
尽兴-9 小时前
ES 深度分页问题及其解决方案详解
大数据·elasticsearch·搜索引擎·滚动分页·游标分页·基础分页
运营小白10 小时前
2026年,我如何用AI自动化构建一个持续增长的博客矩阵
人工智能·经验分享·搜索引擎·自动化·ai自动写作