Skip to content

Commit

Permalink
[grid] Saving Selenium logs in Dynamic Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Jun 29, 2022
1 parent 8645caf commit ed7d29e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion java/src/org/openqa/selenium/grid/node/docker/DockerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@
import org.openqa.selenium.remote.tracing.Tracer;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DockerSession extends ProtocolConvertingSession {

private static final Logger LOG = Logger.getLogger(DockerSession.class.getName());
private final Container container;
private final Container videoContainer;
private final DockerAssetsPath assetsPath;

DockerSession(
Container container,
Expand All @@ -46,17 +53,31 @@ public class DockerSession extends ProtocolConvertingSession {
Capabilities capabilities,
Dialect downstream,
Dialect upstream,
Instant startTime) {
Instant startTime,
DockerAssetsPath assetsPath) {
super(tracer, client, id, url, downstream, upstream, stereotype, capabilities, startTime);
this.container = Require.nonNull("Container", container);
this.videoContainer = videoContainer;
this.assetsPath = Require.nonNull("Assets path", assetsPath);
}

@Override
public void stop() {
if (videoContainer != null) {
videoContainer.stop(Duration.ofSeconds(10));
}
saveLogs();
container.stop(Duration.ofMinutes(1));
}

private void saveLogs() {
String sessionAssetsPath = assetsPath.getContainerPath(getId());
String seleniumServerLog = String.format("%s/selenium-server.log", sessionAssetsPath);
try {
List<String> logs = container.getLogs().getLogLines();
Files.write(Paths.get(seleniumServerLog), logs);
} catch (Exception e) {
LOG.log(Level.WARNING, "Error saving logs", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
mergedCapabilities,
downstream,
result.getDialect(),
Instant.now()));
Instant.now(),
assetsPath));
}
}

Expand Down

0 comments on commit ed7d29e

Please sign in to comment.