ui自动化报表截图查看

This commit is contained in:
2025-05-28 18:20:06 +08:00
parent e5dc3bab05
commit a9d0f68f52
4 changed files with 94 additions and 24 deletions

View File

@@ -1,5 +1,9 @@
package com.test.test.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import com.test.test.domain.UiReport;
@@ -7,14 +11,7 @@ import com.test.test.service.IUiReportService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
@@ -70,4 +67,28 @@ public class UiReportController extends BaseController
{
return toAjax(uiReportService.deleteUiReportByIds(ids));
}
@GetMapping("/screenshot")
public void getScreenshot(@RequestParam String path, HttpServletResponse response) throws IOException {
File file = new File(path);
if (!file.exists()) {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException e) {
throw new RuntimeException(e);
}
return;
}
response.setContentType("image/png");
try (FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream()) {
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
}
}
}

View File

@@ -424,13 +424,14 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
Thread.sleep(beforeAwaitTime);
}
// 3. 执行具体步骤
stepExecution.execute(step, seleniumUtils);
if (screenshotConfiguration == 1) {
report.setScreenshot(seleniumUtils.takeScreenshotAsFile(TestConfig.getProfile()));
log.info("截图成功,路径:{}", seleniumUtils.takeScreenshotAsFile(TestConfig.getProfile()));
}
// 3. 执行具体步骤
stepExecution.execute(step, seleniumUtils);
// 执行后置等待
if (afterAwaitTime > 0) {
log.info("执行后置等待: {}ms", afterAwaitTime);