Динамически назвать видеофайлы перед началом тестаJAVA

Программисты JAVA общаются здесь
Anonymous
Динамически назвать видеофайлы перед началом теста

Сообщение Anonymous »

Я ищу способ назвать видео, сгенерированное Selenium Grid 4 на основе имени тестового примера. Docker Compose Services: < /p>
hromeService:
image: selenium/node-chrome:latest
container_name: chromeNode
shm_size: "2gb" # Recommended for browser nodes
ports:
- "5900"
- "7900"
environment:
- SE_EVENT_BUS_HOST=seleniumHub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_MAX_SESSIONS=1
depends_on:
- HubService

# Video recording service for Chrome
chrome_video:
image: selenium/video:latest
volumes:
- ./TestsRecordings:/videos # Mounts a local directory for saving videos
depends_on:
- ChromeService # Ensures ChromeService starts before chrome_video
environment:
- DISPLAY_CONTAINER_NAME=ChromeService # Crucial: tells the video container where to find the display
- SE_VIDEO_FILE_NAME=auto # This is the key!
- SE_NODE_GRID_URL=http://ChromeService:4444
< /code>
java-код для настройки драйвера браузера < /p>
@Parameters("browser")
@BeforeTest(alwaysRun = true)
public void setUp(String browser) {

WebDriver webDriver = null;

String remoteUrl = System.getenv("SELENIUM_REMOTE_URL");

if (browser.equalsIgnoreCase("Chrome")) {
//String downloadPath = System.getProperty("user.dir") + "/downloads";

ChromeOptions options = new ChromeOptions();

options = new ChromeOptions();

options.setCapability("se:name", "AnyName"); /// here I give the intiaital video name AnyName

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL); // Enable performance logging
options.setCapability("goog:loggingPrefs", logPrefs);
options.addArguments("--incognito");

if ((remoteUrl == null || remoteUrl.isEmpty())) {

// initlize locally browser

webDriver = new ChromeDriver(options);
}

else{
// complete setup for remote browser
options.setCapability("browserName", "chrome"); // maybe be requrired for grid to recognize the browser type selected.

try {
webDriver = new RemoteWebDriver(new URL(remoteUrl), options);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

} else if (browser.equalsIgnoreCase("edge")) {

//String downloadPath = System.getProperty("user.dir") + "/downloads";

// will test chrome setup firstly if it working remotely, then solution will be propagated to other browsers

System.out.println("Edge:::: " + System.getProperty("webdriver.edge.driver")); // Should be null

WebDriverManager.edgedriver().setup();

EdgeOptions options = new EdgeOptions();

options.addArguments("--incognito");

if ((remoteUrl == null || remoteUrl.isEmpty())) {

// initlize locally browser
webDriver = new EdgeDriver(options);
}

else{
// complete setup for remote browser
options.setCapability("browserName", "edge");

try {
webDriver = new RemoteWebDriver(new URL(remoteUrl), options);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

} else if (browser.equalsIgnoreCase("firefox")) {

//String downloadPath = System.getProperty("user.dir") + "/downloads";

// will test chrome setup firstly if it working remotely, then solution will be propagated to other browsers

FirefoxOptions options = new FirefoxOptions();

options.addArguments("-private");

if ((remoteUrl == null || remoteUrl.isEmpty())) {

// initlize locally browser
webDriver = new FirefoxDriver(options);
}

else{
// complete setup for remote browser
options.setCapability("browserName", "firefox"); // maybe be requrired for grid to recognize the browser type selected.

try {
webDriver = new RemoteWebDriver(new URL(remoteUrl), options);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

}

driver.set(webDriver); // Set the WebDriver instance for the current thread

// webVideoRecorder = new WebVideoRecorder();

if (getDriver() != null) {
System.out.println(browser + " WebDriver is initialized on thread: " + Thread.currentThread().getId());
} else {
System.err.println("WebDriver is not properly initialized on thread: " + Thread.currentThread().getId());
}

}

< /code>
Я хочу иметь что-то вроде < /p>
@BeforeMethod
public void beforeTestCase(ITestResult result, ITestContext iTestContext) {
String methodName = result.getMethod().getMethodName();

// code to name video by methodName


Подробнее здесь: https://stackoverflow.com/questions/797 ... est-starts

Вернуться в «JAVA»