本文展示了如何对星海乐园系统进行功能测试
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
星海乐园系统功能测试用例
测试总视频链接
一、测试用例设计
public class InitAndClose {
static WebDriver webDriver;
@BeforeAll
static void Setup(){
webDriver = new ChromeDriver();
}
@AfterAll
static void TearDown(){
webDriver.quit();
}
}
二、验证注册功能
1.未输入信息的清空下
在这里,我们会先验证用户名、密码、确认密码、真实姓名、生日是否为空 如图 如果有信息未填写 则会弹窗提示。
如果账号已经存在 则会提升注册失败 需要重新填写用户名
2.正确填写测试员的身份信息
下面展示一些 内联代码片
。
@Order(1)
@ParameterizedTest
@MethodSource("Generator01")
void RegisterSuccess(String username,String password,String password2,
String realname,String birthday,String expected_url) throws InterruptedException {
//打开注册页面
webDriver.get("http://localhost:8080/reg.html");
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
//输入用户名:测试员
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
//输入密码:123
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
//输入确认密码:123
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
//输入真实姓名:测试员
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#realname")).sendKeys(realname);
//输入生日:20240101
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#idnumber")).sendKeys(birthday);
//点击注册按钮
sleep(2000);
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(2000);
webDriver.switchTo().alert().accept();
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
//判断是否跳转到登录页面
String cur_url = webDriver.getCurrentUrl();
Assertions.assertEquals(expected_url,cur_url);
}
二、验证登录功能
1.登录信息填写错误
2.密码填写错误
为了保证系统的安全性 如果连续3次输入密码错误 则会冻结账户
需要30秒后才能输入密码
3.正确填写信息 成功登录
三、验证修改密码功能
点击找回密码链接 进入找回密码页面 进行页面修改
1.输入信息有误
如图 对生日输入有误 则会弹窗提示修改密码失败 请重试
2.两次输入的密码不一致
新密码输入123
确认密码输入1234
因此点击修改密码会提示两次修改的密码不一致
3.正确填写信息 修改密码成功
四、验证星辰大海页面
星辰大海对未登录的用户展示了发布的文章 这样可以吸引用户进行注册账号登录
@Order(4)
@Test
void homepageUnLogin() throws InterruptedException {
//点击星辰大海链接
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();
//首页有四篇文章数量和标题星辰乐园 共五个
int first_title_count = webDriver.findElements(By.cssSelector(".title")).size();
Assertions.assertEquals(5,first_title_count);
//点击首页按钮 显示 当前已经在首页了
webDriver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(1)")).click();
String first_alert = webDriver.switchTo().alert().getText();
sleep(2000);
Assertions.assertEquals(first_alert,"当前已经在首页了!");
webDriver.switchTo().alert().accept();
//点击上一页 显示当前已经在首页了
webDriver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(2)")).click();
String before_alert = webDriver.switchTo().alert().getText();
sleep(2000);
Assertions.assertEquals("当前已经在首页了~",before_alert);
sleep(2000);
webDriver.switchTo().alert().accept();
//点击下一页 title数量大于等于2
webDriver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(3)")).click();
int next_title_count = webDriver.findElements(By.cssSelector(".title")).size();
Assertions.assertNotEquals(1,next_title_count);
//点击尾页 title数量大于等于2
webDriver.findElement(By.cssSelector("body > div.container > div > div.blog-pagnation-wrapper > button:nth-child(4)")).click();
int last_title_count = webDriver.findElements(By.cssSelector(".title")).size();
Assertions.assertNotEquals(1,last_title_count);
//点击我的主页链接
webDriver.findElement(By.xpath("/html/body/div[1]/a[4]")).click();
//出现alert弹窗 未登录跳转到登录页面
sleep(2000);
String unlogin_alert = webDriver.switchTo().alert().getText();
Assertions.assertEquals("您还未登录呢 快去登录吧~",unlogin_alert);
webDriver.switchTo().alert().accept();
}
测试四个按钮功能
如果用户未登录 查看文章 则不能进行评论、点赞或者收藏
否则直接跳转到登录页面。
五、验证修改个人信息功能
此时先进行登录
1.验证修改昵称功能
如图所示:昵称修改成功
2.验证修改头像功能
头像修改成功!
@Order(6)
@Test
void testSubPhoto() throws InterruptedException {
//点击头像
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#photo")).click();
//上传头像
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("input")).sendKeys("D:\\photo\\66I%@SH}@1_LH0YQ@LNHWZJ.png");
//更换头像成功 弹窗alert
sleep(2000);
webDriver.switchTo().alert().accept();
sleep(2000);
//修改昵称为:测试大师
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#nick")).sendKeys("测试大师");
webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > div.row > button")).click();
sleep(2000);
webDriver.switchTo().alert().accept();
}
六、验证草稿功能
点击手绘繁星链接 进行草稿文章编写
1.验证保存草稿功能
可以在草稿页面看到保存的草稿
2.验证删除草稿功能
点击删除草稿按钮后 弹出显示删除成功 然后点击确定
@Order(7)
@Test
void testDraft() throws InterruptedException {
//点击手绘繁星链接
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
//在输入框内输入:自动化测试草稿
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys("自动化测试草稿");
//点击保存草稿
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button:nth-child(5)")).click();
//出现alert弹窗
sleep(2000);
webDriver.switchTo().alert().accept();
//点击我的草稿链接
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[1]/a[5]")).click();
//点击修改草稿按钮
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("//*[@id=\"draftDiv\"]/div/a[1]")).click();
//在输入框内修改文章题目为:自动化测试01
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys("01");
//点击保存草稿
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[2]/div[1]/button[2]")).click();
//出现alert弹窗
sleep(2000);
webDriver.switchTo().alert().accept();
//点击我的草稿链接
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[1]/a[5]")).click();
//点出删除草稿按钮
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#draftDiv > div > a:nth-child(5)")).click();
sleep(2000);
webDriver.switchTo().alert().accept();
sleep(2000);
webDriver.switchTo().alert().accept();
}
七、验证定时发布功能
该系统具有定时发布文章的功能
等待时间到达后 文章列表页就会出现
在规定的时间内 定时发布文章成功出现。
八、验证文章发布功能
1.未输入文章题目
2.正确发布一篇文章
文章在我的繁星点点页面得到展示
删除文章成功!!
九、验证点赞、收藏、评论功能
1.验证点赞功能
如果用户本人已经点赞过这篇文章,则弹窗会显示已经点赞过这篇文章了 避免刷赞。
2.验证收藏功能
如果已经收藏过这篇文章 则弹窗显示您已经收藏过这篇文章啦 避免刷数据
3.验证评论功能
@Order(10)
@Test
void TestArticleIssue() throws InterruptedException {
//输入文章标题:自动化测试
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys("自动化测试");
//点击发布文章
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button:nth-child(6)")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
sleep(2000);
webDriver.switchTo().alert().accept();
//测试查看全文、修改、和删除三个功能
//测试查看全文按钮
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#artDiv > div > a:nth-child(6)")).click();
//增加一条评论
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#inputcomment")).sendKeys("自动化测试的一条评论");
sleep(1000);
webDriver.findElement(By.cssSelector("#sub-comment")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
//删除评论
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#commentDiv > div > a")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
sleep(1000);
webDriver.switchTo().alert().accept();
//测试点赞和收藏功能
//第一次点赞
webDriver.findElement(By.cssSelector("#likes-count")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
//第二次点赞
webDriver.findElement(By.cssSelector("#likes-count")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
//第一次收藏
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#collect-count")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
//第二次收藏
webDriver.findElement(By.cssSelector("#collect-count")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
//浏览器后退
webDriver.navigate().back();
//测试修改功能
//点击修改按钮
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("//*[@id=\"artDiv\"]/div/a[2]")).click();
//将文章标题修改为:自动化测试01
webDriver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys("01");
//点击发布文章按钮
webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
webDriver.findElement(By.xpath("/html/body/div[2]/div[1]/button[3]")).click();
webDriver.switchTo().alert().accept();
sleep(1000);
webDriver.switchTo().alert().accept();
//点击删除文章按钮
webDriver.findElement(By.xpath("//*[@id=\"artDiv\"]/div/a[1]")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
sleep(1000);
webDriver.switchTo().alert().accept();
}