|
23 | 23 | import org.apache.commons.lang3.mutable.MutableInt;
|
24 | 24 | import org.apache.commons.lang3.tuple.ImmutablePair;
|
25 | 25 | import org.apache.commons.lang3.tuple.Pair;
|
| 26 | +import org.apache.logging.log4j.Level; |
| 27 | +import org.apache.logging.log4j.LogManager; |
26 | 28 | import org.jetbrains.annotations.Contract;
|
27 | 29 | import org.jetbrains.annotations.NotNull;
|
28 | 30 | import org.jetbrains.annotations.Nullable;
|
|
80 | 82 | import org.openqa.selenium.chrome.ChromeDriver;
|
81 | 83 | import org.openqa.selenium.chrome.ChromeDriverService;
|
82 | 84 | import org.openqa.selenium.chrome.ChromeOptions;
|
| 85 | +import org.openqa.selenium.devtools.DevTools; |
| 86 | +import org.openqa.selenium.devtools.HasDevTools; |
| 87 | +import org.openqa.selenium.devtools.v85.log.Log; |
| 88 | +import org.openqa.selenium.devtools.v85.log.model.LogEntry; |
| 89 | +import org.openqa.selenium.devtools.v85.runtime.model.ConsoleAPICalled; |
83 | 90 | import org.openqa.selenium.firefox.FirefoxBinary;
|
84 | 91 | import org.openqa.selenium.firefox.FirefoxDriver;
|
85 | 92 | import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
|
|
89 | 96 | import org.openqa.selenium.firefox.GeckoDriverService;
|
90 | 97 | import org.openqa.selenium.ie.InternetExplorerDriver;
|
91 | 98 | import org.openqa.selenium.interactions.Actions;
|
| 99 | +import org.openqa.selenium.remote.Augmenter; |
92 | 100 | import org.openqa.selenium.remote.RemoteWebDriver;
|
93 | 101 | import org.openqa.selenium.remote.service.DriverService;
|
94 | 102 | import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
131 | 139 | import java.util.concurrent.Future;
|
132 | 140 | import java.util.concurrent.TimeUnit;
|
133 | 141 | import java.util.function.Supplier;
|
134 |
| -import java.util.logging.Level; |
135 | 142 | import java.util.logging.Logger;
|
136 | 143 | import java.util.regex.Matcher;
|
137 | 144 | import java.util.regex.Pattern;
|
138 | 145 | import java.util.stream.Collectors;
|
| 146 | +import org.openqa.selenium.devtools.v85.runtime.Runtime; |
139 | 147 |
|
140 | 148 | import static org.apache.commons.lang3.StringUtils.trimToNull;
|
141 | 149 | import static org.junit.Assert.assertEquals;
|
@@ -171,7 +179,7 @@ public abstract class WebDriverWrapper implements WrapsDriver
|
171 | 179 | {
|
172 | 180 | // Eliminate noise from org.openqa.selenium.remote.ProtocolHandshake and org.openqa.selenium.interactions.Actions
|
173 | 181 | if (!isWebDriverLoggingEnabled())
|
174 |
| - Logger.getLogger("org.openqa.selenium").setLevel(Level.WARNING); |
| 182 | + Logger.getLogger("org.openqa.selenium").setLevel(java.util.logging.Level.WARNING); |
175 | 183 | }
|
176 | 184 |
|
177 | 185 | public WebDriverWrapper()
|
@@ -393,6 +401,12 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
|
393 | 401 |
|
394 | 402 | if (newWebDriver != null)
|
395 | 403 | {
|
| 404 | + newWebDriver = new Augmenter().augment(newWebDriver); |
| 405 | + DevTools devTools = ((HasDevTools) newWebDriver).getDevTools(); |
| 406 | + devTools.createSession(); |
| 407 | + devTools.send(Log.enable()); |
| 408 | + devTools.addListener(Log.entryAdded(), BrowserConsoleLog::log); |
| 409 | + |
396 | 410 | Capabilities caps = ((HasCapabilities) newWebDriver).getCapabilities();
|
397 | 411 | String browserName = caps.getBrowserName();
|
398 | 412 | String browserVersion = caps.getBrowserVersion();
|
@@ -444,6 +458,11 @@ private void configureGeckoDriverLogging(File downloadDir)
|
444 | 458 | System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
|
445 | 459 | }
|
446 | 460 |
|
| 461 | + protected void enableConsoleLogCapture(boolean enable) |
| 462 | + { |
| 463 | + |
| 464 | + } |
| 465 | + |
447 | 466 | public boolean isFirefox()
|
448 | 467 | {
|
449 | 468 | return getDriver().getClass().isAssignableFrom(FirefoxDriver.class);
|
@@ -3922,3 +3941,20 @@ public void waitForElements(final Locator loc, final int count, int wait)
|
3922 | 3941 | assertEquals("Element not present expected number of times", count, loc.findElements(getDriver()).size());
|
3923 | 3942 | }
|
3924 | 3943 | }
|
| 3944 | + |
| 3945 | +class BrowserConsoleLog |
| 3946 | +{ |
| 3947 | + private static final Map<LogEntry.Level, Level> LOG_ENTRY_LEVELS = Map.of( |
| 3948 | + LogEntry.Level.VERBOSE, Level.DEBUG, |
| 3949 | + LogEntry.Level.INFO, Level.INFO, |
| 3950 | + LogEntry.Level.WARNING, Level.WARN, |
| 3951 | + LogEntry.Level.ERROR, Level.ERROR |
| 3952 | + ); |
| 3953 | + |
| 3954 | + static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(BrowserConsoleLog.class); |
| 3955 | + |
| 3956 | + static void log(LogEntry logEntry) |
| 3957 | + { |
| 3958 | + LOGGER.log(LOG_ENTRY_LEVELS.get(logEntry.getLevel()), logEntry.getText()); |
| 3959 | + } |
| 3960 | +} |
0 commit comments