Skip to content

Commit

Permalink
Consider sorting of one element collection as passed
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski committed Jun 11, 2024
1 parent effc24d commit 8dfc0da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/modules/plugins/partials/generic-ui-steps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ When I wait until element located by `id(indicator)` has text matching `\d+`
=== Verify elements order

Gets a collection of elements by locator and checks that they are sorted by
their text in the specified order. The collection should have more than 1
their text in the specified order. The collection should have at least one
element with not empty text, otherwise the step fails.

[source,gherkin]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void assertElementsNumberInState(State state, Locator locator, Comparison
@Then("elements located by `$locator` are sorted by text in $sortingOrder order")
public void areElementSorted(Locator locator, StringSortingOrder sortingOrder)
{
ComparisonRule rule = ComparisonRule.GREATER_THAN;
ComparisonRule rule = ComparisonRule.GREATER_THAN_OR_EQUAL_TO;
int requiredNumber = 1;

List<WebElement> elements = baseValidations.assertNumberOfElementsFound("The elements to check the sorting",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -136,8 +136,8 @@ void shouldCheckThatElementsAreSorted()
List<WebElement> elements = List.of(webElement, webElement, webElement);
Locator locator = new Locator(TestLocatorType.SEARCH, VALUE);

when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1, ComparisonRule.GREATER_THAN))
.thenReturn(elements);
when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1,
ComparisonRule.GREATER_THAN_OR_EQUAL_TO)).thenReturn(elements);
when(elementActions.getElementText(webElement)).thenReturn(A_LETTER)
.thenReturn(C_LETTER)
.thenReturn(B_LETTER);
Expand All @@ -156,14 +156,12 @@ void shouldCheckThatElementsAreSorted()
}

@Test
void shouldNotCheckIfNumberOfElementsIsLessThanTwo()
void shouldNotCheckIfNumberOfElementsIsLessThanOne()
{
WebElement webElement = mock(WebElement.class);
List<WebElement> elements = List.of(webElement);
Locator locator = new Locator(TestLocatorType.SEARCH, VALUE);

when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1, ComparisonRule.GREATER_THAN))
.thenReturn(elements);
when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1,
ComparisonRule.GREATER_THAN_OR_EQUAL_TO)).thenReturn(List.of());

elementSteps.areElementSorted(locator, StringSortingOrder.ASCENDING);

Expand All @@ -175,24 +173,22 @@ void shouldNotCheckIfNumberOfElementsIsLessThanTwo()
void shouldNotCheckIfElementsAreFiltredOutByText()
{
WebElement webElement = mock(WebElement.class);
List<WebElement> elements = List.of(webElement, webElement, webElement);
List<WebElement> elements = List.of(webElement, webElement);
Locator locator = new Locator(TestLocatorType.SEARCH, VALUE);

when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1, ComparisonRule.GREATER_THAN))
.thenReturn(elements);
when(elementActions.getElementText(webElement)).thenReturn(A_LETTER)
.thenReturn(StringUtils.EMPTY)
when(baseValidations.assertNumberOfElementsFound(ELEMENTS_TO_CHECK, locator, 1,
ComparisonRule.GREATER_THAN_OR_EQUAL_TO)).thenReturn(elements);
when(elementActions.getElementText(webElement)).thenReturn(StringUtils.EMPTY)
.thenReturn(null);


when(softAssert.assertTrue(String.format(ELEMENT_CONTAINS_TEXT, 1), true)).thenReturn(true);
when(softAssert.assertTrue(String.format(ELEMENT_CONTAINS_TEXT, 1), false)).thenReturn(false);
when(softAssert.assertTrue(String.format(ELEMENT_CONTAINS_TEXT, 2), false)).thenReturn(false);
when(softAssert.assertTrue(String.format(ELEMENT_CONTAINS_TEXT, 3), false)).thenReturn(false);

elementSteps.areElementSorted(locator, StringSortingOrder.ASCENDING);

verify(softAssert).recordFailedAssertion(
"There are not enough elements with text to check sorting: " + List.of(A_LETTER));
"There are not enough elements with text to check sorting: " + List.of());
verifyNoMoreInteractions(baseValidations, softAssert, elementActions);
}

Expand Down

0 comments on commit 8dfc0da

Please sign in to comment.