Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
kurento-test: geckodriver (Firefox) cannot fetch console logs
Browse files Browse the repository at this point in the history
geckodriver (Selenium driver for Firefox) does NOT implement fetching
console logs through its API (like Chrome does):
driver.manage().logs() throws org.openqa.selenium.json.JsonException.

For more information, follow this issue:
mozilla/geckodriver#284

This commit:

-> Adds comments and explanations about this, and catch the
org.openqa.selenium.json.JsonException that is thrown when the test is
running Firefox and log fetching is attempted.

-> Enables Firefox profile settings that should output all console logs
to stdout.
  • Loading branch information
j1elo committed Feb 25, 2020
1 parent 39785ff commit 987f856
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,20 @@ public void teardownBrowserTest() {
WebDriver webDriver = browser.getWebDriver();
if (webDriver != null) {
String screenshotFileName = getDefaultOutputFile("-" + browserId + ".png");
getOrCreatePage(browserId).takeScreeshot(screenshotFileName);
browserLogs.put(browserId,
webDriver.manage().logs().get(LogType.BROWSER));
try {
getOrCreatePage(browserId).takeScreeshot(screenshotFileName);
} catch (IOException e) {
log.warn("Error taking screenshot from browser '{}': {}", browserId, e.getMessage());
}
try {
browserLogs.put(browserId, webDriver.manage().logs().get(LogType.BROWSER));
} catch (org.openqa.selenium.json.JsonException e) {
// TODO: Remove this catch() if/when Firefox geckodriver implements the logs() method
// (https://github.com/mozilla/geckodriver/issues/284)
log.warn(
"Error fetching console logs from browser '{}': {} -- This is expected on Firefox, geckodriver doesn't implement 'driver.manage().logs()'. More info: https://github.com/mozilla/geckodriver/issues/284",
browserId, e.getMessage());
}
} else {
log.warn("It was not possible to recover logs for '{}' "
+ "since browser is no longer available (maybe "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ private void createFirefoxBrowser(DesiredCapabilities capabilities) throws Malfo
firefoxOptions.addPreference("media.autoplay.default", 0);
firefoxOptions.addPreference("media.autoplay.enabled.user-gestures-needed", false);

// Route all console logs to stdout (https://github.com/mozilla/geckodriver/issues/284#issuecomment-458305621)
//
// This is needed because geckodriver (Selenium driver for Firefox) does NOT
// implement fetching console logs through its API (like Chrome does):
// driver.manage().logs() throws org.openqa.selenium.json.JsonException.
// For more information, follow this issue: https://github.com/mozilla/geckodriver/issues/284
firefoxOptions.addPreference("devtools.console.stdout.chrome", true); // Enable the stdout logging in console API when used in UI ("chrome") contexts
firefoxOptions.addPreference("devtools.console.stdout.content", true); // Enable the stdout logging in console API when used in content contexts

// This allows to load pages with self-signed certificates
capabilities.setCapability("acceptInsecureCerts", true);

Expand Down

0 comments on commit 987f856

Please sign in to comment.