Skip to content

Commit

Permalink
[java][grid]: Set test name to video file name in dynamic grid (#13907)
Browse files Browse the repository at this point in the history
* [java][grid]: Set test name to video file name in dynamic grid

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>

* Revert unexpected changes

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>

---------

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 authored May 6, 2024
1 parent 7b83fc1 commit 8e3e26e
Showing 1 changed file with 41 additions and 16 deletions.
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

0 comments on commit 8e3e26e

Please sign in to comment.