Skip to content

Commit

Permalink
Add support to listen "refresh" events
Browse files Browse the repository at this point in the history
Currently WebDriverEventListener supports different navigation
event types, but not refresh events. This commit adds support for
refresh.

Fixes #1584

Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
  • Loading branch information
semonte authored and lukeis committed Feb 18, 2016
1 parent 91ed440 commit 0cbe9dc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public void afterNavigateForward(WebDriver driver) {
// Do nothing.
}

public void beforeNavigateRefresh(WebDriver driver) {
// Do nothing.
}

public void afterNavigateRefresh(WebDriver driver) {
// Do nothing.
}

public void beforeFindBy(By by, WebElement element, WebDriver driver) {
// Do nothing.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ public void forward() {
}

public void refresh() {
dispatcher.beforeNavigateRefresh(driver);
navigation.refresh();
dispatcher.afterNavigateRefresh(driver);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public interface WebDriverEventListener {
*/
void afterNavigateForward(WebDriver driver);

/**
* Called before {@link org.openqa.selenium.WebDriver.Navigation#refresh navigate().refresh()}.
*
* @param driver WebDriver
*/
void beforeNavigateRefresh(WebDriver driver);

/**
* Called after {@link org.openqa.selenium.WebDriver.Navigation#refresh navigate().refresh()}. Not called,
* if an exception is thrown.
*
* @param driver WebDriver
*/
void afterNavigateRefresh(WebDriver driver);

/**
* Called before {@link WebDriver#findElement WebDriver.findElement(...)}, or
* {@link WebDriver#findElements WebDriver.findElements(...)}, or {@link WebElement#findElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,23 @@ public void beforeNavigateForward(WebDriver driver) {
public void afterNavigateForward(WebDriver driver) {
log.append("afterNavigateForward\n");
}

@Override
public void beforeNavigateRefresh(WebDriver driver) {
log.append("beforeNavigateRefresh\n");
}

@Override
public void afterNavigateRefresh(WebDriver driver) {
log.append("afterNavigateRefresh\n");
}
});

testedDriver.get("http://www.get.com");
testedDriver.navigate().to("http://www.navigate-to.com");
testedDriver.navigate().back();
testedDriver.navigate().forward();
testedDriver.navigate().refresh();

assertEquals(
"beforeNavigateTo http://www.get.com\n" +
Expand All @@ -106,14 +117,17 @@ public void afterNavigateForward(WebDriver driver) {
"beforeNavigateBack\n" +
"afterNavigateBack\n" +
"beforeNavigateForward\n" +
"afterNavigateForward\n",
"afterNavigateForward\n" +
"beforeNavigateRefresh\n" +
"afterNavigateRefresh\n",
log.toString());

InOrder order = Mockito.inOrder(mockedDriver, mockedNavigation);
order.verify(mockedDriver).get("http://www.get.com");
order.verify(mockedNavigation).to("http://www.navigate-to.com");
order.verify(mockedNavigation).back();
order.verify(mockedNavigation).forward();
order.verify(mockedNavigation).refresh();
order.verifyNoMoreInteractions();
}

Expand Down

0 comments on commit 0cbe9dc

Please sign in to comment.