-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogTest.java
53 lines (42 loc) · 1.66 KB
/
LogTest.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
48
49
50
51
52
53
public class LogTest {
private ChromeDriver chtomeDriver = null;
private DevTools devTools = null;
@Before
public void setup() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeDriver = new ChromeDriver(chromeOptions);
devTools = chromeDriver.getDevTools();
devTools.createSession();
}
@After
public void cleanup() { chromeDriver.quit(); }
@Test
public void consoleLogTest() throws InterruptedException {
List<String> logs = new ArrayList<>();
devTools.send(Log.enable());
devTools.send(Runtime.enable());
devTools.addListener(Log.entryAdded(), logEntry -> logs.add(logEntry.getText()));
// https://chromedevtools.github.io/devtools-protocol/tot/Console/ states that post deprecation either Runtime or Log domain is to be used
// Depending on the implementation, events from either of the domains can be fired for console logs
// Usage in accordance with the DevTools version
devTools.addListener(org.openqa.selenium.devtools.v167.runtime.Runtime.consoleAPICalled(), consoleAPICalled -> {
logs.add(consoleAPICalled.getArgs().get(0).getValue().get().toString());
});
chromeDriver.get(“https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html”);
WebElement element - new WebDriverWait(chromeDriver,
Duration.ofSeconds(10)).until(driver -> driver.findElement(By.id(“consoleLog”)));
// Thread.sleep(3000);
element.click();
// Thread.sleep(3000);
boolean logFound = false;
for (String log : logs) {
if (log.contains(“Hello, world!”)) {
assertThat(log).isEqualTo(“Hello, world!”);
logFound = true;
break;
}
}
assetThat(logFound).isTrue();
logs.clear();
}
}