博客系统–项目介绍
背景:以一种新型做笔记的方式来记录学习中遇到的困难问题。
概述:一个Web网站程序,你可以看到其他用户发布的博客,也可以登录自己的账号发布博客,也可以对自己的文章内容进行修改删除。
相应技术栈:
博客登录页:
博客列表页(个人)(用户“dwj”为例):
博客详情页:
博客博客编辑页:
博客主页:
1、测试计划
1.1 功能测试
1.1.1 编写测试用例
1.1.2 实际执行步骤
博客登录页:检测界面是否符合预期,输入正确或错误的账号和密码是否能得到预期的响应
a、界面
b、输入正确的账号和密码(以用户"dwj"为例):
预期结果:跳转到博客列表页(个人)。
实际结果如下:
c、输入错误的账号或密码
预期结果:提示用户名或密码输入错误。
实际结果如下:
d、什么也不输:
预期结果:提示请先输入用户名
实际结果如下:
e、点击注册,注册一个新账号(举例用户名:wlk
密码:020304)
预期结果:注册成功跳转到登录页
博客列表页:检测界面是否符合预期,点击“查看全文”按钮是否能跳转到对应的博客详情页,点击写博客能否新增博客,点击修改按钮能否修改对应的博客,点击删除按钮能否删除对应的博客,点击注销能否退出账号
a、界面
b、点击查看全文
预期结果:跳转到博客详情页
实际结果:
c、点击写博客(举例,新增标题为我要好好学习,内容为:今天多学两分钟,明天。。。)
预期结果:可以新增博客
实际结果:
d、点击修改按钮(举例在标题为2的文章中再增添一段文字“ArrayList是一个动态类型的顺序表,在插入元素的过程中会自动扩容,可以以O(1)的时间复杂度实现随机访问,但是对于插入和删除,因为要移动元素,时间复杂度为O(n);调用不带参数的构造方法,在你第一次add的时候,底层数组容量才变成了10;在放第11个的时候,以1.5倍方式扩容”)
预期结果:提示恭喜修改成功,并且下次查询可以看到变化
实际结果:
e、删除文章(举例标题为2的文章)
预期结果:提示删除成功
实际结果:
f、点击注销
预期结果:退出当前账号并跳转到主页
实际结果:
主页:针对首页,下一页,上一页,尾页进行测试
a、首页
b、下一页
c、上一页
d、尾页
1.2、使用Selenium进行Web自动化测试
为什么选择selenium作为web自动化工具
| selenium是开源的
| selenium支持多种语言
| selenium支持各种浏览器
| selenium有丰富的API
什么是自动化以及为什么要做自动化
| 自动化是测试人员为了提高测试效率或者保证测试质量,让代码辅助测试人员执行测试的这个过程
Junit5:
1.2.1、引入依赖
进行Web自动化测试,我们需要创建Maven项目引入如下依赖(selenium4、junit5``):
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</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>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</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.2</version>
</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>
<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>
</dependencies>
1.2.2提取共性,实现代码复用
在此处我们针对博客登录页、博客列表页进行自动化测试、主页进行测试
代码结构设计:因为每个测试用例都需要驱动,我们把它封装成一个类,让其他类进行继承即可
package BLOG;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class InitAndEnd {
static WebDriver webDriver;
@BeforeAll
static void SetUp(){
webDriver=new ChromeDriver();
}
//退出浏览器
@AfterAll
static void TearDown(){
webDriver.quit();
}
}
1.2.3、博客登录页自动化测试
创建一个类BlogCases继承InitAndEnd,通过csv的方式传参,输入正确的站好密码,观察结果是否跳转到博客列表页
public class BlogCases extends InitAndEnd{
// 输入正确的账号密码登陆成功
@ParameterizedTest
@CsvFileSource(resources = "LoginSuccess.csv")
void LoginSuccess(String username,String password,String blog_list_url) {
//打开博客登录页面
webDriver.get("http://127.0.0.1:9090/login.html");
//输入账号dwj
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(30, 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://127.0.0.1:9090/myblog_list.html测试通过,否则不通过
Assertions.assertEquals(blog_list_url,cur_url);
}
LoginSuccess.csv
测试预期结果:dwj通过wlk不通过(密码错误)
实际结果:
1.2.4博客详情页
得到博客正文标题,如果博客正文标题不为空,测试通过
@Test
void BlogDetail(){
//打开列表页
//webDriver.get("http://127.0.0.1:9090/myblog_list.html");
//停3秒
// webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//点击查看全文
webDriver.findElement(By.xpath("//*[@id=\"artlist\"]/div[1]/a[1]")).click();
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//获取博客标题
String t=webDriver.findElement(By.xpath("//*[@id=\"title\"]")).getText();
// 如果博客正文标题不为空,测试通过
// 否则测试不通过
Assertions.assertNotNull(t);
// Assertions.assertEquals(expected_t,t);
}
1.2.5写博客
/**
* 写博客
*/
@Test
void EditBlog(){
webDriver.get("http://127.0.0.1:9090/myblog_list.html");
//找到写博客按钮
webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();
//找到输入框输入标题
// 执行js(选中标题输入框,输入字符串)
((JavascriptExecutor)webDriver).executeScript("document.querySelector(\"title\").value=\"自动化测试\"");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//点击发布
webDriver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
// 校验已发布博客
@ParameterizedTest
@MethodSource("Genertor")
@Test
void checkBlog(){
webDriver.get("http://127.0.0.1:9090/myblog_list.html");
//获取博客标题#artlist > div:nth-child(1) > div.title
String t=webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > div.title")).getText();
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
Assertions.assertEquals("自动化测试",t);
}
1.2.6跳到主页
@Test
void mainLog(){
webDriver.get("http://127.0.0.1:9090/myblog_list.html");
webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
String cur_url= webDriver.getCurrentUrl();
Assertions.assertEquals("http://127.0.0.1:9090/blog_list.html",cur_url);
}
1.3、性能测试
1.3.1基础回顾:
a、什么是性能测试
| 测试人员借助性能测试工具模拟特殊场景,观察软件在这些特殊场景下的性能指标是否符合预期
b、性能测试和功能测试的区别
| 功能测试的重点是功能是否满足客户的需求
| 性能测试的重点是性能指标(响应速度,并发用户数量…)能否满足客户的需求
c、性能测试相关的专业术语以及衡量指标
并发:大量用户,同时请求,当系统达到并发状态时,此时系统承载一定的压力
并发用户:在达到并发用户条件的时候,此时访问系统对应的用户数就是并发用户数
用户数:系统用户数:当前系统数据库中维护的用户数量
在线用户数:当前系统成功登录的用户数
并发请求数:达到并发条件时,用户同时发起http请求的数量,就是并发请求数;
响应时间:用户发起请求到系统把数据返回给前端,然后在前端进行渲染
事务:业务上操作的集合
事务响应时间:处理一个事务对应花费的时间
每秒事务请求数:一秒钟事务完成的数量
点击率:一秒钟点击的数量
吞吐量:吞吐量/时间
资源利用率:CPU使用率,带宽,内存使用率
1.3.2功能介绍
VUG:用来录制脚本,编写脚本
Controller:设计脚本运行场景
Analysis:产生性能测试报告
1.3.3Loadrunner脚本录制