Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream based lists are not working with await #787

Open
filipcynarski opened this issue Mar 20, 2019 · 0 comments
Open

Stream based lists are not working with await #787

filipcynarski opened this issue Mar 20, 2019 · 0 comments
Assignees
Labels
Milestone

Comments

@filipcynarski
Copy link
Member

filipcynarski commented Mar 20, 2019

As a user I'd like to pass supplier which is a stream reference to the list. Now, it is not working as expected in await conditions.

Example:

@FindBy(css = ".row")
    private FluentList<RowComponent> componentsList;

    private Supplier<Boolean> subscribersListContains(String text) {
        return () -> isSubscribersListContaining(text);
    }

    private boolean isSubscribersListContaining(String text) {
        return componentsList.stream()
                .anyMatch(subscriber -> subscriber.text().contains(text));
    }

    @Test
    void streamListChangeTest() {
        goTo(ELEMENT_REPLACE_URL);
        await().until(rowsListPage.getComponentsList()).size(4);

        await().until(subscribersListContains("replaced"));
    }

Will Pass

but if I change

await().until(rowsListPage.getComponentsList()).size(4);

to

await().until(rowsListPage.getComponentsList()).size(2);

It won't

Please add this piece of code to WaitComponentsListTest test

So you have

package org.fluentlenium.test.await.component;

import static org.assertj.core.api.Assertions.assertThat;
import static org.fluentlenium.assertj.FluentLeniumAssertions.assertThat;

import org.fluentlenium.core.FluentControl;
import org.fluentlenium.core.FluentPage;
import org.fluentlenium.core.annotation.Page;
import org.fluentlenium.core.components.ComponentInstantiator;
import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;
import org.fluentlenium.test.IntegrationFluentTest;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.function.Supplier;

class WaitComponentsListTest extends IntegrationFluentTest {

    private static final int POSITION_OF_REPLACED_ROW = 1;
    private static final String INITIAL_VALUE_OF_REPLACED_ROW = "row2";
    private static final String VALUE_OF_REPLACED_ROW = "replaced row2";

    @Page
    private RowsListPage rowsListPage;


    @FindBy(css = ".row")
    private FluentList<RowComponent> componentsList;

    private Supplier<Boolean> subscribersListContains(String text) {
        return () -> isSubscribersListContaining(text);
    }

    private boolean isSubscribersListContaining(String text) {
        return componentsList.stream()
                .anyMatch(subscriber -> subscriber.text().contains(text));
    }

    @Test
    void streamListChangeTest() {
        goTo(ELEMENT_REPLACE_URL);
        await().until(subscribersListContains("replaced"));
    }

    @Test
    void shouldReturnActualValueFromTheChangedList() {
        goTo(ELEMENT_REPLACE_URL);
        await().until(rowsListPage.getComponentsList()).size(2);
        assertThat(rowsListPage.getComponentsList()).hasSize(2);
        assertThat(rowsListPage.getComponentsList().get(POSITION_OF_REPLACED_ROW).getText())
                .isEqualTo(INITIAL_VALUE_OF_REPLACED_ROW);
        await().until(rowsListPage.getComponentsList()).size(4);
        assertThat(rowsListPage.getComponentsList()).hasSize(4);
        assertThat(rowsListPage.getComponentsList().reset().get(POSITION_OF_REPLACED_ROW).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

    @Test
    void shouldReturnActualElementWithGetFromTheChangedListWhenUsedPreviously() {
        goTo(ELEMENT_REPLACE_URL);
        rowsListPage.getComponentsList().get(1).getText();
        await().until(rowsListPage.getComponentsList()).size().greaterThan(3);
        assertThat(rowsListPage.getComponentsList().get(POSITION_OF_REPLACED_ROW).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

    @Test
    void shouldReturnActualElementWithGetFromTheChangedListAfterListReset() {
        goTo(ELEMENT_REPLACE_URL);
        rowsListPage.getComponentsList().get(1).getText();
        FluentList<RowComponent> rowsList = rowsListPage.getComponentsList().reset();
        await().until(rowsList).size().greaterThan(3);
        assertThat(rowsList.get(POSITION_OF_REPLACED_ROW).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

    @Test
    void shouldReturnActualValueFromResetElementWithGetFromTheChangedListAfterListReset() {
        goTo(ELEMENT_REPLACE_URL);
        rowsListPage.getComponentsList().get(1).getText();
        FluentList<RowComponent> rowsList = rowsListPage.getComponentsList().reset();
        await().until(rowsList).size().greaterThan(3);
        assertThat(rowsList.get(POSITION_OF_REPLACED_ROW).reset().as(RowComponent.class).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

    @Test
    void shouldReturnActualElementWithIndexFromTheChangedListAfterListReset() {
        goTo(ELEMENT_REPLACE_URL);
        rowsListPage.getComponentsList().get(1).getText();
        FluentList<RowComponent> rowsList = rowsListPage.getComponentsList().reset();
        await().until(rowsList).size().greaterThan(3);
        assertThat(rowsList.index(POSITION_OF_REPLACED_ROW).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

    @Test
    void shouldReturnActualValueFromResetElementWithIndexFromTheChangedListAfterListReset() {
        goTo(ELEMENT_REPLACE_URL);
        RowsListPage rowsPage = newInstance(RowsListPage.class);
        rowsPage.getComponentsList().get(1).getText();
        FluentList<RowComponent> rowsList = rowsPage.getComponentsList().reset();
        await().until(rowsList).size().greaterThan(3);
        assertThat(rowsList.index(1).reset().as(RowComponent.class).getText())
                .isEqualTo(VALUE_OF_REPLACED_ROW);
    }

}

class RowsListPage extends FluentPage {
    @FindBy(css = ".row")
    private FluentList<RowComponent> componentsList;

    FluentList<RowComponent> getComponentsList() {
        return componentsList;
    }
}

class RowComponent extends FluentWebElement {
    @FindBy(css = ".inner-row")
    private FluentWebElement innerTag;

    RowComponent(WebElement element, FluentControl control, ComponentInstantiator instantiator) {
        super(element, control, instantiator);
    }

    String getText() {
        return innerTag.text();
    }
}

Ideally I'd like to skip this wait:

await().until(rowsListPage.getComponentsList()).size(4);

and have only one await await().until(subscribersListContains("replaced")); it is not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants