-
-
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.
Refactor UITest abstraction & implementation APIs
- Loading branch information
Showing
5 changed files
with
80 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Xunit; | ||
|
||
namespace OrchardCoreContrib.Testing.UI; | ||
|
||
/// <summary> | ||
/// Represents a contract for UI test. | ||
/// </summary> | ||
public interface IUITest : IAsyncLifetime | ||
{ | ||
/// <summary> | ||
/// Gets or sets the browser instance to be used during the test. | ||
/// </summary> | ||
public IBrowser Browser { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the options used during the test. | ||
/// </summary> | ||
public UITestOptions Options { get; } | ||
} |
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,17 @@ | ||
using Microsoft.Playwright; | ||
using Xunit; | ||
|
||
namespace OrchardCoreContrib.Testing.UI; | ||
namespace OrchardCoreContrib.Testing.UI; | ||
|
||
/// <summary> | ||
/// Represents a UI testing class. | ||
/// </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> | ||
public class UITest(BrowserType browserType = BrowserType.Edge, bool headless = true) : IAsyncLifetime | ||
{ | ||
private IPlaywright _playwright; | ||
|
||
/// <summary> | ||
/// Gets the browser instance to be used during the test. | ||
/// </summary> | ||
public IBrowser Browser { get; private set; } | ||
|
||
public UITestOptions Options { get; private set; } | ||
|
||
/// <inheritdoc/> | ||
public async Task InitializeAsync() | ||
/// <param name="delay">The amount of time to wait between execute two actions. Defaults to <c>0</c>.</param> | ||
public class UITest(BrowserType browserType = BrowserType.Edge, bool headless = true, int delay = 0) | ||
: UITestBase(new UITestOptions | ||
{ | ||
Options = new UITestOptions | ||
{ | ||
BrowserType = browserType, | ||
Headless = headless | ||
}; | ||
|
||
_playwright = await Playwright.CreateAsync(); | ||
|
||
Browser = await BrowserFactory.CreateAsync(_playwright, Options); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task DisposeAsync() | ||
{ | ||
_playwright.Dispose(); | ||
|
||
await Task.CompletedTask; | ||
} | ||
BrowserType = browserType, | ||
Headless = headless, | ||
Delay = delay | ||
}) | ||
{ | ||
} |
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,18 +1,34 @@ | ||
using OrchardCoreContrib.Testing.UI.Infrastructure; | ||
using Microsoft.Playwright; | ||
|
||
namespace OrchardCoreContrib.Testing.UI; | ||
|
||
/// <summary> | ||
/// Represents a base class for UI testing. | ||
/// </summary> | ||
/// <typeparam name="TStartup">The startup class that will be used as entry point.</typeparam> | ||
/// <param name="fixture">The <see cref="WebApplicationFactoryFixture{TStartup}"/>.</param> | ||
public abstract class UITestBase<TStartup>(WebApplicationFactoryFixture<TStartup> fixture) where TStartup : class | ||
public abstract class UITestBase(UITestOptions testOptions) : IUITest | ||
{ | ||
private IPlaywright _playwright; | ||
|
||
/// <summary> | ||
/// Gets or sets the browser instance to be used during the test. | ||
/// </summary> | ||
public IBrowser Browser { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the base URL used for the tested website. | ||
/// Gets the options used during the test. | ||
/// </summary> | ||
public string BaseUrl => fixture.ServerAddress; | ||
public UITestOptions Options => testOptions; | ||
|
||
/// <inheritdoc/> | ||
public virtual async Task InitializeAsync() | ||
{ | ||
_playwright = await Playwright.CreateAsync(); | ||
|
||
Browser = await BrowserFactory.CreateAsync(_playwright, Options); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public virtual async Task DisposeAsync() | ||
{ | ||
_playwright.Dispose(); | ||
|
||
public UITestOptions Options { get; protected set; } | ||
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,17 @@ | ||
using OrchardCoreContrib.Testing.UI.Infrastructure; | ||
|
||
namespace OrchardCoreContrib.Testing.UI; | ||
|
||
/// <summary> | ||
/// Represents a base class for UI testing. | ||
/// </summary> | ||
/// <typeparam name="TStartup">The startup class that will be used as entry point.</typeparam> | ||
/// <param name="fixture">The <see cref="WebApplicationFactoryFixture{TStartup}"/>.</param> | ||
public abstract class UITestBase<TStartup>(WebApplicationFactoryFixture<TStartup> fixture, UITestOptions testOptions) | ||
: UITestBase(testOptions) where TStartup : class | ||
{ | ||
/// <summary> | ||
/// Gets the base URL used for the tested website. | ||
/// </summary> | ||
public string BaseUrl => fixture.ServerAddress; | ||
} |
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