提交 807f10f3 authored 作者: 黄承天's avatar 黄承天

测试报告下载接口增加补充说明 以html文件形式提供下载

上级 0374e699
......@@ -10,7 +10,7 @@
</parent>
<groupId>com.zjty</groupId>
<artifactId>automated-testing</artifactId>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.4-SNAPSHOT</version>
<name>automated-testing</name>
<packaging>jar</packaging>
<properties>
......@@ -26,10 +26,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
......@@ -102,37 +98,22 @@
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
......@@ -40,6 +40,12 @@ public class ReportController {
return ResponseEntity.ok(reportService.findByPage(page));
}
@ApiOperation(value = "根据所属测试用例的id查询测试报告.返回由该测试用例执行后生成的所有报告.")
@GetMapping(value = "/get/case/{caseId}")
public ResponseEntity<List<ReportVo>> getByCaseId(@PathVariable Integer caseId) {
return ResponseEntity.ok(reportService.findByCaseId(caseId));
}
@ApiOperation(value = "获取单个测试报告.")
@GetMapping(value = "/get/{id}")
public ResponseEntity<ReportVo> getById(@PathVariable Integer id) {
......
......@@ -24,22 +24,24 @@ public class Report {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 所属的测试用例id.指明由该报告是哪个测试用例执行后生成的.
*/
private Integer caseId;
/**
* 测试用例标题
*/
@ApiModelProperty(value = "测试用例标题", example = "百度一下", position = 1)
private String title;
/**
* 浏览器
*/
@ApiModelProperty(value = "浏览器", example = "firefox", position = 2)
private String browser;
/**
* 网站地址
*/
@ApiModelProperty(value = "网站地址", example = "http://www.baidu.com", position = 3)
private String url;
/**
......
package com.zjty.automatedtesting.service;
import com.zjty.automatedtesting.pojo.report.Report;
import com.zjty.automatedtesting.pojo.report.ReportVo;
import org.springframework.stereotype.Service;
......@@ -13,7 +14,7 @@ public interface ReportService {
*
* @return 保存的id
*/
Integer save(ReportVo reportVo);
Integer save(Report report);
/**
* 查询所有
......@@ -30,6 +31,14 @@ public interface ReportService {
*/
List<ReportVo> findByPage(Integer page);
/**
* 根据所属测试用例的id查询测试报告
*
* @param caseId 测试用例的id
* @return 该测试用例执行后生成的所有报告的集合形式
*/
List<ReportVo> findByCaseId(Integer caseId);
/**
* 按id查询单个
*
......
......@@ -23,8 +23,7 @@ public class ReportServiceImpl implements ReportService {
TransHelper transHelper;
@Override
public Integer save(ReportVo reportVo) {
Report report = transHelper.toReport(reportVo);
public Integer save(Report report) {
Integer id;
if (Objects.isNull(report.getId()) || repository.existsById(report.getId())) {
id = repository.save(report).getId();
......@@ -45,6 +44,14 @@ public class ReportServiceImpl implements ReportService {
return repository.findAll(request).stream().map(transHelper::toReportVo).collect(Collectors.toList());
}
@Override
public List<ReportVo> findByCaseId(Integer caseId) {
return repository.findAll().stream()
.filter(report -> Objects.equals(caseId, report.getCaseId()))
.map(transHelper::toReportVo)
.collect(Collectors.toList());
}
@Override
public ReportVo findById(Integer id) {
Optional<ReportVo> reportVo = repository.findById(id).map(transHelper::toReportVo);
......
......@@ -4,10 +4,12 @@ import com.google.common.collect.Lists;
import com.zjty.automatedtesting.common.action.Assertion;
import com.zjty.automatedtesting.common.action.Browser;
import com.zjty.automatedtesting.pojo.report.Measure;
import com.zjty.automatedtesting.pojo.report.Report;
import com.zjty.automatedtesting.pojo.report.ReportVo;
import com.zjty.automatedtesting.pojo.test.Step;
import com.zjty.automatedtesting.pojo.test.CaseVo;
import com.zjty.automatedtesting.util.CommonUtils;
import com.zjty.automatedtesting.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
......@@ -24,6 +26,7 @@ import java.util.stream.Collectors;
import static com.zjty.automatedtesting.common.action.Action.*;
import static com.zjty.automatedtesting.common.action.ByType.*;
import static com.zjty.automatedtesting.util.JsonUtil.toJSon;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
......@@ -71,7 +74,7 @@ public class SeleniumServiceImpl implements SeleniumService {
List<Measure> measures = Lists.newArrayList();
List<Step> steps = testCase.getSteps().stream().sorted(Comparator.comparingInt(Step::getOrder)).collect(Collectors.toList());
for (Step step : steps) {
boolean success = false;
boolean success;
String practice = null;
String message;
WebElement webElement = null;
......@@ -93,20 +96,26 @@ public class SeleniumServiceImpl implements SeleniumService {
}
}
if (Objects.equals(step.getAssertion(), Assertion.VALUE)) {
if (nonNull(webElement)) {
practice = webElement.getAttribute("value");
}
} else if (Objects.equals(step.getAssertion(), Assertion.TITLE)) {
practice = driver.getTitle();
} else {
throw new RuntimeException("不匹配的判断类型:" + step.getAssertion());
}
if (Objects.equals(practice, step.getExpected())) {
if (isNull(step.getAssertion())){
success = true;
message = "成功";
} else {
message = String.format("失败 实际与预期不符 预期:[%s] 实际:[%s] ", step.getExpected(), practice);
}else {
if (Objects.equals(step.getAssertion(), Assertion.VALUE)) {
if (nonNull(webElement)) {
practice = webElement.getAttribute("value");
}
} else if (Objects.equals(step.getAssertion(), Assertion.TITLE)) {
practice = driver.getTitle();
} else {
throw new RuntimeException("不匹配的判断类型:" + step.getAssertion());
}
if (Objects.equals(practice, step.getExpected())) {
success = true;
message = "成功";
}else {
success = false;
message = String.format("失败 实际与预期不符 预期:[%s] 实际:[%s] ", step.getExpected(), practice);
}
}
} catch (Exception e) {
e.printStackTrace();
......@@ -131,8 +140,17 @@ public class SeleniumServiceImpl implements SeleniumService {
testCase.getUrl(),
measures
);
Integer id = reportService.save(reportVo);
Report report = new Report(
null,
testCase.getId(),
testCase.getTitle(),
testCase.getBrowser(),
testCase.getUrl(),
toJSon(measures)
);
Integer id = reportService.save(report);
reportVo.setId(id);
driver.close();
return reportVo;
}
......
......@@ -37,17 +37,6 @@ public class TransHelper {
);
}
public Report toReport(ReportVo reportVo){
String measures = JsonUtil.toJSon(reportVo.getMeasures());
return new Report(
reportVo.getId(),
reportVo.getTitle(),
reportVo.getBrowser(),
reportVo.getUrl(),
measures
);
}
public ReportVo toReportVo(Report report){
List<Measure> measures = JSON.parseArray(report.getMeasures(), Measure.class);
return new ReportVo(
......
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>adapter</title><link href=static/css/databaseConfig.6b0f0024.css rel=prefetch><link href=static/css/dependConfig.2aaa86c3.css rel=prefetch><link href=static/css/details.34c83a51.css rel=prefetch><link href=static/css/home.0ec7bde1.css rel=prefetch><link href=static/css/middlewareConfig.e2ffc848.css rel=prefetch><link href=static/css/regularConfig.027cf8ba.css rel=prefetch><link href=static/css/serviceConfig.e688006a.css rel=prefetch><link href=static/js/databaseConfig.c0721f54.js rel=prefetch><link href=static/js/dependConfig.22d94790.js rel=prefetch><link href=static/js/details.551bcead.js rel=prefetch><link href=static/js/home.3e4b65f5.js rel=prefetch><link href=static/js/middlewareConfig.181174d3.js rel=prefetch><link href=static/js/regularConfig.2bb5c8b1.js rel=prefetch><link href=static/js/serviceConfig.28ca100e.js rel=prefetch><link href=static/css/app.6703eb5f.css rel=preload as=style><link href=static/css/chunk-vendors.717c90ab.css rel=preload as=style><link href=static/js/app.a405f5af.js rel=preload as=script><link href=static/js/chunk-vendors.5f648e7a.js rel=preload as=script><link href=static/css/chunk-vendors.717c90ab.css rel=stylesheet><link href=static/css/app.6703eb5f.css rel=stylesheet></head><body><noscript><strong>We're sorry but adapter doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.5f648e7a.js></script><script src=static/js/app.a405f5af.js></script></body></html>
\ No newline at end of file
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>adapter</title><link href=static/css/serviceConfig.008ef5a3.css rel=prefetch><link href=static/js/serviceConfig.15284ede.js rel=prefetch><link href=static/css/app.f596fcc9.css rel=preload as=style><link href=static/css/chunk-vendors.717c90ab.css rel=preload as=style><link href=static/js/app.b64cb21f.js rel=preload as=script><link href=static/js/chunk-vendors.5f648e7a.js rel=preload as=script><link href=static/css/chunk-vendors.717c90ab.css rel=stylesheet><link href=static/css/app.f596fcc9.css rel=stylesheet></head><body><noscript><strong>We're sorry but adapter doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.5f648e7a.js></script><script src=static/js/app.b64cb21f.js></script></body></html>
\ No newline at end of file
server.address=0.0.0.0
server.port=13500
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/automated_testing?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8
spring.datasource.url=jdbc:mysql://120.55.57.35:3306/automated_testing?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=false
spring.resources.static-locations=classpath:adapter/
spring.resources.static-locations=classpath:/adapter/
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论