Search in sources :

Example 1 with Lorsque

use of io.cucumber.java.fr.Lorsque in project NoraUi by NoraUi.

the class CommonSteps method doUntil.

/**
 * Does steps execution until a given condition is unverified.
 *
 * @param actual
 *            actual value for global condition.
 * @param expected
 *            expected value for global condition.
 * @param key
 *            key of 'expected' values ('actual' values)
 * @param breakCondition
 *            'expected' values
 * @param tries
 *            number of max tries (no infinity loop).
 * @param conditions
 *            list of steps run in a loop.
 */
@Lorsque("Si {string} vérifie {string}, je fais jusqu'à {string} respecte {string} avec {int} essais maxi:")
@Then("If {string} matches {string}, I do until {string} respects {string} with {int} max tries:")
public void doUntil(String actual, String expected, String key, String breakCondition, int tries, List<GherkinConditionedLoopedStep> conditions) {
    try {
        if (new GherkinStepCondition("doUntilKey", expected, actual).checkCondition()) {
            int i = 0;
            Context.setCurrentSubStepIndex(1);
            do {
                i++;
                runAllStepsInLoop(conditions);
            } while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i < tries);
            Context.setCurrentSubStepIndex(0);
        }
    } catch (final TechnicalException e) {
        Context.setCurrentSubStepIndex(0);
        throw new AssertError(Messages.getMessage(TechnicalException.TECHNICAL_SUBSTEP_ERROR_MESSAGE) + e.getMessage());
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) GherkinStepCondition(com.github.noraui.gherkin.GherkinStepCondition) AssertError(com.github.noraui.exception.AssertError) Lorsque(io.cucumber.java.fr.Lorsque) Then(io.cucumber.java.en.Then)

Example 2 with Lorsque

use of io.cucumber.java.fr.Lorsque in project NoraUi by NoraUi.

the class CommonSteps method loop.

/**
 * Loops on steps execution for a specific number of times.
 *
 * @param actual
 *            actual value for global condition.
 * @param expected
 *            expected value for global condition.
 * @param times
 *            Number of loops.
 * @param steps
 *            List of steps run in a loop.
 */
