All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openqa.selenium.devtools.v121.v121Log Maven / Gradle / Ivy

Go to download

Selenium automates browsers. That's it! What you do with that power is entirely up to you.

The newest version!
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.devtools.v121;

import java.util.function.Function;
import java.util.logging.Level;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.ConverterFunctions;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.v121.log.Log;
import org.openqa.selenium.devtools.v121.log.model.LogEntry;
import org.openqa.selenium.devtools.v121.runtime.model.Timestamp;
import org.openqa.selenium.json.JsonInput;

public class v121Log implements org.openqa.selenium.devtools.idealized.log.Log {

  @Override
  public Command enable() {
    return Log.enable();
  }

  @Override
  public Command clear() {
    return Log.clear();
  }

  @Override
  public Event entryAdded() {
    return new Event<>(
        Log.entryAdded().getMethod(),
        input -> {
          Function mapper = ConverterFunctions.map("entry", LogEntry.class);
          LogEntry entry = mapper.apply(input);

          return new org.openqa.selenium.devtools.idealized.log.model.LogEntry(
              entry.getSource().toString(),
              new org.openqa.selenium.logging.LogEntry(
                  fromCdpLevel(entry.getLevel()),
                  fromCdpTimestamp(entry.getTimestamp()),
                  entry.getText()));
        });
  }

  private Level fromCdpLevel(LogEntry.Level level) {
    switch (level.toString()) {
      case "verbose":
        return Level.FINEST;

      case "info":
        return Level.INFO;

      case "warning":
        return Level.WARNING;

      case "error":
        return Level.SEVERE;

      default:
        return Level.INFO;
    }
  }

  private long fromCdpTimestamp(Timestamp timestamp) {
    try {
      return Long.parseLong(timestamp.toString());
    } catch (NumberFormatException e) {
      return System.currentTimeMillis();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy