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

OSOE-795: Upgrade to latest OC preview to test System.Text.Json #348

Merged
merged 59 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
922c733
Update NuGet versions to pre-release.
sarahelsaig Feb 22, 2024
da354c8
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Feb 22, 2024
0f8b56d
Fix interface change.
sarahelsaig Feb 22, 2024
953f7d3
Fix obsolete Refit usage
sarahelsaig Feb 24, 2024
df237e0
Replace JsonConvert.SerializeObject.
sarahelsaig Feb 24, 2024
706e733
Remove remaining Newtonsoft referenes.
sarahelsaig Feb 24, 2024
f66a14b
unusing
sarahelsaig Feb 25, 2024
781d8aa
Fix uninitialized IActionContextAccessor in UsingScopeAsync and Execu…
sarahelsaig Feb 26, 2024
e59fc8e
Fix uninitialized IActionContextAccessor in UsingScopeAsync and Execu…
sarahelsaig Feb 26, 2024
9d7d62c
Merge branch 'issue/OSOE-795-backport' into issue/OSOE-795
sarahelsaig Feb 26, 2024
3e74508
Ensure content is loaded first for real.
sarahelsaig Feb 26, 2024
19a1f5b
Break chained test into individual calls because it's completely opaq…
sarahelsaig Feb 27, 2024
07b628a
Don't try to look up all feature names (it's broken).
sarahelsaig Feb 27, 2024
e243e62
revert to dev
sarahelsaig Feb 27, 2024
f062c39
Fix Features atata map.
sarahelsaig Feb 27, 2024
1ac5a64
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Mar 1, 2024
736972f
Update OC to latest (because of bug fix for WorkflowTypeStep)
sarahelsaig Mar 3, 2024
3463af5
Not needed after all.
sarahelsaig Mar 4, 2024
76dae1a
unusing
sarahelsaig Mar 4, 2024
8cc60b0
Add ExecuteJsonRecipeSiteSettingAsync extension method.
sarahelsaig Mar 4, 2024
bfdddd8
Update OC preview version.
sarahelsaig Mar 7, 2024
6bbe0ca
Add ShouldBeByLine extension method.
sarahelsaig Mar 13, 2024
483f77b
Fix SetContentPickerByDisplayTextAsync extension method.
sarahelsaig Mar 13, 2024
97af173
Update OC package
sarahelsaig Mar 13, 2024
508d9a0
Fix TestMediaOperationsAsync (due to newly added cache busting argume…
sarahelsaig Mar 13, 2024
af0fc18
The expected file name for MS Edge verification image has changed.
sarahelsaig Mar 13, 2024
1591aa8
Add and use new email test extension methods.
sarahelsaig Mar 13, 2024
6b9a3ab
Use GoToAdminRelativeUrlAsync.
sarahelsaig Mar 13, 2024
fd565c7
Code cleanup.
sarahelsaig Mar 13, 2024
84d57d9
Fix (?) the email configuration for UITT.
sarahelsaig Mar 14, 2024
1bd7940
unusing
sarahelsaig Mar 15, 2024
0488632
clean up ConfigureSmtpPortAsync
sarahelsaig Mar 15, 2024
2ccfb0e
Add GoToEmailSettingsAsync.
sarahelsaig Mar 16, 2024
2e475c2
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Mar 29, 2024
25e5b97
Temporarily block SqlServerTests.
sarahelsaig Apr 2, 2024
7135a08
Rename verification test to match expectation.
sarahelsaig Apr 2, 2024
3c9afb9
Always generate the verification image in GitHub environment.
sarahelsaig Apr 2, 2024
232dc98
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Apr 22, 2024
dc94f44
Update OC preview version.
sarahelsaig Apr 23, 2024
281e4e7
Update login atata thing.
sarahelsaig Apr 23, 2024
940e848
Update OrchardCoreRegistrationPage.
sarahelsaig Apr 25, 2024
bac7736
Update ValidationMessage.
sarahelsaig Apr 25, 2024
0e58431
Revert "Update ValidationMessage."
sarahelsaig Apr 25, 2024
5794eda
no
sarahelsaig Apr 25, 2024
07d2a59
Fix S1854.
sarahelsaig Apr 25, 2024
8423eb3
LoginForm_
sarahelsaig Apr 25, 2024
cbfcf3e
Update OC package version.
sarahelsaig Apr 27, 2024
3938489
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig May 4, 2024
437e140
Update OC versions
sarahelsaig May 4, 2024
c96d36b
Unskip tests.
sarahelsaig May 4, 2024
a41f4a5
unusing
sarahelsaig May 4, 2024
58669b9
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig May 7, 2024
3638ad2
Update OC to the latest preview.
sarahelsaig May 7, 2024
7769369
To ensure we don't encounter any concurrency issue, enable EnableThre…
sarahelsaig May 7, 2024
9f5b503
Merge branch 'task/system-text-json-migration' into issue/OSOE-795
sarahelsaig May 12, 2024
20c9827
merge
sarahelsaig May 12, 2024
c2cf81e
Post merge fixup.
sarahelsaig May 13, 2024
c772898
Update test.
sarahelsaig May 13, 2024
477c61f
Update test again.
sarahelsaig May 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore" Version="1.8.2" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="2.0.0-preview-18200" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Lombiq.Tests.UI.Samples/Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public Task LoginShouldWork() =>
// Let's fill out the login form. In UI tests, nothing is certain. If you fill out a form it's not
// actually sure that the values are indeed there! To make things more reliable, we've added a lot of
// useful methods like FillInWithRetriesAsync().
await context.FillInWithRetriesAsync(By.Id("UserName"), DefaultUser.UserName);
await context.FillInWithRetriesAsync(By.Id("Password"), DefaultUser.Password);
await context.FillInWithRetriesAsync(By.Id("LoginForm_UserName"), DefaultUser.UserName);
await context.FillInWithRetriesAsync(By.Id("LoginForm_Password"), DefaultUser.Password);

// Even clicking can be unreliable thus we have a helper for that too.
await context.ClickReliablyOnSubmitAsync();
Expand Down
32 changes: 6 additions & 26 deletions Lombiq.Tests.UI.Samples/Tests/EmailTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Helpers;
using OpenQA.Selenium;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -25,31 +23,13 @@ public Task SendingTestEmailShouldWork() =>
// A shortcut to sign in without going through (and thus testing) the login screen.
await context.SignInDirectlyAsync();

// Let's go to the "Test settings" option of the e-mail admin page. The default sender is configured in
// the test recipe so we can use the test feature.
await context.GoToAdminRelativeUrlAsync("/Email/Index");

// Let's send a basic e-mail.
await context.FillInWithRetriesAsync(By.Id("To"), "[email protected]");
await context.FillInWithRetriesAsync(By.Id("Subject"), "Test message");
await context.FillInWithRetriesAsync(By.Id("Body"), "Hi, this is a test.");

// With the button being under the fold in the configured screen size, we need to make sure it's
// actually clicked. Scrolling there first doesn't work for some reason.
await ReliabilityHelper.DoWithRetriesOrFailAsync(
async () =>
{
try
{
await context.ClickReliablyOnAsync(By.Id("emailtestsend")); // #spell-check-ignore-line
return true;
}
catch (WebDriverException ex) when (ex.Message.Contains("move target out of bounds"))
{
return false;
}
});
// Set up the SMTP port. This is a dynamic value unique to each UI test so it can't come from a recipe.
await context.ConfigureSmtpPortAsync();

// Let's go to the "Test settings" option of the e-mail admin page and send a basic e-mail. The default
// sender is configured in the test recipe so we can use the test feature.
await context.GoToEmailTestAsync();
await context.FillEmailTestFormAsync("Test message");
context.ShouldBeSuccess();

// The SMTP service running behind the scenes also has a web UI that we can access to see all outgoing
Expand Down
3 changes: 2 additions & 1 deletion Lombiq.Tests.UI.Samples/Tests/MonkeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public Task TestAdminBackgroundTasksAsMonkeyRecursivelyShouldWorkWithAdminUser()
// You could also configure the same thing with regex:
////_monkeyTestingOptions.UrlFilters.Add(new MatchesRegexMonkeyTestingUrlFilter(@"\/Admin\/BackgroundTasks"));

await context.SignInDirectlyAndGoToRelativeUrlAsync("/Admin/BackgroundTasks");
await context.SignInDirectlyAsync();
await context.GoToAdminRelativeUrlAsync("/BackgroundTasks");
await context.TestCurrentPageAsMonkeyRecursivelyAsync(monkeyTestingOptions);
},
configuration => configuration.AssertBrowserLog = (logEntries) => logEntries
Expand Down
18 changes: 9 additions & 9 deletions Lombiq.Tests.UI.Shortcuts/Lombiq.Tests.UI.Shortcuts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Tenants" Version="1.8.2" />
<PackageReference Include="OrchardCore.Themes" Version="1.8.2" />
<PackageReference Include="OrchardCore.Users" Version="1.8.2" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Recipes.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Workflows" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Tenants" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Themes" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Users" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Recipes.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Workflows" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using OrchardCore.Modules;
using OrchardCore.ResourceManagement;
using System;
using System.Text.Json;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Shortcuts.Services;

