Skip to content

Commit 12b904a

Browse files
authored
Merge pull request #101 from quantori/bindings-refactoring
BAP-113 Bindings refactoring
2 parents c3b8275 + 9afd55c commit 12b904a

18 files changed

+141
-148
lines changed

Behavioral.Automation.DemoBindings/Behavioral.Automation.DemoBindings.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Selenium.Support" Version="4.1.0" />
1313
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
14-
<PackageReference Include="SpecFlow" Version="3.9.40" />
14+
<PackageReference Include="SpecFlow" Version="3.9.50" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

Behavioral.Automation.DemoScenarios/Behavioral.Automation.DemoScenarios.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1313
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="96.0.4664.4500" />
14-
<PackageReference Include="SpecFlow" Version="3.9.40" />
15-
<PackageReference Include="SpecFlow.NUnit" Version="3.9.40" />
16-
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.40" />
14+
<PackageReference Include="SpecFlow" Version="3.9.50" />
15+
<PackageReference Include="SpecFlow.NUnit" Version="3.9.50" />
16+
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.50" />
1717
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
1818
</ItemGroup>
1919

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
[1.8.1] - 2022-01-27
7+
[1.8.5] - 2022-01-27
88
### Changed
9-
- Changed scope selector to use global scope if provided one is not defined
9+
- Bindings code refactoring
10+
- Updated Specflow package version

src/Behavioral.Automation/Behavioral.Automation.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
@@ -16,7 +16,7 @@ The whole automation code is divided into the following parts:
1616
- UI structure descriptive code
1717
- Supportive code</Description>
1818
<Copyright>Quantori Inc.</Copyright>
19-
<PackageVersion>1.8.1</PackageVersion>
19+
<PackageVersion>1.8.5</PackageVersion>
2020
<RepositoryUrl>https://github.com/quantori/Behavioral.Automation</RepositoryUrl>
2121
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2222
<IncludeSymbols>true</IncludeSymbols>
@@ -25,7 +25,7 @@ The whole automation code is divided into the following parts:
2525
<ItemGroup>
2626
<PackageReference Include="ExcelDataReader" Version="3.6.0" />
2727
<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
28-
<PackageReference Include="FluentAssertions" Version="6.2.0" />
28+
<PackageReference Include="FluentAssertions" Version="6.4.0" />
2929
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
3030
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
3131
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
@@ -38,7 +38,7 @@ The whole automation code is divided into the following parts:
3838
<PackageReference Include="NUnit" Version="3.13.2" />
3939
<PackageReference Include="Selenium.Support" Version="4.1.0" />
4040
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
41-
<PackageReference Include="SpecFlow" Version="3.9.40" />
41+
<PackageReference Include="SpecFlow" Version="3.9.50" />
4242
</ItemGroup>
4343

4444
</Project>

src/Behavioral.Automation/Bindings/AttributeBinding.cs

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using Behavioral.Automation.Elements;
43
using Behavioral.Automation.FluentAssertions;
54
using Behavioral.Automation.Model;
5+
using Behavioral.Automation.Services;
66
using JetBrains.Annotations;
77
using TechTalk.SpecFlow;
88

