-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add label element #154
Open
Oleg-Mozhey
wants to merge
2
commits into
main
Choose a base branch
from
feature/add_label_element
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions
7
Behavioral.Automation.AsyncAbstractions.UI/Interfaces/ILabelElement.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,7 @@ | ||
namespace Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
|
||
public interface ILabelElement : IWebElement | ||
{ | ||
public Task ShouldHaveTextAsync(string text); | ||
public Task ShouldNotHaveTextAsync(string text); | ||
} |
35 changes: 35 additions & 0 deletions
35
Behavioral.Automation.AsyncAbstractions.UI/StepDefinitions/LabelStepDefinitions.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 TechTalk.SpecFlow; | ||
|
||
namespace Behavioral.Automation.AsyncAbstractions.UI.StepDefinitions; | ||
|
||
[Binding] | ||
public class LabelStepDefinitions | ||
{ | ||
/// <summary> | ||
/// Check that element's text is equal to the expected one | ||
/// </summary> | ||
/// <param name="label">Tested label object</param> | ||
/// <param name="type">Assertion behavior</param> | ||
/// <param name="value">Expected value</param> | ||
/// <example>Then "Test" element text should be "expected text"</example> | ||
[Given("the \"(.*?)\" label text (is|is not) \"(.*)\"")] | ||
[Then("the \"(.*?)\" label text should (become|become not) \"(.*)\"")] | ||
public async Task CheckSelectedText(ILabelElement label, string type, string value) | ||
{ | ||
if (type.Equals("is") || type.Equals("become")) | ||
{ | ||
await label.ShouldHaveTextAsync(value); | ||
} | ||
else | ||
{ | ||
await label.ShouldNotHaveTextAsync(value); | ||
} | ||
} | ||
|
||
[Then(@"the ""(.*)"" label should become visible")] | ||
public async Task CheckLabelVisibility(ILabelElement label) | ||
{ | ||
await label.ShouldBecomeVisibleAsync(); | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
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,15 +1,10 @@ | ||
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"}; | ||
public LabelSelector DemoLabel = new() {IdSelector = "label-simple-text"}; | ||
public LabelSelector CountQuantityLabel = new LabelSelector() {IdSelector = "count-quantity-label"}; | ||
} |
8 changes: 8 additions & 0 deletions
8
Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Selectors/LabelSelector.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 LabelSelector : ElementSelector | ||
{ | ||
|
||
} |
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
24 changes: 24 additions & 0 deletions
24
...utomation.Playwright/Behavioral.Automation.Playwright/WebElementsWrappers/LabelElement.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,24 @@ | ||
using System.Threading.Tasks; | ||
using Behavioral.Automation.AsyncAbstractions.UI.BasicImplementations; | ||
using Behavioral.Automation.AsyncAbstractions.UI.Interfaces; | ||
using Behavioral.Automation.Playwright.Selectors; | ||
using Microsoft.Playwright; | ||
|
||
namespace Behavioral.Automation.Playwright.WebElementsWrappers; | ||
|
||
public class LabelElement : PlaywrightWebElement, ILabelElement | ||
{ | ||
public LabelElement(WebContext webContext, LabelSelector selector) : base(webContext, selector) | ||
{ | ||
} | ||
|
||
public async Task ShouldHaveTextAsync(string text) | ||
{ | ||
await Assertions.Expect(Locator).ToHaveTextAsync(text); | ||
} | ||
|
||
public async Task ShouldNotHaveTextAsync(string text) | ||
{ | ||
await Assertions.Expect(Locator).Not.ToHaveTextAsync(text); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
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; | ||
|
@@ -11,6 +13,8 @@ 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(); | ||
|
@@ -28,10 +32,18 @@ public ILocator Locator | |
{ | ||
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); | ||
if (ElementSelector.XpathSelector != null) | ||
{ | ||
return ((Page) WebContext.Page).GetPlaywrightPage().Locator(ElementSelector.XpathSelector); | ||
} | ||
|
||
if (ElementSelector.IdSelector != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess automation id selector has more priority than xpath if provided, no? |
||
{ | ||
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"); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to have selector validation here ? Does it mean that we will need to have it in every wrapper method? Isn't it better to have different class and methods for getting Locators, which will check the selector inside them ? E.G. - GetLocator(ElementSelector selector), GetSubLocator(ElementSelector selector, ElementSelector subSelector), GetParentLocator(ElementSelector selector, ElementSelector parentSelector) ?