public class ApplicationInfoInjectingFilter : IAsyncResultFilter
{
private static readonly JsonSerializerOptions _indentedJsonSerializerOptions = new() { WriteIndented = true };

private readonly IResourceManager _resourceManager;
private readonly IConfiguration _shellConfiguration;
private readonly IApplicationContext _applicationContext;
Expand All @@ -35,7 +37,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE

_resourceManager.RegisterHeadScript(new HtmlString(
$"<!--{Environment.NewLine}" +
JsonConvert.SerializeObject(_applicationContext.GetApplicationInfo(), Formatting.Indented) +
JsonSerializer.Serialize(_applicationContext.GetApplicationInfo(), _indentedJsonSerializerOptions) +
Environment.NewLine +
"-->"));

Expand Down
4 changes: 4 additions & 0 deletions Lombiq.Tests.UI.Shortcuts/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lombiq.HelpfulLibraries.AspNetCore.Extensions;
using Lombiq.Tests.UI.Shortcuts.Services;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Data.YesSql;
using OrchardCore.Modules;

namespace Lombiq.Tests.UI.Shortcuts;
Expand All @@ -11,5 +12,8 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IInteractiveModeStatusAccessor, InteractiveModeStatusAccessor>();
services.AddAsyncResultFilter<ApplicationInfoInjectingFilter>();

// To ensure we don't encounter any concurrency issue, enable EnableThreadSafetyChecks for all tests.
services.Configure<YesSqlOptions>(options => options.EnableThreadSafetyChecks = true);
dministro marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 2 additions & 2 deletions Lombiq.Tests.UI.Shortcuts/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@using Lombiq.Tests.UI.Shortcuts.Controllers
@using Microsoft.AspNetCore.Mvc.Localization
@using Newtonsoft.Json
@using Newtonsoft.Json.Serialization
@using System.Text.Json
@using System.Text.Json.Serialization
@using OrchardCore.Mvc.Core.Utilities
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lombiq.Tests.UI.Models;
using Lombiq.Tests.UI.Pages;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using Shouldly;
using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -416,8 +417,8 @@ public static Task TestRegistrationWithInvalidDataAsync(
async () =>
{
var registrationPage = await context.GoToRegistrationPageAsync();
registrationPage = await registrationPage.RegisterWithAsync(context, parameters);
registrationPage.ShouldStayOnRegistrationPage().ValidationMessages.Should.Not.BeEmpty();
await registrationPage.RegisterWithAsync(context, parameters);
context.Exists(By.XPath("//div[contains(concat(' ', normalize-space(@class), ' '), ' validation-summary-errors ')]//li"));
});
}

