如何在Selenium Dynamic Grid中自定义录制视频文件名及输出目录名(替代默认video.mp4)
Got it, let’s walk through how to get the exact directory structure and filenames you want. Here’s a straightforward breakdown:
1. Replace Session-ID Directory with Custom Scenario Name
By default, Dynamic Grid uses the session ID for the output folder. To override this, you’ll set the se:outputDirectory capability in your test’s desired capabilities. This defines a custom folder path relative to the base assets directory that Dynamic Grid uses.
Example Code Snippets
Java:
ChromeOptions options = new ChromeOptions(); // Set custom directory name options.setCapability("se:outputDirectory", "succesfullLoginScenario"); // Add other required capabilities (like browser version, etc.) WebDriver driver = new RemoteWebDriver(new URL("http://your-grid-url:4444"), options);
Python:
from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.set_capability("se:outputDirectory", "succesfullLoginScenario") driver = webdriver.Remote( command_executor='http://your-grid-url:4444', options=chrome_options )
This will create the assets/succesfullLoginScenario folder instead of the session-ID-named one.
2. Customize the Video Filename
The default video.mp4 can be replaced using the se:videoName capability. Explicitly set your desired filename (including the .mp4 extension to avoid any auto-naming surprises).
Extending the Examples
Java:
// Add this to the options setup options.setCapability("se:videoName", "succesfullLoginScenario.mp4");
Python:
// Add this to the chrome_options setup chrome_options.set_capability("se:videoName", "succesfullLoginScenario.mp4")
Final Result
When you combine both capabilities, your test will generate exactly the structure you asked for:
-> assets/succesfullLoginScenario
-> sessionCapabilities.json
-> succesfullLoginScenario.mp4
Quick Tips
- Ensure your Dynamic Grid nodes have video recording enabled (this is typically configured when starting the node with the video service).
- For parallel tests, generate unique directory/video names dynamically (e.g., pull the test method name from your framework like TestNG, JUnit, or pytest) to avoid overwriting files.
- Verify the Grid user has write permissions to the
assetsdirectory and custom subfolders.
内容的提问来源于stack exchange,提问作者Necati Özdemir

