From 4350eb1d0b0d7f668f7b9ee2674485974cb47dae Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Fri, 12 Jan 2024 13:53:02 +0530 Subject: [PATCH] [java] Add a warning while passing a decorated driver to augmenter Related to https://github.com/SeleniumHQ/selenium/issues/13246 --- .../org/openqa/selenium/remote/Augmenter.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/java/src/org/openqa/selenium/remote/Augmenter.java b/java/src/org/openqa/selenium/remote/Augmenter.java index d64f25a0ff055..65949af893f00 100644 --- a/java/src/org/openqa/selenium/remote/Augmenter.java +++ b/java/src/org/openqa/selenium/remote/Augmenter.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.function.BiFunction; import java.util.function.Predicate; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -59,6 +60,8 @@ */ @Beta public class Augmenter { + + private static final Logger LOG = Logger.getLogger(Augmenter.class.getName()); private final Set> augmentations; public Augmenter() { @@ -147,6 +150,19 @@ public WebDriver augment(WebDriver driver) { Require.precondition( driver instanceof HasCapabilities, "Driver must have capabilities", driver); + if (driver instanceof Decorated) { + LOG.warning( + "Warning: In future versions, passing a decorated driver will no longer be allowed.\n" + + " Instead, augment the driver first and then use it to created a decorated" + + " driver.\n" + + " Explanation: Decorated drivers are not aware of the augmentations applied to" + + " them. It can lead to expected behavior.\n" + + " For example, augmenting HasDevTools interface to a decorated driver. \n" + + " The decorated driver is not aware that after augmentation it is an instance of" + + " HasDevTools. So it does not invoke the close() method of the underlying" + + " websocket, potentially causing a memory leak. "); + } + Capabilities caps = ImmutableCapabilities.copyOf(((HasCapabilities) driver).getCapabilities()); // Collect the interfaces to apply