-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPlayWrightWebElement.cs
More file actions
49 lines (42 loc) · 1.73 KB
/
Copy pathPlayWrightWebElement.cs
File metadata and controls
49 lines (42 loc) · 1.73 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
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Threading.Tasks;
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations;
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces;
using Behavioral.Automation.Configs;
using Behavioral.Automation.Playwright.Configs;
using Microsoft.Playwright;
namespace Behavioral.Automation.Playwright.WebElementsWrappers;
public abstract class PlaywrightWebElement : IWebElement
{
public WebContext WebContext { get; }
public ElementSelector ElementSelector { get; }
public string? Description { get; set; }
private static readonly string Id = ConfigManager.GetConfig<Config>().SearchAttribute;
public async Task ShouldBecomeVisibleAsync()
{
await Assertions.Expect(Locator).ToBeVisibleAsync();
}
protected PlaywrightWebElement(WebContext webContext, ElementSelector baseSelector)
{
ElementSelector = baseSelector;
WebContext = webContext;
}
public ILocator Locator
{
get
{
if (WebContext is null) throw new NullReferenceException("Please set web context.");
// Locator for Playwright can be retrieved from Page element:
if (ElementSelector.XpathSelector != null)
{
return ((Page) WebContext.Page).GetPlaywrightPage().Locator(ElementSelector.XpathSelector);
}
if (ElementSelector.IdSelector != null)
{
return ((Page) WebContext.Page).GetPlaywrightPage().Locator($"//*[@{Id}='{ElementSelector.IdSelector}']");
}
// TODO: Think about moving validation into element factory method or in element constructor
throw new Exception("Please provide XpathSelector or IdSelector");
}
}
}