-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageFactory.cs
More file actions
37 lines (31 loc) · 1.01 KB
/
Copy pathPageFactory.cs
File metadata and controls
37 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace OrchardCoreContrib.Testing.UI.PageObjects;
/// <summary>
/// Represents a factory for creating page objects.
/// </summary>
public class PageFactory
{
private static IPage _page;
private static string _baseUrl;
/// <summary>
/// Initializes the page factory.
/// </summary>
/// <param name="browser">The <see cref="IBrowser"/>.</param>
/// <param name="baseUrl">The base URL.</param>
/// <returns></returns>
public static async Task InitializeAsync(IBrowser browser, string baseUrl)
{
_page = await browser.OpenPageAsync(baseUrl);
_baseUrl = baseUrl;
}
/// <summary>
/// Creates a page object of the specified type.
/// </summary>
/// <typeparam name="TPage">The page type.</typeparam>
public static async Task<TPage> CreateAsync<TPage>() where TPage : PageBase
{
var page = Activator.CreateInstance<TPage>();
page.Page = _page;
page.BaseUrl = _baseUrl;
return (TPage)await page.GoToAsync();
}
}