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

Consider sorting of one element collection as passed #5115

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading