Skip to content

Commit 52270ec

Browse files
committed
Capture the logs from the Firefox console.
mozilla/geckodriver#284 (comment)
1 parent 393f076 commit 52270ec

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

systemtests/src/main/java/io/enmasse/systemtest/GlobalLogCollector.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ public class GlobalLogCollector {
3131
private final String namespace;
3232

3333
public GlobalLogCollector(Kubernetes kubernetes, File logDir) {
34+
this(kubernetes, logDir, kubernetes.getInfraNamespace());
35+
}
36+
37+
public GlobalLogCollector(Kubernetes kubernetes, File logDir, String namespace) {
3438
this.kubernetes = kubernetes;
3539
this.logDir = logDir;
36-
this.namespace = kubernetes.getInfraNamespace();
40+
this.namespace = namespace;
3741
}
3842

3943

systemtests/src/main/java/io/enmasse/systemtest/selenium/SeleniumManagement.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
package io.enmasse.systemtest.selenium;
66

77

8-
import io.enmasse.systemtest.CustomLogger;
9-
import io.enmasse.systemtest.Kubernetes;
10-
import io.enmasse.systemtest.SystemtestsKubernetesApps;
11-
import io.enmasse.systemtest.TimeoutBudget;
8+
import io.enmasse.systemtest.*;
129
import io.enmasse.systemtest.timemeasuring.SystemtestsOperation;
1310
import io.enmasse.systemtest.timemeasuring.TimeMeasuringSystem;
1411
import io.enmasse.systemtest.utils.TestUtils;
1512
import org.slf4j.Logger;
1613

14+
import java.nio.file.Files;
15+
import java.nio.file.Path;
1716
import java.util.List;
1817
import java.util.concurrent.TimeUnit;
1918
import java.util.stream.Collectors;
@@ -53,6 +52,16 @@ public static void removeFirefoxApp() throws Exception {
5352
TimeMeasuringSystem.stopOperation(operationID);
5453
}
5554

55+
public static void collectAppLogs(Path path) {
56+
try {
57+
Files.createDirectories(path);
58+
GlobalLogCollector collector = new GlobalLogCollector(Kubernetes.getInstance(), path.toFile(), SystemtestsKubernetesApps.SELENIUM_PROJECT);
59+
collector.collectLogsOfPodsInNamespace(SystemtestsKubernetesApps.SELENIUM_PROJECT);
60+
} catch (Exception e) {
61+
log.error("Failed to collect pod logs from namespace : {}", SystemtestsKubernetesApps.SELENIUM_PROJECT);
62+
}
63+
}
64+
5665
public static void removeChromeApp() throws Exception {
5766
String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.DELETE_SELENIUM_CONTAINER);
5867
SystemtestsKubernetesApps.deleteChromeSeleniumApp(SystemtestsKubernetesApps.SELENIUM_PROJECT, Kubernetes.getInstance());

systemtests/src/main/java/io/enmasse/systemtest/selenium/SeleniumProvider.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,34 @@ public static synchronized SeleniumProvider getInstance() {
6161
public void onFailed(ExtensionContext extensionContext) {
6262
String getTestClassName = extensionContext.getTestClass().get().getName();
6363
String getTestMethodName = extensionContext.getTestMethod().get().getName();
64-
saveBrowserLog(getTestClassName, getTestMethodName);
65-
saveScreenShots(getTestClassName, getTestMethodName);
64+
Path webConsolePath = getWebConsolePath(Environment.getInstance().testLogDir(), getTestClassName, getTestMethodName);
65+
saveBrowserLog(webConsolePath);
66+
SeleniumManagement.collectAppLogs(webConsolePath);
67+
saveScreenShots(webConsolePath, getTestClassName, getTestMethodName);
68+
6669
}
6770

68-
public void saveBrowserLog(String className, String methodName) {
71+
private void saveBrowserLog(Path path) {
6972
try {
7073
log.info("Saving browser console log...");
71-
Path path = Paths.get(
72-
Environment.getInstance().testLogDir(),
73-
webconsoleFolder,
74-
className,
75-
methodName);
7674
Files.createDirectories(path);
7775
File consoleLog = new File(path.toString(), "browser_console.log");
7876
StringBuilder logEntries = formatedBrowserLogs();
7977
Files.write(Paths.get(consoleLog.getPath()), logEntries.toString().getBytes());
80-
log.info("Browser console log saved successfully");
78+
log.info("Browser console log saved successfully : {}", consoleLog);
8179
} catch (Exception ex) {
8280
log.warn("Cannot save browser log: " + ex.getMessage());
8381
}
8482
}
8583

8684
public void saveScreenShots(String className, String methodName) {
85+
Path webConsolePath = getWebConsolePath(Environment.getInstance().testLogDir(), className, methodName);
86+
saveScreenShots(webConsolePath, className, methodName);
87+
}
88+
89+
private void saveScreenShots(Path path, String className, String methodName) {
8790
try {
8891
takeScreenShot();
89-
Path path = Paths.get(
90-
Environment.getInstance().testLogDir(),
91-
webconsoleFolder,
92-
className,
93-
methodName);
9492
Files.createDirectories(path);
9593
for (Date key : browserScreenshots.keySet()) {
9694
FileUtils.copyFile(browserScreenshots.get(key), new File(Paths.get(path.toString(),
@@ -100,7 +98,7 @@ public void saveScreenShots(String className, String methodName) {
10098
} catch (Exception ex) {
10199
log.warn("Cannot save screenshots: " + ex.getMessage());
102100
} finally {
103-
tearDownDrivers();
101+
//tearDownDrivers();
104102
}
105103
}
106104

@@ -286,6 +284,14 @@ public void waitUntilItemNotPresent(int timeInSeconds, Supplier<WebItem> item) t
286284
waitUntilItem(timeInSeconds, item, false);
287285
}
288286

287+
private Path getWebConsolePath(String target, String className, String methodName) {
288+
return Paths.get(
289+
target,
290+
webconsoleFolder,
291+
className,
292+
methodName);
293+
}
294+
289295
private <T extends WebItem> T waitUntilItem(int timeInSeconds, Supplier<T> item, boolean present) throws Exception {
290296
log.info("Waiting for element be present");
291297
int attempts = 0;

systemtests/src/main/java/io/enmasse/systemtest/utils/TestUtils.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import org.junit.jupiter.api.function.ThrowingSupplier;
2323
import org.openqa.selenium.Capabilities;
2424
import org.openqa.selenium.chrome.ChromeOptions;
25+
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
2526
import org.openqa.selenium.firefox.FirefoxOptions;
27+
import org.openqa.selenium.firefox.FirefoxProfile;
2628
import org.openqa.selenium.remote.RemoteWebDriver;
2729
import org.slf4j.Logger;
2830

@@ -492,7 +494,14 @@ public static void deleteAddressSpaceCreatedBySC(Kubernetes kubernetes, AddressS
492494

493495
public static RemoteWebDriver getFirefoxDriver() throws Exception {
494496
Endpoint endpoint = SystemtestsKubernetesApps.getFirefoxSeleniumAppEndpoint(Kubernetes.getInstance());
495-
return getRemoteDriver(endpoint.getHost(), endpoint.getPort(), new FirefoxOptions());
497+
FirefoxOptions options = new FirefoxOptions();
498+
FirefoxProfile myProfile = new FirefoxProfile();
499+
// https://github.com/mozilla/geckodriver/issues/330 enable the emission of console.info(), warn() etc
500+
// to stdout of the browser process. Works around the fact that Firefox logs do are not available through
501+
// WebDriver.manage().logs()
502+
myProfile.setPreference("devtools.console.stdout.content", true);
503+
options.setProfile(myProfile);
504+
return getRemoteDriver(endpoint.getHost(), endpoint.getPort(), options);
496505
}
497506

498507
public static RemoteWebDriver getChromeDriver() throws Exception {

0 commit comments

Comments
 (0)