|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.remote; |
| 19 | + |
| 20 | +import static org.openqa.selenium.remote.Browser.CHROME; |
| 21 | +import static org.openqa.selenium.remote.Browser.EDGE; |
| 22 | +import static org.openqa.selenium.remote.Browser.OPERA; |
| 23 | + |
| 24 | +import org.openqa.selenium.Capabilities; |
| 25 | +import org.openqa.selenium.WebDriver; |
| 26 | +import org.openqa.selenium.devtools.HasDevTools; |
| 27 | +import org.openqa.selenium.logging.EventType; |
| 28 | +import org.openqa.selenium.logging.HasLogEvents; |
| 29 | + |
| 30 | +import java.util.function.Predicate; |
| 31 | + |
| 32 | +public class AddHasLogEvents |
| 33 | + implements AugmenterProvider<HasLogEvents> { |
| 34 | + |
| 35 | + private static final Predicate<String> IS_CHROMIUM_BROWSER = name -> |
| 36 | + CHROME.is(name) || |
| 37 | + EDGE.is(name) || |
| 38 | + OPERA.is(name); |
| 39 | + |
| 40 | + @Override |
| 41 | + public Predicate<Capabilities> isApplicable() { |
| 42 | + return caps -> IS_CHROMIUM_BROWSER.test(caps.getBrowserName()); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public Class<HasLogEvents> getDescribedInterface() { |
| 47 | + return HasLogEvents.class; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public HasLogEvents getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { |
| 52 | + return new HasLogEvents() { |
| 53 | + @Override |
| 54 | + public <X> void onLogEvent(EventType<X> kind) { |
| 55 | + if (((RemoteExecuteMethod) executeMethod).getWrappedDriver() instanceof HasDevTools) { |
| 56 | + WebDriver driver = ((RemoteExecuteMethod) executeMethod).getWrappedDriver(); |
| 57 | + kind.initializeListener(driver); |
| 58 | + } |
| 59 | + } |
| 60 | + }; |
| 61 | + } |
| 62 | +} |
0 commit comments