http://8.130.98.211:8080/login.html项目访问地址:即时通讯平台http://8.130.98.211:8080/login.html
本篇文章进行项目主页面的测试。
在测试前需要先对待测内容进行分类,按照功能进行分类可以分为:个人信息设置、发送/接收消息、添加好友、创建群聊、好友搜索。
个人信息设置
UI测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe");
webDriver = new EdgeDriver();
webDriver.manage().window().maximize();
}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#password")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#submit")).click();
}
@Test
public void test() throws InterruptedException, IOException {
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user")).click();
//等待页面跳转
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//截图
File file = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("D://个人主页.png"));
}
}
预期结果:
实际结果:
实际结果与预期结果不符图片未展示成功。
BUG描述
BUG出现的环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
BUG出现的操作步骤:
- 打开Edge浏览器输入网址http://8.130.98.211:8080/login.html
- 在登陆页面输入账号:zhangsan,密码:zhangsan进行登录
- 点击用户头像进入用户信息设置页面
预期结果:头像模块会展示用户头像图片
实际结果:头像图片展示异常
功能测试
用户名修改
根据测试需求文档(用户名要求长度为2~16位,只能由英文字母或数字组成)先编写测试点:
当欲修改的用户名不存在:
如果欲修改的用户名存在则修改失败。
有了这些测试点之后在进行测试用例的编写:
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe");
webDriver = new EdgeDriver();
webDriver.manage().window().maximize();
}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#password")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#submit")).click();
}
@Test
//测试前已存在用户lisi
//预期结果:第一个是false紧接着十二个是true,后面除最后一个是true其余都是false;
public void setUserNameTest() throws InterruptedException {
String[] values = {
"lisi","aaa","123","12asd","as","12","a2","qwertyuiopasdfgh","1234567890123456","123456789012345w",
"zhangsande","1234567890","qwe1234567",
"a","1","qweqwwwwwwwqqqqwee","12132234534363623464",
"qweqwe7dhf7y76647yruh","@uhas()","asds asds","13213 32",
"@12312334","asd12 ","asd12@","","@(){}"," ","a@",
"w ","2 ","2@","@#"," ","qwertyuiopasdfg@","qwertyuiopasdfg@","qwertyuiopasdfg ",
"123456789012345 ", "123456789012345@","12345678901234 w",
"12 456789012345w","12345678901234$w","*&^%$#@!@#$%^&*&",
" ","12345678901234562","oqwertyuiopasdfgh","oqwertyuiopasdfg4",
"qwe@werewq","qwertyuiop ","123456789 ","123456789@","12345678d ","q12345678@",
"!@#$%^&*()"," ","zhangsan"
};
boolean[] result = new boolean[values.length];
for (int i = 0; i < values.length; i++) {
//进入用户信息修改页面
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user")).click();
//等待页面跳转
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//修改用户名
webDriver.findElement(By.cssSelector("#userName")).clear();
webDriver.findElement(By.cssSelector("#userName")).sendKeys(values[i]);
webDriver.findElement(By.cssSelector("#upload")).click();
sleep(1000);
//获取弹窗信息
Alert alert = webDriver.switchTo().alert();
String text = alert.getText();
alert.accept();
//等待页面跳转
sleep(500);
result[i] = "信息修改成功".equals(text);
}
System.out.println(Arrays.toString(result));
}
}
测试数据:
"lisi","aaa","123","12asd","as","12","a2","qwertyuiopasdfgh","1234567890123456","123456789012345w",
"zhangsande","1234567890","qwe1234567",
"a","1","qweqwwwwwwwqqqqwee","12132234534363623464",
"qweqwe7dhf7y76647yruh","@uhas()","asds asds","13213 32",
"@12312334","asd12 ","asd12@","","@(){}"," ","a@",
"w ","2 ","2@","@#"," ","qwertyuiopasdfg@","qwertyuiopasdfg@","qwertyuiopasdfg ",
"123456789012345 ", "123456789012345@","12345678901234 w",
"12 456789012345w","12345678901234$w","*&^%$#@!@#$%^&*&",
" ","12345678901234562","oqwertyuiopasdfgh","oqwertyuiopasdfg4",
"qwe@werewq","qwertyuiop ","123456789 ","123456789@","12345678d ","q12345678@",
"!@#$%^&*()"," ","zhangsan"
预期结果:第一个是false紧接着十二个是true,后面都是false;
实际结果:与预期结果相同
修改密码
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe");
webDriver = new EdgeDriver();
webDriver.manage().window().maximize();
}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#password")).sendKeys("123456");
webDriver.findElement(By.cssSelector("#submit")).click();
}
@ParameterizedTest
@CsvSource({"zhangsan, zhangsan"})
//测试修改用户密码
//预期结果:true
public void setPasswordTest(String userName, String password) throws InterruptedException {
//进入用户信息修改页面
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user")).click();
//等待页面跳转
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//设置密码
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#upload")).click();
sleep(300);
//关闭弹窗提示
webDriver.switchTo().alert().accept();
//重新登录
webDriver.get("http://8.130.98.211: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("#submit")).click();
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//获取页面url
System.out.println("http://8.130.98.211:8080/client.html".equals(webDriver.getCurrentUrl()));
}
}
预期结果:打印 true
实际结果:与预期结果一致
修改图片
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe");
webDriver = new EdgeDriver();
webDriver.manage().window().maximize();
}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() throws InterruptedException {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#password")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#submit")).click();
//等待页面跳转
sleep(200);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
//测试修改用户头像
//预期结果:用户头像变为修改后的图片
@ParameterizedTest
@ValueSource(strings = {"C:\\Users\\13900\\Pictures\\头像.png"})
public void setUserPhotoTest(String photoPath) throws IOException, InterruptedException {
//截图保存当前的头像
File old = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(old, new File("D:\\修改前.png"));
//进行修改操作
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user")).click();
//等待页面跳转
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//上传文件
webDriver.findElement(By.cssSelector("#fileUpdate")).sendKeys(photoPath);
webDriver.findElement(By.cssSelector("#upload")).click();
sleep(1000);
webDriver.switchTo().alert().accept();
sleep(500);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//截图保存修改后的头像
File newFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(newFile, new File("D:\\修改后.png"));
}
}
测试数据:
预期结果:用户头像变为修改后的图片
实际结果:与预期结果一致
发送/接收消息
UI测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:人工测试
测试步骤:
- 打开Edge浏览器输入网址http://8.130.98.211:8080/login.html
- 在登陆页面输入账号:zhangsan,密码:zhangsan进行登录
- 点击左下方 lisi 的信息提示框。
预期结果:
实际结果:与预期结果相符
功能测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe");
webDriver = new EdgeDriver();
webDriver.manage().window().maximize();
}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() throws InterruptedException {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#password")).sendKeys("zhangsan");
webDriver.findElement(By.cssSelector("#submit")).click();
//等待页面跳转
sleep(200);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
//测试收发消息
@ParameterizedTest
@CsvSource({"在干嘛?"})
public void setMessageTest(String message) throws InterruptedException, IOException {
webDriver.findElement(By.cssSelector("#session-list > li:nth-child(2)")).click();
sleep(1000);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > textarea")).sendKeys(message);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.ctrl > button")).click();
//截图保存结果
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\发送方.png"));
//登录李四的账号查看消息是否收到
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys("lisi");
webDriver.findElement(By.cssSelector("#password")).sendKeys("lisi");
webDriver.findElement(By.cssSelector("#submit")).click();
//等待页面跳转
sleep(1000);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#session-list > li:nth-child(1)")).click();
sleep(1000);
//截图保存结果
File screenshotAs1 = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs1, new File("D:\\接收方.png"));
}
}
测试数据:zhangsan给lisi发信息:在干嘛?
预期结果:zhangsan消息成功发出,lisi顺利收到消息,且双发的消息提示框中都显示该条消息。
实际测试:与预期结果相符。
用户搜索
UI测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:人工测试
测试步骤:
- 打开Edge浏览器输入网址http://8.130.98.211:8080/login.html
- 在登陆页面输入账号:zhangsan,密码:zhangsan进行登录
- 在搜索框中输入‘l’点击搜索
预期结果:
实际结果:与预期结果不符,右侧添加好友按钮过小
BUG描述
BUG出现的环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
BUG出现的操作步骤:
- 打开Edge浏览器输入网址http://8.130.98.211:8080/login.html
- 在登陆页面输入账号:zhangsan,密码:zhangsan进行登录
- 在搜索框中输入‘l’点击搜索
预期结果:界面右侧会展示搜索到的用户,如果不是好友关系会显示添加好友按钮
实际结果:添加好友按钮较小,不美观
功能测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {……}
@AfterAll
public static void delete() {
webDriver.close();
}
//进入主界面
@BeforeEach
public void intoPage() throws InterruptedException {……}
//测试用户搜索
@ParameterizedTest
@CsvSource({"lyq"})
public void sourceTest(String name) throws InterruptedException, IOException {
webDriver.findElement(By.cssSelector("#search-input")).sendKeys(name);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.search > button")).click();
sleep(1500);
//截图
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\搜索.png"));
}
}
测试数据:lyq
预期结果:界面右侧会展示搜索到的用户,如果不是好友关系会显示添加好友按钮
实际结果:与预期结果一致
添加好友
功能测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {……}
@AfterAll
public static void delete() {……}
//进入主界面
@BeforeEach
public void intoPage() throws InterruptedException {……}
//测试添加好友
@Order(1)
@ParameterizedTest
@CsvSource({"lyq, 你好!", "zzz, 你好!"})
public void addFriendTest1(String name, String message) throws InterruptedException {
webDriver.findElement(By.cssSelector("#search-input")).clear();
webDriver.findElement(By.cssSelector("#search-input")).sendKeys(name);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.search > button")).click();
sleep(1500);
webDriver.findElement(By.cssSelector("#add-user")).sendKeys(message);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div > button")).click();
sleep(500);
webDriver.switchTo().alert().accept();
}
@Order(2)
@ParameterizedTest
@CsvSource({"lyq, lyq, true", "zzz, zzz, false"})
public void addFriendTest2(String name, String password, boolean is) throws InterruptedException, IOException {
webDriver.get("http://8.130.98.211:8080/login.html");
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
webDriver.findElement(By.cssSelector("#userName")).sendKeys(name);
webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
webDriver.findElement(By.cssSelector("#submit")).click();
//等待页面跳转
sleep(200);
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
if (is) {
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div > button.true")).click();
sleep(500);
webDriver.switchTo().alert().accept();
sleep(500);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend")).click();
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\"+name+".png"));
} else {
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div > button.false")).click();
sleep(500);
webDriver.switchTo().alert().accept();
sleep(500);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend")).click();
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\"+name+".png"));
}
}
}
测试数据:用户zhangsan发起两个好友请求(lyq、你好!、true;zzz、你好、false)
预期结果:用户lyq成功收到请求并同意好友请求;用户zzz成功收到请求并拒绝好友请求
实际结果:与预期结果一致
创建群聊
UI测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:人工测试
测试步骤:
- 打开Edge浏览器输入网址http://8.130.98.211:8080/login.html
- 在登陆页面输入账号:zhangsan,密码:zhangsan进行登录
- 在搜索框下方点击右侧好友图标
- 点击下方建群按钮
预期结果:当点击左侧建群按钮右侧会显示好友
实际结果:与预期结果相同
功能测试
测试环境:Win11;IntelliJ IDEA 2023.2;Microsoft Edge版本 125.0.2535.51 (正式版本) (64 位)
测试方法:自动化测试
测试脚本:
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MainPage {
private static WebDriver webDriver;
@BeforeAll
public static void init() {……}
@AfterAll
public static void delete() {……}
//进入主界面
@BeforeEach
public void intoPage() throws InterruptedException {……}
//测试建群
@Order(1)
@Test
public void addGroupTest1() throws InterruptedException, IOException {
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend")).click();
sleep(200);
webDriver.findElement(By.cssSelector("#friend-list > button")).click();
sleep(500);
webDriver.findElement(By.cssSelector("#\\31 ")).click();
webDriver.findElement(By.cssSelector("#\\33 ")).click();
webDriver.findElement(By.cssSelector("#\\34 ")).click();
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > button")).click();
sleep(500);
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\三人群.png"));
}
@Order(2)
@Test
public void addGroupTest2() throws InterruptedException, IOException {
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend")).click();
sleep(200);
webDriver.findElement(By.cssSelector("#friend-list > button")).click();
sleep(500);
webDriver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > button")).click();
sleep(500);
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotAs, new File("D:\\无人.png"));
}
}
预期结果:如果不选择好友建群操作将会失败;否则建群成功并显示在消息提示区
实际结果:与预期结果相同,当没有选择好友时点击创建群聊系统没有反应
选择三个好友:
没有选择好友:
本篇文章中自动化脚本所配置的依赖如下:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!--截图-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</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.1</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>
</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>