Search in sources :

Example 11 with FailureException

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());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Example 12 with FailureException

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());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Example 13 with FailureException

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()));
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Example 14 with FailureException

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());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Aggregations

FailureException (com.github.noraui.exception.FailureException)14 Result (com.github.noraui.exception.Result)13 TechnicalException (com.github.noraui.exception.TechnicalException)13 WebElement (org.openqa.selenium.WebElement)11 ParseException (java.text.ParseException)10 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)2 RetryOnFailure (com.github.noraui.cucumber.annotation.RetryOnFailure)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 And (cucumber.api.java.en.And)1 Then (cucumber.api.java.en.Then)1 When (cucumber.api.java.en.When)1 Alors (cucumber.api.java.fr.Alors)1 Et (cucumber.api.java.fr.Et)1 Quand (cucumber.api.java.fr.Quand)1 StepDefAnnotation (cucumber.runtime.java.StepDefAnnotation)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1