Skip to content

Commit

Permalink
[java] Add multiple interface test for Augmenter
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Oct 21, 2021
1 parent 42218df commit 833c6d6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions java/test/org/openqa/selenium/remote/AugmenterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.html5.LocationContext;
import org.openqa.selenium.html5.WebStorage;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.testing.UnitTests;

import java.util.ArrayList;
Expand Down Expand Up @@ -201,6 +203,28 @@ public void shouldAllowReflexiveCalls() {
assertThat(seen).isSameAs(element);
}

@Test
public void shouldAugmentMultipleInterfaces() {
final Capabilities caps = new ImmutableCapabilities("magic.numbers", true,
"numbers", true);
WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps);

WebDriver returned = getAugmenter()
.addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42)
.addDriverAugmentation("numbers", HasNumbers.class, (c, exe) -> webDriver -> {
Require.precondition(webDriver instanceof HasMagicNumbers, "Driver must implement HasMagicNumbers");
return ((HasMagicNumbers)webDriver).getMagicNumber();
})
.augment(driver);

assertThat(returned).isNotSameAs(driver);
assertThat(returned).isInstanceOf(HasMagicNumbers.class);
assertThat(returned).isInstanceOf(HasNumbers.class);

int number = ((HasNumbers)returned).getNumbers(returned);
assertThat(number).isEqualTo(42);
}

private static class ByMagic extends By {
private final String magicWord;

Expand Down Expand Up @@ -327,6 +351,10 @@ public interface HasMagicNumbers {
int getMagicNumber();
}

public interface HasNumbers {
int getNumbers(WebDriver driver);
}

public static class ChildRemoteDriver extends RemoteWebDriver implements HasMagicNumbers {
private int magicNumber = 3;

Expand Down

0 comments on commit 833c6d6

Please sign in to comment.