Java Code Examples for com.codeborne.selenide.Selenide#sleep()

The following examples show how to use com.codeborne.selenide.Selenide#sleep() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelenideAddons.java    From neodymium-library with MIT License 6 votes vote down vote up
/**
 * Drag and drop an element to a given position. The position will be set by the user. It drags the element and
 * moves it to a specific position of the respective slider.
 * 
 * @param elementToMove
 *            The selector of the slider to drag and drop
 * @param elementToCheck
 *            The locator of the slider value
 * @param horizontalMovement
 *            The offset for the horizontal movement
 * @param verticalMovement
 *            The offset for the vertical movement
 * @param pauseBetweenMovements
 *            Time to pass after the slider do the next movement step
 * @param retryMovements
 *            Amount of retries the slider will be moved
 * @param condition
 *            The condition for the slider to verify the movement
 */

public static void dragAndDropUntilCondition(SelenideElement elementToMove, SelenideElement elementToCheck, int horizontalMovement, int verticalMovement,
                                             int pauseBetweenMovements, int retryMovements, Condition condition)
{
    Actions moveSlider = new Actions(Neodymium.getDriver());

    int counter = 0;
    while (!elementToCheck.has(condition))
    {
        if (counter > retryMovements)
        {
            SelenideAddons.wrapAssertionError(() -> {
                Assert.assertTrue("CircutBreaker: Was not able to move the element and to reach the condition. Tried: " + retryMovements
                                  + " times to move the element.", false);
            });
        }
        Action action = moveSlider.dragAndDropBy(elementToMove.getWrappedElement(), horizontalMovement, verticalMovement).build();
        action.perform();
        Selenide.sleep(pauseBetweenMovements);
        counter++;
    }
}
 
Example 2
Source File: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * Executes the given code at least once but potentially multiple times as long as a
 * {@link StaleElementReferenceException} occurs.
 * <p>
 * Attention: Since the SelenideElement class implements the InvocationHandler interface you have to make sure that
 * the element is retrieved in order to provoke a StaleElementReferenceException. You can do this by calling a
 * should function that uses a condition.
 * </p>
 * <p>
 * The following settings can be configured within the Neodymium configuration to tune the retry behavior:
 * </p>
 * <ul>
 * <li>neodymium.selenideAddons.staleElement.retry.count (default 3 retries)</li>
 * <li>neodymium.selenideAddons.staleElement.retry.timeout (default 500ms pause between retries)</li>
 * </ul>
 * <p>
 * <b>Example:</b>
 * </p>
 * 
 * <pre>
 * SelenideAddons.$safe(() -&gt; {
 *     return $("selector").should(exist);
 * });
 * </pre>
 *
 * @param code
 *            the code to run
 * @return the element of the execution or any exception that might bubble up
 */
public static SelenideElement $safe(final Supplier<SelenideElement> code)
{
    final int maxRetryCount = Neodymium.configuration().staleElementRetryCount();
    int retryCounter = 0;

    while (retryCounter <= maxRetryCount)
    {
        try
        {
            return code.get();
        }
        catch (final Throwable t)
        {
            if (isThrowableCausedBy(t, StaleElementReferenceException.class))
            {
                retryCounter++;
                if (retryCounter > maxRetryCount)
                {
                    // fail
                    throw t;
                }
                else
                {
                    AllureAddons.addToReport("StaleElementReferenceException catched times: \"" + retryCounter + "\".", retryCounter);
                    Selenide.sleep(Neodymium.configuration().staleElementRetryTimeout());
                }
            }
            else
            {
                // not the kind of error we are looking for
                throw t;
            }
        }
    }

    // never get here
    return null;
}
 
Example 3
Source File: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * Executes the given code at least once but potentially multiple times as long as a
 * {@link StaleElementReferenceException} occurs.
 * <p>
 * The following settings can be configured within the Neodymium configuration to tune the retry behavior:
 * </p>
 * <ul>
 * <li>neodymium.selenideAddons.staleElement.retry.count (default 3 retries)</li>
 * <li>neodymium.selenideAddons.staleElement.retry.timeout (default 500ms pause between retries)</li>
 * </ul>
 * <p>
 * <b>Example:</b>
 * </p>
 * 
 * <pre>
 * SelenideAddons.$safe(() -&gt; {
 *     $("selectorOne").find("selectorTwo").shouldBe(visible);
 * });
 * </pre>
 * 
 * @param code
 *            the code to run
 */
public static void $safe(final Runnable code)
{
    final int maxRetryCount = Neodymium.configuration().staleElementRetryCount();
    int retryCounter = 0;

    while (retryCounter <= maxRetryCount)
    {
        try
        {
            code.run();
            break;
        }
        catch (final Throwable t)
        {
            if (isThrowableCausedBy(t, StaleElementReferenceException.class))
            {
                retryCounter++;
                if (retryCounter > maxRetryCount)
                {
                    // fail
                    throw t;
                }
                else
                {
                    AllureAddons.addToReport("StaleElementReferenceException catched times: \"" + retryCounter + "\".", retryCounter);
                    Selenide.sleep(Neodymium.configuration().staleElementRetryTimeout());
                }
            }
            else
            {
                // not the kind of error we are looking for
                throw t;
            }
        }
    }
}
 
