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

OFFI-33: Add GetBoolAttribute and IsDisabled extension methods #376

Merged
merged 2 commits into from
May 30, 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
14 changes: 14 additions & 0 deletions Lombiq.Tests.UI/Extensions/BasicWebElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ public static class BasicWebElementExtensions
/// Returns the text content of the <paramref name="element"/> without surrounding whitespace.
/// </summary>
public static string GetTextTrimmed(this IWebElement element) => element.Text.Trim();

/// <summary>
/// Returns a value indicating whether the boolean attribute called <paramref name="attributeName"/> exists. This
/// returns <see langword="true"/> even if the value is empty, in accordance to how HTML works (e.g. all of the
/// following are considered true: <c>&lt;input required&gt;</c>, <c>&lt;input required=""&gt;</c>,
/// <c>&lt;input required="required"&gt;</c>).
/// </summary>
public static bool GetBoolAttribute(this IWebElement element, string attributeName) =>
element.GetAttribute(attributeName) != null;

/// <summary>
/// Returns a value indicating whether the element has the <c>disabled</c> attribute.
/// </summary>
public static bool IsDisabled(this IWebElement element) => element.GetBoolAttribute("disabled");
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void SuccessMessageExists(this UITestContext context, string match
if (within is { } timeSpan) by = by.Within(timeSpan);

var element = context.Get(by);
if (!string.IsNullOrEmpty(matchText)) element.Text.Trim().ShouldContain(matchText);
if (!string.IsNullOrEmpty(matchText)) element.GetTextTrimmed().ShouldContain(matchText);
}

/// <summary>
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void VerifyElementTexts(this UITestContext context, By by, params

context
.GetAll(by)
.Select((element, index) => dontCare.Contains(index) ? null : element.Text.Trim())
.Select((element, index) => dontCare.Contains(index) ? null : element.GetTextTrimmed())
.ToArray()
.ShouldBe(target);
}
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Extensions/FormUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static async Task<string> GetSelectedTabTextAsync(
await context.DoWithRetriesOrFailAsync(
() =>
{
title = context.Get(By.CssSelector(".nav-item.nav-link.active")).Text.Trim();
title = context.Get(By.CssSelector(".nav-item.nav-link.active")).GetTextTrimmed();
return Task.FromResult(title != defaultTitle);
},
timeout,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using System;
using System.Net;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Extensions;
Expand Down Expand Up @@ -106,11 +107,9 @@ public static async Task ClickNewContentItemAsync(this UITestContext context, st
}
}

public static async Task GoToUsersAsync(this UITestContext context)
{
await context.ClickReliablyOnAsync(By.CssSelector("#security .title"));
await context.ClickReliablyOnAsync(By.CssSelector(".item-label.users .title"));
}
public static Task GoToUsersAsync(this UITestContext context, string query = null) =>
context.GoToAdminRelativeUrlAsync(
string.IsNullOrWhiteSpace(query) ? "/Users/Index" : $"/Users/Index?q={WebUtility.UrlEncode(query)}");

public static Task GoToContentItemEditorByIdAsync(this UITestContext context, string contentItemId) =>
context.GoToAdminRelativeUrlAsync($"/Contents/ContentItems/{contentItemId}/Edit");
Expand Down