Skip to content

Commit

Permalink
Adding SetTaxonomyFieldByTextAsync function
Browse files Browse the repository at this point in the history
  • Loading branch information
DemeSzabolcs committed Feb 17, 2024
1 parent 9c83e88 commit 811f97e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lombiq.Tests.UI/Extensions/NavigationUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ public static Task SetTaxonomyFieldByIndexAsync(this UITestContext context, stri
return SetFieldDropdownByIndexAsync(context, baseSelector, index);
}

public static Task SetTaxonomyFieldByTextAsync(this UITestContext context, string taxonomyId, string text)
{
var baseSelector = ByHelper.Css($".tags[data-taxonomy-content-item-id='{taxonomyId}']");
return SetFieldDropdownByTextAsync(context, baseSelector, text);
}

public static async Task SetContentPickerByDisplayTextAsync(this UITestContext context, string part, string field, string text)
{
var searchUrl = context.Get(ByHelper.GetContentPickerSelector(part, field)).GetAttribute("data-search-url");
Expand Down Expand Up @@ -275,6 +281,20 @@ private static async Task SetFieldDropdownByIndexAsync(UITestContext context, By
await context.ClickReliablyOnAsync(byItem);
}

private static async Task SetFieldDropdownByTextAsync(UITestContext context, By baseSelector, string text)
{
var byItem = baseSelector
.Then(By.XPath($"//span[contains(@class,'multiselect__option')]//span[text() = '{text}']"))
.Visible();

while (!context.Exists(byItem.Safely()))
{
await context.ClickReliablyOnAsync(baseSelector.Then(By.CssSelector(".multiselect__select")));
}

await context.ClickReliablyOnAsync(byItem);
}

/// <summary>
/// A convenience method that merges <see cref="ElementRetrievalUITestContextExtensions.Get"/> and <see
/// cref="NavigationWebElementExtensions.ClickReliablyAsync(IWebElement, UITestContext, int)"/> so the <paramref
Expand Down

0 comments on commit 811f97e

Please sign in to comment.