diff --git a/bellatrix.plugins.screenshots/src/main/java/plugins/screenshots/ScreenshotPlugin.java b/bellatrix.plugins.screenshots/src/main/java/plugins/screenshots/ScreenshotPlugin.java index c6a4e880..c28b90c2 100644 --- a/bellatrix.plugins.screenshots/src/main/java/plugins/screenshots/ScreenshotPlugin.java +++ b/bellatrix.plugins.screenshots/src/main/java/plugins/screenshots/ScreenshotPlugin.java @@ -17,6 +17,7 @@ import solutions.bellatrix.core.plugins.EventListener; import solutions.bellatrix.core.plugins.Plugin; import solutions.bellatrix.core.plugins.TestResult; +import solutions.bellatrix.core.plugins.TimeRecord; import java.lang.reflect.Method; import java.nio.file.Paths; @@ -37,7 +38,7 @@ public ScreenshotPlugin(boolean isEnabled) { @Override @SneakyThrows - public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) { + public void preAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo) { if (!isEnabled || testResult == TestResult.SUCCESS) return; diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java index 0668f5ed..9d5865ff 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java @@ -124,8 +124,14 @@ public WebElement getWrappedElement() { } else { return findElement(); } - } catch (Exception ex ) { + } catch (ElementNotInteractableException ex ) { + scrollToVisible(); return findElement(); + } catch (StaleElementReferenceException ex ) { + return findElement(); + } catch (WebDriverException ex ) { + toExist().waitToBe(); + return wrappedElement; } } @@ -844,7 +850,7 @@ private boolean inShadowContext() { } public WebElement findElement() { - if (waitStrategies.size() == 0) { + if (waitStrategies.isEmpty()) { waitStrategies.add(Wait.to().exist(webSettings.getTimeoutSettings().getElementWaitTimeout(), webSettings.getTimeoutSettings().getSleepInterval())); } @@ -893,7 +899,8 @@ private void clickInternal() { try { wait.until(x -> tryClick()); } catch (TimeoutException e) { - toBeVisible().toBeClickable().findElement().click(); + Log.info("Click has timed out. Trying with JS click()..."); + javaScriptService.execute("arguments[0].click()", findElement()); } } @@ -902,9 +909,15 @@ private boolean tryClick() { toBeVisible().toBeClickable().findElement().click(); return true; } catch (ElementNotInteractableException e) { + Log.error("ElementNotInteractableException found - retrying with scroll.. "); + scrollToVisible(); + return false; + } catch (StaleElementReferenceException e) { + Log.error("StaleElementReference Exception found - retrying with a new Find... "); + findElement(); return false; } catch (WebDriverException e) { - toBeVisible().toBeClickable().waitToBe(); + Log.error("WebDriverException found - trying again... "); return false; } } @@ -1291,6 +1304,9 @@ private void scrollToVisible(WebElement wrappedElement, boolean shouldWait, Scro public boolean isVisible() { try { return getWrappedElement().isDisplayed(); + } catch (StaleElementReferenceException e) { + wrappedElement = findElement(); + return false; } catch (NotFoundException e) { return false; }