public SeleniumQueryObject filterPredicate(SeleniumQueryObject seleniumQueryObject, Predicate<WebElement> filterFunction) { return new FilterPredicateFunction().filter(seleniumQueryObject, filterFunction); }
public SeleniumQueryObject filterPredicate(SeleniumQueryObject seleniumQueryObject, Predicate<WebElement> filterFunction) { return new FilterPredicateFunction().filter(seleniumQueryObject, filterFunction); }
@Test public void resultSQO_should_have_targetSQO_as_previous_object__and_same_SQFunctions_as_targetSQO__and_same_WebDriver_as_targetSQO() { FunctionsTestUtils.verifyFunctionReturnsSQOWithCorrectWebDriverAndFunctionsAndPrevious(targetSQO -> filterPredicateFunction.filter(targetSQO, PREDICATE_DOES_NOT_MATTER_IN_THIS_TEST)); }
@Test public void filterred_object_should_have_invalidBy_as_by() { // given SeleniumQueryObject targetSQO = createStubSeleniumQueryObjectWithElements(createWebElementWithTag("doesnt-matter")); // when SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, NULL_PREDICATE); // then assertThat(resultSQO.getBy(), instanceOf(SeleniumQueryInvalidBy.class)); assertThat(resultSQO.getBy().toString(), equalTo("$(\"dummy#by\").filter(<function>)") ); }
@Test public void null_predicate__should_return_EMPTY_element_set() { // given SeleniumQueryObject targetSQO = createStubSeleniumQueryObjectWithAtLeastOneElement(); // when SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, NULL_PREDICATE); // then assertThat(resultSQO.get(), empty()); }
@Test public void resultSQO_should_onlyKeepElementsThatPassThePredicateFunction() { // given WebElement spanOne = createWebElementWithTag("span"); WebElement notSpan = createWebElementWithTag("div"); WebElement spanTwo = createWebElementWithTag("span"); SeleniumQueryObject targetSQO = createStubSeleniumQueryObjectWithElements(spanOne, notSpan, spanTwo); // when SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, e -> "span".equals(e.getTagName())); // then assertThat(resultSQO.get(), contains(spanOne, spanTwo)); }