Skip to content

Commit

Permalink
Greenscreen all tests
Browse files Browse the repository at this point in the history
All test.playlist unit tests and WebForms/MVC Core/WebSharper SPA
tests are now green. When run at once, they rarely pass as a whole
due to stalled web servers. A test run takes way over half an hour,
primarily because Selenium.Firefox.WebDriver with Firefox is
extremely slow compared with Chrome (fast) and Selenium
InternetExplorer (significantly slower than IIE COM InternetExplorer).

Consolidated Click() test methods across project types and added an
optional awaitRemoved parameter that polls the DOM element for being
removed from the DOM and an optional (higher) timeout to AssertPoll.
Only this makes WebSharper SPA GUI tests reliable.

Updated dependencies except WebSharper, as with 4.6.4,
asplib.websharper can't even indirectly depend on the shared
netstandard2.0 asplib project no more. Related:
dotnet-websharper/core#1055 - the whole .\tools\netstandard2.0
directory is missing in the NuGet package, and the build fails
due to the missing WebSharper.MSBuild.CSharp.
  • Loading branch information
toniarnold committed Jun 15, 2020
1 parent a3ec33f commit 62a0d9f
Show file tree
Hide file tree
Showing 41 changed files with 321 additions and 165 deletions.
2 changes: 1 addition & 1 deletion db.ssmssln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 14.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "db", "db\db.ssmssqlproj", "{3107E538-B771-4F20-A68F-E7B9827FCBE6}"
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "db", "src\db\db.ssmssqlproj", "{3107E538-B771-4F20-A68F-E7B9827FCBE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 3 additions & 3 deletions src/apicaller.core/apicaller.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/apiservice.core/Controllers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Accesscode_sm.dot: Accesscode.sm

Accesscode_sm.png: Accesscode_sm.dot
dot -T png -o Accesscode_sm.png Accesscode_sm.dot
xcopy /D /F /Y Accesscode_sm.png ..\..\doc\img
xcopy /D /F /Y Accesscode_sm.png ..\..\..\doc\img

clean:
-del Accesscode_sm.cs
Expand Down
10 changes: 5 additions & 5 deletions src/apiservice.core/apiservice.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/apitest.core/apitest.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.5" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
1 change: 1 addition & 0 deletions src/asp.core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage(); // always for this demo
app.UseExceptionHandler("/Error/Error");
app.UseMiddleware<IIEMiddleware>(); // Global.asax
app.UseMiddleware<NoCacheMiddleware>();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseSession();
Expand Down
21 changes: 6 additions & 15 deletions src/asp.webforms/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />

<pages>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
</system.web>
</pages></system.web>
<appSettings>
<!-- [ViewState|Session|Database], default is ViewState -->
<add key="SessionStorage" value="" />
Expand Down Expand Up @@ -47,18 +44,12 @@
</providers>
</entityFramework>
<connectionStrings>
<add name="ASP_DBEntities"
connectionString="metadata=res://*/Model.Db.csdl|res://*/Model.Db.ssdl|res://*/Model.Db.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=HP;initial catalog=ASP_DB;persist security info=True;user id=iis;password=pass;multipleactiveresultsets=True;application name=EntityFramework&quot;"
providerName="System.Data.EntityClient" />
<add name="ASP_DBEntities" connectionString="metadata=res://*/Model.Db.csdl|res://*/Model.Db.ssdl|res://*/Model.Db.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=HP;initial catalog=ASP_DB;persist security info=True;user id=iis;password=pass;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
4 changes: 2 additions & 2 deletions src/asp.webforms/asp.webforms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AjaxControlToolkit, Version=19.1.0.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e, processorArchitecture=MSIL">
<HintPath>..\..\packages\AjaxControlToolkit.19.1.0\lib\net40\AjaxControlToolkit.dll</HintPath>
<Reference Include="AjaxControlToolkit, Version=20.1.0.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e, processorArchitecture=MSIL">
<HintPath>..\..\packages\AjaxControlToolkit.20.1.0\lib\net40\AjaxControlToolkit.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion src/asp.webforms/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AjaxControlToolkit" version="19.1.0" targetFramework="net461" />
<package id="AjaxControlToolkit" version="20.1.0" targetFramework="net461" />
<package id="EntityFramework" version="6.4.4" targetFramework="net461" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.Net.Compilers" version="3.6.0" targetFramework="net461" developmentDependency="true" />
Expand Down
3 changes: 2 additions & 1 deletion src/asp.websharper.spa.fs/Startup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type Startup private () =
member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) =
if (env.IsDevelopment()) then
WebSharper.Web.Remoting.DisableCsrfProtection() |> ignore // Prevent HTTP 403 errors in GUI tests
app.UseDeveloperExceptionPage() |> ignore
app.UseDeveloperExceptionPage()
.UseMiddleware<NoCacheMiddleware>() |> ignore
else
app.UseHttpsRedirection()
.UseHsts() |> ignore
Expand Down
2 changes: 2 additions & 0 deletions src/asp.websharper.spa.fs/wwwroot/triptych.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
}

