use of com.seleniumtests.customexception.ScenarioException 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());
}
}
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class Element method checkForMobile.
/**
* Check if the current platform is a mobile platform
* if it's the case, search for the element, else, raise a ScenarioException
*/
protected PerformsTouchActions checkForMobile() {
CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false);
if (driver == null) {
throw new ScenarioException("Driver has not already been created");
}
if (!SeleniumTestsContextManager.isMobileTest()) {
throw new ScenarioException("action is available only for mobile platforms");
}
if (!(driver.getWebDriver() instanceof AppiumDriver<?>)) {
throw new ScenarioException("action is available only for mobile platforms");
}
findElement(true);
return (PerformsTouchActions) driver.getWebDriver();
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class ExcelHelper method readSheet.
/**
* Read a sheet by name in the excel file
* @param fis
* @param sheetName
* @return
* @throws IOException
*/
public List<Map<String, String>> readSheet(InputStream fis, String sheetName, boolean headerPresent) throws IOException {
try (Workbook workbook = WorkbookFactory.create(fis)) {
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter dataFormatter = new DataFormatter();
Sheet sheet = workbook.getSheet(sheetName);
if (sheet == null) {
throw new ScenarioException(String.format("Sheet %s does not exist", sheetName));
}
List<Map<String, String>> sheetContent = readSheet(sheet, headerPresent, formulaEvaluator, dataFormatter);
if (sheetContent == null) {
throw new ScenarioException(String.format("No data in sheet %s", sheetName));
}
return sheetContent;
} catch (IOException e) {
throw new ScenarioException(e.getMessage());
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class ExcelHelper method read.
/**
* Read an excel file and returns the content
* @param fis
* @param headerPresent
* @return
* @throws IOException
*/
public Map<String, List<Map<String, String>>> read(InputStream fis, boolean headerPresent) throws IOException {
Map<String, List<Map<String, String>>> content = new LinkedHashMap<>();
try (Workbook workbook = WorkbookFactory.create(fis)) {
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter dataFormatter = new DataFormatter();
for (int sheetIdx = workbook.getNumberOfSheets() - 1; sheetIdx >= 0; sheetIdx--) {
Sheet sheet = workbook.getSheetAt(sheetIdx);
List<Map<String, String>> sheetContent = readSheet(sheet, headerPresent, formulaEvaluator, dataFormatter);
if (sheetContent == null) {
continue;
}
content.put(sheet.getSheetName(), sheetContent);
}
return content;
} catch (IOException e) {
throw new ScenarioException(e.getMessage());
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class SelectList method findElement.
@Override
protected void findElement() {
// set a default type so that use of selectImplementation can be done
selectImplementation = new StubSelect();
super.findElement(true);
// if we have a prefered implementation, use it
// search the right select list handler
implementationList = orderImplementations(getPreferedUiLibraries());
for (Class<? extends ISelectList> selectClass : implementationList) {
try {
ISelectList selectInstance = selectClass.getConstructor(WebElement.class, FrameElement.class).newInstance(getRealElementNoSearch(), frameElement);
if (selectInstance.isApplicable()) {
selectImplementation = selectInstance;
selectInstance.setDriver(getDriver());
break;
}
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
logger.error(String.format("Cannot use Select implementation %s: %s", selectClass.getName(), e.getMessage()));
}
}
if (selectImplementation instanceof StubSelect) {
throw new ScenarioException("Cannot find type of select " + getRealElementNoSearch().getTagName());
}
options = selectImplementation.getOptions();
multiple = selectImplementation.isMultipleWithoutFind();
}
Aggregations