Search in sources :

Example 1 with FailureException

use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.

the class Step method uploadFile.

/**
 * Updates a html file input with the path of the file to upload.
 *
 * @param pageElement
 *            Is target element
 * @param fileOrKey
 *            Is the file path (text or text in context (after a save))
 * @param args
 *            list of arguments to format the found selector with
 * @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_UPLOADING_FILE} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void uploadFile(PageElement pageElement, String fileOrKey, Object... args) throws TechnicalException, FailureException {
    final String path = Context.getValue(fileOrKey) != null ? Context.getValue(fileOrKey) : System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER + File.separator + fileOrKey;
    if (!"".equals(path)) {
        try {
            final WebElement element = Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(pageElement, args)));
            element.clear();
            if (DriverFactory.IE.equals(Context.getBrowser())) {
                final String javascript = "arguments[0].value='" + path + "';";
                ((JavascriptExecutor) getDriver()).executeScript(javascript, element);
            } else {
                element.sendKeys(path);
            }
        } catch (final Exception e) {
            new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UPLOADING_FILE), path), true, pageElement.getPage().getCallBack());
        }
    } else {
        logger.debug("Empty data provided. No need to update file upload path. If you want clear data, you need use: \"I clear text in ...\"");
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) 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 2 with FailureException

use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.

the class Step method updateText.

/**
 * Update a html input text with a text.
 *
 * @param pageElement
 *            Is target element
 * @param textOrKey
 *            Is the new data (text or text in context (after a save))
 * @param keysToSend
 *            character to send to the element after {@link org.openqa.selenium.WebElement#sendKeys(CharSequence...) sendKeys} with textOrKey
 * @param args
 *            list of arguments to format the found selector with
 * @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_ERROR_ON_INPUT} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void updateText(PageElement pageElement, String textOrKey, CharSequence keysToSend, Object... args) throws TechnicalException, FailureException {
    final String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
    if (!"".equals(value)) {
        try {
            final WebElement element = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(pageElement, args)));
            element.clear();
            if (DriverFactory.IE.equals(Context.getBrowser())) {
                final String javascript = "arguments[0].value='" + value + "';";
                ((JavascriptExecutor) getDriver()).executeScript(javascript, element);
            } else {
                element.sendKeys(value);
            }
            if (keysToSend != null) {
                element.sendKeys(keysToSend);
            }
        } catch (final Exception e) {
            new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_ERROR_ON_INPUT), pageElement, pageElement.getPage().getApplication()), true, pageElement.getPage().getCallBack());
        }
    } else {
        logger.debug("Empty data provided. No need to update text. If you want clear data, you need use: \"I clear text in ...\"");
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) 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 3 with FailureException

use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.

the class Step method expectText.

/**
 * Expects that an element contains expected value.
 *
 * @param pageElement
 *            Is target element
 * @param textOrKey
 *            Is the expected data (text or text in context (after a save))
 * @throws FailureException
 *             if the scenario encounters a functional error
 * @throws TechnicalException
 */
protected void expectText(PageElement pageElement, String textOrKey) throws FailureException, TechnicalException {
    WebElement element = null;
    final String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
    try {
        element = 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());
    }
    try {
        Context.waitUntil(ExpectSteps.textToBeEqualsToExpectedValue(Utilities.getLocator(pageElement), value));
    } catch (final Exception e) {
        logger.error("error in expectText. element is [{}]", element == null ? null : element.getText());
        new Result.Failure<>(element == null ? null : element.getText(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_WRONG_EXPECTED_VALUE), pageElement, value, pageElement.getPage().getApplication()), 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)

Example 4 with FailureException

use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.

the class Step method checkTextSelectedInList.

/**
 * Check text selected in list (html select option).
 *
 * @param pageElement
 *            Is target element
 * @param text
 *            is text searched
 * @return true or false
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected boolean checkTextSelectedInList(PageElement pageElement, String text) throws FailureException {
    try {
        final WebElement select = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(pageElement)));
        final Select dropDown = new Select(select);
        return text.equalsIgnoreCase(dropDown.getFirstSelectedOption().getText());
    } catch (final Exception e) {
        new Result.Failure<>(text, Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, pageElement.getPage().getCallBack());
        return false;
    }
}
Also used : Select(org.openqa.selenium.support.ui.Select) 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 5 with FailureException

use of com.github.noraui.exception.FailureException in project NoraUi by NoraUi.

the class Step method clearText.

/**
 * Update a html input text with "".
 *
 * @param pageElement
 *            Is target element
 * @param keysToSend
 *            character to send to the element after {@link org.openqa.selenium.WebElement#sendKeys(CharSequence...) sendKeys} with textOrKey
 * @param args
 *            list of arguments to format the found selector with
 * @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_ERROR_CLEAR_ON_INPUT} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void clearText(PageElement pageElement, CharSequence keysToSend, Object... args) throws TechnicalException, FailureException {
    try {
        final WebElement element = Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(pageElement, args)));
        element.clear();
        if (keysToSend != null) {
            element.sendKeys(keysToSend);
        }
    } catch (final Exception e) {
        new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_ERROR_CLEAR_ON_INPUT), pageElement, pageElement.getPage().getApplication()), 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