Skip to content

Commit

Permalink
Avoid an infinite loop when trying to find the innermost driver (#937) (
Browse files Browse the repository at this point in the history
#949)

Fixes #945
  • Loading branch information
alvarezguille committed Oct 26, 2017
1 parent 310a659 commit b7c5494
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ protected TestBenchDriverProxy(WebDriver webDriver) {

@Override
public WebDriver getWrappedDriver() {
// This is in practice the same thing as actualDriver because of proxy.
// Selenium can use us exactly the same way.
return this;
return actualDriver;
}

public WebDriver getActualDriver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected boolean isFirefox() {
public Capabilities getCapabilities() {
WebDriver driver;
if (getDriver() instanceof TestBenchDriverProxy) {
driver = ((TestBenchDriverProxy) getDriver()).getActualDriver();
driver = ((TestBenchDriverProxy) getDriver()).getWrappedDriver();
} else {
driver = getDriver();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ public void testTestBenchDriverActsAsProxy() {
expect(mockDriver.getPageSource()).andReturn("<html></html>");
expect(mockDriver.getTitle()).andReturn("bar");
expect(mockDriver.getWindowHandle()).andReturn("baz");
Set<String> handles = new HashSet<String>();
Set<String> handles = new HashSet<>();
expect(mockDriver.getWindowHandles()).andReturn(handles);
Options mockOptions = createNiceMock(Options.class);
expect(mockDriver.manage()).andReturn(mockOptions);
Navigation mockNavigation = createNiceMock(Navigation.class);
expect(mockDriver.navigate()).andReturn(mockNavigation);
mockDriver.quit();
expectLastCall().once();
expect(
((JavascriptExecutor) mockDriver)
.executeScript(anyObject(String.class))).andStubReturn(
true);
expect(((JavascriptExecutor) mockDriver)
.executeScript(anyObject(String.class))).andStubReturn(true);
TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
replay(mockDriver);
Expand All @@ -78,8 +76,10 @@ public void testTestBenchDriverActsAsProxy() {
WebDriver driver = TestBench.createDriver(mockDriver);
driver.close();
By mockBy = createNiceMock(By.class);
assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
assertTrue(
driver.findElement(mockBy) instanceof TestBenchElementCommands);
assertTrue(driver.findElements(mockBy)
.get(0) instanceof TestBenchElementCommands);
driver.get("foo");
assertEquals("foo", driver.getCurrentUrl());
assertEquals("<html></html>", driver.getPageSource());
Expand All @@ -103,11 +103,11 @@ public void testAugmentedDriver() {
}

@Test
public void getWrappedDriver_returnsItself() {
public void getWrappedDriver_returnsParent() {
WebDriver driverMock = createNiceMock(WebDriver.class);
WebDriver driver = TestBench.createDriver(driverMock);
WebDriver wrappedDriver = ((WrapsDriver) driver).getWrappedDriver();
assertEquals(driver, wrappedDriver);
assertEquals(driverMock, wrappedDriver);
}

@Test
Expand All @@ -118,9 +118,11 @@ public void testDisableWaitForVaadin() {

FirefoxDriver mockFF = createMock(FirefoxDriver.class);
expect(mockFF.getCapabilities()).andReturn(mockCapabilities).anyTimes();
expect(mockFF.executeScript(contains("clients[client].isActive()"))).andReturn(true).once();
expect(mockFF.executeScript(contains("clients[client].isActive()")))
.andReturn(true).once();
WebElement mockElement = createNiceMock(WebElement.class);
expect(mockFF.findElement(isA(By.class))).andReturn(mockElement).times(2);
expect(mockFF.findElement(isA(By.class))).andReturn(mockElement)
.times(2);
replay(mockFF, mockElement, mockCapabilities);

TestBenchDriverProxy tb = (TestBenchDriverProxy) TestBench
Expand Down

0 comments on commit b7c5494

Please sign in to comment.