Expand Down Expand Up @@ -446,11 +447,13 @@ public static Task TestRegistrationWithAlreadyRegisteredEmailAsync(
async () =>
{
var registrationPage = await context.GoToRegistrationPageAsync();
registrationPage = await registrationPage.RegisterWithAsync(context, parameters);
await registrationPage.RegisterWithAsync(context, parameters);
context.RefreshCurrentAtataContext();
registrationPage
.ShouldStayOnRegistrationPage()
.ValidationMessages[page => page.Email].Should.BeVisible();

context
.Get(By.CssSelector(".text-danger.field-validation-error"))
.Text
.ShouldContain("A user with the same username already exists.");
});
}

Expand Down Expand Up @@ -544,22 +547,23 @@ public static Task TestTurningFeatureOnAndOffAsync(

context.RefreshCurrentAtataContext();

featuresPage.SearchForFeature(featureName).IsEnabled.Get(out var originalEnabledState);
featuresPage.Features[featureName].CheckBox.Check();
featuresPage.BulkActions.Toggle.Click();

featuresPage
.AggregateAssert(page => page
.ShouldContainSuccessAlertMessage(TermMatch.Contains, featureName)
.AdminMenu.FindMenuItem(featureName).IsPresent.Should.Equal(!originalEnabledState)
.SearchForFeature(featureName).IsEnabled.Should.Equal(!originalEnabledState));
featuresPage.Features[featureName].CheckBox.Check();
featuresPage.BulkActions.Toggle.Click();

featuresPage
.SearchForFeature(featureName).IsEnabled.Get(out bool originalEnabledState)
.Features[featureName].CheckBox.Check()
.BulkActions.Toggle.Click()

.AggregateAssert(page => page
.ShouldContainSuccessAlertMessage(TermMatch.Contains, featureName)
.AdminMenu.FindMenuItem(featureName).IsPresent.Should.Equal(!originalEnabledState)
.SearchForFeature(featureName).IsEnabled.Should.Equal(!originalEnabledState))
.Features[featureName].CheckBox.Check()
.BulkActions.Toggle.Click()

.AggregateAssert(page => page
.ShouldContainSuccessAlertMessage(TermMatch.Contains, featureName)
.AdminMenu.FindMenuItem(featureName).IsPresent.Should.Equal(originalEnabledState)
.SearchForFeature(featureName).IsEnabled.Should.Equal(originalEnabledState));
.AggregateAssert(page => page
.ShouldContainSuccessAlertMessage(TermMatch.Contains, featureName)
.AdminMenu.FindMenuItem(featureName).IsPresent.Should.Equal(originalEnabledState)
.SearchForFeature(featureName).IsEnabled.Should.Equal(originalEnabledState));
});

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Task TestMediaOperationsAsync(this UITestContext context) =>
context.Exists(By.XPath($"//span[contains(text(), '{imageName}')]"));

