diff --git a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/SearchActions.java b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/SearchActions.java index 623fa67b99..8ea541beab 100644 --- a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/SearchActions.java +++ b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/SearchActions.java @@ -18,7 +18,6 @@ import java.util.Iterator; import java.util.List; -import java.util.Map.Entry; import java.util.Optional; import javax.inject.Inject; @@ -28,10 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.vividus.ui.action.search.ElementActionService; -import org.vividus.ui.action.search.IElementFilterAction; import org.vividus.ui.action.search.IElementSearchAction; import org.vividus.ui.action.search.Locator; -import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.context.IUiContext; @@ -47,29 +44,8 @@ public List findElements(SearchContext searchContext, Locator locato { SearchParameters searchParameters = locator.getSearchParameters(); IElementSearchAction searchAction = elementActionService.find(locator.getLocatorType()); - List foundElements = searchAction.search(searchContext, searchParameters); - for (Entry> entry : locator.getFilterAttributes().entrySet()) - { - IElementFilterAction filterAction = elementActionService.find(entry.getKey()); - for (String filterValue : entry.getValue()) - { - int size = foundElements.size(); - if (size == 0) - { - break; - } - - List filteredElements = filterAction.filter(foundElements, filterValue); - - LOGGER.atInfo().addArgument(() -> size - filteredElements.size()) - .addArgument(size) - .addArgument(entry::getKey) - .addArgument(filterValue) - .log("{} of {} elements were filtered out by {} filter with '{}' value"); - - foundElements = filteredElements; - } - } + List foundElements = searchAction.search(searchContext, searchParameters, + locator.getFilterAttributes()); List childLocators = locator.getChildLocators(); for (Locator attributes : childLocators) { diff --git a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/AbstractElementAction.java b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/AbstractElementAction.java index 8672aa7a96..fe317c9207 100644 --- a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/AbstractElementAction.java +++ b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/AbstractElementAction.java @@ -18,6 +18,7 @@ import java.time.Duration; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.inject.Inject; @@ -39,6 +40,7 @@ public abstract class AbstractElementAction implements IElementAction private IWaitActions waitActions; @Inject private IExpectedConditions expectedConditions; @Inject private ElementActions elementActions; + @Inject private ElementActionService elementActionService; private Duration waitForElementTimeout; private boolean retrySearchIfStale; @@ -55,18 +57,19 @@ public LocatorType getType() return type; } - protected List findElements(SearchContext searchContext, By locator, SearchParameters parameters) + protected List findElements(SearchContext searchContext, By locator, SearchParameters parameters, + Map> filters) { if (searchContext != null) { - return findElements(searchContext, locator, parameters, false); + return findElements(searchContext, locator, parameters, filters, false); } LOGGER.error(IElementAction.NOT_SET_CONTEXT); return List.of(); } private List findElements(SearchContext searchContext, By locator, SearchParameters parameters, - boolean retry) + Map> filters, boolean retry) { List elements = parameters.isWaitForElement() ? waitForElement(searchContext, locator) @@ -77,16 +80,16 @@ private List findElements(SearchContext searchContext, By locator, S .log("Total number of elements found {} is {}"); if (elementsFound) { - Visibility visibility = parameters.getVisibility(); try { - return Visibility.ALL == visibility - ? elements - : filterElementsByVisibility(elements, visibility, retry); + List filteredElements = filterElementsByTypes(elements, filters); + Visibility visibility = parameters.getVisibility(); + return Visibility.ALL == visibility ? filteredElements + : filterElementsByVisibility(filteredElements, visibility, retry); } catch (StaleElementReferenceException e) { - return findElements(searchContext, locator, parameters, true); + return findElements(searchContext, locator, parameters, filters, true); } } return List.of(); @@ -119,6 +122,42 @@ protected List filterElementsByVisibility(List elements, })); } + private List filterElementsByTypes(List foundElements, + Map> filters) + { + List filteredElements = foundElements; + for (Map.Entry> entry : filters.entrySet()) + { + IElementFilterAction filterAction = elementActionService.find(entry.getKey()); + for (String filterValue : entry.getValue()) + { + int size = filteredElements.size(); + if (size == 0) + { + break; + } + try + { + filteredElements = filterAction.filter(filteredElements, filterValue); + } + catch (StaleElementReferenceException e) + { + if (retrySearchIfStale) + { + throw e; + } + LOGGER.warn(e.getMessage(), e); + } + + int filteredElementsCount = size - filteredElements.size(); + LOGGER.atInfo().addArgument(filteredElementsCount).addArgument(size) + .addArgument(entry::getKey).addArgument(filterValue) + .log("{} of {} elements were filtered out by {} filter with '{}' value"); + } + } + return filteredElements; + } + private List waitForElement(SearchContext searchContext, By locator) { return waitActions.wait(searchContext, waitForElementTimeout, diff --git a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/ByLocatorSearch.java b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/ByLocatorSearch.java index fd3bde48d7..9f4f6dcc0e 100644 --- a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/ByLocatorSearch.java +++ b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/ByLocatorSearch.java @@ -17,6 +17,7 @@ package org.vividus.ui.action.search; import java.util.List; +import java.util.Map; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; @@ -29,8 +30,9 @@ public ByLocatorSearch(LocatorType type) } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { - return findElements(searchContext, getType().buildBy(parameters.getValue()), parameters); + return findElements(searchContext, getType().buildBy(parameters.getValue()), parameters, filters); } } diff --git a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/IElementSearchAction.java b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/IElementSearchAction.java index ddbe2ac42a..b9312309a8 100644 --- a/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/IElementSearchAction.java +++ b/vividus-extension-selenium/src/main/java/org/vividus/ui/action/search/IElementSearchAction.java @@ -17,11 +17,13 @@ package org.vividus.ui.action.search; import java.util.List; +import java.util.Map; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; public interface IElementSearchAction extends IElementAction { - List search(SearchContext searchContext, SearchParameters parameters); + List search(SearchContext searchContext, SearchParameters parameters, + Map> filters); } diff --git a/vividus-extension-selenium/src/test/java/org/vividus/testdouble/TestElementSearch.java b/vividus-extension-selenium/src/test/java/org/vividus/testdouble/TestElementSearch.java index 9d3d838a69..5b7d859962 100644 --- a/vividus-extension-selenium/src/test/java/org/vividus/testdouble/TestElementSearch.java +++ b/vividus-extension-selenium/src/test/java/org/vividus/testdouble/TestElementSearch.java @@ -17,6 +17,7 @@ package org.vividus.testdouble; import java.util.List; +import java.util.Map; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; @@ -27,7 +28,8 @@ public class TestElementSearch implements IElementSearchAction { @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { return List.of(); } diff --git a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/SearchActionsTests.java b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/SearchActionsTests.java index 15b09d5113..a571f61e5b 100644 --- a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/SearchActionsTests.java +++ b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/SearchActionsTests.java @@ -16,18 +16,16 @@ package org.vividus.ui.action; -import static com.github.valfirst.slf4jtest.LoggingEvent.info; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import java.util.ArrayList; @@ -51,7 +49,6 @@ import org.vividus.testdouble.TestElementSearch; import org.vividus.testdouble.TestLocatorType; import org.vividus.ui.action.search.ElementActionService; -import org.vividus.ui.action.search.IElementFilterAction; import org.vividus.ui.action.search.Locator; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.context.IUiContext; @@ -60,7 +57,6 @@ class SearchActionsTests { private static final String VALUE = "value"; - private static final String FILTER_MESSAGE = "{} of {} elements were filtered out by {} filter with '{}' value"; @Mock private WebElement webElement; @Mock private SearchContext searchContext; @@ -84,7 +80,7 @@ void init() @Test void testFindElementsByLocatorSingleAttribute() { - when(testSearch.search(eq(searchContext), any(SearchParameters.class))) + when(testSearch.search(eq(searchContext), any(SearchParameters.class), anyMap())) .thenReturn(List.of(webElement)); Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); List foundElements = searchActions.findElements(searchContext, locator); @@ -95,7 +91,7 @@ void testFindElementsByLocatorSingleAttribute() @Test void shouldFindElementsUsingLocatorAndUiContext() { - when(testSearch.search(eq(searchContext), any(SearchParameters.class))) + when(testSearch.search(eq(searchContext), any(SearchParameters.class), anyMap())) .thenReturn(List.of(webElement)); when(uiContext.getSearchContext()).thenReturn(searchContext); Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); @@ -107,7 +103,7 @@ void shouldFindElementsUsingLocatorAndUiContext() @Test void shouldReturnEmptyOptionalIfNoElementFound() { - when(testSearch.search(eq(searchContext), any(SearchParameters.class))).thenReturn(List.of()); + when(testSearch.search(eq(searchContext), any(SearchParameters.class), anyMap())).thenReturn(List.of()); when(uiContext.getSearchContext()).thenReturn(searchContext); Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); assertEquals(Optional.empty(), searchActions.findElement(locator)); @@ -119,7 +115,7 @@ void shouldReturnFirstElementIfFewFound() { WebElement element1 = mock(WebElement.class); WebElement element2 = mock(WebElement.class); - when(testSearch.search(eq(searchContext), any(SearchParameters.class))) + when(testSearch.search(eq(searchContext), any(SearchParameters.class), anyMap())) .thenReturn(List.of(element1, element2)); when(uiContext.getSearchContext()).thenReturn(searchContext); Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); @@ -133,7 +129,7 @@ void shouldFindElementInSearchContext() WebDriver webDriver = mock(WebDriver.class); WebElement element = mock(WebElement.class); - when(testSearch.search(eq(webDriver), any(SearchParameters.class))).thenReturn(List.of(element)); + when(testSearch.search(eq(webDriver), any(SearchParameters.class), anyMap())).thenReturn(List.of(element)); Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); assertEquals(Optional.of(element), searchActions.findElement(webDriver, locator)); @@ -141,81 +137,6 @@ void shouldFindElementInSearchContext() assertThat(logger.getLoggingEvents(), is(empty())); } - @Test - void testFindElementsByLocatorSeveralAttributes() - { - List list = List.of(webElement); - when(testSearch.search(eq(searchContext), any(SearchParameters.class))) - .thenReturn(List.of(webElement)); - when(((IElementFilterAction) testFilter).filter(List.of(webElement), VALUE)).thenReturn(list); - Locator locator = new Locator(TestLocatorType.SEARCH, VALUE) - .addFilter(TestLocatorType.FILTER, VALUE); - List foundElements = searchActions.findElements(searchContext, locator); - assertEquals(list, foundElements); - assertThat(logger.getLoggingEvents(), - equalTo(List.of(info(FILTER_MESSAGE, 0, 1, TestLocatorType.FILTER, VALUE)))); - } - - @Test - void shouldFindElementsAndFilter() - { - Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); - String filterOne = "filter-one"; - locator.addFilter(TestLocatorType.FILTER, filterOne); - String filterTwo = "filter-two"; - locator.addFilter(TestLocatorType.FILTER, filterTwo); - String filterThree = "filter-three"; - locator.addFilter(TestLocatorType.ADDITIONAL_FILTER, filterThree); - locator.addFilter(TestLocatorType.ADDITIONAL_FILTER, "filter-four"); - - WebElement element = mock(WebElement.class); - TestElementFilter additionalFilter = mock(TestElementFilter.class); - - when(elementActionService.find(TestLocatorType.SEARCH)).thenReturn(testSearch); - when(elementActionService.find(TestLocatorType.FILTER)).thenReturn(testFilter); - when(elementActionService.find(TestLocatorType.ADDITIONAL_FILTER)).thenReturn(additionalFilter); - when(testSearch.search(searchContext, locator.getSearchParameters())) - .thenReturn(List.of(element, element, element)); - when(testFilter.filter(List.of(element, element, element), filterOne)) - .thenReturn(List.of(element, element, element)); - when(testFilter.filter(List.of(element, element, element), filterTwo)) - .thenReturn(List.of(element, element)); - when(additionalFilter.filter(List.of(element, element), filterThree)).thenReturn(List.of()); - - assertEquals(List.of(), searchActions.findElements(searchContext, locator)); - - assertThat(logger.getLoggingEvents(), equalTo(List.of( - info(FILTER_MESSAGE, 0, 3, TestLocatorType.FILTER, filterOne), - info(FILTER_MESSAGE, 1, 3, TestLocatorType.FILTER, filterTwo), - info(FILTER_MESSAGE, 2, 2, TestLocatorType.ADDITIONAL_FILTER, filterThree) - ))); - verifyNoMoreInteractions(testFilter, additionalFilter); - } - - @Test - void testFindElementsWithChildrenSearchAndFilter() - { - TestElementSearch additionalTestSearch = mock(TestElementSearch.class); - when(elementActionService.find(TestLocatorType.ADDITIONAL_SEARCH)) - .thenReturn(additionalTestSearch); - List webElements = new ArrayList<>(); - webElements.add(webElement); - Locator locator = new Locator(TestLocatorType.SEARCH, VALUE); - Locator childAttributes = new Locator(TestLocatorType.ADDITIONAL_SEARCH, - VALUE); - childAttributes.addFilter(TestLocatorType.FILTER, VALUE); - locator.addChildLocator(childAttributes); - WebElement wrongElement = mock(WebElement.class); - webElements.add(wrongElement); - List list = List.of(webElement); - when(testSearch.search(eq(searchContext), any(SearchParameters.class))).thenReturn(webElements); - when(additionalTestSearch.search(eq(webElement), any(SearchParameters.class))).thenReturn(list); - when(((IElementFilterAction) testFilter).filter(list, VALUE)).thenReturn(list); - List foundElements = searchActions.findElements(searchContext, locator); - webElements.remove(wrongElement); - assertEquals(webElements, foundElements); - } - @Test void testFindElementsWithChildrenEmptyResults() { @@ -228,8 +149,8 @@ void testFindElementsWithChildrenEmptyResults() Locator childAttributes = new Locator(TestLocatorType.ADDITIONAL_SEARCH, VALUE); locator.addChildLocator(childAttributes); - when(testSearch.search(eq(searchContext), any(SearchParameters.class))).thenReturn(webElements); - when(additionalTestSearch.search(eq(webElement), any(SearchParameters.class))).thenReturn(List.of()); + when(testSearch.search(eq(searchContext), any(SearchParameters.class), anyMap())).thenReturn(webElements); + when(additionalTestSearch.search(eq(webElement), any(SearchParameters.class), anyMap())).thenReturn(List.of()); List foundElements = searchActions.findElements(searchContext, locator); assertEquals(List.of(), foundElements); assertThat(logger.getLoggingEvents(), is(empty())); diff --git a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/AbstractElementSearchActionTests.java b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/AbstractElementSearchActionTests.java index 2a01bef570..4102f5d453 100644 --- a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/AbstractElementSearchActionTests.java +++ b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/AbstractElementSearchActionTests.java @@ -32,6 +32,7 @@ import java.time.Duration; import java.util.List; +import java.util.Map; import java.util.stream.Stream; import com.github.valfirst.slf4jtest.TestLogger; @@ -66,6 +67,7 @@ class AbstractElementSearchActionTests private static final String NUMBER_OF_VISIBLE_ELEMENTS = "Number of {} elements is {}"; private static final String EXCEPTION = "exception"; private static final Duration TIMEOUT = Duration.ofSeconds(0); + private static final Map> FILTERS = Map.of(); private final TestLogger logger = TestLoggerFactory.getTestLogger(AbstractElementAction.class); @@ -90,7 +92,7 @@ void testGetAttributeType() void testFindElementsSearchContextIsNull() { SearchParameters parameters = mock(SearchParameters.class); - List elements = elementSearchAction.findElements(null, locator, parameters); + List elements = elementSearchAction.findElements(null, locator, parameters, FILTERS); assertThat(elements, empty()); assertThat(logger.getLoggingEvents(), equalTo(List.of( error("Unable to locate elements, because search context is not set")))); @@ -102,7 +104,7 @@ void testFindNoElements() elementSearchAction.setWaitForElementTimeout(TIMEOUT); when(searchContext.findElements(locator)).thenReturn(null); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters().setWaitForElement(false)); + new SearchParameters().setWaitForElement(false), FILTERS); assertThat(foundElements, empty()); assertThat(logger.getLoggingEvents(), equalTo(List.of(info(TOTAL_NUMBER_OF_ELEMENTS, locator, 0)))); } @@ -120,7 +122,7 @@ void testFindAndScroll() when(result.getData()).thenReturn(elements); when(elementActions.isElementVisible(element)).thenReturn(true); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters()); + new SearchParameters(), FILTERS); assertEquals(1, foundElements.size()); assertEquals(element, foundElements.get(0)); verify(waitActions).wait(searchContext, TIMEOUT, condition, false); @@ -140,7 +142,7 @@ void testFindElementsDisplayedOnly() when(elementActions.isElementVisible(element1)).thenReturn(Boolean.TRUE); when(elementActions.isElementVisible(element2)).thenReturn(Boolean.FALSE); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters().setWaitForElement(false)); + new SearchParameters().setWaitForElement(false), FILTERS); assertEquals(1, foundElements.size()); assertEquals(element1, foundElements.get(0)); assertThat(logger.getLoggingEvents(), equalTo(List.of( @@ -162,7 +164,7 @@ void shouldFindAllElements() IExpectedSearchContextCondition> condition = mock(IExpectedSearchContextCondition.class); when(expectedConditions.presenceOfAllElementsLocatedBy(any(By.class))).thenReturn(condition); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters().setVisibility(Visibility.ALL)); + new SearchParameters().setVisibility(Visibility.ALL), FILTERS); assertEquals(2, foundElements.size()); assertEquals(element1, foundElements.get(0)); assertEquals(element2, foundElements.get(1)); @@ -185,7 +187,7 @@ void shouldFindInvisibleElements() IExpectedSearchContextCondition> condition = mock(IExpectedSearchContextCondition.class); when(expectedConditions.presenceOfAllElementsLocatedBy(any(By.class))).thenReturn(condition); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters().setVisibility(Visibility.INVISIBLE)); + new SearchParameters().setVisibility(Visibility.INVISIBLE), FILTERS); assertEquals(1, foundElements.size()); assertEquals(List.of(element2), foundElements); verify(waitActions).wait(searchContext, TIMEOUT, condition, false); @@ -203,7 +205,7 @@ void testFindAllElementsWithException() Mockito.doThrow(new StaleElementReferenceException(EXCEPTION)).when(elementActions).isElementVisible(element); when(searchContext.findElements(locator)).thenReturn(elements); List foundElements = elementSearchAction.findElements(searchContext, locator, - new SearchParameters().setWaitForElement(false)); + new SearchParameters().setWaitForElement(false), FILTERS); assertEquals(0, foundElements.size()); verify(element, Mockito.never()).getSize(); verifyNoInteractions(waitActions); @@ -231,7 +233,7 @@ void testStaleElementSearchRetry(Answer answer, int expectedSize, .when(elementActions).isElementVisible(element); when(searchContext.findElements(locator)).thenReturn(elements); List foundElements = elementSearchAction - .findElements(searchContext, locator, new SearchParameters().setWaitForElement(false)); + .findElements(searchContext, locator, new SearchParameters().setWaitForElement(false), FILTERS); assertEquals(expectedSize, foundElements.size()); verify(element, Mockito.never()).getSize(); verifyNoInteractions(waitActions); diff --git a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/ByLocatorSearchTests.java b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/ByLocatorSearchTests.java index dc3544e11d..f79e6a9628 100644 --- a/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/ByLocatorSearchTests.java +++ b/vividus-extension-selenium/src/test/java/org/vividus/ui/action/search/ByLocatorSearchTests.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; import org.openqa.selenium.SearchContext; @@ -40,6 +41,6 @@ void testSearch() when(searchContext.findElements(locatorType.buildBy(parameters.getValue()))).thenReturn(webElements); - assertEquals(webElements, searchAction.search(searchContext, parameters)); + assertEquals(webElements, searchAction.search(searchContext, parameters, Map.of())); } } diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/AbstractWebElementSearchAction.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/AbstractWebElementSearchAction.java index a9e4d846db..9d7af4609d 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/AbstractWebElementSearchAction.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/AbstractWebElementSearchAction.java @@ -17,6 +17,7 @@ package org.vividus.ui.web.action.search; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -50,12 +51,12 @@ public abstract class AbstractWebElementSearchAction extends AbstractElementActi protected List findElementsByText(SearchContext searchContext, By defaultLocator, SearchParameters parameters, String... tagNames) { - List elements = findElements(searchContext, defaultLocator, parameters); + List elements = findElements(searchContext, defaultLocator, parameters, Map.of()); if (elements.isEmpty()) { String text = parameters.getValue(); By newLocator = generateCaseInsensitiveLocator(text, tagNames); - return findElements(searchContext, newLocator, parameters) + return findElements(searchContext, newLocator, parameters, Map.of()) .stream() .filter(element -> matchesToText(element, text)) .collect(Collectors.toList()); diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ButtonNameSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ButtonNameSearch.java index 52e623f3e8..321ee2a92e 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ButtonNameSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ButtonNameSearch.java @@ -17,11 +17,13 @@ package org.vividus.ui.web.action.search; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.web.util.LocatorUtil; @@ -37,7 +39,8 @@ public ButtonNameSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String value = parameters.getValue(); By locator = LocatorUtil.getXPathLocator(".//" + BUTTON_WITH_ANY_ATTRIBUTE_NAME_PATTERN, value); diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CaseSensitiveTextSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CaseSensitiveTextSearch.java index dfd1c84d41..a0d30650cf 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CaseSensitiveTextSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CaseSensitiveTextSearch.java @@ -17,6 +17,7 @@ package org.vividus.ui.web.action.search; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; @@ -24,6 +25,7 @@ import org.openqa.selenium.WebElement; import org.vividus.ui.action.search.IElementFilterAction; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.web.util.LocatorUtil; @@ -36,11 +38,12 @@ public CaseSensitiveTextSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String value = parameters.getValue(); List elements = findElements(searchContext, LocatorUtil.getXPathLocatorByFullInnerText(value), - parameters); + parameters, filters); if (elements.isEmpty()) { By locator = LocatorUtil.getXPathLocatorByInnerText(value); diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CheckboxNameSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CheckboxNameSearch.java index 4308f86f69..d18952e660 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CheckboxNameSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/CheckboxNameSearch.java @@ -19,12 +19,14 @@ import static org.vividus.ui.web.util.LocatorUtil.getXPathLocator; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; import org.vividus.selenium.element.Checkbox; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.action.search.Visibility; @@ -43,19 +45,21 @@ public CheckboxNameSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String checkBoxName = parameters.getValue(); SearchParameters nonDisplayedParameters = new SearchParameters(parameters.getValue(), Visibility.ALL, parameters.isWaitForElement()); List checkboxLabels = findElements(searchContext, - getXPathLocator(String.format(CHECKBOX_LABEL_FORMAT, checkBoxName)), parameters); + getXPathLocator(String.format(CHECKBOX_LABEL_FORMAT, checkBoxName)), parameters, filters); List matchedCheckboxLabels = searchCheckboxByLabels(searchContext, nonDisplayedParameters, checkboxLabels); if (matchedCheckboxLabels.isEmpty()) { - checkboxLabels = findElements(searchContext, getXPathLocator(CHECKBOX_LABEL_DEEP), parameters).stream() + checkboxLabels = findElements(searchContext, getXPathLocator(CHECKBOX_LABEL_DEEP), parameters, filters) + .stream() .filter(e -> getWebElementActions().getElementText(e).contains(checkBoxName)) .collect(Collectors.toList()); return searchCheckboxByLabels(searchContext, nonDisplayedParameters, checkboxLabels); @@ -73,7 +77,7 @@ private List searchCheckboxByLabels(SearchContext searchContext, Sea if (checkBoxId != null) { checkboxes = findElements(searchContext, - getXPathLocator(".//input[@type='checkbox' and @id=%s]", checkBoxId), parameters); + getXPathLocator(".//input[@type='checkbox' and @id=%s]", checkBoxId), parameters, Map.of()); } else { diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ElementNameSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ElementNameSearch.java index 0b3dc2ce3e..6408f66172 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ElementNameSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/ElementNameSearch.java @@ -17,6 +17,7 @@ package org.vividus.ui.web.action.search; import java.util.List; +import java.util.Map; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; @@ -33,7 +34,8 @@ public ElementNameSearch(LocatorType elementActionType) } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String elementName = parameters.getValue(); return findElementsByText(searchContext, diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkTextSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkTextSearch.java index f687e19dd2..bb49ec039b 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkTextSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkTextSearch.java @@ -17,11 +17,13 @@ package org.vividus.ui.web.action.search; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.web.util.LocatorUtil; @@ -35,10 +37,11 @@ public LinkTextSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String text = parameters.getValue(); - List links = findElements(searchContext, By.linkText(text), parameters); + List links = findElements(searchContext, By.linkText(text), parameters, filters); if (links.isEmpty()) { By locator = LocatorUtil.getXPathLocator(LINK_WITH_ANY_ATTRIBUTE_OR_TEXT, text); diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlPartSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlPartSearch.java index 9d5f1d2a9b..bef6746d5b 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlPartSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlPartSearch.java @@ -18,12 +18,14 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; import org.vividus.ui.action.search.IElementFilterAction; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.web.util.LocatorUtil; @@ -41,12 +43,13 @@ public LinkUrlPartSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String searchValue = parameters.getValue(); By xpathLocator = caseSensitiveSearch ? LocatorUtil.getXPathLocator(LINK_WITH_PART_URL_PATTERN, searchValue) : LocatorUtil.getXPathLocator(LINK_WITH_CASE_INSENSITIVE_URL_PART, searchValue.toLowerCase()); - return findElements(searchContext, xpathLocator, parameters); + return findElements(searchContext, xpathLocator, parameters, filters); } @Override diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlSearch.java b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlSearch.java index fceade866b..f471922c20 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlSearch.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/ui/web/action/search/LinkUrlSearch.java @@ -21,6 +21,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,6 +33,7 @@ import org.vividus.selenium.IWebDriverProvider; import org.vividus.ui.action.search.IElementFilterAction; import org.vividus.ui.action.search.IElementSearchAction; +import org.vividus.ui.action.search.LocatorType; import org.vividus.ui.action.search.SearchParameters; import org.vividus.ui.web.util.LocatorUtil; import org.vividus.util.UriUtils; @@ -54,12 +56,13 @@ public LinkUrlSearch() } @Override - public List search(SearchContext searchContext, SearchParameters parameters) + public List search(SearchContext searchContext, SearchParameters parameters, + Map> filters) { String searchValue = parameters.getValue(); By xpathLocator = caseSensitiveSearch ? LocatorUtil.getXPathLocator(LINK_PATTERN, searchValue) : LocatorUtil.getXPathLocator(LINK_WITH_CASE_INSENSITIVE_URL, searchValue.toLowerCase()); - return findElements(searchContext, xpathLocator, parameters); + return findElements(searchContext, xpathLocator, parameters, filters); } @Override