Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wait to fix the flaky test #1690

Merged
merged 14 commits into from
Sep 22, 2023
Merged
3 changes: 2 additions & 1 deletion .github/uitest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
required: false
build-configuration:
default: Debug
description: which --configuration to pass to dotnet build / dotnet run
description: which --configuration to pass to dotnet build / dotnet run
required: false
runtime-environment:
default: Development
Expand All @@ -25,6 +25,7 @@ inputs:
runs:
using: composite
steps:

# run the appropriate uitest script
- if: ${{ runner.os != 'Windows' }}
name: uitest.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
name: webforms-adapters-tests
title: WebForms Adapter Tests
github-token: ${{ secrets.GITHUB_TOKEN }}
target-framework: net472
target-framework: net472

js-tests:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.6" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Selenium.Support" Version="4.0.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0" />
<PackageReference Include="Selenium.Support" Version="4.11.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.11.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Samples/Api.Owin/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"DotVVM.Samples.BasicSamples.Api.Owin": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:61453",
"applicationUrl": "http://localhost:61453",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:61453"
}
}
}
}
1 change: 1 addition & 0 deletions src/Samples/AspNetCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:16019",
"applicationUrl": "http://localhost:16019",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:16019",
"applicationUrl": "http://localhost:16019",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
5 changes: 3 additions & 2 deletions src/Samples/Owin/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"DotVVM.Samples.BasicSamples.Owin": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5407",
"applicationUrl": "http://localhost:5407",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5407"
}
}
}
}
3 changes: 2 additions & 1 deletion src/Samples/Tests/Tests/Complex/SPAErrorReportingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Chromium;
using Riganti.Selenium.Core;
using Riganti.Selenium.Core.Abstractions.Attributes;
using Riganti.Selenium.DotVVM;
Expand Down Expand Up @@ -31,7 +32,7 @@ public void Complex_SPAErrorReporting_NavigationAndPostbacks()

void SetOfflineMode(bool offline)
{
((ChromeDriver)browser.Driver).NetworkConditions = new ChromeNetworkConditions() {
((ChromeDriver)browser.Driver).NetworkConditions = new ChromiumNetworkConditions() {
IsOffline = offline,
Latency = TimeSpan.FromMilliseconds(5),
DownloadThroughput = 500 * 1024,
Expand Down
29 changes: 19 additions & 10 deletions src/Samples/Tests/Tests/DotVVM.Samples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>

<!-- Use this to run agains local clone of the Selenium Utils repo -->
<LocalSeleniumUtilsPath></LocalSeleniumUtilsPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="Selenium.Support" Version="4.11.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.11.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Riganti.Selenium.Coordinator.Client" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Core" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Core.Abstractions" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.DotVVM" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.AssertApi" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.xUnitIntegration" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Validators" Version="3.0.0-preview09-final" />
</ItemGroup>

<ItemGroup Condition="'$(LocalSeleniumUtilsPath)' == ''">
<PackageReference Include="Riganti.Selenium.DotVVM" Version="3.0.0-preview15-final" />
<PackageReference Include="Riganti.Selenium.AssertApi" Version="3.0.0-preview15-final" />
<PackageReference Include="Riganti.Selenium.xUnitIntegration" Version="3.0.0-preview15-final" />
</ItemGroup>
<ItemGroup Condition="'$(LocalSeleniumUtilsPath)' != ''">
<ProjectReference Include="$(LocalSeleniumUtilsPath)\src\Core\Riganti.Selenium.AssertApi\Riganti.Selenium.AssertApi.csproj" />
<ProjectReference Include="$(LocalSeleniumUtilsPath)\src\Integrations\Riganti.Selenium.DotVVM.MSTest2\Riganti.Selenium.DotVVM.csproj" />
<ProjectReference Include="$(LocalSeleniumUtilsPath)\src\Integrations\Riganti.Selenium.xUnit\Riganti.Selenium.xUnitIntegration.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public void Feature_ActionFilterErrorHandling_ActionFilterRedirect()
// try the first button
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ActionFilterErrorHandling_ActionFilterRedirect);
AssertUI.Url(browser, u => !u.Contains("?redirected=true"));
browser.ElementAt("input", 0).Click();
browser.ElementAt("input", 0).Click().Wait(1000);
AssertUI.Url(browser, u => u.Contains("?redirected=true"));

// try the second button
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ActionFilterErrorHandling_ActionFilterRedirect);
AssertUI.Url(browser, u => !u.Contains("?redirected=true"));
browser.ElementAt("input", 1).Click();
browser.ElementAt("input", 1).Click().Wait(1000);
AssertUI.Url(browser, u => u.Contains("?redirected=true"));
});
}
Expand Down
19 changes: 18 additions & 1 deletion src/Samples/Tests/Tests/Feature/PostbackConcurrencyTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading;
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
using OpenQA.Selenium;
using Riganti.Selenium.Core;
using Riganti.Selenium.Core.Abstractions.Attributes;
using Riganti.Selenium.DotVVM;
Expand Down Expand Up @@ -256,11 +257,27 @@ public void Feature_PostbackConcurrency_RedirectPostbackQueueSpa_PostbackFromPre
browser.ElementAt("input[type=button]", 0).Click();
browser.ElementAt("input[type=button]", 2).Click();

var attempt = 0;
while (!browser.CurrentUrl.Contains("?time"))
{
attempt++;
if (attempt > 50)
{
Assert.Fail("The redirect didn't happen.");
}

Thread.Sleep(100);
AssertUI.TextNotEquals(browser.Single(".result"), "1");
try
{
AssertUI.TextNotEquals(browser.Single(".result"), "1", waitForOptions: WaitForOptions.Disabled);
}
catch (StaleElementReferenceException)
{
// ignore
break;
}
}
AssertUI.Url(browser, u => u.Contains("?time"));

for (int i = 0; i < 8; i++)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Samples/Tests/Tests/seleniumconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"factories": {
"chrome:fast": {
"capabilities": [ "--headless" ]
}
"firefox:fast": {}
},
"baseUrls": [
"http://localhost:16019/"
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/DotVVM.Framework.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.17.0" />
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.0" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.6" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down