Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski committed Dec 13, 2024
1 parent 85f4d9b commit b17daf9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
18 changes: 0 additions & 18 deletions docs/modules/plugins/partials/generic-ui-steps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,6 @@ Then element located by `$locator` exists for `$duration` duration
Then element located by `id(banner)` exists for `PT5S` duration
----

=== Wait until element has text matching regular expression

Waits until an element with the specified locator has text that matches the provided https://www.regular-expressions.info/[regular expression].

[source,gherkin]
----
When I wait until element located by `$locator` has text matching `$regex`
----

* `$locator` - The <<_locator>> of the element which text to check.
* `$regex` - The https://www.regular-expressions.info/[regular expression] used to validate the text of the element.

.The element should have text consisting of numbers only
[source,gherkin]
----
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
Expand Down
18 changes: 18 additions & 0 deletions docs/modules/plugins/partials/ui-wait-element-state-steps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,21 @@ When I wait `$duration` with `$pollingDuration` polling until element located by
----
When I wait `PT10S` with `PT1S` polling until element located by `id(element-to-hide)` becomes not visible
----

=== Wait until element has text matching regular expression

Waits until an element with the specified locator has text that matches the provided https://www.regular-expressions.info/[regular expression].

[source,gherkin]
----
When I wait until element located by `$locator` has text matching `$regex`
----

* `$locator` - The <<_locator>> of the element which text to check.
* `$regex` - The https://www.regular-expressions.info/[regular expression] used to validate the text of the element.

.The element should have text consisting of numbers only
[source,gherkin]
----
When I wait until element located by `id(indicator)` has text matching `\d+`
----
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static org.vividus.ui.web.playwright.PlaywrightAssertionConfiguration.ASSERTION_NO_WAIT_TIMEOUT;

import java.util.regex.Pattern;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.assertions.LocatorAssertions;
import com.microsoft.playwright.assertions.PlaywrightAssertions;
Expand All @@ -28,6 +30,13 @@ private PlaywrightLocatorAssertions()
{
}

public static void assertElementHasTextMatchingRegex(Locator locator, Pattern pattern, boolean waitForState)
{
LocatorAssertions.ContainsTextOptions options = waitForState ? null
: new LocatorAssertions.ContainsTextOptions().setTimeout(ASSERTION_NO_WAIT_TIMEOUT);
getLocatorAssertions(locator).containsText(pattern, options);
}

Check warning on line 38 in vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/assertions/PlaywrightLocatorAssertions.java

View check run for this annotation

Codecov / codecov/patch

vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/assertions/PlaywrightLocatorAssertions.java#L36-L38

Added lines #L36 - L38 were not covered by tests

public static void assertElementVisible(Locator locator, boolean waitForState)
{
LocatorAssertions.IsVisibleOptions options = waitForState ? null : new LocatorAssertions.IsVisibleOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.regex.Pattern;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
Expand All @@ -32,6 +33,7 @@
import org.vividus.ui.web.playwright.BrowserContextProvider;
import org.vividus.ui.web.playwright.UiContext;
import org.vividus.ui.web.playwright.action.WaitActions;
import org.vividus.ui.web.playwright.assertions.PlaywrightLocatorAssertions;
import org.vividus.ui.web.playwright.locator.PlaywrightLocator;
import org.vividus.ui.web.playwright.locator.Visibility;
import org.vividus.util.wait.DurationBasedWaiter;
Expand Down Expand Up @@ -160,6 +162,24 @@ public void waitDurationWithPollingTillElementState(Duration duration, Duration
isElementInState);
}

/**
* Waits until an element with the specified locator has text that matches the provided regular expression.
*
* @param locator The locator of the element which text to check
* @param regex The regular expression used to validate the text of the element
*/
@When("I wait until element located by `$locator` has text matching `$regex`")
public void waitUntilElementHasTextMatchingRegex(PlaywrightLocator locator, Pattern regex)
{
Supplier<String> conditionDescription = () -> "The element located by `%s` has text matching regex %s"
.formatted(locator, regex);
waitActions.runWithTimeoutAssertion(conditionDescription, () ->

Check warning on line 176 in vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/steps/WaitSteps.java

View check run for this annotation

Codecov / codecov/patch

vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/steps/WaitSteps.java#L174-L176

Added lines #L174 - L176 were not covered by tests
{
Locator element = uiContext.locateElement(locator);
PlaywrightLocatorAssertions.assertElementHasTextMatchingRegex(element, regex, true);
});
}

Check warning on line 181 in vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/steps/WaitSteps.java

View check run for this annotation

Codecov / codecov/patch

vividus-plugin-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/steps/WaitSteps.java#L178-L181

Added lines #L178 - L181 were not covered by tests

private void waitForElementStateValidatingVisibility(PlaywrightLocator locator,
ElementState state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ When I scroll context to TOP edge
When I reset context
When I wait until element located by `id(current-vertical):a` contains text `0`

Scenario: Verify steps: "When I scroll element located by `$locator` into view", "Then element located by `$locator` $presence visible in viewport"
Scenario: Verify steps: "When I scroll element located by `$locator` into view", "Then element located by `$locator` $presence visible in viewport", "When I wait until element located by `$locator` has text matching `$regex`"
Meta:
@requirementId 436
@playwrightSupported
Given I am on page with URL `${vividus-test-site-url}/scrollableElements.html`
Then element located by `xpath(//a[text()="Contact"])` is not visible in viewport
When I scroll element located by `xpath(//a[text()="Contact"])` into view
Then element located by `xpath(//a[text()="Contact"])` is visible in viewport
When I save text of element located by `id(current-vertical):a` to scenario variable `currentVertical`
Then `${currentVertical}` matches `\d+`
When I wait until element located by `id(current-vertical):a` has text matching `\d+`

Scenario: Verify deprecated steps: "When I scroll element located `$locator` into view", "Then page is scrolled to element located `$locator`"
When I refresh page
Expand Down

0 comments on commit b17daf9

Please sign in to comment.