await context
.Get(By.CssSelector($"a[href=\"/media/{imageName}\"]").OfAnyVisibility())
.Get(By.CssSelector($"a[href^=\"/media/{imageName}\"]").OfAnyVisibility())
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

Expand All @@ -52,7 +52,7 @@ await context
.ClickReliablyAsync(context);

await context
.Get(By.CssSelector($"a[href=\"/media/{documentName}\"]"))
.Get(By.CssSelector($"a.btn-link[href^=\"/media/{documentName}\"]"))
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public static Task TestWorkflowsAsync(this UITestContext context) =>
await context.ClickReliablyOnAsync(By.XPath("//button[@data-activity-type='Event']"));
await context.ClickReliablyOnAsync(By.XPath("//a[contains(@href, 'ContentPublishedEvent')]"));

await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_Title"), "Content Published Trigger");
await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_ActivityMetadata_Title"), "Content Published Trigger");
await context.SetCheckboxValueAsync(By.XPath("//input[@value='Page']"));
await context.ClickReliablyOnSubmitAsync();

await context.ClickReliablyOnAsync(By.XPath("//button[@data-activity-type='Task']"));
await context.ClickReliablyOnAsync(By.XPath("//a[contains(@href, 'NotifyTask')]"));

await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_Title"), "Content Published Notification");
await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_ActivityMetadata_Title"), "Content Published Notification");
await context.ClickAndFillInWithRetriesAsync(By.Id("NotifyTask_Message"), contentItemPublishTestSuccessMessage);
await context.ClickReliablyOnSubmitAsync();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Lombiq.Tests.UI.Services.GitHub;
using System;

namespace Lombiq.Tests.UI.Exceptions;
Expand All @@ -16,11 +17,11 @@ public VisualVerificationBaselineImageNotFoundException(
}

