Skip to content

Commit

Permalink
Merge pull request #586 from amuniz/scrolling-failure
Browse files Browse the repository at this point in the history
Do not fail too early on scrolling
  • Loading branch information
amuniz committed Jun 19, 2020
2 parents a173d1b + 9dc451f commit 37e4b8d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/org/jenkinsci/test/acceptance/selenium/Scroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.IOUtils;
import org.jenkinsci.test.acceptance.junit.Wait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrapsDriver;
Expand Down Expand Up @@ -66,6 +69,9 @@
* @author Kohsuke Kawaguchi
*/
public class Scroller extends AbstractWebDriverEventListener {

private Logger LOGGER = Logger.getLogger(Scroller.class.getName());

private final String scrollJs;

public Scroller() {
Expand Down Expand Up @@ -105,9 +111,15 @@ public void scrollIntoView(WebElement e, WebDriver driver) {
final String id = e.getAttribute("id");
final JavascriptExecutor executor = (JavascriptExecutor) driver;
// Wait until web element is successfully scrolled.
new Wait<>(Boolean.TRUE)
.withTimeout(5, TimeUnit.SECONDS) // Wall-clock time
.until(() -> (Boolean)executor.executeScript(scrollJs, eYCoord, eXCoord, id))
;
try {
new Wait<>(Boolean.TRUE)
.withTimeout(5, TimeUnit.SECONDS) // Wall-clock time
.until(() -> (Boolean) executor.executeScript(scrollJs, eYCoord, eXCoord, id))
;
} catch (TimeoutException ex) {
// Scrolling failed, but sometimes the element to click is already visible, let the test continue and eventually fail later
// This log message should be sufficient to diagnose the issue
LOGGER.log(Level.WARNING, "Scrolling failed, letting the test to continue anyways, but \"Element is not clickable\" error will likely be thrown", ex);
}
}
}

0 comments on commit 37e4b8d

Please sign in to comment.