-
Notifications
You must be signed in to change notification settings - Fork 20
Bap 98 create project template for behaviour.automation #98
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
Merged
ILastovka
merged 6 commits into
main
from
BAP-98-create-project-template-for-behaviour.automation
Feb 4, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2cdb3ee
Added Behavioral.Automation.Template folder with projects to create t…
ILastovka 7473524
Reference Behavioral.Automation package version 1.*
ILastovka 43c3ad8
Deleted nuget.config from Template solution
ILastovka 09e2426
Code review
ILastovka 5aa6017
Added TextElementWrapper realization
ILastovka 777d6af
Temporarily cleared Build instructions section of readme.md
ILastovka 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
25 changes: 25 additions & 0 deletions
25
Behavioral.Automation.Template/.template.config/template.json
This file contains hidden or 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,25 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Quantori LLC", | ||
| "classifications": [ | ||
| "BDD", | ||
| "Automation" | ||
| ], | ||
| "identity": "BDDTemplate", | ||
| "name": "Template for Behavioral Automation Framework", | ||
| "sourceName": "Behavioral.Automation.Template", | ||
| "shortName": "bddautomation", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| }, | ||
| "sources": [ | ||
| { | ||
| "modifiers": [ | ||
| { | ||
| "exclude": [ ".vs/**", "**/**.feature.cs", "**.nuspec" ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
14 changes: 14 additions & 0 deletions
14
Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json
This file contains hidden or 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,14 @@ | ||
| { | ||
| "BASE_URL": "http://localhost:4200/", | ||
| "TEST_EMAIL": "", | ||
| "TEST_PASSWORD": "", | ||
| "BASE_AUTH_URL": "", | ||
| "BROWSER_PARAMS": "--window-size=1920,1080", | ||
| "ACCESS_CLIPBOARD": false, | ||
| "DOWNLOAD_PATH": "", | ||
| "SEARCH_ATTRIBUTE": "id", | ||
| "BAUTH_LOGIN": "", | ||
| "BAUTH_PWD": "", | ||
| "BAUTH_IGNORE": "true", | ||
| "BROWSER_BINARY_LOCATION" : "" | ||
| } |
21 changes: 21 additions & 0 deletions
21
...te/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj
This file contains hidden or 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,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <IsPackable>false</IsPackable> | ||
| <Authors>Quantori Inc.</Authors> | ||
| <Description>Demo project that can be used as example of test configuration.</Description> | ||
| <RepositoryUrl>https://github.com/quantori/Behavioral.Automation</RepositoryUrl> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Behavioral.Automation" Version="1.8.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="AutomationConfig.json"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
29 changes: 29 additions & 0 deletions
29
...n.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs
This file contains hidden or 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,29 @@ | ||
| using Behavioral.Automation.Services; | ||
| using Behavioral.Automation.Services.Mapping.Contract; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.ElementStorage | ||
| { | ||
| public class UserInterfaceBuilder : UserInterfaceBuilderBase | ||
| { | ||
| public UserInterfaceBuilder(IScopeMarkupMapper mapper) | ||
| : base(mapper) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public override void Build() | ||
| { | ||
| using (var mappingPipe = Mapper.GetGlobalMappingPipe()) | ||
| { | ||
| mappingPipe.Register("input").Alias("input") | ||
| .With("searchInput").As("Search"); | ||
|
|
||
| mappingPipe.Register("input").Alias("button") | ||
| .With("searchButton").As("Magnifying glass"); | ||
|
|
||
| mappingPipe.Register("h1") | ||
| .With("firstHeading").As("Page header"); | ||
| } | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...on.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/TextElementWrapper.cs
This file contains hidden or 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.Diagnostics.CodeAnalysis; | ||
| using Behavioral.Automation.Elements; | ||
| using Behavioral.Automation.FluentAssertions; | ||
| using Behavioral.Automation.Model; | ||
| using Behavioral.Automation.Services; | ||
| using OpenQA.Selenium; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.ElementWrappers | ||
| { | ||
| public sealed class TextElementWrapper : WebElementWrapper, ITextElementWrapper | ||
| { | ||
| public TextElementWrapper([NotNull] IWebElementWrapper wrapper, string caption, [NotNull] IDriverService driverService) | ||
| : base(() => wrapper.Element, caption, driverService) { } | ||
|
|
||
| public void EnterString(string input) | ||
| { | ||
| Assert.ShouldBecome(() => Enabled, true, | ||
| new AssertionBehavior(AssertionType.Continuous, false), | ||
| $"{Caption} is not enabled"); | ||
| Element.SendKeys(input); | ||
| Driver.RemoveFocusFromActiveElement(); | ||
| } | ||
|
|
||
| public void ClearInput() | ||
| { | ||
| Assert.ShouldBecome(() => Enabled, true, | ||
| new AssertionBehavior(AssertionType.Continuous, false), | ||
| $"{Caption} is not enabled"); | ||
|
|
||
| while (Element.GetAttribute("value").Length > 0) | ||
| { | ||
| Element.SendKeys(Keys.Backspace); | ||
| } | ||
| Driver.RemoveFocusFromActiveElement(); | ||
| } | ||
| } | ||
| } |
122 changes: 122 additions & 0 deletions
122
...ion.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/WebElementWrapper.cs
This file contains hidden or 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,122 @@ | ||
| using Behavioral.Automation.Elements; | ||
| using Behavioral.Automation.FluentAssertions; | ||
| using Behavioral.Automation.Services; | ||
| using OpenQA.Selenium; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.ElementWrappers | ||
| { | ||
| public class WebElementWrapper : IWebElementWrapper | ||
| { | ||
| private readonly Func<IWebElement> _elementSelector; | ||
| private readonly IDriverService _driverService; | ||
|
|
||
| public WebElementWrapper([NotNull] Func<IWebElement> elementSelector, [NotNull] string caption, [NotNull] IDriverService driverService) | ||
| { | ||
| _elementSelector = elementSelector; | ||
| _driverService = driverService; | ||
| Caption = caption; | ||
| } | ||
|
|
||
| public string Caption { get; } | ||
|
|
||
| public IWebElement Element => _elementSelector(); | ||
|
|
||
| public string Text => Element.Text; | ||
|
|
||
| public string GetAttribute(string attribute) => Element.GetAttribute(attribute); | ||
|
|
||
| public void Click() | ||
| { | ||
| MouseHover(); | ||
| Assert.ShouldGet(() => Enabled); | ||
| _driverService.MouseClick(); | ||
| } | ||
|
|
||
| public void MouseHover() | ||
| { | ||
| Assert.ShouldBecome(() => Enabled, true, $"{Caption} is disabled"); | ||
| _driverService.ScrollTo(Element); | ||
| } | ||
|
|
||
| public void SendKeys(string text) | ||
| { | ||
| Assert.ShouldBecome(() => Enabled, true, $"{Caption} is disabled"); | ||
| Element.SendKeys(text); | ||
| } | ||
|
|
||
| public bool Displayed => Element != null && Element.Displayed; | ||
|
|
||
| public bool Enabled => Displayed && Element.Enabled && AriaEnabled; | ||
|
|
||
| public string Tooltip | ||
| { | ||
| get | ||
| { | ||
| var matTooltip = GetAttribute("matTooltip"); | ||
| if (matTooltip != null) | ||
| { | ||
| return matTooltip; | ||
| } | ||
| var ngReflectTip = GetAttribute("ng-reflect-message"); //some elements have their tooltips' texts stored inside 'ng-reflect-message' attribute | ||
| if (ngReflectTip != null) | ||
| { | ||
| return ngReflectTip; | ||
| } | ||
|
|
||
| return GetAttribute("aria-label"); //some elements have their tooltips' texts stored inside 'aria-label' attribute | ||
| } | ||
| } | ||
|
|
||
| public bool Stale | ||
| { | ||
| get | ||
| { | ||
| try | ||
| { | ||
| // Calling any method forces a staleness check | ||
| var elementEnabled = Element.Enabled; | ||
| return false; | ||
| } | ||
| catch (StaleElementReferenceException) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public IEnumerable<IWebElementWrapper> FindSubElements(By locator, string caption) | ||
| { | ||
| var elements = Assert.ShouldGet(() => Element.FindElements(locator)); | ||
| return ElementsToWrappers(elements, caption); | ||
| } | ||
|
|
||
| private IEnumerable<IWebElementWrapper> ElementsToWrappers(IEnumerable<IWebElement> elements, string caption) | ||
| { | ||
| foreach (var element in elements) | ||
| { | ||
| var wrapper = new WebElementWrapper(() => element, caption, _driverService); | ||
| yield return wrapper; | ||
| } | ||
| } | ||
|
|
||
| protected IDriverService Driver => _driverService; | ||
|
|
||
| private bool AriaEnabled | ||
| { | ||
| get | ||
| { | ||
| switch (Element.GetAttribute("aria-disabled")) | ||
| { | ||
| case null: | ||
| case "false": | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Hooks/Bootstrapper.cs
This file contains hidden or 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,42 @@ | ||
| using Behavioral.Automation.FluentAssertions; | ||
| using Behavioral.Automation.Services; | ||
| using Behavioral.Automation.Template.Bindings.ElementStorage; | ||
| using BoDi; | ||
| using TechTalk.SpecFlow; | ||
| using Behavioral.Automation; | ||
| using Behavioral.Automation.Template.Bindings.Services; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.Hooks | ||
| { | ||
| [Binding] | ||
| public class Bootstrapper | ||
| { | ||
| private readonly IObjectContainer _objectContainer; | ||
| private readonly ITestRunner _runner; | ||
| private readonly DemoTestServicesBuilder _servicesBuilder; | ||
| private readonly BrowserRunner _browserRunner; | ||
|
|
||
| public Bootstrapper(IObjectContainer objectContainer, ITestRunner runner, BrowserRunner browserRunner) | ||
| { | ||
| _objectContainer = objectContainer; | ||
| _runner = runner; | ||
| _browserRunner = browserRunner; | ||
| _servicesBuilder = new DemoTestServicesBuilder(objectContainer, new TestServicesBuilder(_objectContainer)); | ||
| } | ||
|
|
||
| [AfterScenario] | ||
| public void CloseBrowser() | ||
| { | ||
| _browserRunner.CloseBrowser(); | ||
| } | ||
|
|
||
| [BeforeScenario(Order = 0)] | ||
| public void Bootstrap() | ||
| { | ||
| Assert.SetRunner(_runner); | ||
| _objectContainer.RegisterTypeAs<UserInterfaceBuilder, IUserInterfaceBuilder>(); | ||
| _servicesBuilder.Build(); | ||
| _browserRunner.OpenChrome(); | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...tion.Template/Behavioral.Automation.Template.Bindings/Services/DemoTestServicesBuilder.cs
This file contains hidden or 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,22 @@ | ||
| using BoDi; | ||
| using Behavioral.Automation; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.Services | ||
| { | ||
| internal class DemoTestServicesBuilder | ||
| { | ||
| private readonly IObjectContainer _objectContainer; | ||
| private readonly TestServicesBuilder _servicesBuilder; | ||
|
|
||
| internal DemoTestServicesBuilder(IObjectContainer objectContainer, TestServicesBuilder servicesBuilder) | ||
| { | ||
| _objectContainer = objectContainer; | ||
| _servicesBuilder = servicesBuilder; | ||
| } | ||
|
|
||
| internal void Build() | ||
| { | ||
| _servicesBuilder.Build(); | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...vioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs
This file contains hidden or 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 Behavioral.Automation.Template.Bindings.ElementWrappers; | ||
| using Behavioral.Automation.Elements; | ||
| using Behavioral.Automation.Services; | ||
| using JetBrains.Annotations; | ||
| using TechTalk.SpecFlow; | ||
|
|
||
| namespace Behavioral.Automation.Template.Bindings.StepArgumentTransformations | ||
| { | ||
| [Binding] | ||
| class ElementTransformations | ||
| { | ||
| private readonly IDriverService _driverService; | ||
| private readonly IElementSelectionService _selectionService; | ||
|
|
||
| public ElementTransformations( | ||
| [NotNull] IDriverService driverService, | ||
| [NotNull] IElementSelectionService selectionService) | ||
| { | ||
| _driverService = driverService; | ||
| _selectionService = selectionService; | ||
| } | ||
|
|
||
| [StepArgumentTransformation] | ||
| public IWebElementWrapper FindElement([NotNull] string caption) | ||
| { | ||
| return new WebElementWrapper(() => _selectionService.Find(caption), | ||
| caption, | ||
| _driverService); | ||
| } | ||
|
|
||
| [StepArgumentTransformation("(.*)")] | ||
| public ITextElementWrapper FindTextElement([NotNull] IWebElementWrapper element) | ||
| { | ||
| return new TextElementWrapper(element, element.Caption, _driverService); | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
.../Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj
This file contains hidden or 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,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <Authors>Quantori Inc.</Authors> | ||
| <Description>Specflow scenarios for demonstration of Behavioral.Automation framework features and testing.</Description> | ||
| <Copyright>Quantori Inc.</Copyright> | ||
| <RepositoryUrl>https://github.com/quantori/Behavioral.Automation</RepositoryUrl> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> | ||
| <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="96.0.4664.4500" /> | ||
| <PackageReference Include="SpecFlow" Version="3.9.40" /> | ||
| <PackageReference Include="SpecFlow.NUnit" Version="3.9.40" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="specflow.json"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
andrey-brovko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <ProjectReference Include="..\Behavioral.Automation.Template.Bindings\Behavioral.Automation.Template.Bindings.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
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.
Uh oh!
There was an error while loading. Please reload this page.