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