-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
LoggingTest.java
55 lines (45 loc) · 1.88 KB
/
LoggingTest.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
54
55
package dev.selenium.troubleshooting;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.manager.SeleniumManager;
import org.openqa.selenium.remote.RemoteWebDriver;
public class LoggingTest {
@AfterEach
public void loggingOff() {
Logger logger = Logger.getLogger("");
logger.setLevel(Level.INFO);
Arrays.stream(logger.getHandlers()).forEach(handler -> {
handler.setLevel(Level.INFO);
});
}
@Test
public void logging() throws IOException {
Logger logger = Logger.getLogger("");
logger.setLevel(Level.FINE);
Arrays.stream(logger.getHandlers()).forEach(handler -> {
handler.setLevel(Level.FINE);
});
Handler handler = new FileHandler("selenium.xml");
logger.addHandler(handler);
Logger.getLogger(RemoteWebDriver.class.getName()).setLevel(Level.FINEST);
Logger.getLogger(SeleniumManager.class.getName()).setLevel(Level.SEVERE);
Logger localLogger = Logger.getLogger(this.getClass().getName());
localLogger.warning("this is a warning");
localLogger.info("this is useful information");
localLogger.fine("this is detailed debug information");
byte[] bytes = Files.readAllBytes(Paths.get("selenium.xml"));
String fileContent = new String(bytes);
Assertions.assertTrue(fileContent.contains("this is a warning"));
Assertions.assertTrue(fileContent.contains("this is useful information"));
Assertions.assertTrue(fileContent.contains("this is detailed debug information"));
}
}