Skip to content

Commit

Permalink
Add SpecFlow BDD tests for blazor examples
Browse files Browse the repository at this point in the history
Blazor: Allow multiple test assembles in the testbutton

Blazor: Add SpecFlow test suites, enabling writing GUI tests
in the Gherkin language.
  • Loading branch information
toniarnold committed Feb 14, 2023
1 parent b44caa6 commit 5a2763e
Show file tree
Hide file tree
Showing 53 changed files with 1,451 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Technical Documentation](./doc/toc.md)

[Most recent development: Blazor Server](./doc/blazor.md),
[Most recent development: Blazor Server with SpecFlow](./doc/blazor.md),
[LinkedIn-Artikelserie (in German)](https://www.linkedin.com/pulse/blazor-1-disruptive-entwicklungen-toni-arnold)

## [Don't Develop GUI Tests, Teach Your App To Test Itself!](http://www.drdobbs.com/testing/dont-develop-gui-tests-teach-your-app-to/240168468) - in ASP.NET/NUnit/C#
Expand Down
40 changes: 27 additions & 13 deletions asp.blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "asp.blazor", "src\asp.blazo
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc", "doc\doc.vcxproj", "{80277C55-F818-4639-A4AB-8E42F013FA8B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calculator.blazor", "src\asp.blazor\CalculatorSmc\calculator.blazor.vcxproj", "{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calculator.blazor", "src\asp.blazor\CalculatorSmc\calculator.blazor.vcxproj", "{BAC05072-44C6-4C3E-A938-F987E16324CF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iselenium.blazor", "src\iselenium.blazor\iselenium.blazor.csproj", "{C42178F0-41FC-4631-8EEF-A50C4020E83C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "asptest.blazor.bunit", "src\asptest.blazor.bunit\asptest.blazor.bunit.csproj", "{CF3AD587-533F-4944-A47E-213AE41F4DF6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "asptestrunner.blazor", "src\asptestrunner.blazor\asptestrunner.blazor.csproj", "{64259526-AEED-485B-9824-14C19ED16915}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asptest.blazor.specflow", "src\asptest.blazor.specflow\asptest.blazor.specflow.csproj", "{91A7610B-757E-4B56-BFCC-CDBFF020A692}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -147,18 +149,18 @@ Global
{80277C55-F818-4639-A4AB-8E42F013FA8B}.Release|x64.Build.0 = Release|x64
{80277C55-F818-4639-A4AB-8E42F013FA8B}.Release|x86.ActiveCfg = Release|Win32
{80277C55-F818-4639-A4AB-8E42F013FA8B}.Release|x86.Build.0 = Release|Win32
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|Any CPU.ActiveCfg = Debug|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|Any CPU.Build.0 = Debug|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|x64.ActiveCfg = Debug|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|x64.Build.0 = Debug|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|x86.ActiveCfg = Debug|Win32
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Debug|x86.Build.0 = Debug|Win32
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|Any CPU.ActiveCfg = Release|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|Any CPU.Build.0 = Release|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|x64.ActiveCfg = Release|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|x64.Build.0 = Release|x64
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|x86.ActiveCfg = Release|Win32
{69EB69AB-0D24-4974-8D7D-2D2CDB62DCFA}.Release|x86.Build.0 = Release|Win32
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|Any CPU.ActiveCfg = Debug|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|Any CPU.Build.0 = Debug|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|x64.ActiveCfg = Debug|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|x64.Build.0 = Debug|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|x86.ActiveCfg = Debug|Win32
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Debug|x86.Build.0 = Debug|Win32
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|Any CPU.ActiveCfg = Release|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|Any CPU.Build.0 = Release|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|x64.ActiveCfg = Release|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|x64.Build.0 = Release|x64
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|x86.ActiveCfg = Release|Win32
{BAC05072-44C6-4C3E-A938-F987E16324CF}.Release|x86.Build.0 = Release|Win32
{C42178F0-41FC-4631-8EEF-A50C4020E83C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C42178F0-41FC-4631-8EEF-A50C4020E83C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C42178F0-41FC-4631-8EEF-A50C4020E83C}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -195,6 +197,18 @@ Global
{64259526-AEED-485B-9824-14C19ED16915}.Release|x64.Build.0 = Release|Any CPU
{64259526-AEED-485B-9824-14C19ED16915}.Release|x86.ActiveCfg = Release|Any CPU
{64259526-AEED-485B-9824-14C19ED16915}.Release|x86.Build.0 = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|x64.ActiveCfg = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|x64.Build.0 = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|x86.ActiveCfg = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Debug|x86.Build.0 = Debug|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|Any CPU.Build.0 = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|x64.ActiveCfg = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|x64.Build.0 = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|x86.ActiveCfg = Release|Any CPU
{91A7610B-757E-4B56-BFCC-CDBFF020A692}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
26 changes: 26 additions & 0 deletions aspnettest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget-info", "nuget-info",
nuget-info\version.txt = nuget-info\version.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp1SpecFlowTest", "src\template.blazor\src\BlazorApp1SpecFlowTest\BlazorApp1SpecFlowTest.csproj", "{81B353D4-1FCC-4400-91D3-F17787018CAE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1701,6 +1703,30 @@ Global
{85AD8957-3B5C-4704-A8EE-7DC75A5AB6EE}.ReleaseNoTrace|x64.Build.0 = Release|Any CPU
{85AD8957-3B5C-4704-A8EE-7DC75A5AB6EE}.ReleaseNoTrace|x86.ActiveCfg = Release|Any CPU
{85AD8957-3B5C-4704-A8EE-7DC75A5AB6EE}.ReleaseNoTrace|x86.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|x64.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|x64.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|x86.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Debug|x86.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|Any CPU.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|Any CPU.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|x64.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|x64.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|x86.ActiveCfg = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.DebugNoTrace|x86.Build.0 = Debug|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|Any CPU.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|x64.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|x64.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|x86.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.Release|x86.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|Any CPU.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|Any CPU.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|x64.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|x64.Build.0 = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|x86.ActiveCfg = Release|Any CPU
{81B353D4-1FCC-4400-91D3-F17787018CAE}.ReleaseNoTrace|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions nuget-info/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
* Blazor: Add URL QueryString persistence, enable it with:
`"SessionStorage": "UrlQuery"`

* Blazor: Allow multiple test assemblies in the `<testbutton>`

* Add SpecFlow test suite, enabling writing GUI tests
in the Gherkin language.

* Add optional ViewState gzip compression, enable it with:
`"ViewStateCompressionLevel": "Optimal"`
which sets a `System.IO.Compression.CompressionLevel`
Expand Down
2 changes: 1 addition & 1 deletion src/asp.blazor/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<CalculatorComponent @ref="calculator" StorageLinkUrl="triptych" StorageLinkClientID="triptychLink" />

<TestButton testproject="asptest.blazor" />
<TestButton testproject="asptest.blazor asptest.blazor.specflow" />

@code {
CalculatorComponent? calculator;
Expand Down
3 changes: 2 additions & 1 deletion src/asp.blazor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("asptest.blazor")]
[assembly: InternalsVisibleTo("asptest.blazor.bunit")]
[assembly: InternalsVisibleTo("asptest.blazor.bunit")]
[assembly: InternalsVisibleTo("asptest.blazor.specflow")]
12 changes: 11 additions & 1 deletion src/asp.blazor/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
},
"AllowedHosts": "*",
"SessionStorage": "ViewState",
"DatabaseStorageExpires": "1",
"EncryptDatabaseStorage": "False",
"EncryptViewStateKey": "<-- secret w/o server affinity -->",
"ViewStateCompressionLevel": "Optimal",
"ASP_DBEntities": "Data Source=(local);Initial Catalog=ASP_DB;Persist Security Info=True;User ID=iis;Password=pass;multipleactiveresultsets=True;TrustServerCertificate=true;",
"RequestTimeout": "5",
"asptest.CalculatorTest.FibonacciTest": "45aff7ba-2137-4cef-1997-08da438d667f",
"TestFilterWhere": ""
}
8 changes: 7 additions & 1 deletion src/asp.blazor/asp.blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@

<ItemGroup>
<PackageReference Include="Selenium.WebDriver" Version="4.8.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="111.0.5563.1900-beta" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="110.0.5481.7700" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="110.0.1587.22-pre" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
</ItemGroup>

<ItemGroup>
<Reference Include="asptest.blazor">
<HintPath>..\bin\asptest.blazor.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="asptest.blazor.specflow">
<HintPath>..\bin\asptest.blazor.specflow.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
79 changes: 79 additions & 0 deletions src/asptest.blazor.specflow/Drivers/CalculatorDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using asp.blazor.Components.CalculatorParts;
using static asptest.blazor.specflow.Features.CalculatorFeature;

namespace asptest.blazor.specflow.Drivers
{
public class CalculatorDriver
{
public void EnterTheFirstNumber(int number)
{
Driver.Navigate("/");
Driver.Click(Driver.Cut.footer.enterButton);
Assert.That(Driver.State, Is.EqualTo(CalculatorContext.Map1.Enter));
Driver.Write(Driver.Dynamic<Enter>(Driver.Cut.calculatorPart).operand, number.ToString());
Driver.Click(Driver.Cut.footer.enterButton);
Assert.That(Driver.State, Is.EqualTo(CalculatorContext.Map1.Calculate));
}

public void EnterTheSecondNumber(int number)
{
Driver.Click(Driver.Cut.footer.enterButton);
Assert.That(Driver.State, Is.EqualTo(CalculatorContext.Map1.Enter));
Driver.Write(Driver.Dynamic<Enter>(Driver.Cut.calculatorPart).operand, number.ToString());
Driver.Click(Driver.Cut.footer.enterButton);
Assert.That(Driver.State, Is.EqualTo(CalculatorContext.Map1.Calculate));
}

public void ClickAdd()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).addButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before - 1));
}

public void ClickSub()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).subButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before - 1));
}

