| 30 | import org.openqa.selenium.logging.Logs; |
| 31 | |
| 32 | @Beta |
| 33 | public class RemoteLogs implements Logs { |
| 34 | private static final String LEVEL = "level"; |
| 35 | private static final String TIMESTAMP = "timestamp"; |
| 36 | private static final String MESSAGE = "message"; |
| 37 | |
| 38 | protected ExecuteMethod executeMethod; |
| 39 | |
| 40 | public static final String TYPE_KEY = "type"; |
| 41 | |
| 42 | public RemoteLogs(ExecuteMethod executeMethod) { |
| 43 | this.executeMethod = executeMethod; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public LogEntries get(String logType) { |
| 48 | return getRemoteEntries(logType); |
| 49 | } |
| 50 | |
| 51 | private LogEntries getRemoteEntries(String logType) { |
| 52 | Object raw = executeMethod.execute(DriverCommand.GET_LOG, Map.of(TYPE_KEY, logType)); |
| 53 | if (!(raw instanceof List)) { |
| 54 | throw new UnsupportedCommandException("malformed response to remote logs command"); |
| 55 | } |
| 56 | @SuppressWarnings("unchecked") |
| 57 | List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw; |
| 58 | List<LogEntry> remoteEntries = |
| 59 | rawList.stream().map(this::createLogEntry).collect(Collectors.toList()); |
| 60 | |
| 61 | return new LogEntries(remoteEntries); |
| 62 | } |
| 63 | |
| 64 | private LogEntry createLogEntry(Map<String, Object> obj) { |
| 65 | return new LogEntry( |
| 66 | LogLevelMapping.toLevel((String) obj.get(LEVEL)), |
| 67 | (Long) obj.get(TIMESTAMP), |
| 68 | (String) obj.get(MESSAGE)); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Set<String> getAvailableLogTypes() { |
| 73 | List<String> rawList = executeMethod.execute(DriverCommand.GET_AVAILABLE_LOG_TYPES); |
| 74 | return Set.copyOf(new LinkedHashSet<>(rawList)); |
| 75 | } |
| 76 | } |
nothing calls this directly
no outgoing calls
no test coverage detected