Example 4
Source File: DebugUtils.java    From neodymium-library with MIT License 5 votes vote down vote up
public static void highlightAllElements(By by, WebDriver driver)
{
    if (Neodymium.configuration().debuggingHighlightSelectedElements())
    {
        List<WebElement> foundElements = driver.findElements(by);
        highlightElements(foundElements, driver);
        if (Neodymium.configuration().debuggingHighlightDuration() > 0)
        {
            Selenide.sleep(Neodymium.configuration().debuggingHighlightDuration());
        }
        resetAllHighlight();
    }
}
 
Example 5
Source File: StandardFieldSubmitAT.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Test
public void testSubmit() {
    InputText inputText = fields.field("Имя").control(InputText.class);
    inputText.shouldExists();
    inputText.shouldHaveValue("Joe");

    Select select = fields.field("Пол").control(Select.class);
    select.shouldHaveValue("Мужской");

    DateInterval dateInterval = fields.field("Даты отпуска").control(DateInterval.class);
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем обычное текстовое поле
    inputText.val("Ann");
    // обновляем страницу и проверяем значения всех полей
    // ожидание отправки поля
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Мужской");
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем списковое поле
    select.select(1);
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем интервальное поле
    dateInterval.beginVal("18.01.2020");
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("18.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    dateInterval.endVal("24.01.2020");
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("18.01.2020");
    dateInterval.endShouldHaveValue("24.01.2020");
}
 
Example 6
Source File: FormSubmitAT.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Test
public void testSubmit() {
    builder.sources(new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit/index.page.xml"),
            new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit/test.query.xml"),
            new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit/test.object.xml"));

    SimplePage page = open(SimplePage.class);
    page.shouldExists();
    Fields fields = page.single().widget(FormWidget.class).fields();
    fields.shouldHaveSize(3);

    InputText inputText = fields.field("Имя").control(InputText.class);
    inputText.shouldExists();
    inputText.shouldHaveValue("Joe");

    Select select = fields.field("Пол").control(Select.class);
    select.shouldHaveValue("Мужской");

    DateInterval dateInterval = fields.field("Даты отпуска").control(DateInterval.class);
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем обычное текстовое поле
    inputText.val("Ann");
    // обновляем страницу и проверяем значения всех полей
    // ожидание отправки поля
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Мужской");
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем списковое поле
    select.select(1);
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("15.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    // изменяем интервальное поле
    dateInterval.beginVal("18.01.2020");
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("18.01.2020");
    dateInterval.endShouldHaveValue("30.01.2020");

    dateInterval.endVal("24.01.2020");
    Selenide.sleep(500);
    Selenide.refresh();
    inputText.shouldHaveValue("Ann");
    select.shouldHaveValue("Женский");
    dateInterval.beginShouldHaveValue("18.01.2020");
    dateInterval.endShouldHaveValue("24.01.2020");
}
 
Example 7
Source File: FormSubmitAT.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Test
public void testModalSubmit() {
    builder.sources(new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit_modal/index.page.xml"),
            new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit_modal/modal.page.xml"),
            new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit_modal/test.query.xml"),
            new CompileInfo("net/n2oapp/framework/autotest/widget/form/submit_modal/test.object.xml"));

    SimplePage page = open(SimplePage.class);
    page.shouldExists();
    TableWidget table = page.single().widget(TableWidget.class);
    table.shouldExists();
    table.columns().rows().shouldHaveSize(3);

    Cells row = table.columns().rows().row(1);
    row.cell(1).textShouldHave("test2");
    row.cell(2).textShouldHave("20");

    // открываем модальную страницу для второй записи
    row.click();
    StandardButton btn = table.toolbar().topLeft().button("Открыть");
    btn.click();
    Modal modal = N2oSelenide.modal();

    FormWidget modalForm = modal.content(SimplePage.class).single().widget(FormWidget.class);
    InputText name = modalForm.fields().field("Имя").control(InputText.class);
    InputText age = modalForm.fields().field("Возраст").control(InputText.class);
    name.shouldHaveValue("test2");
    age.shouldHaveValue("20");

    // меняем имя и ждем отправки значения
    name.val("test123");
    Selenide.sleep(500);
    modalForm.toolbar().bottomRight().button("Закрыть").click();

    row.cell(1).textShouldHave("test123");
    row.cell(2).textShouldHave("20");

    // открываем модальную страницу для второй записи
    row.click();
    btn.click();

    // меняем возраст и ждем отправки значения
    age.val("99");
    Selenide.sleep(500);
    modalForm.toolbar().bottomRight().button("Закрыть").click();

    row.cell(1).textShouldHave("test123");
    row.cell(2).textShouldHave("99");
}
 
Example 8
Source File: AkitaScenario.java    From akita with Apache License 2.0 4 votes vote down vote up
public static void sleep(int seconds) {
    Selenide.sleep(TimeUnit.MILLISECONDS.convert(seconds, TimeUnit.SECONDS));
}