场景执行bug修改

This commit is contained in:
2025-05-12 10:19:21 +08:00
parent 78cb16fd19
commit a3e13b3972

View File

@@ -1,5 +1,8 @@
package com.test.test.service.impl;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -27,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.UnexpectedTagNameException;
import org.springframework.beans.BeanUtils;
@@ -95,7 +99,24 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
createSceneStepsReport(orderNumber, step, reportId);
}
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
WebDriver driver = new ChromeDriver();
// 2. 创建一个临时目录作为 user-data-dir
Path tempDir = null;
try {
tempDir = Files.createTempDirectory("chrome-profile-");
} catch (IOException e) {
throw new RuntimeException(e);
}
// 3. 配置 ChromeOptions
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new"); // 无头模式(可选)
options.addArguments("--no-sandbox"); // Docker/Linux 可能需要
options.addArguments("--disable-dev-shm-usage"); // 避免 /dev/shm 不足
options.addArguments("--remote-allow-origins=*"); // Chrome 11+ 需要
options.addArguments("--user-data-dir=" + tempDir.toAbsolutePath()); // 关键:唯一目录
// 4. 启动 Chrome
WebDriver driver = new ChromeDriver(options);
SeleniumUtils seleniumUtils = new SeleniumUtils(driver);
try {
// 3. 执行所有步骤