- Remove
Lombiq.Tests.UI.AppExtensions
project reference or NuGet package from the web app, if yourProgram
file/class not using functionality from it (e.g.configuration.IsUITesting()
). - Add
Microsoft.Extensions.Configuration.ConfigurationManager
instance directly toWebApplicationBuilder.Services
in yourProgram
file/class.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Logging;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseNLogHost();
var configuration = builder.Configuration;
- builder.Services.AddOrchardCms(orchard => orchard.ConfigureUITesting(configuration, enableShortcutsDuringUITesting: true));
+ builder.Services
.AddSingleton(configuration);
+ .AddOrchardCms();
var app = builder.Build();
app.UseStaticFiles();
app.UseOrchardCore();
app.Run();
+ [SuppressMessage(
+ "Design",
+ "CA1050: Declare types in namespaces",
+ Justification = "As described here: https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests.")]
+ public partial class Program
+ {
+ protected Program()
+ {
+ // Nothing to do here.
+ }
+ }
-
Add a project reference of the web app to be tested to the UI test project:
</ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\src\Lombiq.OSOCE.Web\Lombiq.OSOCE.Web.csproj" /> <ProjectReference Include="..\..\src\Modules\Lombiq.ChartJs\Lombiq.ChartJs.Tests.UI\Lombiq.ChartJs.Tests.UI.csproj" /> <ProjectReference Include="..\..\src\Modules\Lombiq.DataTables\Lombiq.DataTables\Tests\Lombiq.DataTables.Tests.UI\Lombiq.DataTables.Tests.UI.csproj" /> <ProjectReference Include="..\..\src\Modules\Lombiq.HelpfulExtensions\Lombiq.HelpfulExtensions.Tests.UI\Lombiq.HelpfulExtensions.Tests.UI.csproj" />
-
Change
OrchardCoreUITestBase
implementation like below.AppAssemblyPath
is not required anymore:namespace Lombiq.OSOCE.Tests.UI; - public class UITestBase : OrchardCoreUITestBase + public class UITestBase : OrchardCoreUITestBase<Program> { - protected override string AppAssemblyPath => WebAppConfigHelper - .GetAbsoluteApplicationAssemblyPath("Lombiq.OSOCE.Web", "net6.0");
There is a breaking change in adding command line arguments to the WebApplication:
-
To add a command line argument with value, use
InstanceCommandLineArgumentsBuilder.AddWithValue
instead of the two calls toArgumentsBuilder.Add
:configuration.HtmlValidationConfiguration.RunHtmlValidationAssertionOnAllPageChanges = false; configuration.OrchardCoreConfiguration.BeforeAppStart += (_, argsBuilder) => { - argsBuilder.Add("--OrchardCore:OrchardCore_Admin:AdminUrlPrefix").Add("custom-admin"); + argsBuilder.AddWithValue("OrchardCore:OrchardCore_Admin:AdminUrlPrefix", "custom-admin"); return Task.CompletedTask; };
-
To add a command line switch, use
InstanceCommandLineArgumentsBuilder.AddSwitch
.
The following extension methods behave largely the same and their signatures didn't change. Using WebApplicationFactory
made it possible to use OC services directly instead of using controller actions invoked via browser navigation.
As a consequence, calling the below extension methods does not cause browser navigation anymore:
SetUserRegistrationTypeAsync
CreateUserAsync
AddUserToRoleAsync
AddPermissionToRoleAsync
EnableFeatureDirectlyAsync
DisableFeatureDirectlyAsync
ExecuteRecipeDirectlyAsync
SelectThemeAsync
GenerateHttpEventUrlAsync
public static async Task EnablePrivacyConsentBannerFeatureAndAcceptPrivacyConsentAsync(this UITestContext context)
{
await context.EnablePrivacyConsentBannerFeatureAsync();
- await context.GoToHomePageAsync();
+ await context.GoToHomePageAsync(onlyIfNotAlreadyThere: false);
await context.AcceptPrivacyConsentAsync();
context.Refresh();
}
The original code with the new behavior failed a test, because the browser pointed to the Home page before await context.EnablePrivacyConsentBannerFeatureAsync()
was called. Consequently, the context.EnableFeatureDirectlyAsync()
didn't navigate away, the await context.GoToHomePageAsync()
call did nothing, and the consent banner didn't appear.
The solution, in this case, is to call await context.GoToHomePageAsync(onlyIfNotAlreadyThere: false)
. This results in a page reload, and the consent banner appears.