|
21 | 21 | import org.openqa.selenium.chrome.ChromeOptions;
|
22 | 22 | import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
|
23 | 23 | import org.openqa.selenium.chromium.ChromiumNetworkConditions;
|
24 |
| -import org.openqa.selenium.logging.LogEntries; |
25 |
| -import org.openqa.selenium.logging.LogType; |
26 |
| -import org.openqa.selenium.logging.LoggingPreferences; |
| 24 | +import org.openqa.selenium.logging.*; |
27 | 25 | import org.openqa.selenium.remote.service.DriverFinder;
|
28 | 26 |
|
| 27 | + |
29 | 28 | public class ChromeTest extends BaseTest {
|
30 | 29 | @AfterEach
|
31 | 30 | public void clearProperties() {
|
32 | 31 | System.clearProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY);
|
33 | 32 | System.clearProperty(ChromeDriverService.CHROME_DRIVER_LOG_LEVEL_PROPERTY);
|
34 | 33 | }
|
| 34 | + |
35 | 35 | @Test
|
36 | 36 | public void basicOptions() {
|
37 | 37 | ChromeOptions options = new ChromeOptions();
|
@@ -236,4 +236,26 @@ public void castFeatures() {
|
236 | 236 |
|
237 | 237 | driver.quit();
|
238 | 238 | }
|
| 239 | + |
| 240 | + @Test |
| 241 | + public void getBrowserLogs() { |
| 242 | + ChromeDriver driver = new ChromeDriver(); |
| 243 | + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); |
| 244 | + WebElement consoleLogButton = driver.findElement(By.id("consoleError")); |
| 245 | + consoleLogButton.click(); |
| 246 | + |
| 247 | + LogEntries logs = driver.manage().logs().get(LogType.BROWSER); |
| 248 | + |
| 249 | + // Assert that at least one log contains the expected message |
| 250 | + boolean logFound = false; |
| 251 | + for (LogEntry log : logs) { |
| 252 | + if (log.getMessage().contains("I am console error")) { |
| 253 | + logFound = true; |
| 254 | + break; |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + Assertions.assertTrue(logFound, "No matching log message found."); |
| 259 | + driver.quit(); |
| 260 | + } |
239 | 261 | }
|
0 commit comments