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
2 changes: 2 additions & 0 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ jobs:
beforeBuild:
- bash: "./eng/scripts/install-nginx-linux.sh"
displayName: Installing Nginx
- bash: "echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p"
displayName: Increase inotify limit
afterBuild:
- bash: ./build.sh --no-build --ci --test -p:RunFlakyTests=true
displayName: Run Flaky Tests
Expand Down
2 changes: 2 additions & 0 deletions .azure/pipelines/jobs/default-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ jobs:
displayName: Install JDK 11
- powershell: Write-Host "##vso[task.prependpath]$env:JAVA_HOME\bin"
displayName: Prepend JAVA bin folder to the PATH.
- powershell: Write-Host "##vso[task.setvariable variable=SeleniumProcessTrackingFolder]$(BuildDirectory)\obj\selenium\"
displayName: Add Selenium process tracking folder environment variable
- powershell: ./eng/scripts/InstallGoogleChrome.ps1
displayName: Install chrome
- ${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.agentOs, 'Windows'), eq(parameters.codeSign, 'true')) }}:
Expand Down
17 changes: 17 additions & 0 deletions eng/scripts/KillProcesses.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ function _killJavaInstances() {
}
}

function _killSeleniumTrackedProcesses() {
$files = Get-ChildItem $env:SeleniumProcessTrackingFolder -ErrorAction SilentlyContinue;
# PID files have a format of <<pid>>.<<guid>>.pid
$pids = $files |
Where-Object { $_.Name -match "([0-9]+)\..*?.pid"; } |
Foreach-Object { $Matches[1] };

foreach ($currentPid in $pids) {
try {
& cmd /c "taskkill /T /F /PID $currentPid 2>&1"
} catch {
Write-Host "Failed to kill process: $currentPid"
}
}
}

_kill dotnet.exe
_kill testhost.exe
_kill iisexpress.exe
Expand All @@ -35,6 +51,7 @@ _kill chrome.exe
_kill h2spec.exe
_kill WerFault.exe
_killJavaInstances
_killSeleniumTrackedProcesses

if (Get-Command iisreset -ErrorAction ignore) {
iisreset /restart
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.E2ETesting;
using Xunit;

[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "Microsoft.AspNetCore.Components.E2ETests")]
[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void ThrowsIfRenderIsRequestedOutsideSyncContext()

appElement.FindElement(By.Id("run-without-dispatch")).Click();

WaitAssert.Contains(
Browser.Contains(
$"{typeof(InvalidOperationException).FullName}: The current thread is not associated with the renderer's synchronization context",
() => result.Text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenQA.Selenium.Support.UI;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -23,12 +24,14 @@ public ServerSideAppTest(
{
_serverFixture.Environment = AspNetEnvironment.Development;
_serverFixture.BuildWebHostMethod = ComponentsApp.Server.Program.BuildWebHost;
}

protected override void InitializeAsyncCore()
{
Navigate("/", noReload: false);
WaitUntilLoaded();
}


[Fact]
public void HasTitle()
{
Expand Down Expand Up @@ -56,13 +59,13 @@ public void NavMenuHighlightsCurrentLocation()
Browser.FindElement(By.LinkText("Counter")).Click();

// Verify we're now on the counter page, with that nav link (only) highlighted
WaitAssert.Equal("Counter", () => Browser.FindElement(mainHeaderSelector).Text);
Browser.Equal("Counter", () => Browser.FindElement(mainHeaderSelector).Text);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for changing these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were relying on an async local and I wanted to avoid that as much as possible. I considered either passing the browser explicitly or making them extension methods, and I did the second because it felt more "idiomatic".

I didn't think a lot of one way or the other. Just wanted the async local usage limited to the minimum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't this a big change in functionality? If these needed waitassert in the past, why is this safe to remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't remove anything. I transformed the method.
This used to be WaitAssert.Equal(string expected, Func func) and internally used BrowserTestBase.Browser (an async local).

I converted it into WaitAssert.Equal(IWebDriver browser, string expected, Func func) and to make it more similar to what it was I made WaitAssert.Equal and related methods extension methods on IWebDriver, so WaitAssert.Equal(this IWebDriver browser, string expected, Func<string> func).

Functionality wise they are equivalent. The use of an async local was unnecessary, when we can just pass the browser parameter explicitly.

Assert.Collection(Browser.FindElements(activeNavLinksSelector),
item => Assert.Equal("Counter", item.Text));

// Verify we can navigate back to home too
Browser.FindElement(By.LinkText("Home")).Click();
WaitAssert.Equal("Hello, world!", () => Browser.FindElement(mainHeaderSelector).Text);
Browser.Equal("Hello, world!", () => Browser.FindElement(mainHeaderSelector).Text);
Assert.Collection(Browser.FindElements(activeNavLinksSelector),
item => Assert.Equal("Home", item.Text));
}
Expand All @@ -72,7 +75,7 @@ public void HasCounterPage()
{
// Navigate to "Counter"
Browser.FindElement(By.LinkText("Counter")).Click();
WaitAssert.Equal("Counter", () => Browser.FindElement(By.TagName("h1")).Text);
Browser.Equal("Counter", () => Browser.FindElement(By.TagName("h1")).Text);

// Observe the initial value is zero
var countDisplayElement = Browser.FindElement(By.CssSelector("h1 + p"));
Expand All @@ -81,19 +84,19 @@ public void HasCounterPage()
// Click the button; see it counts
var button = Browser.FindElement(By.CssSelector(".main button"));
button.Click();
WaitAssert.Equal("Current count: 1", () => countDisplayElement.Text);
Browser.Equal("Current count: 1", () => countDisplayElement.Text);
button.Click();
WaitAssert.Equal("Current count: 2", () => countDisplayElement.Text);
Browser.Equal("Current count: 2", () => countDisplayElement.Text);
button.Click();
WaitAssert.Equal("Current count: 3", () => countDisplayElement.Text);
Browser.Equal("Current count: 3", () => countDisplayElement.Text);
}

[Fact]
public void HasFetchDataPage()
{
// Navigate to "Fetch Data"
Browser.FindElement(By.LinkText("Fetch data")).Click();
WaitAssert.Equal("Weather forecast", () => Browser.FindElement(By.TagName("h1")).Text);
Browser.Equal("Weather forecast", () => Browser.FindElement(By.TagName("h1")).Text);

// Wait until loaded
var tableSelector = By.CssSelector("table.table");
Expand Down
8 changes: 6 additions & 2 deletions src/Components/test/E2ETest/Tests/BinaryHttpClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
public class BinaryHttpClientTest : BasicTestAppTestBase, IClassFixture<AspNetSiteServerFixture>
{
readonly ServerFixture _apiServerFixture;
readonly IWebElement _appElement;
IWebElement _appElement;
IWebElement _responseStatus;
IWebElement _responseStatusText;
IWebElement _testOutcome;
Expand All @@ -30,11 +31,14 @@ public BinaryHttpClientTest(
{
apiServerFixture.BuildWebHostMethod = TestServer.Program.BuildWebHost;
_apiServerFixture = apiServerFixture;
}

protected override void InitializeAsyncCore()
{
Navigate(ServerPathBase, noReload: true);
_appElement = MountTestComponent<BinaryHttpRequestsComponent>();
}

[Fact]
public void CanSendAndReceiveBytes()
{
Expand Down
Loading