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

The following examples show how to use com.codeborne.selenide.Selenide#open() . 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: 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 2
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 3
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 4
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 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: 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 7
Source File: JavaScriptUtilsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testWaitingJQueryIsRequired()
{
    Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.jQueryIsRequired", "true");
    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 unavailable on the site, timeout should be reached.",
               end - start > Neodymium.configuration().javaScriptTimeout());
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testMatchAttributeCondition()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();

    $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "^S.a.c.\\s…"));
    $("#search-container .search-field").should(SelenideAddons.matchAttribute("placeholder", "\\D+"));
}
 
Example 16
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testMatchesAttributeCondition()
{
    Selenide.open("https://blog.xceptance.com/");
    $("#masthead .search-toggle").click();

    $("#search-container .search-field").should(SelenideAddons.matchesAttribute("placeholder", "Search"));
}
 
Example 17
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 18
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 19
Source File: SelenideAddonsTest.java    From neodymium-library with MIT License 4 votes vote down vote up
@Test()
public void testSafeSupplier()
{
    // preparing the test setup as kind of generator
    AtomicInteger counter = new AtomicInteger(0);
    List<Runnable> runArray = new ArrayList<Runnable>();
    runArray.add(
                 () -> {
                     throw new StaleElementReferenceException("You shall not pass!");
                 });
    runArray.add(
                 () -> {
                     throw new StaleElementReferenceException("You shall not pass!");
                 });
    runArray.add(
                 () -> {
                     throw new StaleElementReferenceException("You shall not pass!");
                 });
    runArray.add(
                 () -> {
                     throw new StaleElementReferenceException("You shall pass!");
                 });
    runArray.add(
                 () -> {
                     throw new StaleElementReferenceException("You shall never be seen!");
                 });
    final Iterator<Runnable> iterator = runArray.iterator();

    // testing the error path after three exceptions
    Selenide.open("https://blog.xceptance.com/");
    long startTime = new Date().getTime();
    try
    {
        SelenideAddons.$safe(() -> {
            counter.incrementAndGet();
            if (iterator.hasNext())
            {
                iterator.next().run();
            }
            return $("body").should(exist);
        });
    }
    catch (StaleElementReferenceException e)
    {
        Assert.assertTrue(e.getMessage().startsWith("You shall pass!"));
    }
    long endTime = new Date().getTime();
    Assert.assertTrue(endTime - startTime > Neodymium.configuration().staleElementRetryTimeout());
    Assert.assertEquals(counter.get(), Neodymium.configuration().staleElementRetryCount() + 1);

    // testing the happy path after one exception
    SelenideElement element = SelenideAddons.$safe(() -> {
        counter.incrementAndGet();
        if (iterator.hasNext())
        {
            iterator.next().run();
        }
        return $("body");
    });
    Assert.assertEquals(counter.get(), Neodymium.configuration().staleElementRetryCount() + 3);
    element.shouldBe(visible);
}
 
Example 20
Source File: RunWithProxy.java    From neodymium-library with MIT License 4 votes vote down vote up
@Test
public void testProxyBypassConfiguration()
{
    Selenide.open("https://www.xceptance.com");
    $("#page #navigation").shouldBe(visible);
}