Skip to content

Commit

Permalink
Pass WebDriver instead of Loggable to allow augmentation of HasLogEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Oct 19, 2021
1 parent f2d79cf commit a25ad32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 6 additions & 8 deletions java/src/org/openqa/selenium/devtools/events/CdpEventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public void consume(ConsoleEvent event) {
}

@Override
public void initializeListener(HasLogEvents loggable) {
Require.precondition(loggable instanceof HasDevTools, "Loggable must implement HasDevTools");
public void initializeListener(WebDriver webDriver) {
Require.precondition(webDriver instanceof HasDevTools, "Loggable must implement HasDevTools");

DevTools tools = ((HasDevTools) loggable).getDevTools();
DevTools tools = ((HasDevTools) webDriver).getDevTools();
tools.createSessionIfThereIsNotOne();

tools.getDomains().events().addConsoleListener(handler);
Expand Down Expand Up @@ -87,16 +87,14 @@ public void consume(Void event) {
}

@Override
public void initializeListener(HasLogEvents loggable) {
Require.precondition(loggable instanceof WebDriver, "Loggable must be a WebDriver");
Require.precondition(loggable instanceof HasDevTools, "Loggable must implement HasDevTools");
public void initializeListener(WebDriver driver) {
Require.precondition(driver instanceof HasDevTools, "Loggable must implement HasDevTools");

DevTools tools = ((HasDevTools) loggable).getDevTools();
DevTools tools = ((HasDevTools) driver).getDevTools();
tools.createSessionIfThereIsNotOne();

tools.getDomains().javascript().pin("__webdriver_attribute", script);

WebDriver driver = (WebDriver) loggable;
// And add the script to the current page
((JavascriptExecutor) driver).executeScript(script);

Expand Down
4 changes: 3 additions & 1 deletion java/src/org/openqa/selenium/logging/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

package org.openqa.selenium.logging;

import org.openqa.selenium.WebDriver;

@FunctionalInterface
public interface EventType<X> {
void consume(X event);

default void initializeListener(HasLogEvents loggable) {
default void initializeListener(WebDriver webDriver) {
// no-op
}
}

0 comments on commit a25ad32

Please sign in to comment.