Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][grid]: Set test name to video file name in dynamic grid #13907

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,34 @@ private Container createBrowserContainer(int port, Capabilities sessionCapabilit
}

private Map<String, String> getBrowserContainerEnvVars(Capabilities sessionRequestCapabilities) {
Optional<Dimension> screenResolution =
ofNullable(getScreenResolution(sessionRequestCapabilities));
Map<String, String> envVars = new HashMap<>();
if (screenResolution.isPresent()) {
envVars.put("SE_SCREEN_WIDTH", String.valueOf(screenResolution.get().getWidth()));
envVars.put("SE_SCREEN_HEIGHT", String.valueOf(screenResolution.get().getHeight()));
}
Optional<TimeZone> timeZone = ofNullable(getTimeZone(sessionRequestCapabilities));
timeZone.ifPresent(zone -> envVars.put("TZ", zone.getID()));
// Passing env vars set to the child container
setEnvVarsToContainer(envVars);
// Capabilities set to env vars with higher precedence
setCapsToEnvVars(sessionRequestCapabilities, envVars);
return envVars;
}

private void setEnvVarsToContainer(Map<String, String> envVars) {
Map<String, String> seEnvVars = System.getenv();
seEnvVars.entrySet().stream()
.filter(
entry ->
entry.getKey().startsWith("SE_") || entry.getKey().equalsIgnoreCase("LANGUAGE"))
.forEach(entry -> envVars.put(entry.getKey(), entry.getValue()));
return envVars;
}

private void setCapsToEnvVars(
Capabilities sessionRequestCapabilities, Map<String, String> envVars) {
Optional<Dimension> screenResolution =
ofNullable(getScreenResolution(sessionRequestCapabilities));
screenResolution.ifPresent(
dimension -> {
envVars.put("SE_SCREEN_WIDTH", String.valueOf(dimension.getWidth()));
envVars.put("SE_SCREEN_HEIGHT", String.valueOf(dimension.getHeight()));
});
Optional<TimeZone> timeZone = ofNullable(getTimeZone(sessionRequestCapabilities));
timeZone.ifPresent(zone -> envVars.put("TZ", zone.getID()));
}

private Container startVideoContainer(
Expand Down Expand Up @@ -357,17 +368,31 @@ private Container startVideoContainer(
private Map<String, String> getVideoContainerEnvVars(
Capabilities sessionRequestCapabilities, String containerIp) {
Map<String, String> envVars = new HashMap<>();
// Passing env vars set to the child container
setEnvVarsToContainer(envVars);
// Capabilities set to env vars with higher precedence
setCapsToEnvVars(sessionRequestCapabilities, envVars);
envVars.put("DISPLAY_CONTAINER_NAME", containerIp);
Optional<Dimension> screenResolution =
ofNullable(getScreenResolution(sessionRequestCapabilities));
screenResolution.ifPresent(
dimension -> {
envVars.put("SE_SCREEN_WIDTH", String.valueOf(dimension.getWidth()));
envVars.put("SE_SCREEN_HEIGHT", String.valueOf(dimension.getHeight()));
});
Optional<String> testName = ofNullable(getTestName(sessionRequestCapabilities));
testName.ifPresent(name -> envVars.put("SE_VIDEO_FILE_NAME", String.format("%s.mp4", name)));
return envVars;
}

private String getTestName(Capabilities sessionRequestCapabilities) {
Optional<Object> testName = ofNullable(sessionRequestCapabilities.getCapability("se:name"));
if (testName.isPresent()) {
String name = testName.get().toString();
if (!name.isEmpty()) {
name = name.replaceAll(" ", "_").replaceAll("[^a-zA-Z0-9_-]", "");
if (name.length() > 251) {
name = name.substring(0, 251);
}
return name;
}
}
return null;
}

private TimeZone getTimeZone(Capabilities sessionRequestCapabilities) {
Optional<Object> timeZone = ofNullable(sessionRequestCapabilities.getCapability("se:timeZone"));
if (timeZone.isPresent()) {
Expand Down
Loading