Skip to content

Commit

Permalink
Merge pull request #598 from FluentLenium/bugfix/#593
Browse files Browse the repository at this point in the history
WIP: Fix for #593
  • Loading branch information
filipcynarski committed Aug 21, 2018
2 parents ffbb451 + a7dda7e commit 0045787
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.fluentlenium.core.conditions;

import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;

import java.util.List;
import java.util.function.Predicate;

import org.fluentlenium.core.domain.FluentWebElement;

/**
* Abstract class conditions on list of elements.
*/
Expand All @@ -24,10 +25,17 @@ protected AbstractFluentListConditions(List<? extends FluentWebElement> elements

@Override
public boolean size(int size) {
int elementsSize;
if (elements instanceof FluentList) {
elementsSize = ((FluentList) elements).count();
} else {
elementsSize = elements.size();
}

if (negation) {
return elements.size() != size;
return elementsSize != size;
}
return elements.size() == size;
return elementsSize == size;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DynamicIntegerConditionsImpl extends AbstractObjectConditions<List<
/**
* Creates a new conditions object on integer.
*
* @param supplier underlying list
* @param supplier underlying list
* @param negation negation value
*/
public DynamicIntegerConditionsImpl(Supplier<List<? extends FluentWebElement>> supplier, boolean negation) {
Expand All @@ -34,26 +34,34 @@ public DynamicIntegerConditionsImpl not() {

@Override
public boolean equalTo(int value) {
return verify(input -> input.size() == value);
return verify(input -> getListSize(input) == value);
}

@Override
public boolean lessThan(int value) {
return verify(input -> ((FluentList<FluentWebElement>) input).count() < value);
return verify(input -> getListSize(input) < value);
}

@Override
public boolean lessThanOrEqualTo(int value) {
return verify(input -> ((FluentList<FluentWebElement>) input).count() <= value);
return verify(input -> getListSize(input) <= value);
}

@Override
public boolean greaterThan(int value) {
return verify(input -> ((FluentList<FluentWebElement>) input).count() > value);
return verify(input -> getListSize(input) > value);
}

@Override
public boolean greaterThanOrEqualTo(int value) {
return verify(input -> ((FluentList<FluentWebElement>) input).count() >= value);
return verify(input -> getListSize(input) >= value);
}

private <T extends List> int getListSize(T input) {
if (input instanceof FluentList) {
return ((FluentList<FluentWebElement>) input).count();
} else {
return input.size();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public void waitForListChangeUsingListVariableExpectingTooMuch() {
goTo(SIZE_CHANGE_URL);
await().atMost(2, TimeUnit.SECONDS).until(myList).size().greaterThan(3);
}

@Test
public void waitForListChangeUsingListVariableAndEqualMethod() {
FluentList<FluentWebElement> myList = $(".row");
goTo(SIZE_CHANGE_URL);
await().until(myList).size().equalTo(3);
}

@Test
public void waitForListChangeToValueDefinedInSizeMethod() {
FluentList<FluentWebElement> myList = $(".row");
goTo(SIZE_CHANGE_URL);
await().until(myList).size(3);
}
}

class SizeChangePage extends FluentPage {
Expand Down

0 comments on commit 0045787

Please sign in to comment.