use of com.seleniumtests.uipage.htmlelements.GenericPictureElement in project seleniumRobot by bhecquet.
the class PageObject method assertForVisible.
@GenericStep
public <T extends PageObject> T assertForVisible(String fieldName) {
Element element = getElement(fieldName);
if (element instanceof HtmlElement) {
Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
Assert.assertTrue(((HtmlElement) element).isDisplayed(), String.format("Element %s is not visible", fieldName));
} else {
Assert.assertTrue(((GenericPictureElement) element).isElementPresent(), String.format("Element %s is not visible", fieldName));
}
return (T) this;
}
use of com.seleniumtests.uipage.htmlelements.GenericPictureElement in project seleniumRobot by bhecquet.
the class ReplayAction method replay.
/**
* Replay all actions annotated by ReplayOnError if the class is not a subclass of
* HtmlElement
* @param joinPoint
* @throws Throwable
*/
@Around("!execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)")
public Object replay(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable {
int replayDelayMs = replay != null ? replay.replayDelayMs() : 100;
Instant end = systemClock.instant().plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout());
Object reply = null;
String targetName = joinPoint.getTarget().toString();
TestAction currentAction = null;
if (joinPoint.getTarget() instanceof GenericPictureElement) {
String methodName = joinPoint.getSignature().getName();
List<String> pwdToReplace = new ArrayList<>();
String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>()));
currentAction = new TestAction(actionName, false, pwdToReplace);
// order of steps is the right one (first called is first displayed)
if (TestStepManager.getParentTestStep() != null) {
TestStepManager.getParentTestStep().addAction(currentAction);
}
}
boolean actionFailed = false;
Throwable currentException = null;
try {
while (end.isAfter(systemClock.instant())) {
// raised if action cannot be performed
if (((CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false)).getBrowserInfo().getBrowser() == BrowserType.CHROME || ((CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false)).getBrowserInfo().getBrowser() == BrowserType.EDGE) {
updateScrollFlagForElement(joinPoint, true, null);
}
try {
reply = joinPoint.proceed(joinPoint.getArgs());
WaitHelper.waitForMilliSeconds(200);
break;
// do not replay if error comes from scenario
} catch (ScenarioException | ConfigurationException | DatasetException e) {
throw e;
} catch (MoveTargetOutOfBoundsException | InvalidElementStateException e) {
updateScrollFlagForElement(joinPoint, null, e);
} catch (Throwable e) {
if (end.minusMillis(200).isAfter(systemClock.instant())) {
WaitHelper.waitForMilliSeconds(replayDelayMs);
continue;
} else {
throw e;
}
}
}
return reply;
} catch (Throwable e) {
actionFailed = true;
currentException = e;
throw e;
} finally {
if (currentAction != null && TestStepManager.getParentTestStep() != null) {
currentAction.setFailed(actionFailed);
scenarioLogger.logActionError(currentException);
if (joinPoint.getTarget() instanceof GenericPictureElement) {
currentAction.setDurationToExclude(((GenericPictureElement) joinPoint.getTarget()).getActionDuration());
}
}
}
}
Aggregations