From 2cdb3eef8381c244c5081fe5e25929e9ef13c70c Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Wed, 26 Jan 2022 12:21:16 +0400 Subject: [PATCH 1/6] Added Behavioral.Automation.Template folder with projects to create template from --- .../.template.config/template.json | 25 ++++ .../AutomationConfig.json | 14 ++ ...vioral.Automation.Template.Bindings.csproj | 24 ++++ .../Bindings/ElementTransformations.cs | 31 +++++ .../Bootstrapper.cs | 41 ++++++ .../DemoTestServicesBuilder.cs | 22 ++++ .../Elements/WebElementWrapper.cs | 122 ++++++++++++++++++ .../Services/UserInterfaceBuilder.cs | 23 ++++ ...ioral.Automation.Template.Scenarios.csproj | 36 ++++++ .../Features/ExampleBinding.feature | 7 + .../Properties/AssemblyInfo.cs | 6 + .../specflow.json | 19 +++ .../Behavioral.Automation.Template.sln | 31 +++++ .../Behavioral.Automation.nuspec | 19 +++ Behavioral.Automation.Template/nuget.config | 12 ++ Behavioral.Automation.Template/readme.md | 15 +++ 16 files changed, 447 insertions(+) create mode 100644 Behavioral.Automation.Template/.template.config/template.json create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Properties/AssemblyInfo.cs create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/specflow.json create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.sln create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.nuspec create mode 100644 Behavioral.Automation.Template/nuget.config create mode 100644 Behavioral.Automation.Template/readme.md diff --git a/Behavioral.Automation.Template/.template.config/template.json b/Behavioral.Automation.Template/.template.config/template.json new file mode 100644 index 00000000..0358ab26 --- /dev/null +++ b/Behavioral.Automation.Template/.template.config/template.json @@ -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" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json new file mode 100644 index 00000000..e87898d9 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json @@ -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": "automation-id", + "BAUTH_LOGIN": "", + "BAUTH_PWD": "", + "BAUTH_IGNORE": "true", + "BROWSER_BINARY_LOCATION" : "" +} \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj new file mode 100644 index 00000000..3a2cbe67 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp3.1 + false + Quantori Inc. + Demo project that can be used as example of test configuration. + https://github.com/quantori/Behavioral.Automation + + + + + + + + + + + + Always + + + + diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs new file mode 100644 index 00000000..42ba9dcb --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs @@ -0,0 +1,31 @@ +using Behavioral.Automation.Template.Bindings.Elements; +using Behavioral.Automation.Elements; +using Behavioral.Automation.Services; +using JetBrains.Annotations; +using TechTalk.SpecFlow; + +namespace Behavioral.Automation.Template.Bindings +{ + [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); + } + } +} diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs new file mode 100644 index 00000000..1f640bbf --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs @@ -0,0 +1,41 @@ +using Behavioral.Automation.FluentAssertions; +using Behavioral.Automation.Services; +using Behavioral.Automation.Template.Services; +using BoDi; +using TechTalk.SpecFlow; +using Behavioral.Automation; + +namespace Behavioral.Automation.Template.Bindings +{ + [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(); + _servicesBuilder.Build(); + _browserRunner.OpenChrome(); + } + } +} diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs new file mode 100644 index 00000000..b6ccb9be --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs @@ -0,0 +1,22 @@ +using BoDi; +using Behavioral.Automation; + +namespace Behavioral.Automation.Template.Bindings +{ + 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(); + } + } +} \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs new file mode 100644 index 00000000..36c44926 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs @@ -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.Elements +{ + public class WebElementWrapper : IWebElementWrapper + { + private readonly Func _elementSelector; + private readonly IDriverService _driverService; + + public WebElementWrapper([NotNull] Func 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 FindSubElements(By locator, string caption) + { + var elements = Assert.ShouldGet(() => Element.FindElements(locator)); + return ElementsToWrappers(elements, caption); + } + + private IEnumerable ElementsToWrappers(IEnumerable 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; + } + } + } +} diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs new file mode 100644 index 00000000..a5db5e9a --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs @@ -0,0 +1,23 @@ +using Behavioral.Automation.Services; +using Behavioral.Automation.Services.Mapping.Contract; + +namespace Behavioral.Automation.Template.Services +{ + public class UserInterfaceBuilder : UserInterfaceBuilderBase + { + public UserInterfaceBuilder(IScopeMarkupMapper mapper) + : base(mapper) + { + + } + + public override void Build() + { + using (var mappingPipe = Mapper.GetGlobalMappingPipe()) + { + mappingPipe.Register("label").Alias("label") + .With("label-simple-text").As("Demo"); + } + } + } +} diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj new file mode 100644 index 00000000..ee5ed8a4 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj @@ -0,0 +1,36 @@ + + + + netcoreapp3.1 + Quantori Inc. + Specflow scenarios for demonstration of Behavioral.Automation framework features and testing. + Quantori Inc. + https://github.com/quantori/Behavioral.Automation + + + + + + + + + + + + + + + Always + + + + + + + + + + + + + \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature new file mode 100644 index 00000000..e1202f4c --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature @@ -0,0 +1,7 @@ +Feature: ExampleBinding + +@Automated +Scenario: Open Google page + When user opens URL "https://www.google.com/" + Then page title should become "Google" + diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Properties/AssemblyInfo.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..98c5f084 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using NUnit.Framework; + +[assembly: Parallelizable(ParallelScope.Fixtures)] + +//edit if more threads are needed +[assembly: LevelOfParallelism(1)] \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/specflow.json b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/specflow.json new file mode 100644 index 00000000..797f0043 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/specflow.json @@ -0,0 +1,19 @@ +{ + "bindingCulture": { + "language": "en-us" + }, + "language": { + "feature": "en-us" + }, + "runtime": { + "missingOrPendingStepsOutcome": "Error" + }, + "stepAssemblies": [ + { + "assembly": "Behavioral.Automation.Template.Bindings" + }, + { + "assembly": "Behavioral.Automation" + } + ] +} diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.sln b/Behavioral.Automation.Template/Behavioral.Automation.Template.sln new file mode 100644 index 00000000..8e1669d3 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Behavioral.Automation.Template.Bindings", "Behavioral.Automation.Template.Bindings\Behavioral.Automation.Template.Bindings.csproj", "{97A76E21-F1E4-49D8-B419-BAFD89B565BD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Behavioral.Automation.Template.Scenarios", "Behavioral.Automation.Template.Scenarios\Behavioral.Automation.Template.Scenarios.csproj", "{0958EBF8-72A6-45DA-A552-C9B18F6A1695}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {97A76E21-F1E4-49D8-B419-BAFD89B565BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97A76E21-F1E4-49D8-B419-BAFD89B565BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97A76E21-F1E4-49D8-B419-BAFD89B565BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97A76E21-F1E4-49D8-B419-BAFD89B565BD}.Release|Any CPU.Build.0 = Release|Any CPU + {0958EBF8-72A6-45DA-A552-C9B18F6A1695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0958EBF8-72A6-45DA-A552-C9B18F6A1695}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0958EBF8-72A6-45DA-A552-C9B18F6A1695}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0958EBF8-72A6-45DA-A552-C9B18F6A1695}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {762FF955-CF9D-4647-87C5-7F974941573C} + EndGlobalSection +EndGlobal diff --git a/Behavioral.Automation.Template/Behavioral.Automation.nuspec b/Behavioral.Automation.Template/Behavioral.Automation.nuspec new file mode 100644 index 00000000..0c93f776 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.nuspec @@ -0,0 +1,19 @@ + + + + Behavioral.Automation.Template + 1.7.0 + + Template for easy start with Behavioral.Automation framework + + Quantori LLC + + + + readme.md + + + + + + \ No newline at end of file diff --git a/Behavioral.Automation.Template/nuget.config b/Behavioral.Automation.Template/nuget.config new file mode 100644 index 00000000..3314a7f9 --- /dev/null +++ b/Behavioral.Automation.Template/nuget.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Behavioral.Automation.Template/readme.md b/Behavioral.Automation.Template/readme.md new file mode 100644 index 00000000..de35aa41 --- /dev/null +++ b/Behavioral.Automation.Template/readme.md @@ -0,0 +1,15 @@ +# Quantori Behavioral Automation Testing System +Copyright (c) 2022 Quantori. + +Quantori Behavioral Automation is an open-source framework for UI testing automation based on Selenium and Specflow which incorporates good portability and ability to be integrated into a custom web-application. Quantori Behavioral Automation is designed to be used by both manual and automation QA engineers in projects which are built based on Behaviour Driven Development approach. + +## KEY FEATURES +* Allows to create project for BDD Automation needs using Behavioral.Automation framework + +## Build instructions +Using cmd run these commands in order to create Behavioral.Automation project from template +dotnet new --install C:\Temp\Behavioral.Automation.Template.0.0.2.nupkg from command line --TODO replace with link after publishing the nuget +dotnet new bddautomation -o {outputDirectory} -n {desiredNamespace} + +## License +Quantori Behavioral Automation Testing System is released under [Apache License, Version 2.0](LICENSE) From 7473524ce68c88b26c6c846de55a44a5a8b3624a Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Wed, 26 Jan 2022 18:20:52 +0400 Subject: [PATCH 2/6] Reference Behavioral.Automation package version 1.* --- .../Behavioral.Automation.Template.Bindings.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj index 3a2cbe67..e9a6892a 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj @@ -12,7 +12,7 @@ - + From 43c3ad828281957f502e63142b7ec67873b69bbf Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Thu, 27 Jan 2022 12:50:29 +0400 Subject: [PATCH 3/6] Deleted nuget.config from Template solution --- Behavioral.Automation.Template/nuget.config | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 Behavioral.Automation.Template/nuget.config diff --git a/Behavioral.Automation.Template/nuget.config b/Behavioral.Automation.Template/nuget.config deleted file mode 100644 index 3314a7f9..00000000 --- a/Behavioral.Automation.Template/nuget.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file From 09e24269bcfe127d4b691146b30554cc8dff82c7 Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Wed, 2 Feb 2022 16:57:23 +0400 Subject: [PATCH 4/6] Code review --- .../Behavioral.Automation.Template.Bindings.csproj | 7 ++----- .../UserInterfaceBuilder.cs | 2 +- .../WebElementWrapper.cs | 2 +- .../{ => Hooks}/Bootstrapper.cs | 5 +++-- .../{ => Services}/DemoTestServicesBuilder.cs | 2 +- .../ElementTransformations.cs | 4 ++-- .../Behavioral.Automation.Template.Scenarios.csproj | 13 +++---------- 7 files changed, 13 insertions(+), 22 deletions(-) rename Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/{Services => ElementStorage}/UserInterfaceBuilder.cs (89%) rename Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/{Elements => ElementWrappers}/WebElementWrapper.cs (98%) rename Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/{ => Hooks}/Bootstrapper.cs (87%) rename Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/{ => Services}/DemoTestServicesBuilder.cs (90%) rename Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/{Bindings => StepArgumentTransformations}/ElementTransformations.cs (85%) diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj index e9a6892a..5fcba859 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Behavioral.Automation.Template.Bindings.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 false Quantori Inc. Demo project that can be used as example of test configuration. @@ -9,10 +9,7 @@ - - - - + diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs similarity index 89% rename from Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs rename to Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs index a5db5e9a..45194662 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/UserInterfaceBuilder.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs @@ -1,7 +1,7 @@ using Behavioral.Automation.Services; using Behavioral.Automation.Services.Mapping.Contract; -namespace Behavioral.Automation.Template.Services +namespace Behavioral.Automation.Template.Bindings.ElementStorage { public class UserInterfaceBuilder : UserInterfaceBuilderBase { diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/WebElementWrapper.cs similarity index 98% rename from Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs rename to Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/WebElementWrapper.cs index 36c44926..27e19e7b 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Elements/WebElementWrapper.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/WebElementWrapper.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -namespace Behavioral.Automation.Template.Bindings.Elements +namespace Behavioral.Automation.Template.Bindings.ElementWrappers { public class WebElementWrapper : IWebElementWrapper { diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Hooks/Bootstrapper.cs similarity index 87% rename from Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs rename to Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Hooks/Bootstrapper.cs index 1f640bbf..6c0dfc34 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bootstrapper.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Hooks/Bootstrapper.cs @@ -1,11 +1,12 @@ using Behavioral.Automation.FluentAssertions; using Behavioral.Automation.Services; -using Behavioral.Automation.Template.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 +namespace Behavioral.Automation.Template.Bindings.Hooks { [Binding] public class Bootstrapper diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/DemoTestServicesBuilder.cs similarity index 90% rename from Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs rename to Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/DemoTestServicesBuilder.cs index b6ccb9be..59026254 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/DemoTestServicesBuilder.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Services/DemoTestServicesBuilder.cs @@ -1,7 +1,7 @@ using BoDi; using Behavioral.Automation; -namespace Behavioral.Automation.Template.Bindings +namespace Behavioral.Automation.Template.Bindings.Services { internal class DemoTestServicesBuilder { diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs similarity index 85% rename from Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs rename to Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs index 42ba9dcb..6eec6922 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/Bindings/ElementTransformations.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs @@ -1,10 +1,10 @@ -using Behavioral.Automation.Template.Bindings.Elements; +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 +namespace Behavioral.Automation.Template.Bindings.StepArgumentTransformations { [Binding] class ElementTransformations diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj index ee5ed8a4..be043f26 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Behavioral.Automation.Template.Scenarios.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 Quantori Inc. Specflow scenarios for demonstration of Behavioral.Automation framework features and testing. Quantori Inc. @@ -11,11 +11,9 @@ - - - + + - @@ -24,11 +22,6 @@ - - - - - From 5aa601722905b9f6997ca9d8357b1b673b556d67 Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Thu, 3 Feb 2022 14:40:41 +0400 Subject: [PATCH 5/6] Added TextElementWrapper realization Added sample scenario --- .../AutomationConfig.json | 2 +- .../ElementStorage/UserInterfaceBuilder.cs | 10 ++++- .../ElementWrappers/TextElementWrapper.cs | 37 +++++++++++++++++++ .../ElementTransformations.cs | 6 +++ .../Features/ExampleBinding.feature | 7 ---- .../Features/Examples.feature | 13 +++++++ 6 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/TextElementWrapper.cs delete mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature create mode 100644 Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/Examples.feature diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json index e87898d9..e2d76509 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/AutomationConfig.json @@ -6,7 +6,7 @@ "BROWSER_PARAMS": "--window-size=1920,1080", "ACCESS_CLIPBOARD": false, "DOWNLOAD_PATH": "", - "SEARCH_ATTRIBUTE": "automation-id", + "SEARCH_ATTRIBUTE": "id", "BAUTH_LOGIN": "", "BAUTH_PWD": "", "BAUTH_IGNORE": "true", diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs index 45194662..2673f456 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementStorage/UserInterfaceBuilder.cs @@ -15,8 +15,14 @@ public override void Build() { using (var mappingPipe = Mapper.GetGlobalMappingPipe()) { - mappingPipe.Register("label").Alias("label") - .With("label-simple-text").As("Demo"); + 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"); } } } diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/TextElementWrapper.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/TextElementWrapper.cs new file mode 100644 index 00000000..bcdc8a9d --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/ElementWrappers/TextElementWrapper.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs index 6eec6922..cc181a23 100644 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Bindings/StepArgumentTransformations/ElementTransformations.cs @@ -27,5 +27,11 @@ public IWebElementWrapper FindElement([NotNull] string caption) caption, _driverService); } + + [StepArgumentTransformation("(.*)")] + public ITextElementWrapper FindTextElement([NotNull] IWebElementWrapper element) + { + return new TextElementWrapper(element, element.Caption, _driverService); + } } } diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature deleted file mode 100644 index e1202f4c..00000000 --- a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/ExampleBinding.feature +++ /dev/null @@ -1,7 +0,0 @@ -Feature: ExampleBinding - -@Automated -Scenario: Open Google page - When user opens URL "https://www.google.com/" - Then page title should become "Google" - diff --git a/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/Examples.feature b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/Examples.feature new file mode 100644 index 00000000..65166345 --- /dev/null +++ b/Behavioral.Automation.Template/Behavioral.Automation.Template.Scenarios/Features/Examples.feature @@ -0,0 +1,13 @@ +Feature: Examples + +@Automated +Scenario: Open Google page + When user opens URL "https://www.google.com/" + Then page title should become "Google" + +@Automated +Scenario: Find something on Wikipedia + When user opens URL "https://en.wikipedia.org/" + And user enters "French bulldog" into "Search" input + And user clicks on "Magnifying glass" button + Then the "Page header" text should become "French Bulldog" \ No newline at end of file From 777d6af846df9362d8f21d34c2036f240a26deae Mon Sep 17 00:00:00 2001 From: Igor Lastovka Date: Thu, 3 Feb 2022 15:07:56 +0400 Subject: [PATCH 6/6] Temporarily cleared Build instructions section of readme.md --- Behavioral.Automation.Template/readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Behavioral.Automation.Template/readme.md b/Behavioral.Automation.Template/readme.md index de35aa41..3a083e2f 100644 --- a/Behavioral.Automation.Template/readme.md +++ b/Behavioral.Automation.Template/readme.md @@ -7,9 +7,7 @@ Quantori Behavioral Automation is an open-source framework for UI testing automa * Allows to create project for BDD Automation needs using Behavioral.Automation framework ## Build instructions -Using cmd run these commands in order to create Behavioral.Automation project from template -dotnet new --install C:\Temp\Behavioral.Automation.Template.0.0.2.nupkg from command line --TODO replace with link after publishing the nuget -dotnet new bddautomation -o {outputDirectory} -n {desiredNamespace} +TBD ## License Quantori Behavioral Automation Testing System is released under [Apache License, Version 2.0](LICENSE)