use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.
the class Step method saveElementValue.
/**
* Save value in memory.
*
* @param field
* is name of the field to retrieve.
* @param targetKey
* is the key to save value to
* @param page
* is target page.
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT} message (with screenshot, with exception) or with
* {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_RETRIEVE_VALUE} message
* (with screenshot, with exception)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void saveElementValue(String field, String targetKey, Page page) throws TechnicalException, FailureException {
logger.debug("saveValueInStep: {} to {} in {}.", field, targetKey, page.getApplication());
String txt = "";
try {
final WebElement elem = Utilities.findElement(page, field);
txt = elem.getAttribute(VALUE) != null ? elem.getAttribute(VALUE) : elem.getText();
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, page.getCallBack());
}
try {
Context.saveValue(targetKey, txt);
Context.getCurrentScenario().write("SAVE " + targetKey + "=" + txt);
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_RETRIEVE_VALUE), page.getPageElementByKey(field), page.getApplication()), true, page.getCallBack());
}
}
use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.
the class Step method selectCheckbox.
/**
* Checks a checkbox type element (value corresponding to key "valueKey").
*
* @param element
* Target page element
* @param valueKeyOrKey
* is valueKey (valueKey or key in context (after a save)) to match in values map
* @param values
* Values map
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Failure with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT} message (with screenshot)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void selectCheckbox(PageElement element, String valueKeyOrKey, Map<String, Boolean> values) throws TechnicalException, FailureException {
final String valueKey = Context.getValue(valueKeyOrKey) != null ? Context.getValue(valueKeyOrKey) : valueKeyOrKey;
try {
final WebElement webElement = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(element)));
Boolean checkboxValue = values.get(valueKey);
if (checkboxValue == null) {
checkboxValue = values.get("Default");
}
if (webElement.isSelected() != checkboxValue.booleanValue()) {
webElement.click();
}
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT), element, element.getPage().getApplication()), true, element.getPage().getCallBack());
}
}
use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.
the class Step method checkInputText.
/**
* Checks if input text contains expected value.
*
* @param pageElement
* Is target element
* @param textOrKey
* Is the data to check (text or text in context (after a save))
* @return true or false
* @throws FailureException
* if the scenario encounters a functional error
*/
protected boolean checkInputText(PageElement pageElement, String textOrKey) throws FailureException {
WebElement inputText = null;
final String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
try {
inputText = Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(pageElement)));
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, pageElement.getPage().getCallBack());
}
return !(inputText == null || value == null || inputText.getAttribute(VALUE) == null || !value.equals(inputText.getAttribute(VALUE).trim()));
}
use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.
the class Step method updateRadioList.
/**
* Update html radio button by value (value corresponding to key "index").
*
* @param pageElement
* Is concerned element
* @param valueKeyOrKey
* key printedValues
* @param printedValues
* contain all possible value (order by key)
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_SELECT_RADIO_BUTTON} message (with screenshot, with exception)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void updateRadioList(PageElement pageElement, String valueKeyOrKey, Map<String, String> printedValues) throws TechnicalException, FailureException {
final String valueKey = Context.getValue(valueKeyOrKey) != null ? Context.getValue(valueKeyOrKey) : valueKeyOrKey;
try {
final List<WebElement> radioButtons = Context.waitUntil(ExpectedConditions.presenceOfAllElementsLocatedBy(Utilities.getLocator(pageElement)));
String radioToSelect = printedValues.get(valueKey);
if (radioToSelect == null) {
radioToSelect = printedValues.get("Default");
}
for (final WebElement button : radioButtons) {
if (button.getAttribute(VALUE).equals(radioToSelect)) {
button.click();
break;
}
}
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SELECT_RADIO_BUTTON), pageElement), true, pageElement.getPage().getCallBack());
}
}
Aggregations