@Lorsque("Si {string} vérifie {string}, je fais {int} fois:")
@Then("If {string} matches {string}, I do {int} times:")
public void loop(String actual, String expected, int times, List<GherkinConditionedLoopedStep> steps) {
    try {
        if (new GherkinStepCondition("loopKey", expected, actual).checkCondition()) {
            Context.setCurrentSubStepIndex(1);
            for (int i = 0; i < times; i++) {
                runAllStepsInLoop(steps);
            }
            Context.setCurrentSubStepIndex(0);
        }
    } catch (final TechnicalException e) {
        Context.setCurrentSubStepIndex(0);
        throw new AssertError(Messages.getMessage(TechnicalException.TECHNICAL_SUBSTEP_ERROR_MESSAGE) + e.getMessage());
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) GherkinStepCondition(com.github.noraui.gherkin.GherkinStepCondition) AssertError(com.github.noraui.exception.AssertError) Lorsque(io.cucumber.java.fr.Lorsque) Then(io.cucumber.java.en.Then)

Example 3 with Lorsque

use of io.cucumber.java.fr.Lorsque in project NoraUi by NoraUi.

the class CommonSteps method whileDo.

/**
 * While a given condition is verified, does steps execution.
 *
 * @param actual
 *            actual value for global condition.
 * @param expected
 *            expected value for global condition.
 * @param key
 *            key of 'expected' values ('actual' values)
 * @param breakCondition
 *            'expected' values
 * @param tries
 *            number of max tries (no infinity loop).
 * @param conditions
 *            list of steps run in a loop.
 */
@Lorsque("Si {string} vérifie {string}, Tant que {string} respecte {string} je fais avec {int} essais maxi:")
@Then("If {string} matches {string}, While {string} respects {string} I do with {int} max tries:")
public void whileDo(String actual, String expected, String key, String breakCondition, int tries, List<GherkinConditionedLoopedStep> conditions) {
    try {
        if (new GherkinStepCondition("whileDoKey", expected, actual).checkCondition()) {
            int i = 0;
            Context.setCurrentSubStepIndex(1);
            while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i < tries) {
                i++;
                runAllStepsInLoop(conditions);
            }
            Context.setCurrentSubStepIndex(0);
        }
    } catch (final TechnicalException e) {
        Context.setCurrentSubStepIndex(0);
        throw new AssertError(Messages.getMessage(TechnicalException.TECHNICAL_SUBSTEP_ERROR_MESSAGE) + e.getMessage());
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) GherkinStepCondition(com.github.noraui.gherkin.GherkinStepCondition) AssertError(com.github.noraui.exception.AssertError) Lorsque(io.cucumber.java.fr.Lorsque) Then(io.cucumber.java.en.Then)

Example 4 with Lorsque

use of io.cucumber.java.fr.Lorsque in project NoraUi by NoraUi.

the class FileSteps method waitDownloadFile.

/**
 * Waits the full download of a file with a maximum timeout in seconds.
 *
 * @param file
 *            The name of the file to download
 * @param timeout
 *            The maximum timeout
 * @param conditions
 *            List of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
 * @throws InterruptedException
 *             Exception for the sleep
 * @throws FailureException
 *             if the scenario encounters a functional error
 * @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_DOWNLOADED_FILE_NOT_FOUND} message (with screenshot, no exception)
 */
@Conditioned
@Lorsque("J'attends que le fichier nommé {string} soit téléchargé avec un timeout de {int} seconde(s)(\\?)")
@Then("I wait file named {string} to be downloaded with timeout of {int} second(s)(\\?)")
public void waitDownloadFile(String file, int timeout, List<GherkinStepCondition> conditions) throws InterruptedException, FailureException, TechnicalException {
    File f;
    int nbTry = 0;
    do {
        if (nbTry >= timeout) {
            new Result.Failure<>(file, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_DOWNLOADED_FILE_NOT_FOUND), file), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER));
        }
        Thread.sleep(1000);
        f = new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER + File.separator + file);
        nbTry++;
    } while (!(f.exists() && !f.isDirectory()));
    log.debug("File downloaded in {} seconds.", nbTry);
}
Also used : File(java.io.File) Lorsque(io.cucumber.java.fr.Lorsque) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Then(io.cucumber.java.en.Then)

Example 5 with Lorsque

use of io.cucumber.java.fr.Lorsque in project NoraUi by NoraUi.

the class WaitSteps method waitTextMatches.

@Conditioned
@Lorsque("Le texte de {page-element} {should-shouldnot} respecter {string}(\\?)")
@Then("The text of {page-element} {should-shouldnot} respect {string}(\\?)")
public void waitTextMatches(PageElement pageElement, final Boolean not, String regexp, List<GherkinStepCondition> conditions) throws FailureException {
    try {
        Pattern pattern = Pattern.compile(regexp);
        Wait.until(ExpectedConditions.textMatches(Utilities.getLocator(pageElement), pattern), not);
    } catch (final Exception e) {
        new Result.Failure<>(e.getMessage(), Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, pageElement.getPage().getCallBack());
    }
}
Also used : Pattern(java.util.regex.Pattern) TechnicalException(com.github.noraui.exception.TechnicalException) FailureException(com.github.noraui.exception.FailureException) Result(com.github.noraui.exception.Result) Lorsque(io.cucumber.java.fr.Lorsque) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Then(io.cucumber.java.en.Then)

Aggregations

Lorsque (io.cucumber.java.fr.Lorsque)7 Then (io.cucumber.java.en.Then)5 TechnicalException (com.github.noraui.exception.TechnicalException)4 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)3 AssertError (com.github.noraui.exception.AssertError)3 GherkinStepCondition (com.github.noraui.gherkin.GherkinStepCondition)3 Given (io.cucumber.java.en.Given)2 File (java.io.File)2 FailureException (com.github.noraui.exception.FailureException)1 Result (com.github.noraui.exception.Result)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 By (org.openqa.selenium.By)1