目录
1.项目背景
2.项目功能
3.测试计划
3.1.测试用例
3.2.自动化测试
3.2.1.注册页
3.2.2.登录页
3.2.3.我的作品列表页
3.2.4.作品列表页
3.2.5.作品添加页
3.2.6.作品详情页
3.2.7.作品编辑页
3.2.8.个人中心页
1.项目背景
WhimsyWave妙潮平台是一个创意设计和社交分享平台,旨在为用户提供展示和分享个人创意作品的机会。以下是该项目的背景信息:
1. 创意设计的兴起:随着科技的发展和社交媒体的普及,越来越多的人开始发展自己的创意设计能力,并希望将自己的作品与他人分享,对于个人表达和文化交流有着重要的意义。
2. 社交分享的需求:人们在创作完作品后,常常希望能够与他人分享并得到反馈和认可。社交分享的平台能够满足这一需求,让用户能够展示自己的创意作品,与其他创作者互动和交流。
3. 缺乏合适的平台:尽管有许多社交媒体平台可以进行分享,但并没有一个专门为创意设计和艺术创作提供的平台。因此,创建一个专注于创意设计和社交分享的平台成为一项迫切的需求。
基于以上背景,WhimsyWave妙潮平台应运而生。它旨在为创意设计者提供一个展示、分享和互动的空间,让用户能够展示自己的创意作品,并与其他创作者和爱好者建立联系。通过这个平台,用户可以获得灵感、获取反馈,并进一步提升自己的创作能力。
WhimsyWave妙潮平台希望以其优秀的功能、良好的性能和出色的用户体验,为创意设计者带来全新的社交分享体验,并成为创意设计领域的一张闪亮名片。
2.项目功能
- 注册:用户输入用户名和密码,进行注册。
- 登录:用户输入注册过的用户名和密码以及正确的验证码进行登录。如果忘记密码,可通过邮箱找回密码。
- 主页:支持根据文章获赞数查看总排名和周排名;支持通过关键字搜索对应文章;支持查看当前登录用户作品列表;支持查看所有用户作品列表;支持分页查询;支持创建作品;支持个人中心;支持注销退出登录。
- 创建作品:支持Markdown格式;支持立即发布、定时发布和保存草稿;支持文章实时保存。
- 我的作品列表管理:支持对当前登录用户的发布的作品进行查看、修改和删除。查看全文详情可以看到其他用户对该篇文章的评论、赞或踩;文章修改后也支持立即发布、定时发布和保存草稿。
- 作品列表管理:支持对所有用户发布的作品进行查看,通过查看全文详情可以关注作者、对文章赞或踩、给文章发表评论。
- 个人中心:支持用户修改头像、昵称、登录名、邮箱、密码;显示用户的文章数量、粉丝和关注数量;新注册的用户没有修改个人信息的情况下会有默认的头像和昵称。
3.测试计划
3.1.测试用例
3.2.自动化测试
使用Selenium3+Junit5
3.2.1.注册页
/**
* 密码和确认密码输入不一致
*
* @param username
* @param password
* @param password2
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
public void RegFail1(String username, String password, String password2) throws InterruptedException {
//打开注册页面
webDriver.get("http://47.95.157.248:8080/reg.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
webDriver.findElement(By.cssSelector("#submit")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("两次密码输入不一致,请先检查,重新输入!" ,alertText);
}
/**
* 密码为空
*
* @param username
* @param password
* @param password2
* @throws InterruptedException
*/
@Order(2)
@ParameterizedTest
@CsvSource({"123, '', 123"})
//密码为空
void RegFail2(String username,String password,String password2) throws InterruptedException {
//打开注册页面
webDriver.get("http://47.95.157.248:8080/reg.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
webDriver.findElement(By.cssSelector("#submit")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("请先输入密码!", alertText);
}
/**
* 用户名为空
*
* @param username
* @param password
* @param password2
* @throws InterruptedException
*/
@Order(3)
@ParameterizedTest
@CsvSource({"'', 123, 123"})
void RegFail3(String username, String password, String password2) throws InterruptedException {
//打开注册页面
webDriver.get("http://101.201.119.191:8080/reg.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
webDriver.findElement(By.cssSelector("#submit")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("请先输入用户名!", alertText);
}
/**
* 注册成功
*
* @throws InterruptedException
*/
@Order(4)
@ParameterizedTest
@CsvFileSource(resources = "test04.csv")
void RegSuccess(String username, String password, String password2) throws InterruptedException {
//打开注册页面
webDriver.get("http://47.95.157.248:8080/reg.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//输入账号zhi
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);
//输入确认密码123
webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("恭喜:注册成功!", alertText);
// 关闭弹框
alert.accept();
}
3.2.2.登录页
/**
* 用户名错误
*
* @param username
* @param password
* @throws InterruptedException
*/
@Order(5)
@ParameterizedTest
@CsvFileSource(resources = "test06.csv")
public void LoginFail1(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
webDriver.findElement(By.cssSelector("#submit")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("抱歉:登录失败!用户名不存在!",alertText);
// 关闭弹框
alert.accept();
}
/**
* 密码错误
*
* @param username
* @param password
* @throws InterruptedException
*/
@Order(6)
@ParameterizedTest
@CsvFileSource(resources = "test07.csv")
public void LoginFail2(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
webDriver.findElement(By.cssSelector("#submit")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("抱歉:登录失败!一天内密码输入错误五次,账户将会被冻结!还剩余:4次机会!", alertText);
// 关闭弹框
alert.accept();
}
/**
* 用户名为空
*
* @param username
* @param password
* @throws InterruptedException
*/
@Order(7)
@ParameterizedTest
@CsvSource({"'', 123, 1234"})
public void LoginFail3(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
webDriver.findElement(By.cssSelector("#submit")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("请先输入用户名!",alertText);
// 关闭弹框
alert.accept();
}
/**
* 密码为空
*
* @param username
* @param password
* @throws InterruptedException
*/
@Order(8)
@ParameterizedTest
@CsvSource({"res, '', 1234"})
public void LoginFail4(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
webDriver.findElement(By.cssSelector("#submit")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("请先输入密码!",alertText);
// 关闭弹框
alert.accept();
}
/**
* 验证码错误
*
* @param username
* @param password
* @throws InterruptedException
*/
@Order(9)
@ParameterizedTest
@CsvFileSource(resources = "test08.csv")
public void LoginFail5(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
webDriver.findElement(By.cssSelector("#submit")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("抱歉:登录失败!验证码错误!", alertText);
// 关闭弹框
alert.accept();
}
/**
* 登陆成功
*
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(10)
@ParameterizedTest
@CsvFileSource(resources = "test03.csv")
void LoginSuccess(String username, String password, String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(3000);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户11", cur_name);
}
文章来源:https://www.toymoban.com/news/detail-657198.html
3.2.3.我的作品列表页
/**
* 发布的作品数量不为0
*/
@Order(11)
@Test
void MyBlogList1() {
//打开作品列表页
webDriver.get("http://47.95.157.248:8080/myblog_list.html");
//获取页面上所有博客标题对应的元素
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
int title_num = webDriver.findElements(By.cssSelector(".title")).size();
//如果元素数量局部为0,测试通过
Assertions.assertNotEquals(0, title_num);
}
文章来源地址https://www.toymoban.com/news/detail-657198.html
/**
* 点击查看全文按钮能跳转到对应页面
*
* @throws InterruptedException
*/
@Order(12)
@Test
void MyBlogList2() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/myblog_list.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(4)")).click();
sleep(40);
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/blog_content.html?id=58",cur_url);
}
/**
* 点击修改按钮能够跳转到对应页面
*
* @throws InterruptedException
*/
@Test
void MyBlogList3() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/myblog_list.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(5)")).click();
sleep(40);
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/blog_edit.html?id=58",cur_url);
}
3.2.4.作品列表页
package blog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;
/**
* 作品列表页
*/
public class BlogList extends InitAndEnd{
/**
* 登陆成功
*
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(300);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户18",cur_name);
}
/**
* 点击下一页按钮页面能正常跳转
*
* @throws InterruptedException
*/
@Test
void BlogList2() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/blog_list.html");
WebDriverWait wait = new WebDriverWait(webDriver, 10);
webDriver.findElement(By.xpath("//*[@id=\"pageDiv\"]/button[3]")).click();
sleep(300);
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/blog_list.html?pageIndex=2&pageSize=3&searchName=null", cur_url);
}
/**
* 点击首页按钮页面能正常显示
*
* @throws InterruptedException
*/
@Test
void BlogList3() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/blog_list.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#pageDiv > button.button.is-primary")).click();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("抱歉:不能跳转啦,当前已经在首页!", alertText);
// 关闭弹框
alert.accept();
}
/**
* 点击查看全文按钮能跳转到对应页面
*
* @throws InterruptedException
*/
@Test
void BlogList1() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/blog_list.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a")).click();
sleep(300);
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/blog_content.html?id=10", cur_url);
}
/**
* 点击作品添加按钮跳转至文章添加页
*/
@Test
void BlogList4(){
webDriver.get("http://47.95.157.248:8080/blog_list.html");
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#writeMessage")).click();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/blog_add.html", cur_url);
}
}
3.2.5.作品添加页
package blog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;
/**
* 作品添加页
*/
public class BlogAdd extends InitAndEnd{
/**
* 登陆成功
*
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(40);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户18", cur_name);
}
/**
* 左侧的文章草稿列数目不应该为0(即左侧的草稿列表应该能正常显示)
*/
@Test
void BlogAdd2(){
webDriver.get("http://47.95.157.248:8080/blog_add.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
int title_num = webDriver.findElements(By.cssSelector("#leftContain > div > header > p")).size();
Assertions.assertNotEquals(0, title_num);
}
/**
* 点击发布文章按钮文章能正常发布
*/
@Test
void BlogAdd3() throws InterruptedException {
webDriver.get("http://47.95.157.248:8080/blog_add.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//通过JS脚本进行标题输入
((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试\"");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
///点击发布
webDriver.findElement(By.cssSelector("body > div.edit-contain > div.blog-edit-container > div.title > button:nth-child(2)")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("恭喜:添加成功!是否继续添加文章?", alertText);
alert.dismiss();
String cur_url = webDriver.getCurrentUrl();
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
}
}
3.2.6.作品详情页
package blog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;
public class BlogContent extends InitAndEnd {
/**
* 登陆成功
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(3000);
// webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户18",cur_name);
}
/**
* 点击关注按钮是否能正常关注
* @throws InterruptedException
*/
@Test
void BlogContent1() throws InterruptedException {
webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
webDriver.get("http://47.95.157.248:8080/blog_content.html?id=66");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#pink")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String cur_str = webDriver.findElement(By.cssSelector("#pink")).getText();
Assertions.assertEquals("取消关注", cur_str);
}
/**
* 刷新进入一次页面阅读量是否加1
* @throws InterruptedException
*/
@Test
void BlogContent2() throws InterruptedException {
webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#artlist > div:nth-child(3) > a")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String cur_count = webDriver.findElement(By.cssSelector("#rcount")).getText();
Assertions.assertEquals("5", cur_count);
}
}
3.2.7.作品编辑页
package blog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;
public class BlogEdit extends InitAndEnd {
/**
* 登陆成功
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(40);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户18", cur_name);
}
/**
* 修改文章后点击发布按钮,文章是否能发布成功
* @throws InterruptedException
*/
@Test
void BlogEdit1() throws InterruptedException {
webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(5)")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//通过JS脚本进行标题输入
((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试111\"");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
///点击发布
webDriver.findElement(By.cssSelector("body > div.edit-contain > div > div.title > button:nth-child(2)")).click();
sleep(5000);
//
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("恭喜:成功!",alertText);
alert.accept();
String cur_url = webDriver.getCurrentUrl();
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
}
}
3.2.8.个人中心页
package blog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static blog.InitAndEnd.webDriver;
import static java.lang.Thread.sleep;
/**
* 个人中心页
*/
public class PersonCenter extends InitAndEnd {
/**
* 登陆成功
* @param username
* @param password
* @param valicode
* @throws InterruptedException
*/
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
//打开登录页面
webDriver.get("http://47.95.157.248:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
//点击提交按钮
webDriver.findElement(By.cssSelector("#submit")).click();
sleep(3000);
//跳转到列表页
//获取到当前页面的url
String cur_url = webDriver.getCurrentUrl();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
Assertions.assertEquals("用户18", cur_name);
}
/**
* 自己关注列表的数量是否显示正确
* @throws InterruptedException
*/
@Test
void PersonalCenter1() throws InterruptedException {
webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String cur_str = webDriver.findElement(By.cssSelector("#pinkMyCount")).getText();
Assertions.assertEquals("2", cur_str);
}
/**
* 修改个人信息是否能提交成功
* @throws InterruptedException
*/
@Test
void PersonalCenter2() throws InterruptedException {
//通过JS脚本进行标题输入
//输入名称
((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"nickname\").value=\"小刘\"");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//输入登录名
((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"username\").value=\"xioaliu\"");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//输入邮箱
((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"email\").value=\"3073862723@qq.com\"");
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//点击提交按钮
webDriver.findElement(By.cssSelector("#personInfo > div.btn_submit > button.btn")).click();
sleep(5000);
//验证是否正确
Alert alert = webDriver.switchTo().alert();
String alertText = alert.getText();
Assertions.assertEquals("恭喜:修改成功!", alertText);
alert.accept();
}
}
到了这里,关于博客系统测试报告的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!