-
Notifications
You must be signed in to change notification settings - Fork 4
/
CDPViewConsoleLogs.java
47 lines (39 loc) · 1.43 KB
/
CDPViewConsoleLogs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package example.test;
import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import java.time.Duration;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v91.log.Log;
import io.github.bonigarcia.wdm.WebDriverManager;
public class CDPViewConsoleLogs {
public ChromeDriver driver;
@BeforeClass
public void setUp() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterClass
public void afterClass() {
driver.quit();
}
@Test
public void viewConsoleLogs() {
DevTools devTools = driver.getDevTools();
devTools.createSession();
devTools.send(Log.enable());
devTools.addListener(Log.entryAdded(), logEntry -> {
System.out.println("------------------------------------------------------------");
System.out.println("Request ID = " + logEntry.getNetworkRequestId());
System.out.println("URL = " + logEntry.getUrl());
System.out.println("Source = " + logEntry.getSource());
System.out.println("Level = " + logEntry.getLevel());
System.out.println("Text = " + logEntry.getText());
System.out.println("Timestamp = " + logEntry.getTimestamp());
System.out.println("------------------------------------------------------------");
});
driver.get("https://www.qed42.com/404");
}
}