Skip to content

Commit

Permalink
[java] Add a warning while passing a decorated driver to augmenter
Browse files Browse the repository at this point in the history
Related to #13246
  • Loading branch information
pujagani committed Jan 12, 2024
1 parent 097d301 commit 4350eb1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions java/src/org/openqa/selenium/remote/Augmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,8 @@
*/
@Beta
public class Augmenter {

private static final Logger LOG = Logger.getLogger(Augmenter.class.getName());
private final Set<Augmentation<?>> augmentations;

public Augmenter() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4350eb1

Please sign in to comment.