use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class ScenarioInitiator method injectWithModel.
private static void injectWithModel(String scenarioName, Class<Model> model) throws TechnicalException {
try {
final String[] headers = Context.getDataInputProvider().readLine(0, false);
if (headers != null) {
final List<String[]> examples = new ArrayList<>();
final Constructor<Model> modelConstructor = DataUtils.getModelConstructor(model, headers);
final Map<String, ModelList> fusionedData = DataUtils.fusionProcessor(model, modelConstructor);
for (final Entry<String, ModelList> e : fusionedData.entrySet()) {
examples.add(new String[] { e.getKey(), e.getValue().serialize() });
}
GherkinFactory.injectDataInGherkinExamples(scenarioName, examples);
} else {
logger.error(Messages.getMessage(SCENARIO_INITIATOR_ERROR_EMPTY_FILE));
}
} catch (final Exception te) {
throw new TechnicalException(Messages.getMessage(SCENARIO_INITIATOR_ERROR_ON_INJECTING_MODEL) + te.getMessage(), te);
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DBDataProvider method readValue.
/**
* {@inheritDoc}
*
* @throws TechnicalException
* is thrown if you have a technical error (IOException on .sql file) in NoraUi.
*/
@Override
public String readValue(String column, int line) throws TechnicalException {
logger.debug("readValue: column:[{}] and line:[{}] ", column, line);
String sqlRequest;
try {
final Path file = Paths.get(dataInPath + scenarioName + ".sql");
sqlRequest = new String(Files.readAllBytes(file), Charset.forName(Constants.DEFAULT_ENDODING));
sqlSanitized4readOnly(sqlRequest);
} catch (final IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
}
try (Connection connection = getConnection();
PreparedStatement statement = connection.prepareStatement(sqlRequest);
ResultSet rs = statement.executeQuery()) {
if (line < 1) {
return column;
}
while (rs.next() && rs.getRow() < line) {
}
logger.info("column: {}", column);
return rs.getString(column);
} catch (final SQLException e) {
logger.error("error DBDataProvider.readValue({}, {})", column, line, e);
return "";
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class MailSteps method validActivationEmail.
/**
* Valid activation email.
*
* @param mailHost
* example: imap.gmail.com
* @param mailUser
* login of mail box
* @param mailPassword
* password of mail box
* @param firstCssQuery
* the first matching element
* @param conditions
* list of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
* @throws TechnicalException
* is throws if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Exception with message and with screenshot and with exception if functional error but no screenshot and no exception if technical error.
* @throws FailureException
* if the scenario encounters a functional error
*/
@RetryOnFailure(attempts = 3, delay = 60)
@Conditioned
@Et("Je valide le mail d'activation '(.*)'[\\.|\\?]")
@And("I valid activation email '(.*)'[\\.|\\?]")
public void validActivationEmail(String mailHost, String mailUser, String mailPassword, String senderMail, String subjectMail, String firstCssQuery, List<GherkinStepCondition> conditions) throws FailureException, TechnicalException {
RestTemplate restTemplate = createRestTemplate();
try {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imap");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect(mailHost, mailUser, mailPassword);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
SearchTerm filterA = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
SearchTerm filterB = new FromTerm(new InternetAddress(senderMail));
SearchTerm filterC = new SubjectTerm(subjectMail);
SearchTerm[] filters = { filterA, filterB, filterC };
SearchTerm searchTerm = new AndTerm(filters);
Message[] messages = inbox.search(searchTerm);
for (Message message : messages) {
Document doc = Jsoup.parse(getTextFromMessage(message));
Element link = doc.selectFirst(firstCssQuery);
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(link.attr("href"), HttpMethod.GET, entity, String.class);
if (!response.getStatusCode().equals(HttpStatus.OK)) {
new Result.Failure<>("", Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER));
}
}
} catch (Exception e) {
new Result.Failure<>("", Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER));
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class Step method checkText.
/**
* Checks if HTML text contains expected value.
*
* @param pageElement
* Is target element
* @param textOrKey
* Is the new data (text or text in context (after a save))
* @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_WRONG_EXPECTED_VALUE} message (with screenshot, with exception) or with
* {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT} message
* (with screenshot, with exception)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void checkText(PageElement pageElement, String textOrKey) throws TechnicalException, FailureException {
WebElement webElement = null;
final String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
try {
webElement = 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());
}
final String innerText = webElement == null ? null : webElement.getText();
logger.info("checkText() expected [{}] and found [{}].", value, innerText);
if (!value.equals(innerText)) {
new Result.Failure<>(innerText, 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.TechnicalException 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());
}
}
Aggregations