public void ClickMul()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).mulButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before - 1));
}

public void ClickDiv()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).divButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before - 1));
}

public void ClickPow()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).powButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before));
}

public void ClickSqrt()
{
var before = Driver.Stack.Count;
Driver.Click(Driver.Dynamic<Calculate>(Driver.Cut.calculatorPart).sqrtButton);
Assert.That(Driver.Stack.Count, Is.EqualTo(before));
}

public void AssertResultIs(int result)
{
Assert.Multiple(() =>
{
Assert.That(Driver.State, Is.EqualTo(CalculatorContext.Map1.Calculate));
Assert.That(Driver.Stack.Peek(), Is.EqualTo(result.ToString()));
Assert.That(Driver.Html(), Does.Contain(result.ToString()));
});
}
}
}
17 changes: 17 additions & 0 deletions src/asptest.blazor.specflow/Drivers/CalculatorTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using asp.blazor.CalculatorSmc;
using asp.blazor.Components;
using iselenium;
using OpenQA.Selenium;

namespace asptest.blazor.specflow.Drivers
{
public abstract class CalculatorTestBase<TWebDriver> :
SmcComponentDbTest<TWebDriver, CalculatorComponent, Calculator, CalculatorContext, CalculatorContext.CalculatorState>
where TWebDriver : IWebDriver, new()
{
public Stack<string> Stack
{
get { return Main.Stack; }
}
}
}
37 changes: 37 additions & 0 deletions src/asptest.blazor.specflow/Features/Calculator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Feature: Calculator

SMC RPN calculator test assimilated to the SpecFlow template

Scenario: Add two numbers
Given the first number is 50
And the second number is 70
When the add button is clicked
Then the result should be 120

Scenario: Subtract two numbers
Given the first number is 70
And the second number is 50
When the subtract button is clicked
Then the result should be 20

Scenario: Multiply two numbers
Given the first number is 70
And the second number is 50
When the multiply button is clicked
Then the result should be 3500

Scenario: Divide two numbers
Given the first number is 70
And the second number is 5
When the divide button is clicked
Then the result should be 14

Scenario: Square a number
Given the first number is 70
When the square button is clicked
Then the result should be 4900

Scenario: Extract the root from a number
Given the first number is 49
When the square root button is clicked
Then the result should be 7
Loading

0 comments on commit 5a2763e

Please sign in to comment.