com.codeborne.selenide.Selenide Java Examples

The following examples show how to use com.codeborne.selenide.Selenide. 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: UseSoftAssertions.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test(expected = ElementNotFound.class)
public void validateSoftAssertion()
{
    Neodymium.softAssertions(true);
    Selenide.open("https://blog.xceptance.com/");

    Assert.assertEquals(Configuration.assertionMode, AssertionMode.SOFT);
    $("#notFound1").should(exist);
    $("#notFound2").should(exist);
    $("#masthead .search-toggle").click();
    $("#notFound3").should(exist);
    $("#notFound4").click();

    // This should not be called since
    throw new NullPointerException();
}
 
Example #2
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 #3
Source File: DebugUtilsTest.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test
public void testIFrames() throws Exception
{
    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight", "true");
    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight.duration", "750");

    Selenide.open("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select");
    Neodymium.getDriver().switchTo().frame("iframeResult");

    SelenideElement body = $("body");
    body.click();
    assertJsSuccessfullyInjected();

    final List<WebElement> list = $("body").findElements(By.cssSelector("select"));

    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight", "false");
    DebugUtils.highlightElements(list, Neodymium.getDriver());
    $(".neodymium-highlight-box").shouldBe(visible);

    DebugUtils.resetAllHighlight();
    $(".neodymium-highlight-box").shouldNot(exist);
}
 
Example #4
Source File: ValidateKeepWebDriverOpenOnFailure.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test
public void test2()
{
    Assert.assertNotEquals(webDriver1, webDriver2);
    Assert.assertEquals(webDriver2, Neodymium.getDriver());
    NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1);
    NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2);

    Assert.assertNotEquals(proxy1, proxy2);
    Assert.assertEquals(proxy2, Neodymium.getLocalProxy());
    NeodymiumWebDriverTest.assertProxyStopped(proxy1);
    NeodymiumWebDriverTest.assertProxyAlive(proxy2);

    // Let condition fail so that the WebDriver/browser is kept open
    Selenide.$("#cantFindMe").should(Condition.exist);
}
 
Example #5
Source File: DebugUtilsTest.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test
public void testHighlightingWithoutImplicitWaitTime()
{
    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight.duration", "500");

    Selenide.open("https://blog.xceptance.com/");
    DebugUtils.injectJavaScript();
    assertJsSuccessfullyInjected();

    final List<WebElement> list = $("body").findElements(By.cssSelector("#masthead"));
    DebugUtils.highlightElements(list, Neodymium.getDriver());
    $(".neodymium-highlight-box").shouldBe(visible);

    DebugUtils.resetAllHighlight();
    $(".neodymium-highlight-box").shouldNot(exist);
}
 
Example #6
Source File: DebugUtilsTest.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test
public void testHighlighting()
{
    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight.duration", "500");

    Selenide.open("https://blog.xceptance.com/");
    DebugUtils.injectJavaScript();
    assertJsSuccessfullyInjected();

    final List<WebElement> list = $("body").findElements(By.cssSelector("#masthead"));
    DebugUtils.highlightElements(list, Neodymium.getDriver());
    $(".neodymium-highlight-box").shouldBe(visible);

    DebugUtils.resetAllHighlight();
    $(".neodymium-highlight-box").shouldNot(exist);

    final List<WebElement> list2 = $("body").findElements(By.cssSelector("#content article"));
    DebugUtils.highlightElements(list2, Neodymium.getDriver());
    $$(".neodymium-highlight-box").shouldHaveSize(10);

    DebugUtils.resetAllHighlight();
    $(".neodymium-highlight-box").shouldNot(exist);
}
 
Example #7
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 6 votes vote down vote up
@Test
public void testWrapAssertionErrorWithoutMessage()
{
    final String errMessage = "AssertionError: No error message provided by the Assertion.";
    try
    {
        Selenide.open("https://blog.xceptance.com/");
        SelenideAddons.wrapAssertionError(() -> {
            Assert.assertTrue(Selenide.title().startsWith("MyPageTitle"));
        });
    }
    catch (UIAssertionError e)
    {
        Assert.assertTrue(e.getMessage().startsWith(errMessage));
    }
}
 
Example #8
Source File: Pages.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Получение страницы по классу с возможностью выполнить проверку элементов страницы
 */
public static <T extends AkitaPage> T getPage(Class<T> clazz, boolean checkIfElementsAppeared) {
    T page = Selenide.page(clazz);
    if (checkIfElementsAppeared) {
        page.initialize().isAppeared();
    }
    return page;
}
 
