use of cucumber.api.java.fr.Quand 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());
}
}
}
Aggregations