-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
9cfacb5
commit f92ebe2
Showing
13 changed files
with
224 additions
and
4 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
4 changes: 3 additions & 1 deletion
4
...ywright/Behavioral.Automation.Playwright/ElementTransformations/ElementTransformations.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
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
3 changes: 3 additions & 0 deletions
3
Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Pages/MainPage.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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
using Behavioral.Automation.Configs; | ||
using Behavioral.Automation.Playwright.Configs; | ||
using Behavioral.Automation.Playwright.Selectors; | ||
using Behavioral.Automation.Playwright.Services.ElementSelectors; | ||
|
||
namespace Behavioral.Automation.Playwright.Pages; | ||
|
||
class MainPageExample : ISelectorStorage | ||
{ | ||
private static readonly string Id = ConfigManager.GetConfig<Config>().SearchAttribute; | ||
|
||
public ButtonSelector IncrementCountButton = new() {XpathSelector = "//button[@data-automation-id='increment-count-button']"}; | ||
|
||
public ElementSelector DemoLabel = new() {IdSelector = "label-simple-text"}; | ||
} |
8 changes: 8 additions & 0 deletions
8
...vioral.Automation.Playwright/Behavioral.Automation.Playwright/Selectors/ButtonSelector.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,8 @@ | ||
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations; | ||
|
||
namespace Behavioral.Automation.Playwright.Selectors; | ||
|
||
public class ButtonSelector : ElementSelector | ||
{ | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...tomation.Playwright/Behavioral.Automation.Playwright/Services/WebElementStorageService.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,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations; | ||
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
using Behavioral.Automation.Playwright.Pages; | ||
using Behavioral.Automation.Playwright.Utils; | ||
using BoDi; | ||
|
||
namespace Behavioral.Automation.Playwright.Services; | ||
|
||
public class WebElementStorageService : IWebElementStorageService | ||
{ | ||
private readonly WebContext _webContext; | ||
private readonly IObjectContainer _objectContainer; | ||
|
||
public WebElementStorageService(WebContext webContext, IObjectContainer objectContainer) | ||
{ | ||
_webContext = webContext; | ||
_objectContainer = objectContainer; | ||
} | ||
|
||
//TODO: Impl factory | ||
public T Get<T>(string elementName) where T : IWebElement | ||
{ | ||
var pages = GetAllPagesWithElements(); | ||
var elementSelector = GetElementSelector(pages, elementName); | ||
|
||
// Select proper realisation for element according to registered class in DI framework: | ||
var classType = IWebElementStorageService.RegisteredElements[typeof(T)]; | ||
var element = (IWebElement) Activator.CreateInstance(classType, _webContext, elementSelector); | ||
element.Description = elementName; | ||
return (T) element; | ||
} | ||
|
||
private IEnumerable<Type> GetAllPagesWithElements() | ||
{ | ||
var type = typeof(ISelectorStorage); | ||
return AppDomain.CurrentDomain.GetAssemblies() | ||
.SelectMany(s => s.GetTypes()) | ||
.Where(p => type.IsAssignableFrom(p) && p.IsClass); | ||
} | ||
|
||
private ElementSelector GetElementSelector(IEnumerable<Type> pages, string elementName) | ||
{ | ||
ElementSelector elementSelector = null; | ||
var camelCaseElementName = elementName.ToCamelCase(); | ||
|
||
foreach (var pageType in pages) | ||
{ | ||
var pageTemp = Activator.CreateInstance(pageType); | ||
var temp = (ElementSelector) pageType.GetField(camelCaseElementName)?.GetValue(pageTemp)!; | ||
if (elementSelector != null && temp != null) | ||
throw new Exception($"found the same selector '{elementName}' in different classes"); | ||
elementSelector ??= temp; | ||
} | ||
|
||
if (elementSelector == null) throw new Exception($"'{elementName}' transformed to '{camelCaseElementName}' selectors not found."); | ||
return elementSelector; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...tomation.Playwright/Behavioral.Automation.Playwright/WebElementsWrappers/ButtonElement.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,19 @@ | ||
using System.Threading.Tasks; | ||
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations; | ||
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
using Behavioral.Automation.Playwright.Selectors; | ||
|
||
namespace Behavioral.Automation.Playwright.WebElementsWrappers; | ||
|
||
public class ButtonElement: PlaywrightWebElement, IButtonElement | ||
{ | ||
|
||
public ButtonElement(WebContext webContext, ButtonSelector selector) : base(webContext, selector) | ||
{ | ||
} | ||
|
||
public async Task ClickAsync() | ||
{ | ||
await Locator.ClickAsync(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...vioral.Automation.Playwright/Behavioral.Automation.Playwright/WebElementsWrappers/Page.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,40 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Behavioral.Automation.Configs; | ||
using Behavioral.Automation.Playwright.Configs; | ||
using Microsoft.Playwright; | ||
using IPage = Behavioral.Automation.AsyncAbstractions.UI.Interfaces.IPage; | ||
|
||
namespace Behavioral.Automation.Playwright.WebElementsWrappers; | ||
|
||
public class Page: IPage | ||
{ | ||
private readonly Microsoft.Playwright.IPage _playwrightPage; | ||
|
||
|
||
public Page(Microsoft.Playwright.IPage playwrightPage) | ||
{ | ||
_playwrightPage = playwrightPage; | ||
} | ||
|
||
public Task GoToUrlAsync(string url) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task GoToApplicationUrlAsync() | ||
{ | ||
return _playwrightPage.GotoAsync(ConfigManager.GetConfig<Config>().BaseUrl, | ||
new PageGotoOptions { WaitUntil = WaitUntilState.NetworkIdle, Timeout = 300000 }); | ||
} | ||
|
||
public Task HaveTitleAsync(string title) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Microsoft.Playwright.IPage GetPlaywrightPage() | ||
{ | ||
return _playwrightPage; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...n.Playwright/Behavioral.Automation.Playwright/WebElementsWrappers/PlayWrightWebElement.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,37 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations; | ||
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
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; } | ||
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: | ||
var selector = (ElementSelector.XpathSelector != null) | ||
? ElementSelector.XpathSelector | ||
: ElementSelector.IdSelector; | ||
return ((Page) WebContext.Page).GetPlaywrightPage().Locator(selector); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Behavioral.Automation.Playwright/UITests/Configurations/Configurations.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,35 @@ | ||
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
using Behavioral.Automation.Playwright.Services; | ||
using Behavioral.Automation.Playwright.WebElementsWrappers; | ||
using BoDi; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace Behavioral.Automation.Playwright.Tests.Configurations; | ||
|
||
[Binding] | ||
public class Configurations | ||
{ | ||
private readonly ObjectContainer _objectContainer; | ||
|
||
// Configuration of DI and Factories should be done with order 0 | ||
public Configurations(ObjectContainer objectContainer) | ||
{ | ||
_objectContainer = objectContainer; | ||
} | ||
|
||
[BeforeTestRun(Order = 0)] | ||
public static void ConfigureUiImplementations() | ||
{ | ||
// IWebElementStorageService.RegisterWebElementImplementationAs<InputElement, IInputWebElement>(); | ||
IWebElementStorageService.RegisterWebElementImplementationAs<ButtonElement, IButtonElement>(); | ||
} | ||
|
||
/// <summary> | ||
/// According to our convention all interfaces registrations should go with 0 order | ||
/// </summary> | ||
[BeforeScenario(Order = 0)] | ||
public void Bootstrap() | ||
{ | ||
_objectContainer.RegisterTypeAs<WebElementStorageService, IWebElementStorageService>(); | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
Behavioral.Automation.Playwright/UITests/Features/Tests.feature
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
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