Example #9
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testUpVerticalDragAndDropUntilCondition()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $("#equalizer .k-slider-vertical:first-child a");
    SelenideAddons.dragAndDropUntilCondition(slider, slider, 0, -10, 3000, 23, Condition.attribute("aria-valuenow", "16"));

    Assert.assertEquals($("#equalizer .k-slider-vertical:first-child a").getAttribute("aria-valuenow"), "16");
}
 
Example #10
Source File: Pages.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Получение страницы по классу
 */
@SuppressWarnings("unchecked")
public <T extends AkitaPage> T get(Class<T> clazz, String name) {
    AkitaPage page = Selenide.page(getPageFromPagesByName(name)).initialize();

    if (!clazz.isInstance(page)) {
        throw new IllegalStateException(name + " page is not a instance of " + clazz + ". Named page is a " + page);
    }
    return (T) page;
}
 
Example #11
Source File: RoundUpSteps.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Выполняется запуск js-скрипта с указанием в js.executeScript его логики
 * Скрипт можно передать как аргумент метода или значение из application.properties
 */
@Когда("^выполнен js-скрипт \"([^\"]*)\"")
@When("^executed js-script \"([^\"]*)\"$")
public void executeJsScript(String scriptName) {
    String content = loadValueFromFileOrPropertyOrVariableOrDefault(scriptName);
    Selenide.executeJavaScript(content);
}
 
Example #12
Source File: SelenideAppiumFieldDecorator.java    From selenide-appium with MIT License 5 votes vote down vote up
private Object decorateWithAppium(ClassLoader loader, Field field) {
  Object appiumElement = super.decorate(loader, field);
  if (appiumElement instanceof MobileElement) {
    return Selenide.$((MobileElement) appiumElement);
  }
  return appiumElement;
}
 
Example #13
Source File: DebugUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaiting()
{
    NeodymiumWebDriverTestListener eventListener = new NeodymiumWebDriverTestListener();
    ((EventFiringWebDriver) Neodymium.getDriver()).register(eventListener);

    Neodymium.configuration().setProperty("neodymium.debugUtils.highlight", "true");

    // one wait due to navigation
    Selenide.open("https://blog.xceptance.com/");
    Assert.assertEquals(0, eventListener.implicitWaitCount);

    // one wait due to find
    $("body #masthead").should(exist);
    Assert.assertEquals(1, eventListener.implicitWaitCount);
    assertJsSuccessfullyInjected();

    // two waits due to chain finding
    $("body").findElements(By.cssSelector("#content article"));
    Assert.assertEquals(3, eventListener.implicitWaitCount);

    // two waits due to find and click
    $("#text-3 h1").click();
    Assert.assertEquals(4, eventListener.implicitWaitCount);

    // additional two waits due to find and click
    $("#masthead .search-toggle").click();
    Assert.assertEquals(5, eventListener.implicitWaitCount);

    // three waits due to find and change value (consumes 2 waits)
    $("#search-container .search-form input.search-field").val("abc");
    Assert.assertEquals(6, eventListener.implicitWaitCount);

    // two waits due to find and press enter
    $("#search-container .search-form input.search-field").pressEnter();
    Assert.assertEquals(7, eventListener.implicitWaitCount);
}
 
Example #14
Source File: JavaScriptUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaitingAnimationSelectorExistsOnPage()
{
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.animationSelector", "#main-content");
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000");

    Selenide.open("https://blog.xceptance.com/");
    final long start = System.currentTimeMillis();
    JavaScriptUtils.waitForReady();
    final long end = System.currentTimeMillis();

    assertTrue("The waiting animation selector is available on the site, timeout should be reached.",
               end - start > Neodymium.configuration().javaScriptTimeout());
}
 
Example #15
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void testDragAndDropAssertionError()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $(".balSlider a[role=slider]");
    SelenideAddons.dragAndDropUntilCondition(slider, slider, -10, 0, 3000, -1, Condition.attribute("aria-valuenow", "-16"));
}
 
Example #16
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test(expected = ElementShould.class)
public void testMatchAttributeConditionErrorMissingAttribute()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();

    $("#search-container .search-field").should(SelenideAddons.matchAttribute("foo", "bar"));
}
 
Example #17
Source File: JavaScriptUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaitingAnimationSelectorUnconfigured()
{
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000");
    Selenide.open("https://blog.xceptance.com/");
    final long start = System.currentTimeMillis();
    JavaScriptUtils.waitForReady();
    final long end = System.currentTimeMillis();

    assertTrue("The waiting animation selector is not set, timeout shouldn't be reached.", end - start < Neodymium.configuration().javaScriptTimeout());
}
 
