Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Behavioral.Automation.Template/.template.config/template.json
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" ]
}
]
}
]
}
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" : ""
}
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>
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");
}
}
}
}
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();
}
}
}
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;
}
}
}
}
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();
}
}
}
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();
}
}
}
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);
}
}
}
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>
<ProjectReference Include="..\Behavioral.Automation.Template.Bindings\Behavioral.Automation.Template.Bindings.csproj" />
</ItemGroup>

</Project>
Loading