提交 b3508db4 authored 作者: mry's avatar mry

feat(会议室管理测试):对会议室基本的增删改查测试

上级 51895434
......@@ -51,6 +51,24 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.1</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>testng-extentsreport</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
</dependency>
</dependencies>
<build>
......
package com.example.seleniumtest.conferenceRoomTest;
import com.example.seleniumtest.selenium.enums.Browser;
import com.example.seleniumtest.selenium.util.WebDriverUtil;
import lombok.Data;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.openqa.selenium.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@Data
@Component
......@@ -14,25 +24,265 @@ public class ConferenceActive {
@Value(value = "${conferenceRoomTest.url}")
private String baseUrl;
private WebDriver webDriver;
private WebDriver webDriver = WebDriverUtil.getWebDriver(Browser.FIREFOX, false);
;
//失败截图
public void file() {
File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
String uuid = UUID.randomUUID().toString().replace("-", "");
String fileName = uuid + ".png";
try {
FileUtils.copyFile(screenshotAs, new File("images/" + fileName));
} catch (IOException e) {
e.printStackTrace();
}
Reporter.log("<a href=../images/" + fileName + " target=_blank>这是失败截图</a>", true);
Reporter.log("<img src=../images/" + fileName + " style=width:30px;height:30px />", true);
}
//新增/编辑会议室输入
private void extracted(String s, String test, String test123, String s2) {
WebElement roomName = webDriver.findElement(By.xpath(s));
roomName.click();
roomName.clear();
roomName.sendKeys(test);
WebElement roomAddress = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[2]/div/div/input"));
roomAddress.click();
roomAddress.clear();
roomAddress.sendKeys(test123);
WebElement number = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[4]/div/div/input"));
number.click();
number.clear();
number.sendKeys(s2);
}
public void login(String username,String password){
public void login(String username, String password) {
//todo 这个系统暂时没有登录的功能
}
public void toRowSeat(){
webDriver.get(baseUrl);
public void url(){
webDriver.get("http://123.60.53.83:8080/confhd/");
webDriver.manage().window().maximize();
}
public void toRowSeat() {
url();
WebElement rowSeatButton = webDriver.findElement(By.xpath("/html/body/div/div/div[2]/form/div[3]/div/div/button[1]/span"));
rowSeatButton.click();
}
public void toManager(){
webDriver.get(baseUrl);
public void toManager() {
url();
WebElement managerButton = webDriver.findElement(By.xpath("/html/body/div/div/div[2]/form/div[3]/div/div/button[2]/span"));
managerButton.click();
}
//新增全空的提示信息,失败
@Test(description = "新增空数据会议")
public void insertConferenceRoomFailAll() {
try {
toManager();
webDriver.findElement(By.xpath("//*[@id=\"app\"]/div[2]/div")).click();
//新增/编辑 确定
WebElement element = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[5]/div/button[2]/span"));
element.click();
//请输入会议室名称
String text1 = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[1]/div/div[2]")).getText();
//请输入会议室地址
String text2 = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[2]/div/div[2]")).getText();
//请输入容纳人数
String text3 = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[4]/div/div[2]")).getText();
//请填写内容
String text4 = webDriver.findElement(By.xpath("/html/body/div[4]/p")).getText();
Thread.sleep(300);
Assert.assertEquals("请输入会议室名称", text1);
Assert.assertEquals("请输入会议室地址", text2);
Assert.assertEquals("请输入容纳人数", text3);
Assert.assertEquals("请填写内容!", text4);
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//单独不选择规模,失败
@Test(description = "新增不选择规模会议")
public void insertConferenceRoomOne() {
try{
toManager();
webDriver.findElement(By.xpath("//*[@id=\"app\"]/div[2]/div")).click();
//不选择规模
extracted("/html/body/div[2]/div/div[2]/form/div[1]/div/div[1]/input", "去q1", "去q1", "200");
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[5]/div/button[2]/span")).click();
Thread.sleep(300);
String text = webDriver.findElement(By.className("el-message__content")).getText();
Assert.assertEquals("请选择模板!", text);
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//成功新增会议室
@Test(description = "新增会议室成功")
public void insertConferenceRoom() {
try{
toManager();
webDriver.findElement(By.xpath("//*[@id=\"app\"]/div[2]/div")).click();
extracted("/html/body/div[2]/div/div[2]/form/div[1]/div/div[1]/input", "去q1", "去q1", "200");
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[3]/div/div[2]/div/input")).click();
webDriver.findElement(By.xpath("/html/body/div[4]/div[1]/div[1]/ul/li[1]")).click();
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[5]/div/button[2]")).click();
Thread.sleep(300);
String text = webDriver.findElement(By.className("el-message__content")).getText();
Assert.assertEquals("新增会议室成功", text);
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//修改会议室
@Test(description = "修改会议室成功")
public void updateConferenceRoom() {
try {
toManager();
WebElement tBody = webDriver.findElement(By.xpath("/html/body/div/div/div/div[3]/div/div[3]"));
List<WebElement> trs = tBody.findElements(By.className("tr"));
for (WebElement tr : trs) {
WebElement itemName = tr.findElement(By.className("itemName"));
String text = itemName.getText();
//如果这个会议的名字是你要修改的会议,则点击修改
if ("去q1".equals(text)) {
List<WebElement> deleNs = tr.findElements(By.className("deleN"));
for (WebElement deleN : deleNs) {
if ("修改".equals(deleN.getText())) {
deleN.click();
}
}
}
}
extracted("/html/body/div[2]/div/div[2]/form/div[1]/div/div/input", "去q1ing", "去q1ing", "100");
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[3]/div/div[2]/div[1]/span/span/i")).click();
webDriver.findElement(By.xpath("/html/body/div[4]/div[1]/div[1]/ul/li[2]/span")).click();
//新增/修改的确认按钮
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/form/div[5]/div/button[2]/span")).click();
Thread.sleep(300);
String text = webDriver.findElement(By.className("el-message__content")).getText();
Assert.assertEquals("修改会议室成功", text);
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//会议室查询
@Test(description = "查询功能")
public void findConferenceRoom() {
try{
toManager();
//清除按钮
WebElement clear = webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[4]/button/span"));
//查询按钮
WebElement find = webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[5]/button/span"));
//查询全部
find.click();
//会议室
webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[1]/div/div/div/div/input")).click();
List<WebElement> elements = webDriver.findElements(By.xpath("/html/body/div[2]/div[1]/div[1]/ul"));
for (WebElement element : elements) {
WebElement name = element.findElement(By.className("el-select-dropdown__item"));
String test = name.getText();
if ("去q1ing".equals(test)) {
name.click();
}
}
//查
find.click();
//清除
clear.click();
//容纳人数
WebElement number = webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[2]/div/div/div/input"));
number.click();
number.clear();
number.sendKeys("100");
//查
find.click();
//清除
clear.click();
//小型
//规模
webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[3]/div/div/div/div/span/span/i")).click();
webDriver.findElement(By.xpath("/html/body/div[3]/div[1]/div[1]/ul/li[1]/span")).click();
find.click();
clear.click();
//中型
//规模
webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[3]/div/div/div/div/span/span/i")).click();
webDriver.findElement(By.xpath("/html/body/div[3]/div[1]/div[1]/ul/li[2]/span")).click();
find.click();
clear.click();
//大型
//规模
webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[3]/div/div/div/div/span/span/i")).click();
webDriver.findElement(By.xpath("/html/body/div[3]/div[1]/div[1]/ul/li[3]/span")).click();
find.click();
clear.click();
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//查询错误人数
@Test(description = "人数输入非数字时,提示:请输入数字")
public void findConferenceRoomNumber() {
try {
toManager();
WebElement number = webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[1]/div/form/div/div[2]/div/div/div/input"));
number.click();
number.clear();
number.sendKeys("-");
Thread.sleep(300);
String text = webDriver.findElement(By.className("el-message__content")).getText();
Assert.assertEquals("请输入数字", text);
} catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
//会议室删除 成功删除案例
@Test(description = "会议室删除,提示:删除会议室成功")
public void deleteConferenceRoom() {
try{
toManager();
WebElement tBody = webDriver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/div/div[3]"));
List<WebElement> trs = tBody.findElements(By.className("tr"));
for (WebElement tr : trs) {
WebElement itemName = tr.findElement(By.className("itemName"));
String text = itemName.getText();
// 如果这个名称是你想删除的那个会议室名称 你就去删除它
if ("去q1ing".equals(text)) {
tr.findElement(By.className("deleH")).click();
tr.findElement(By.xpath("/html/body/div[2]/div/div[3]/button[2]")).click();
}
break;
}
Thread.sleep(300);
String text1 = webDriver.findElement(By.className("el-message__content")).getText();
Assert.assertEquals("删除会议室成功", text1);
}catch (Exception | Error e) {
file();
Assert.fail(e.getMessage());
}
}
@AfterClass
public void quit(){
webDriver.quit();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论