Search in sources :

Example 1 with Lorsque

use of cucumber.api.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 TechnicalException
 * @throws FailureException
 */
@Conditioned
@Lorsque("J'attends que le fichier nommé '(.*)' soit téléchargé avec un timeout de '(.*)' secondes[\\.|\\?]")
@Then("I wait file named '(.*)' to be downloaded with timeout of '(.*)' seconds[\\.|\\?]")
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()));
    logger.debug("File downloaded in {} seconds.", nbTry);
}
Also used : File(java.io.File) Lorsque(cucumber.api.java.fr.Lorsque) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Then(cucumber.api.java.en.Then)

Example 2 with Lorsque

use of cucumber.api.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 '(.*)' vérifie '(.*)', je fais jusqu'à '(.*)' respecte '(.*)' avec '(.*)' essais maxi:")
@Then("If '(.*)' matches '(.*)', I do until '(.*)' respects '(.*)' with '(.*)' 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;
            do {
                i++;
                runAllStepsInLoop(conditions);
            } while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i <= tries);
        }
    } catch (final TechnicalException e) {
        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(cucumber.api.java.fr.Lorsque) Then(cucumber.api.java.en.Then)

Example 3 with Lorsque

use of cucumber.api.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 '(.*)' vérifie '(.*)', Tant que '(.*)' respecte '(.*)' je fais avec '(.*)' essais maxi:")
@Then("If '(.*)' matches '(.*)', While '(.*)' respects '(.*)' I do with '(.*)' 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;
            while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i <= tries) {
                i++;
                runAllStepsInLoop(conditions);
            }
        }
    } catch (final TechnicalException e) {
        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(cucumber.api.java.fr.Lorsque) Then(cucumber.api.java.en.Then)

Example 4 with Lorsque

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

the class CommonSteps method waitInvisibilityOf.

/**
 * Waits invisibility of element with timeout of x seconds.
 *
 * @param page
 *            The concerned page of field
 * @param element
 *            is key of PageElement concerned
 * @param time
 *            is custom timeout
 * @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.
 */
@Conditioned
@Lorsque("J'attends l'invisibilité de '(.*)-(.*)' avec un timeout de '(.*)' secondes[\\.|\\?]")
@Then("I wait invisibility of '(.*)-(.*)' with timeout of '(.*)' seconds[\\.|\\?]")
public void waitInvisibilityOf(String page, String element, int time, List<GherkinStepCondition> conditions) throws TechnicalException {
    final WebElement we = Utilities.findElement(Page.getInstance(page).getPageElementByKey('-' + element));
    Context.waitUntil(ExpectedConditions.invisibilityOf(we), time);
}
Also used : WebElement(org.openqa.selenium.WebElement) Lorsque(cucumber.api.java.fr.Lorsque) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Then(cucumber.api.java.en.Then)

Example 5 with Lorsque

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

the class FileSteps method cleanDownloadDirectory.

/**
 * Empties the default downloaded files folder
 *
 * @param conditions
 *            List of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
 * @throws IOException
 */
@Conditioned
@Lorsque("Je vide le repertoire des téléchargements[\\.|\\?]")
@Given("I clean download directory[\\.|\\?]")
public void cleanDownloadDirectory(List<GherkinStepCondition> conditions) throws IOException {
    FileUtils.forceMkdir(new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER));
    FileUtils.cleanDirectory(new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER));
}
Also used : File(java.io.File) Lorsque(cucumber.api.java.fr.Lorsque) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Given(cucumber.api.java.en.Given)

Aggregations

Lorsque (cucumber.api.java.fr.Lorsque)7 Then (cucumber.api.java.en.Then)5 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)4 AssertError (com.github.noraui.exception.AssertError)2 TechnicalException (com.github.noraui.exception.TechnicalException)2 GherkinStepCondition (com.github.noraui.gherkin.GherkinStepCondition)2 Given (cucumber.api.java.en.Given)2 File (java.io.File)2 WebElement (org.openqa.selenium.WebElement)2 Logos (com.github.noraui.application.model.logogame.Logos)1