Skip to content

Commit 9c9dccf

Browse files
committed
[java] only augment with matching augmenters
1 parent 0a5b2d8 commit 9c9dccf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

java/src/org/openqa/selenium/remote/Augmenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public WebDriver augment(WebDriver driver) {
180180
.annotateType(AnnotationDescription.Builder.ofType(Augmentable.class).build())
181181
.method(named("isAugmented")).intercept(FixedValue.value(true));
182182

183-
for (Augmentation<?> augmentation : augmentations) {
183+
for (Augmentation<?> augmentation : matchingAugmenters) {
184184
Class<?> iface = augmentation.interfaceClass;
185185

186186
Object instance = augmentation.implementation.apply(caps, execute);

java/test/org/openqa/selenium/remote/AugmenterTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.firefox.FirefoxOptions;
3434
import org.openqa.selenium.html5.LocationContext;
35+
import org.openqa.selenium.html5.WebStorage;
3536
import org.openqa.selenium.testing.UnitTests;
3637

3738
import java.util.ArrayList;
@@ -100,6 +101,17 @@ public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() {
100101
assertThat(returned).isNotInstanceOf(HasMagicNumbers.class);
101102
}
102103

104+
@Test
105+
public void shouldNotUseNonMatchingInterfaces() {
106+
Capabilities caps = new ImmutableCapabilities("magic.numbers", true);
107+
WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps);
108+
109+
WebDriver returned = getAugmenter()
110+
.addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42)
111+
.augment(driver);
112+
assertThat(returned).isNotInstanceOf(WebStorage.class);
113+
}
114+
103115
@Test
104116
public void shouldDelegateToHandlerIfAdded() {
105117
Capabilities caps = new ImmutableCapabilities("foo", true);

0 commit comments

Comments
 (0)