use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class HtmlFindUtils method findComplexElement.
private <T extends WebElement> ComplexElement findComplexElement(T context, String name, boolean wait) {
ComplexElement<T> element = new ComplexElement<>(context, name, wait);
try {
for (; element.getCurrentPosition() < element.getElementPath().size(); element.setCurrentPosition(element.getCurrentPosition() + 1)) {
Field field = getField(element.getElement(), element.getCurrentName());
if (field == null) {
throw new ElementSearchError("No element declared on page " + formErrorMessage(element));
}
findElement(field, element);
}
if (element.getCurrentPosition() > 0) {
element.setCurrentPosition(element.getCurrentPosition() - 1);
}
} catch (AutotestError | IllegalArgumentException | ElementDescriptionException ex) {
throw new ElementSearchError("Element " + formErrorMessage(element), ex);
}
return element;
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class HtmlFindUtils method getElementTypesMap.
/**
* Specifies a type map: type attribute, type. Data is taken from the json file specified in the 'ui.types' parameter
*
* @return Returns a type map
*/
public Map<String, Class> getElementTypesMap() {
Map<String, Class> elements = new HashMap<>();
try {
String types = PROPERTIES.geUiTypes();
String dir = types.substring(0, types.lastIndexOf("/"));
String name = types.substring(types.lastIndexOf("/")).replace(".json", "");
TestDataProvider dataObject = new JsonDataProvider(dir, name);
for (String typeAttribute : dataObject.getKeySet()) {
elements.put(typeAttribute, Class.forName(dataObject.get(typeAttribute).getValue()));
}
} catch (DataException | ClassNotFoundException ex) {
throw new AutotestError("Error while generating element search types.", ex);
}
return elements;
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class PlaceholderUtils method replaceJsonTemplatePlaceholders.
/**
* Replace Json template placeholders in string on parameters
*
* @param jsonString replace placeholders in this json string
* @param parameters replace these parameters
* @return json string with replaced placeholders
*/
public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String jsonString, Map<String, Object> parameters) {
Set<Map.Entry<String, Object>> mandatoryValues = parameters.entrySet().stream().filter(stringObjectEntry -> stringObjectEntry.getValue() != null).collect(Collectors.toSet());
for (Map.Entry<String, Object> parameter : mandatoryValues) {
String parameterName = parameter.getKey();
Object parameterValue = parameter.getValue();
if (isFieldExists(entry, parameterName)) {
Field declaredField = FieldUtils.getAllFieldsList(entry.getClass()).stream().filter(field -> field.getName().equals(parameterName)).findFirst().orElseThrow(() -> new AutotestError("This error should never appear"));
jsonString = replacePlaceholder(jsonString, declaredField, parameterName, parameterValue);
} else {
jsonString = replacePlaceholder(jsonString, null, parameterName, parameterValue);
}
}
return jsonString;
}
Aggregations