Search in sources :

Example 1 with Quand

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());
        }
    }
}
Also used : Dimension(org.openqa.selenium.Dimension) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result) When(cucumber.api.java.en.When) Conditioned(com.github.noraui.cucumber.annotation.Conditioned) Quand(cucumber.api.java.fr.Quand)

Aggregations

Conditioned (com.github.noraui.cucumber.annotation.Conditioned)1 FailureException (com.github.noraui.exception.FailureException)1 Result (com.github.noraui.exception.Result)1 TechnicalException (com.github.noraui.exception.TechnicalException)1 When (cucumber.api.java.en.When)1 Quand (cucumber.api.java.fr.Quand)1 Dimension (org.openqa.selenium.Dimension)1