99
namespace Behavioral.Automation.Bindings
10-
{ /// <summary>
10+
{
11+
/// <summary>
1112
/// Bindings for element's attributes testing
1213
/// </summary>
1314
[Binding]
1415
public sealed class AttributeBinding
1516
{
16-
private readonly ITestRunner _runner;
17+
private readonly RunnerService _runnerService;
18+
private readonly ScenarioContext _scenarioContext;
1719

18-
public AttributeBinding([NotNull] ITestRunner runner)
20+
public AttributeBinding([NotNull] RunnerService runnerService, [NotNull] ScenarioContext scenarioContext)
1921
{
20-
_runner = runner;
22+
_runnerService = runnerService;
23+
_scenarioContext = scenarioContext;
2124
}
2225

2326
/// <summary>
@@ -41,18 +44,7 @@ public void CheckElementIsDisabled(
4144
}
4245

4346
/// <summary>
44-
/// Transform "enabled" or "disabled" string into bool value
45-
/// </summary>
46-
/// <param name="enabled">"enabled" or "disabled" string</param>
47-
/// <returns></returns>
48-
[StepArgumentTransformation("(enabled|disabled)")]
49-
public bool ConvertEnabledState([NotNull] string enabled)
50-
{
51-
return enabled == "enabled";
52-
}
53-
54-
/// <summary>
55-
/// Check that multiple elements are disabled or enabled in "Then" steps
47+
/// Check that multiple elements are disabled or enabled
5648
/// </summary>
5749
/// <param name="behavior">Assertion behavior (instant or continuous)</param>
5850
/// <param name="enabled">Elements expected status (enabled or disabled)</param>
@@ -63,28 +55,13 @@ public bool ConvertEnabledState([NotNull] string enabled)
6355
/// | "Test1" input |
6456
/// | "Test2" input |
6557
/// </example>
58+
[Given("the following controls (are|are not|become|become not) (enabled|disabled)")]
6659
[Then("the following controls should (be|be not|become|become not) (enabled|disabled):")]
67-
public void CheckThenControlTypeCollectionShown([NotNull] string behavior, string enabled, [NotNull] Table table)
60+
public void CheckControlTypeCollectionShown([NotNull] string behavior, string enabled, [NotNull] Table table)
6861
{
69-
behavior = $"should {behavior}";
70-
CheckControlTypeCollectionEnabled(behavior, enabled, table, _runner.Then);
71-
}
62+
behavior = _runnerService.ConvertBehaviorForGroupRun(_scenarioContext, behavior);
7263

73-
/// <summary>
74-
/// Check that multiple elements are disabled or enabled in "Given" or "When" steps
75-
/// </summary>
76-
/// <param name="behavior">Assertion behavior (instant or continuous)</param>
77-
/// <param name="enabled">>Elements expected status (enabled or disabled)</param>
78-
/// <param name="table">Specflow table with element names to be tested</param>
79-
[Given("the following controls (are|are not|become| become not) (enabled|disabled):")]
80-
[When("the following controls (are|are not|become| become not) (enabled|disabled):")]
81-
public void CheckGivenControlTypeCollectionEnabled([NotNull] string behavior, string enabled, [NotNull] Table table)
82-
{
83-
if (behavior.Contains("are"))
84-
{
85-
behavior = behavior.Replace("are", "is");
86-
}
87-
CheckControlTypeCollectionEnabled(behavior, enabled, table, _runner.Given);
64+
CheckControlTypeCollectionEnabled(behavior, enabled, table);
8865
}
8966

9067
/// <summary>
@@ -97,11 +74,11 @@ public void CheckGivenControlTypeCollectionEnabled([NotNull] string behavior, st
9774
private void CheckControlTypeCollectionEnabled(
9875
[NotNull] string behavior,
9976
string enabled,
100-
[NotNull] Table table,
101-
[NotNull] Action<string> runnerAction)
77+
[NotNull] Table table)
10278
{
10379
foreach (var row in table.Rows)
10480
{
81+
var runnerAction = _runnerService.GetRunner(_scenarioContext);
10582
var control = "the \"" + row.Values.First() + "\" " + row.Values.Last();
10683
runnerAction($"{control} {behavior} {enabled}");
10784
}

src/Behavioral.Automation/Bindings/ClickBinding.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void ClickThreeTimes([NotNull] IWebElementWrapper element)
7575
/// <param name="index">Number of the tested element in the collection</param>
7676
/// <param name="element">Tested web element wrapper</param>
7777
/// <example>When user clicks at first element among "Test" buttons (note that numbers from 1 to 10 can be written as words)</example>
78+
[Given("user clicked at (.*) element among (.*)")]
7879
[When("user clicks at (.*) element among (.*)")]
7980
public void ClickByIndex(int index, IElementCollectionWrapper elements)
8081
{
@@ -87,6 +88,7 @@ public void ClickByIndex(int index, IElementCollectionWrapper elements)
8788
/// <param name="index">Number of the tested element in the collection</param>
8889
/// <param name="element">Tested web element wrapper</param>
8990
/// <example>When user clicks twice at first element among "Test" buttons (note that numbers from 1 to 10 can be written as words)</example>
91+
[Given("user clicked twice at (.*) element among (.*)")]
9092
[When("user clicks twice at (.*) element among (.*)")]
9193
public void ClickTwiceByIndex(int index, IElementCollectionWrapper elements)
9294
{
@@ -100,6 +102,7 @@ public void ClickTwiceByIndex(int index, IElementCollectionWrapper elements)
100102
/// <param name="index">Number of the tested element in the collection</param>
101103
/// <param name="element">Tested web element wrapper</param>
102104
/// <example>When user clicks three times at first element among "Test" buttons (note that numbers from 1 to 10 can be written as words)</example>
105+
[Given("user clicked three times at (.*) element among (.*)")]
103106
[When("user clicks three times at (.*) element among (.*)")]
104107
public void ClickByIndexThreeTimes(int index, IElementCollectionWrapper elements)
105108
{
@@ -113,6 +116,7 @@ public void ClickByIndexThreeTimes(int index, IElementCollectionWrapper elements
113116
/// </summary>
114117
/// <param name="element">Tested web element wrapper</param>
115118
/// <example>When user hovers mouse over "Test" button</example>
119+
[Given("user hovered mouse over (.*)")]
116120
[When("user hovers mouse over (.*)")]
117121
public void HoverMouse(IWebElementWrapper element)
118122
{

src/Behavioral.Automation/Bindings/ControlScopeSelectionBinding.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,5 @@ public void ExecuteActionInsideControlScope(ControlScopeSelector controlScopeSel
9191
controlScopeRuntime.RunAction(action, stepDefinitionType);
9292
}
9393
}
94-
95-
9694
}
9795
}

src/Behavioral.Automation/Bindings/DropdownBinding.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void CheckSelectedValue([NotNull] IDropdownWrapper wrapper, AssertionBeha
5050
/// | Test value 1 |
5151
/// | Test value 2 |
5252
/// </example>
53+
[Given("the (.+?) has the following values:")]
5354
[Then("the (.*?) should have the following values:")]
5455
public void CheckAllItems([NotNull] IDropdownWrapper wrapper, [NotNull] Table items)
5556
{
@@ -67,6 +68,7 @@ public void CheckAllItems([NotNull] IDropdownWrapper wrapper, [NotNull] Table it
6768
/// | Group header 1 |
6869
/// | Group header 2 |
6970
/// </example>
71+
[Given("the (.+?) has the following groups:")]
7072
[Then("(.*?) should have the following groups:")]
7173
public void CheckDropdownHeaders([NotNull] IGroupedDropdownWrapper wrapper, [NotNull] Table items)
7274
{
@@ -128,6 +130,7 @@ public void CheckDropdownContainsMultipleItems([NotNull] IDropdownWrapper wrappe
128130
/// <param name="behavior">Assertion behavior (instant or continuous)</param>
129131
/// <param name="value">Expected value</param>
130132
/// <example>Then "Test" dropdown should have "Test value" in all elements</example>
133+
[Given("all items in the (.+?) (have|does not have) \"(.+?)\"")]
131134
[Then("all items in the (.+?) should (have|not have) \"(.+?)\"")]
132135
public void CheckAllItemsContainString(
133136
[NotNull] IDropdownWrapper wrapper,

src/Behavioral.Automation/Bindings/ElementTransformations.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public AssertionBehavior ParseBehavior(string verb)
5151
}
5252
}
5353

54-
/// <summary>
55-
/// Convert strings into the numbers
56-
/// </summary>
57-
/// <param name="number">String with the number which is received from Specflow steps</param>
54+
/// <summary>
55+
/// Convert strings into the numbers
56+
/// </summary>
57+
/// <param name="number">String with the number which is received from Specflow steps</param>
5858
/// <returns></returns>
5959
[StepArgumentTransformation, NotNull]
6060
public int ParseNumber(string number)
@@ -75,6 +75,17 @@ public int ParseNumber(string number)
7575
};
7676
}
7777

78+
/// <summary>
79+
/// Transform "enabled" or "disabled" string into bool value
80+
/// </summary>
81+
/// <param name="enabled">"enabled" or "disabled" string</param>
82+
/// <returns></returns>
83+
[StepArgumentTransformation("(enabled|disabled)")]
84+
public bool ConvertEnabledState([NotNull] string enabled)
85+
{
86+
return enabled == "enabled";
87+
}
88+
7889
[StepArgumentTransformation]
7990
public ControlScopeSelector ParseControlScopeSelector(string selectionSteps)
8091
{

src/Behavioral.Automation/Bindings/InputBinding.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void ClearInput([NotNull] ITextElementWrapper element)
5353
/// | "Test value" | Test1 | input |
5454
/// | "Test value" | Test2 | input |
5555
/// </example>
56+
[Given("user entered the following values into the following controls:")]
5657
[When("user enters the following values into the following controls:")]
5758
public void EnterInputIntoMultipleControls([NotNull] Table table)
5859
{

0 commit comments

Comments
 (0)