Search in sources :

Example 1 with Experimental

use of com.github.noraui.cucumber.annotation.Experimental 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 senderMail
 *            sender of mail box
 * @param subjectMail
 *            subject 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
 */
@Experimental(name = "validActivationEmail")
@RetryOnFailure(attempts = 3, delay = 60)
@Conditioned
@Et("Je valide le mail d'activation {string}(\\?)")
@And("I valid activation email {string}(\\?)")
public void validActivationEmail(String mailHost, String mailUser, String mailPassword, String senderMail, String subjectMail, String firstCssQuery, List<GherkinStepCondition> conditions) throws FailureException, TechnicalException {
    try {
        final Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imap");
        final Session session = Session.getDefaultInstance(props, null);
        final Store store = session.getStore("imaps");
        store.connect(mailHost, mailUser, mailPassword);
        final Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_ONLY);
        final SearchTerm filterA = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
        final SearchTerm filterB = new FromTerm(new InternetAddress(senderMail));
        final SearchTerm filterC = new SubjectTerm(subjectMail);
        final SearchTerm[] filters = { filterA, filterB, filterC };
        final SearchTerm searchTerm = new AndTerm(filters);
        final Message[] messages = inbox.search(searchTerm);
        for (final Message message : messages) {
            validateActivationLink(subjectMail, firstCssQuery, message);
        }
    } catch (final Exception e) {
        new Result.Failure<>("", Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER));
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Message(javax.mail.Message) Store(javax.mail.Store) Flags(javax.mail.Flags) Properties(java.util.Properties) Folder(javax.mail.Folder) SearchTerm(javax.mail.search.SearchTerm) SubjectTerm(javax.mail.search.SubjectTerm) MessagingException(javax.mail.MessagingException) HttpServiceException(com.github.noraui.exception.HttpServiceException) FailureException(com.github.noraui.exception.FailureException) IOException(java.io.IOException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result) AndTerm(javax.mail.search.AndTerm) FlagTerm(javax.mail.search.FlagTerm) FromTerm(javax.mail.search.FromTerm) Session(javax.mail.Session) Experimental(com.github.noraui.cucumber.annotation.Experimental) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) And(io.cucumber.java.en.And) RetryOnFailure(com.github.noraui.cucumber.annotation.RetryOnFailure) Et(io.cucumber.java.fr.Et)

Example 2 with Experimental

use of com.github.noraui.cucumber.annotation.Experimental in project NoraUi by NoraUi.

the class ExperimentalInterceptor method invoke.

/**
 * {@inheritDoc}
 */
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    // 
    Method m = invocation.getMethod();
    if (m.isAnnotationPresent(Experimental.class)) {
        Experimental experimentalAnnotation = m.getAnnotation(Experimental.class);
        log.warn("CAUTION: You use a experimental generic step named [{}].", experimentalAnnotation.name());
    }
    log.debug("NORAUI ExperimentalInterceptor invoke method {}", invocation.getMethod());
    return invocation.proceed();
}
Also used : Experimental(com.github.noraui.cucumber.annotation.Experimental) Method(java.lang.reflect.Method)

Aggregations

Experimental (com.github.noraui.cucumber.annotation.Experimental)2 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)1 RetryOnFailure (com.github.noraui.cucumber.annotation.RetryOnFailure)1 FailureException (com.github.noraui.exception.FailureException)1 HttpServiceException (com.github.noraui.exception.HttpServiceException)1 Result (com.github.noraui.exception.Result)1 TechnicalException (com.github.noraui.exception.TechnicalException)1 And (io.cucumber.java.en.And)1 Et (io.cucumber.java.fr.Et)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 Flags (javax.mail.Flags)1 Folder (javax.mail.Folder)1 Message (javax.mail.Message)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 Store (javax.mail.Store)1 InternetAddress (javax.mail.internet.InternetAddress)1 AndTerm (javax.mail.search.AndTerm)1