private static string GetExceptionMessage(string path, int maxRetryCount) =>
maxRetryCount == 0 ? $"Baseline image file not found, thus it was created automatically under the path {path}."
+ " Please set its \"Build action\" to \"Embedded resource\" if you want to deploy a self-contained"
+ " (like a NuGet package) UI testing assembly. If you run the test again, this newly created verification"
+ " file will be asserted against and the assertion will pass (unless the display of the app changed in the"
+ " meantime)."
: $"Baseline image file was not found under the path {path} and maxRetryCount is set to "
+ $"{maxRetryCount.ToTechnicalString()}, so it won't be generated. Set maxRetryCount to 0 to generate images.";
maxRetryCount == 0 || GitHubHelper.IsGitHubEnvironment
? $"Baseline image file not found, thus it was created automatically under the path {path}. Please set " +
$"its \"Build action\" to \"Embedded resource\" if you want to deploy a self-contained (like a NuGet " +
$"package) UI testing assembly. If you run the test again, this newly created verification file will " +
$"be asserted against and the assertion will pass (unless the display of the app changed in the meantime)."
: $"Baseline image file was not found under the path {path} and maxRetryCount is set to "
+ $"{maxRetryCount.ToTechnicalString()}, so it won't be generated. Set maxRetryCount to 0 to generate images.";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Atata;
using Lombiq.HelpfulLibraries.Common.Utilities;
using Lombiq.Tests.UI.Services;
using Microsoft.IdentityModel.Tokens;
using OpenQA.Selenium;
using Shouldly;
using System;
Expand Down Expand Up @@ -120,7 +121,8 @@ public static void ErrorMessageExists(this UITestContext context, string errorMe
/// </summary>
public static void VerifyElementTexts(this UITestContext context, By by, params object[] toMatch)
{
context.Exists(by); // Ensure content is loaded first.
// Ensure content is loaded first.
context.DoWithRetriesOrFail(() => !context.Get(by).Text.Trim().IsNullOrEmpty());

var dontCare = toMatch
.Select((item, index) => item == null ? index : -1)
Expand Down
61 changes: 61 additions & 0 deletions Lombiq.Tests.UI/Extensions/EmailUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,65 @@ public static async Task<IWebElement> FindSpecificEmailInInboxAsync(

return currentlySelectedEmail;
}

/// <summary>
/// Navigates to the <c>/Admin/Settings/email</c> page.
/// </summary>
public static Task GoToEmailSettingsAsync(this UITestContext context) =>
context.GoToAdminRelativeUrlAsync("/Settings/email");

/// <summary>
/// Navigates to the <c>/Admin/Email/Test</c> page.
/// </summary>
public static Task GoToEmailTestAsync(this UITestContext context) =>
context.GoToAdminRelativeUrlAsync("/Email/Test");

/// <summary>
/// Fills out the form on the email test page by specifying the recipient address, subject and message body. If the
/// <paramref name="submit"/> is <see langword="true"/>, it also clicks on the send button.
/// </summary>
public static async Task FillEmailTestFormAsync(
this UITestContext context,
string to,
string subject,
string body,
bool submit = true)
{
await context.FillInWithRetriesAsync(By.Id("To"), to);
await context.FillInWithRetriesAsync(By.Id("Subject"), subject);
await context.FillInWithRetriesAsync(By.Id("Body"), body);

if (submit) await context.ClickReliablyOnSubmitAsync();
}

/// <summary>
/// A simplified version of <see cref="FillEmailTestFormAsync(UITestContext,string,string,string,bool)"/> where the
/// sender if <c>"[email protected]"</c> and the message body is <c>"Hi, this is a test."</c>.
/// </summary>
public static Task FillEmailTestFormAsync(this UITestContext context, string subject) =>
context.FillEmailTestFormAsync("[email protected]", subject, "Hi, this is a test.");

/// <summary>
/// Goes to the Email settings and sets the SMTP port to the value of <paramref name="port"/>. If it's <see
/// langword="null"/> then the value in the current configuration (in <see
/// cref="OrchardCoreUITestExecutorConfiguration.SmtpServiceConfiguration"/>) is used instead.
/// The <c>OrchardCore.Email.Smtp</c> feature must be enabled, but if the SMTP provider is not turned on, this will
/// automatically do it as well.
/// </summary>
public static async Task ConfigureSmtpPortAsync(this UITestContext context, int? port = null, bool publish = true)
{
await context.GoToEmailSettingsAsync();
await context.ClickReliablyOnAsync(By.CssSelector("a[href='#tab-s-m-t-p']"));

var byIsEnabled = By.Id("ISite_SmtpSettings_IsEnabled").OfAnyVisibility();
if (context.Get(byIsEnabled).GetAttribute("checked") == null)
{
await context.SetCheckboxValueAsync(byIsEnabled, isChecked: true);
}

var smtpPort = (port ?? context.Configuration.SmtpServiceConfiguration.Context.Port).ToTechnicalString();
await context.ClickAndFillInWithRetriesAsync(By.Id("ISite_SmtpSettings_Port"), smtpPort);

if (publish) await context.ClickReliablyOnAsync(By.ClassName("save"));
}
}
Loading