-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Microsoft.Playwright; | ||
using OrchardCoreContrib.Testing.UI.Infrastructure; | ||
using Xunit; | ||
|
||
namespace OrchardCoreContrib.Testing.UI; | ||
|
||
/// <summary> | ||
/// Represents a UI testing class that extends <see cref="UITestBase{TStartup}"/>. | ||
/// </summary> | ||
/// <param name="browserType">The browser type that will be used during the test. Defaults to <see cref="BrowserType.Edge"/>.</param> | ||
/// <param name="headless">Whether the browser runs in headless mode or not. Defaults to <c>true</c>.</param> | ||
/// <typeparam name="TStartup">The startup class type that will be used as entry point.</typeparam> | ||
public class UITest<TStartup>(BrowserType browserType = BrowserType.Edge, bool headless = true) : | ||
UITestBase<TStartup>(new WebApplicationFactoryFixture<TStartup>()), | ||
IAsyncLifetime where TStartup : class | ||
{ | ||
private IPlaywright _playwright; | ||
|
||
/// <summary> | ||
/// Gets the browser instance to be used during the test. | ||
/// </summary> | ||
public IBrowser Browser { get; private set; } | ||
|
||
/// <inheritdoc/> | ||
public async Task InitializeAsync() | ||
{ | ||
_playwright = await Playwright.CreateAsync(); | ||
|
||
Browser = await BrowserFactory.CreateAsync(_playwright, browserType, headless); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task DisposeAsync() | ||
{ | ||
_playwright.Dispose(); | ||
|
||
await Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OrchardCoreContrib.Testing.UI.Tests; | ||
|
||
public static class PageHelper | ||
{ | ||
public static string GetFullPath(string pageName) | ||
=> new Uri(Path.Combine(Environment.CurrentDirectory, "Pages", pageName)).AbsoluteUri; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/OrchardCoreContrib.Testing.UI.Tests/UITestOfTTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace OrchardCoreContrib.Testing.UI.Tests; | ||
|
||
public class UITestOfTTests : UITest<UITestOfTTests.SimpleStartup> | ||
{ | ||
[Fact] | ||
public async Task RunTest() | ||
{ | ||
// Arrange | ||
var test = new UITest<SimpleStartup>(); | ||
|
||
// Act | ||
await test.InitializeAsync(); | ||
|
||
// Assert | ||
Assert.NotNull(test.Browser); | ||
Assert.NotNull(test.BaseUrl); | ||
} | ||
|
||
[Fact] | ||
public async Task NavigateToHomePage() | ||
{ | ||
// Arrange & Act | ||
var page = await Browser.OpenPageAsync(BaseUrl + "foo"); | ||
|
||
// Assert | ||
Assert.Contains("Hello, world!", page.Content); | ||
} | ||
|
||
public class SimpleStartup | ||
{ | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Map("/foo", app => | ||
{ | ||
app.Run(async context => await context.Response.WriteAsync("Hello, world!")); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,29 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
namespace OrchardCoreContrib.Testing.UI.Tests; | ||
|
||
namespace OrchardCoreContrib.Testing.UI.Tests; | ||
|
||
public class UITestTests : UITest<UITestTests.SimpleStartup> | ||
public class UITestTests : UITest | ||
{ | ||
[Fact] | ||
public async Task RunTest() | ||
{ | ||
// Arrange | ||
var test = new UITest<SimpleStartup>(); | ||
var test = new UITest(); | ||
|
||
// Act | ||
await test.InitializeAsync(); | ||
|
||
// Assert | ||
Assert.NotNull(test.Browser); | ||
Assert.NotNull(test.BaseUrl); | ||
} | ||
|
||
[Fact] | ||
public async Task NavigateToHomePage() | ||
{ | ||
// Arrange & Act | ||
var page = await Browser.OpenPageAsync(BaseUrl + "foo"); | ||
// Arrange | ||
var url = PageHelper.GetFullPath("index.html"); | ||
// Act | ||
var page = await Browser.OpenPageAsync(url); | ||
|
||
// Assert | ||
Assert.Contains("Hello, world!", page.Content); | ||
} | ||
|
||
public class SimpleStartup | ||
{ | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Map("/foo", app => | ||
{ | ||
app.Run(async context => await context.Response.WriteAsync("Hello, world!")); | ||
}); | ||
} | ||
Assert.Contains("Orchard Core Contrib", page.Title); | ||
} | ||
} |