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

fix(自动测试成功):修改了报告以及截图生成的位置,准备Jenkins自动测试

上级 55e7c1e7
# 会议室管理排座的自动测试
## 会议室管理
- 会议室新增测试
1. 都为空新增
2. 规模为空新增
3. 成功添加
- 会议室修改测试
1. 修改全部内容,成功修改
- 会议室查询测试
1. 会议室名称查询
2. 人数查询
3. 会议室规模查询
4. 数据有效性
- 会议室删除测试
1. 删除会议室
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.1.4.RELEASE</version>
<relativePath>pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>seleniumTest</artifactId>
<name>seleniumTest</name>
<version>0.0.1-SNAPSHOT</version>
<description>Demo project for Spring Boot</description>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration />
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\main\resources\test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\main\resources\test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.4.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>protobuf-java</artifactId>
<groupId>com.google.protobuf</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.4.RELEASE</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-test</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-test-autoconfigure</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
<exclusion>
<artifactId>json-path</artifactId>
<groupId>com.jayway.jsonpath</groupId>
</exclusion>
<exclusion>
<artifactId>assertj-core</artifactId>
<groupId>org.assertj</groupId>
</exclusion>
<exclusion>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<artifactId>hamcrest-library</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
<exclusion>
<artifactId>jsonassert</artifactId>
<groupId>org.skyscreamer</groupId>
</exclusion>
<exclusion>
<artifactId>spring-test</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>xmlunit-core</artifactId>
<groupId>org.xmlunit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>testng-extentsreport</artifactId>
<version>1.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
......@@ -69,10 +69,52 @@
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\main\resources\test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\main\resources\test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
......
......@@ -4,15 +4,29 @@ import com.example.seleniumtest.conferenceRoomTest.ConferenceActive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication(scanBasePackages = {"com.example.seleniumtest"})
//@Configuration
//@ImportResource(locations = {"classpath:"})
public class SeleniumTestApplication {
@Autowired
ConferenceActive conferenceActive;
// public static boolean started = false;
// private static ApplicationContext applicationContext;
//
// public static ApplicationContext get(){
// return applicationContext;
// }
public static void main(String[] args) {
SpringApplication.run(SeleniumTestApplication.class, args);
// started = true;
}
}
package com.example.seleniumtest.conferenceRoomTest;
import com.example.seleniumtest.SeleniumTestApplication;
import com.example.seleniumtest.selenium.enums.Browser;
import com.example.seleniumtest.selenium.util.WebDriverUtil;
import lombok.Data;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
......@@ -26,18 +30,30 @@ public class ConferenceActive {
private WebDriver webDriver = WebDriverUtil.getWebDriver(Browser.FIREFOX, false);
// public static ApplicationContext applicationContext;
// @BeforeClass
// public void start(){
// if(!SeleniumTestApplication.started){
// applicationContext = SpringApplication.run(SeleniumTestApplication.class);
// SeleniumTestApplication.started = true;
// }else{
// applicationContext = SeleniumTestApplication.get();
// }
// }
//失败截图
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));
FileUtils.copyFile(screenshotAs, new File("/opt/conference_manage_deploy/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);
Reporter.log("<a href=/opt/conference_manage_deploy/images/" + fileName + " target=_blank>这是失败截图</a>", true);
Reporter.log("<img src=/opt/conference_manage_deploy/images/" + fileName + " style=width:30px;height:30px />", true);
}
//新增/编辑会议室输入
......
......@@ -17,7 +17,7 @@ import java.util.*;
public class ExtentTestNGIReporterListener implements IReporter {
//生成的路径以及文件名
private static final String OUTPUT_FOLDER = "test-output/";
private static final String OUTPUT_FOLDER = "/opt/conference_manage_deploy/test_report/";
private static final String FILE_NAME =
new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".html";
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论