use of com.seleniumtests.customexception.DatasetException in project seleniumRobot by bhecquet.
the class Filter method dateFilterCase.
private static boolean dateFilterCase(String name, Object[] values, Operator operator, final Map<String, Object> parameters) {
Date date;
try {
date = DateFormat.getDateInstance().parse(parameters.get(name).toString());
} catch (ParseException e) {
date = (Date) parameters.get(name);
}
Date dateLeft = (Date) values[0];
Date dateRight;
switch(operator) {
case BETWEEN:
dateRight = (Date) values[1];
return (dateLeft.before(date) || dateLeft.equals(date)) && (date.before(dateRight) || date.equals(dateRight));
case LESS_THAN:
return date.before(dateLeft);
case GREATER_THAN:
return date.after(dateLeft);
default:
throw new DatasetException(name + "filter NOT implemented yet for dates.");
}
}
use of com.seleniumtests.customexception.DatasetException in project seleniumRobot by bhecquet.
the class Filter method numberFilterCase.
private static boolean numberFilterCase(String name, Object[] values, Operator operator, final Map<String, Object> parameters) {
BigDecimal val = new BigDecimal(parameters.get(name).toString());
BigDecimal leftValue = new BigDecimal(values[0].toString());
BigDecimal rightValue;
switch(operator) {
case BETWEEN:
rightValue = new BigDecimal(values[1].toString());
return leftValue.compareTo(val) < 1 && rightValue.compareTo(val) > -1;
case LESS_THAN:
return val.compareTo(leftValue) < 0;
case GREATER_THAN:
return val.compareTo(leftValue) > 0;
default:
throw new DatasetException(name + "filter NOT implemented yet for numbers.");
}
}
use of com.seleniumtests.customexception.DatasetException in project seleniumRobot by bhecquet.
the class CSVHelper method getDataFromCSVFile.
/**
* Reads data from csv file.
* class : null => filename : entire path of file
* class : this.getClass(), filename : the filename will be search in the same directory of the class
*
* @param clazz
* @param filename
* @param filter
* @param readHeaders
* @param delimiter
* @param supportDPFilter
* @return
*/
public static Iterator<Object[]> getDataFromCSVFile(final Class<?> clazz, final String filename, Filter filter, final boolean readHeaders, final String delimiter, final boolean supportDPFilter) {
Filter newFilter = filter;
try (InputStream is = (clazz != null) ? clazz.getResourceAsStream(filename) : new FileInputStream(filename)) {
if (is == null) {
return new ArrayList<Object[]>().iterator();
}
// Get the sheet
String[][] csvData = read(is, delimiter);
if (csvData == null) {
return new ArrayList<Object[]>().iterator();
}
List<Object[]> sheetData = new ArrayList<>();
if (readHeaders) {
List<Object> rowData = new ArrayList<>();
for (int j = 0; j < csvData[0].length; j++) {
rowData.add(csvData[0][j]);
}
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
// Check for blank rows first
// First row is the header
StringBuilder sbBlank = new StringBuilder();
if (sbBlank.length() > 0) {
sbBlank.deleteCharAt(sbBlank.length() - 1);
throw new CustomSeleniumTestsException("Blank TestTitle found on Row(s) " + sbBlank.toString() + ".");
}
// Support include tags and exclude tags
if (supportDPFilter) {
Filter dpFilter = SpreadSheetHelper.getDPFilter();
if (dpFilter != null) {
if (newFilter == null) {
newFilter = dpFilter;
} else {
newFilter = Filter.and(newFilter, dpFilter);
}
}
}
// The first row is the header data
for (int i = 1; i < csvData.length; i++) {
Map<String, Object> rowDataMap = new HashMap<>();
List<Object> rowData = new ArrayList<>();
// Create the mapping between headers and column data
for (int j = 0; j < csvData[i].length; j++) {
rowDataMap.put(csvData[0][j], csvData[i][j]);
}
for (int j = 0; j < csvData[0].length; j++) {
// expected.
if (csvData[i].length > j) {
rowData.add(csvData[i][j]);
} else {
rowData.add(null);
}
}
// To support include tags and exclude tags
if (supportDPFilter) {
SpreadSheetHelper.formatDPTags(rowDataMap);
}
if (newFilter == null || newFilter.match(rowDataMap)) {
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
}
if ((!readHeaders && sheetData.isEmpty()) || (readHeaders && sheetData.size() <= 1)) {
logger.warn("No matching data found on csv file: " + filename + " with filter criteria: " + newFilter.toString());
}
return sheetData.iterator();
} catch (Exception e) {
throw new DatasetException(e.getMessage());
}
}
use of com.seleniumtests.customexception.DatasetException in project seleniumRobot by bhecquet.
the class CSVHelper method getHeaderFromCSVFile.
/**
* Get headers from a csv file.
*
* @param clazz - null means use the absolute file path, otherwise use relative path under the class
* @param filename
* @param delimiter - null means ","
*
* @return
*/
public static List<String> getHeaderFromCSVFile(final Class<?> clazz, final String filename, String delimiter) {
String newDelimiter = delimiter == null ? "," : delimiter;
try (InputStream is = clazz != null ? clazz.getResourceAsStream(filename) : new FileInputStream(filename)) {
if (is == null) {
return new ArrayList<>();
}
// Get the sheet
String[][] csvData = read(is, newDelimiter);
if (csvData == null) {
return new ArrayList<>();
}
ArrayList<String> rowData = new ArrayList<>();
for (int j = 0; j < csvData[0].length; j++) {
rowData.add(csvData[0][j]);
}
return rowData;
} catch (Exception e) {
throw new DatasetException(e.getMessage());
}
}
use of com.seleniumtests.customexception.DatasetException 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