Example #18
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testDownVerticalDragAndDropUntilCondition()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $("#equalizer .k-slider-vertical:first-child a");
    SelenideAddons.dragAndDropUntilCondition(slider, slider, 0, 10, 3000, 23, Condition.attribute("aria-valuenow", "-6"));

    Assert.assertEquals($("#equalizer .k-slider-vertical:first-child a").getAttribute("aria-valuenow"), "-6");
}
 
Example #19
Source File: JavaScriptUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaitingAnimationSelectorUnavailableOnPage()
{
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.animationSelector", ".cantFindThisClass");
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000");

    Selenide.open("https://blog.xceptance.com/");
    final long start = System.currentTimeMillis();
    JavaScriptUtils.waitForReady();
    final long end = System.currentTimeMillis();

    assertTrue("The waiting animation selector is unavailable on the site, timeout shouldn't be reached.",
               end - start < Neodymium.configuration().javaScriptTimeout());
}
 
Example #20
Source File: Apicurio.java    From apicurio-studio with Apache License 2.0 5 votes vote down vote up
public void register() {
    open(baseUrl + "/studio");
    Selenide.screenshot("screen-apicurio-0001");

    $(byText("Register")).click();

    $("#firstName").setValue("test");
    $("#lastName").setValue("test");
    $("#email").setValue("[email protected]");
    $("#password").setValue("test");
    $("#password-confirm").setValue("test").pressEnter();
}
 
Example #21
Source File: JavaScriptUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaitingJQueryIsNotRequired()
{
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.jQueryIsRequired", "false");
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000");

    Selenide.open("https://www.google.com/");
    final long start = System.currentTimeMillis();
    JavaScriptUtils.waitForReady();
    final long end = System.currentTimeMillis();

    assertTrue("jQuery is  not required, so the timeout shouldn't be reached.",
               end - start < Neodymium.configuration().javaScriptTimeout());
}
 
Example #22
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testLeftHorizontalDragAndDropUntilText()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $(".balSlider a[role=slider]");
    leftHorizontalDragAndDropUntilText(slider, slider, -40, "aria-valuenow", "-8");

    Assert.assertEquals($(".balSlider a[role=slider]").getAttribute("aria-valuenow"), "-8");
}
 
Example #23
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testLeftHorizontalDragAndDropUntilCondition()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $(".balSlider a[role=slider]");
    SelenideAddons.dragAndDropUntilCondition(slider, slider, -40, 0, 3000, 23, Condition.attribute("aria-valuenow", "-8"));

    Assert.assertEquals($(".balSlider a[role=slider]").getAttribute("aria-valuenow"), "-8");
}
 
Example #24
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testRightHorizontalDragAndDropUntilCondition()
{
    Selenide.open("https://demos.telerik.com/kendo-ui/slider/index");

    SelenideElement slider = $(".balSlider a[role=slider]");
    SelenideAddons.dragAndDropUntilCondition(slider, slider, 40, 0, 3000, 23, Condition.attribute("aria-valuenow", "8"));

    Assert.assertEquals($(".balSlider a[role=slider]").getAttribute("aria-valuenow"), "8");
}
 
Example #25
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test(expected = UIAssertionError.class)
public void testWrapAssertionError()
{
    Selenide.open("https://blog.xceptance.com/");
    SelenideAddons.wrapAssertionError(() -> {
        Assert.assertEquals("MyPageTitle", Selenide.title());
    });
}
 
Example #26
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test()
public void testWrapAssertion()
{
    Selenide.open("https://blog.xceptance.com/");
    SelenideAddons.wrapAssertionError(() -> {
        Assert.assertEquals("Passionate Testing | Xceptance Blog", Selenide.title());
    });
}
 
Example #27
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test(expected = ElementShould.class)
public void testMatchValueConditionError()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();
    $("#search-container .search-field").val("searchphrase").submit();

    $("#content .search-field").should(SelenideAddons.matchValue("\\d+"));
}
 
Example #28
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testMatchValueCondition()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();
    $("#search-container .search-field").val("searchphrase").submit();

    $("#content .search-field").should(SelenideAddons.matchValue("^s.a.c.p.r.s.$"));
    $("#content .search-field").should(SelenideAddons.matchValue("\\D+"));
}
 
Example #29
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testMatchesValueCondition()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();
    $("#search-container .search-field").val("searchphrase").submit();

    $("#content .search-field").should(SelenideAddons.matchesValue("earchphras"));
}
 
Example #30
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test(expected = ElementShould.class)
public void testMatchAttributeConditionError()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();

    $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "\\d+"));
}