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 ...\"");
}
}
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 ...\"");
}
}
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());
}
}
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;
}
}
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());
}
}
Aggregations