use of com.github.noraui.cucumber.annotation.Conditioned 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);
}
use of com.github.noraui.cucumber.annotation.Conditioned in project NoraUi by NoraUi.
the class CommonSteps method clickOnAndSwitchWindow.
/**
* Click on html element and switch window when the scenario contain more one windows (one more application for example), if all 'expected' parameters equals 'actual' parameters in conditions.
*
* @param page
* The concerned page of toClick
* @param toClick
* html element
* @param windowKey
* the key of window (popup, ...) Example: 'demo.Popup1DemoPage'.
* @param conditions
* list of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
* @throws FailureException
* if the scenario encounters a functional error
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
*/
@Conditioned
@Quand("Je clique sur '(.*)-(.*)' et passe sur '(.*)' de type fenêtre[\\.|\\?]")
@When("I click on '(.*)-(.*)' and switch to '(.*)' window[\\.|\\?]")
public void clickOnAndSwitchWindow(String page, String toClick, String windowKey, List<GherkinStepCondition> conditions) throws FailureException, TechnicalException {
final String wKey = Page.getInstance(page).getApplication() + Page.getInstance(windowKey).getPageKey();
final String handleToSwitch = Context.getWindows().get(wKey);
if (handleToSwitch != null) {
Context.getDriver().switchTo().window(handleToSwitch);
// As a workaround: NoraUi specify window size manually, e.g. window_size: 1920 x 1080 (instead of .window().maximize()).
Context.getDriver().manage().window().setSize(new Dimension(1920, 1080));
Context.setMainWindow(windowKey);
} else {
try {
final Set<String> initialWindows = getDriver().getWindowHandles();
clickOn(Page.getInstance(page).getPageElementByKey('-' + toClick));
final String newWindowHandle = Context.waitUntil(WindowManager.newWindowOpens(initialWindows));
Context.addWindow(wKey, newWindowHandle);
getDriver().switchTo().window(newWindowHandle);
// As a workaround: NoraUi specify window size manually, e.g. window_size: 1920 x 1080 (instead of .window().maximize()).
Context.getDriver().manage().window().setSize(new Dimension(1920, 1080));
Context.setMainWindow(newWindowHandle);
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SWITCH_WINDOW), windowKey), true, Page.getInstance(page).getCallBack());
}
if (!Page.getInstance(windowKey).checkPage()) {
new Result.Failure<>(windowKey, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SWITCH_WINDOW), windowKey), true, Page.getInstance(page).getCallBack());
}
}
}
use of com.github.noraui.cucumber.annotation.Conditioned 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);
}
use of com.github.noraui.cucumber.annotation.Conditioned 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));
}
use of com.github.noraui.cucumber.annotation.Conditioned 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));
}
}
Aggregations