diff --git a/src/OrchardCoreContrib.Testing.UI/Browser.cs b/src/OrchardCoreContrib.Testing.UI/Browser.cs
index 2211910..416e313 100644
--- a/src/OrchardCoreContrib.Testing.UI/Browser.cs
+++ b/src/OrchardCoreContrib.Testing.UI/Browser.cs
@@ -11,7 +11,7 @@ namespace OrchardCoreContrib.Testing.UI;
/// The .
/// The .
/// Whether to run browser in headless mode.
-public class Browser(IPlaywrightBrowserAccessor playwrightBrowserAccessor, int delay) : IBrowser
+public class Browser(IPlaywrightBrowserAccessor playwrightBrowserAccessor) : IBrowser
{
///
public PlaywrightBrowser InnerBrowser => playwrightBrowserAccessor.PlaywrightBrowser;
@@ -20,10 +20,10 @@ public class Browser(IPlaywrightBrowserAccessor playwrightBrowserAccessor, int d
public BrowserType Type { get; set; }
///
- public int Delay => delay;
+ public string Version { get; set; } = playwrightBrowserAccessor.PlaywrightBrowser.Version;
///
- public string Version { get; set; } = playwrightBrowserAccessor.PlaywrightBrowser.Version;
+ public UITestOptions TestOptions { get; set; }
///
public async Task OpenPageAsync(string url)
@@ -32,7 +32,7 @@ public async Task OpenPageAsync(string url)
await playwrightPage.GotoAsync(url);
- var page = new Page(new PlaywrightPageAccessor(playwrightPage))
+ var page = new Page(new PlaywrightPageAccessor(playwrightPage), this)
{
Title = await playwrightPage.TitleAsync(),
Content = await playwrightPage.ContentAsync()
diff --git a/src/OrchardCoreContrib.Testing.UI/BrowserFactory.cs b/src/OrchardCoreContrib.Testing.UI/BrowserFactory.cs
index fbc951f..7bd959d 100644
--- a/src/OrchardCoreContrib.Testing.UI/BrowserFactory.cs
+++ b/src/OrchardCoreContrib.Testing.UI/BrowserFactory.cs
@@ -39,6 +39,10 @@ public static async Task CreateAsync(IPlaywright playwright, UITestOpt
_ => throw new NotSupportedException()
};
- return new Browser(new PlaywrightBrowserAccessor(browser)) { Type = testOptions.BrowserType };
+ return new Browser(new PlaywrightBrowserAccessor(browser))
+ {
+ Type = testOptions.BrowserType,
+ TestOptions = testOptions
+ };
}
}
diff --git a/src/OrchardCoreContrib.Testing.UI/Element.cs b/src/OrchardCoreContrib.Testing.UI/Element.cs
index 0cf7c0b..c6e23ba 100644
--- a/src/OrchardCoreContrib.Testing.UI/Element.cs
+++ b/src/OrchardCoreContrib.Testing.UI/Element.cs
@@ -7,14 +7,15 @@ namespace OrchardCoreContrib.Testing.UI;
///
/// The .
/// The .
-public class Element(IPage page, ILocator locator) : IElement
+/// The .
+public class Element(ILocator locator, IPage page) : IElement
{
- private readonly LocatorClickOptions _locatorClickOptions = page.Browser.Delay == 0
+ private readonly LocatorClickOptions _locatorClickOptions = page.Browser.TestOptions.Delay == 0
? null
- : new() { Delay = page.Browser.Delay };
- private readonly LocatorPressSequentiallyOptions _locatorPressSequentiallyOptions = page.Browser.Delay == 0
+ : new() { Delay = page.Browser.TestOptions.Delay };
+ private readonly LocatorPressSequentiallyOptions _locatorPressSequentiallyOptions = page.Browser.TestOptions.Delay == 0
? null
- : new() { Delay = page.Browser.Delay };
+ : new() { Delay = page.Browser.TestOptions.Delay };
IPage IElement.Page => page;
@@ -36,7 +37,7 @@ public class Element(IPage page, ILocator locator) : IElement
///
public async Task TypeAsync(string text)
{
- await locator.FillAsync(text);
+ await locator.PressSequentiallyAsync(text, _locatorPressSequentiallyOptions);
InnerText = await locator.InnerTextAsync();
InnerHtml = await locator.InnerHTMLAsync();
diff --git a/src/OrchardCoreContrib.Testing.UI/IBrowser.cs b/src/OrchardCoreContrib.Testing.UI/IBrowser.cs
index 11946e4..1b78e1f 100644
--- a/src/OrchardCoreContrib.Testing.UI/IBrowser.cs
+++ b/src/OrchardCoreContrib.Testing.UI/IBrowser.cs
@@ -10,6 +10,11 @@ public interface IBrowser
///
public Microsoft.Playwright.IBrowser InnerBrowser { get; }
+ ///
+ /// Gets the test options that will be applied;
+ ///
+ public UITestOptions TestOptions { get; set; }
+
///
/// Gets or sets the browser type.
///
diff --git a/src/OrchardCoreContrib.Testing.UI/Page.cs b/src/OrchardCoreContrib.Testing.UI/Page.cs
index 979f5ad..52ac48e 100644
--- a/src/OrchardCoreContrib.Testing.UI/Page.cs
+++ b/src/OrchardCoreContrib.Testing.UI/Page.cs
@@ -9,11 +9,14 @@ namespace OrchardCoreContrib.Testing.UI;
/// Creates an instance of .
///
/// The .
-public class Page(IPlaywrightPageAccessor playwrightPageAccessor) : IPage
+/// The .
+public class Page(IPlaywrightPageAccessor playwrightPageAccessor, IBrowser browser) : IPage
{
///
public Microsoft.Playwright.IPage InnerPage => playwrightPageAccessor.PlaywrightPage;
+ IBrowser IPage.Browser => browser;
+
///
public string Title { get; set; }
@@ -33,7 +36,7 @@ public async Task GoToAsync(string url)
public IElement FindElement(string selector)
{
var locator = InnerPage.Locator(selector);
- var element = new Element(locator)
+ var element = new Element(locator, this)
{
InnerText = locator.InnerTextAsync().GetAwaiter().GetResult(),
InnerHtml = locator.InnerHTMLAsync().GetAwaiter().GetResult(),
diff --git a/src/OrchardCoreContrib.Testing.UI/UITestOptions.cs b/src/OrchardCoreContrib.Testing.UI/UITestOptions.cs
index 068244c..598e587 100644
--- a/src/OrchardCoreContrib.Testing.UI/UITestOptions.cs
+++ b/src/OrchardCoreContrib.Testing.UI/UITestOptions.cs
@@ -14,4 +14,9 @@ public class UITestOptions
/// Gets or sets the browser type to run the test on. Defaults .
///
public BrowserType BrowserType { get; set; } = BrowserType.Edge;
+
+ ///
+ /// Gets or sets amount of time to wait before executing each event on the page. Defaults 0.
+ ///
+ public int Delay { get; set; } = 0;
}
diff --git a/test/OrchardCoreContrib.Testing.UI.Tests/ElementTests.cs b/test/OrchardCoreContrib.Testing.UI.Tests/ElementTests.cs
index 79a8d48..b608829 100644
--- a/test/OrchardCoreContrib.Testing.UI.Tests/ElementTests.cs
+++ b/test/OrchardCoreContrib.Testing.UI.Tests/ElementTests.cs
@@ -2,11 +2,22 @@
public class ElementTests
{
+ private readonly Page _page;
+
+ public ElementTests()
+ {
+ var browser = new Browser(new PlaywrightBrowserAccessor(Mock.Of()))
+ {
+ TestOptions = new UITestOptions()
+ };
+ _page = new Page(new PlaywrightPageAccessor(Mock.Of()), browser);
+ }
+
[Fact]
public void GetElementInformation()
{
// Act
- var element = new Element(Mock.Of())
+ var element = new Element(Mock.Of(), _page)
{
InnerHtml = "Orchard Core Contrib
",
InnerText = "Orchard Core Contrib",
@@ -26,7 +37,7 @@ public async Task ClickElement()
{
// Arrange
var locatorMock = new Mock();
- var element = new Element(locatorMock.Object);
+ var element = new Element(locatorMock.Object, _page);
// Act
await element.ClickAsync();
@@ -40,13 +51,13 @@ public async Task TypeTextIntoElement()
{
// Arrange
var locatorMock = new Mock();
- locatorMock.Setup(l => l.FillAsync(It.IsAny(), null))
+ locatorMock.Setup(l => l.PressSequentiallyAsync(It.IsAny(), null))
.Callback(() =>
{
locatorMock.Setup(l => l.InnerTextAsync(null))
.ReturnsAsync("Orchard Core Contrib");
});
- var element = new Element(locatorMock.Object);
+ var element = new Element(locatorMock.Object, _page);
// Act
await element.TypeAsync("Orchard Core Contrib");
diff --git a/test/OrchardCoreContrib.Testing.UI.Tests/PageTests.cs b/test/OrchardCoreContrib.Testing.UI.Tests/PageTests.cs
index 40a8ed4..6a3702b 100644
--- a/test/OrchardCoreContrib.Testing.UI.Tests/PageTests.cs
+++ b/test/OrchardCoreContrib.Testing.UI.Tests/PageTests.cs
@@ -2,7 +2,15 @@ namespace OrchardCoreContrib.Testing.UI.Tests;
public class PageTests
{
- private readonly IBrowser _browser = Mock.Of();
+ private readonly Browser _browser;
+
+ public PageTests()
+ {
+ _browser = new Browser(new PlaywrightBrowserAccessor(Mock.Of()))
+ {
+ TestOptions = new UITestOptions()
+ };
+ }
[Fact]
public void ShouldCreatePage()
@@ -11,7 +19,7 @@ public void ShouldCreatePage()
var playwrightPageAccessor = new PlaywrightPageAccessor(Mock.Of());
// Act
- var page = new Page(_browser, playwrightPageAccessor);
+ var page = new Page(playwrightPageAccessor, _browser);
// Assert
Assert.NotNull(page);
@@ -33,7 +41,7 @@ public async Task GetPageInformation()
var playwrightPageAccessor = new PlaywrightPageAccessor(pageMock.Object);
// Act
- var page = new Page(_browser, playwrightPageAccessor);
+ var page = new Page(playwrightPageAccessor, _browser);
await page.GoToAsync("www.occ.com");
// Assert
@@ -52,7 +60,7 @@ public void ShouldFindElement()
var playwrightPageAccessor = new PlaywrightPageAccessor(pageMock.Object);
- var page = new Page(_browser, playwrightPageAccessor);
+ var page = new Page(playwrightPageAccessor, _browser);
// Act
var result = page.FindElement("selector");
diff --git a/test/OrchardCoreContrib.Testing.UI.Tests/PlaywrightPageHelper.cs b/test/OrchardCoreContrib.Testing.UI.Tests/PlaywrightPageHelper.cs
index 37e7f21..bf87057 100644
--- a/test/OrchardCoreContrib.Testing.UI.Tests/PlaywrightPageHelper.cs
+++ b/test/OrchardCoreContrib.Testing.UI.Tests/PlaywrightPageHelper.cs
@@ -6,12 +6,15 @@ public static async Task GotoAsync(string pageName)
{
var playwright = await Playwright.CreateAsync();
var playwrightBrowser = await playwright.Chromium.LaunchAsync();
- var browser = new Browser(new PlaywrightBrowserAccessor(playwrightBrowser), BrowserType.Edge, headless: true, delay: 0);
+ var browser = new Browser(new PlaywrightBrowserAccessor(playwrightBrowser))
+ {
+ TestOptions = new UITestOptions()
+ };
var page = await playwrightBrowser.NewPageAsync();
await page.GotoAsync(PageHelper.GetFullPath(pageName));
- return new Page(browser, new PlaywrightPageAccessor(page));
+ return new Page(new PlaywrightPageAccessor(page), browser);
}
}