.calc-box {
position: relative;
z-index: 1;
border: 1px solid black;
border-radius: 10px;
padding: 30px;
Expand Down
4 changes: 2 additions & 2 deletions src/asp.websharper.spa/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Net.Http.Headers;
using System;
using WebSharper.AspNetCore;

Expand Down Expand Up @@ -51,7 +50,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
WebSharper.Web.Remoting.DisableCsrfProtection(); // Prevent HTTP 403 errors in GUI tests
app.UseDeveloperExceptionPage();
app.UseDeveloperExceptionPage()
.UseMiddleware<NoCacheMiddleware>();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/asp.websharper.spa/wwwroot/triptych.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
}

.calc-box {
position: relative;
z-index: 1;
border: 1px solid black;
border-radius: 10px;
padding: 30px;
Expand Down
8 changes: 4 additions & 4 deletions src/asplib.core/asplib.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.5" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using asplib.Model;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net;
using System;
using System.Threading.Tasks;

namespace asplib.Remoting
{
Expand Down
2 changes: 2 additions & 0 deletions src/asptest.websharper.spa.fs/Calculator/CalculateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using iselenium;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using static asplib.View.TagHelper;

namespace asptest.Calculator
{
[TestFixture(typeof(InternetExplorerDriver))]
public class CalculateTest<TWebDriver> : CalculatorTestBase<TWebDriver>
where TWebDriver : IWebDriver, new()
{
Expand Down
2 changes: 1 addition & 1 deletion src/asptest.websharper.spa.fs/Calculator/FibonacciTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void VerifyFibonacciSums()
// Check the correctness of the Fibonacci sequence in the calculator GUI

// Delete the current sum and recalculate it from the sequence
this.Click(Id(CalculatorDoc.ClrButton));
this.Click(Id(CalculatorDoc.ClrButton), wait: 15);
this.Click(Id(CalculatorDoc.AddButton));
this.AssertPoll(() => this.Stack.ElementAt(0), () => Is.EqualTo(sum));

Expand Down
11 changes: 5 additions & 6 deletions src/asptest.websharper.spa.fs/Calculator/WithSessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,22 @@ private void Reload()
[Test]
public void AddWithPersistenceTest()
{
this.Navigate("/");
this.Click("EnterButton");
this.Click(Id(CalculatorDoc.EnterButton));
this.AssertPoll(() => this.State, () => Is.EqualTo(CalculatorContext.Map1.Enter));
this.Reload();
this.Write(Id(CalculatorDoc.OperandTextbox), "2");
this.Click("EnterButton");
this.Click(Id(CalculatorDoc.EnterButton));
this.AssertPoll(() => this.State, () => Is.EqualTo(CalculatorContext.Map1.Calculate));
this.Reload();
this.Click("EnterButton");
this.Click(Id(CalculatorDoc.EnterButton));
this.AssertPoll(() => this.State, () => Is.EqualTo(CalculatorContext.Map1.Enter));
this.Reload();
this.Write(Id(CalculatorDoc.OperandTextbox), "3");
this.Click("EnterButton");
this.Click(Id(CalculatorDoc.EnterButton));
this.AssertPoll(() => this.State, () => Is.EqualTo(CalculatorContext.Map1.Calculate));
var before = this.Stack.Count;
this.Reload();
this.Click("AddButton");
this.Click(Id(CalculatorDoc.AddButton));
this.AssertAddFinalState(before);
this.Reload();
}
Expand Down
54 changes: 35 additions & 19 deletions src/asptest.websharper.spa.fs/TriptychTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@ namespace asptest
public class TriptychTest<TWebDriver> : CalculatorTestBase<TWebDriver>
where TWebDriver : IWebDriver, new()
{
public override void OneTimeSetUpBrowser()
{
base.OneTimeSetUpBrowser();
driver.Manage().Window.Size = new System.Drawing.Size(1450, 1000);
}

[OneTimeSetUp]
public void DistinctPages()
{
this.samePageDefault = false;
}

[SetUp]
public void UnsetStorage()
public void ReloadUnsetStorage()
{
StorageImplementation.SessionStorage = null;
this.Navigate("/");
StorageImplementation.SessionStorage = null; // defaults to ViewState (DOM)
}

[TearDown]
Expand All @@ -36,47 +49,50 @@ public void ClearStorage()
[Test]
public void NavigateTriptychTest()
{
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: ViewState")); // init view
this.Click(Id(CalculatorDoc.StorageLink));
this.AssertTriptychHtml();
}

/// <summary>
/// Assert the presence of the three calculators superficially by text.
/// </summary>
private void AssertTriptychHtml()
{
Assert.Multiple(() =>
{
// Assert from bottom to top to ensure the page has been fully rendered on the client
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Database"));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Session"));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: ViewState"));
});
}

[Test]
public void CircumambulateStorageTypes()
{
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: ViewState")); // init view
this.Click(Id(CalculatorDoc.StorageLink));
this.AssertTriptychHtml();
this.Click(Id(TriptychDoc.DatabaseDoc, CalculatorDoc.StorageLink));
this.Navigate("/"); // Reload, as static StorageImplementation.SessionStorage is set too late in F#
this.driver.Navigate().Refresh(); // only in the F# port
// Poll SessionStorage first, this.Html() is ambiguous and succeeds too early (still on the triptych)
this.AssertPoll(() => this.ViewModel.SessionStorage, () => Is.EqualTo(Storage.Database));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Database"));

this.Click(Id(CalculatorDoc.StorageLink));
this.AssertTriptychHtml();
this.Click(Id(TriptychDoc.SessionDoc, CalculatorDoc.StorageLink));
this.Navigate("/");
this.driver.Navigate().Refresh();
this.AssertPoll(() => this.ViewModel.SessionStorage, () => Is.EqualTo(Storage.Session));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Session"));

this.Click(Id(CalculatorDoc.StorageLink));
this.AssertTriptychHtml();
this.Click(Id(TriptychDoc.ViewStateDoc, CalculatorDoc.StorageLink));
this.Navigate("/");
this.driver.Navigate().Refresh();
this.AssertPoll(() => this.ViewModel.SessionStorage, () => Is.EqualTo(Storage.ViewState));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: ViewState"));
}

/// <summary>
/// Assert the presence of the three calculators superficially by text.
/// </summary>
private void AssertTriptychHtml()
{
Assert.Multiple(() =>
{
// Assert from bottom to top to ensure the page has been fully rendered on the client
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Database"));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: Session"));
this.AssertPoll(() => this.Html(), () => Does.Contain("Session Storage: ViewState"));
});
}
}
}
2 changes: 1 addition & 1 deletion src/asptest.websharper.spa/Calculator/FibonacciTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void VerifyFibonacciSums()
// Check the correctness of the Fibonacci sequence in the calculator GUI

// Delete the current sum and recalculate it from the sequence
this.Click(Id(CalculatorDoc.ClrButton));
this.Click(Id(CalculatorDoc.ClrButton), wait: 15);
this.Click(Id(CalculatorDoc.AddButton));
this.AssertPoll(() => this.Stack.ElementAt(0), () => Is.EqualTo(sum));

Expand Down
Loading

0 comments on commit 62a0d9f

Please sign in to comment.