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

Playwright 🎭 🛠️ #45682

Merged
merged 43 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5f9b076
Version Bumps
TanayParikh Dec 19, 2022
ceda987
Run with `Test: Windows Server x64`
TanayParikh Dec 19, 2022
68a2f8e
Install Playwright in CI
TanayParikh Dec 19, 2022
31cd474
Add running playwright locally instructions
TanayParikh Dec 19, 2022
5d86d72
Test Cleanup
TanayParikh Dec 19, 2022
02461a8
Remove Selenium
TanayParikh Dec 19, 2022
0de963b
Prebuild for Playwright install
TanayParikh Dec 19, 2022
c803709
Update default-build.yml
TanayParikh Dec 19, 2022
e21e339
Update default-build.yml
TanayParikh Dec 19, 2022
c39f272
Update default-build.yml
TanayParikh Dec 20, 2022
a75e4b8
Update default-build.yml
TanayParikh Dec 20, 2022
89b5876
Update default-build.yml
TanayParikh Dec 20, 2022
6ca74c2
Playwright install in test
TanayParikh Dec 20, 2022
ccbb4d4
New template test pipeline
TanayParikh Dec 20, 2022
599363d
Update components-e2e-tests.yml
TanayParikh Dec 20, 2022
3b5e7e3
Update components-template-tests.yml
TanayParikh Dec 21, 2022
7c6e078
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
c3a796a
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
90da3c8
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
80232fe
Update components-template-tests.yml
TanayParikh Dec 21, 2022
06577b1
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
2483583
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
52cf64c
Update components-e2e-tests.yml
TanayParikh Dec 21, 2022
61ae061
Revert new pipeline changes
TanayParikh Dec 21, 2022
9ed27ed
RestoreAdditionalProjectSources
TanayParikh Dec 21, 2022
245485b
Update Templates.Blazor.Tests.csproj
TanayParikh Dec 21, 2022
4b43b23
PR Feedback
TanayParikh Dec 21, 2022
80250d0
RunBlazorPlaywrightTemplateTests
TanayParikh Dec 21, 2022
3580dcb
Socket logic
TanayParikh Dec 22, 2022
f5e5826
Fixed socket wait logic
TanayParikh Dec 22, 2022
6cfd3ee
Remove redundant process wait for exit
TanayParikh Dec 23, 2022
bc4f85d
Update BlazorWasmTemplateTest.cs
TanayParikh Dec 23, 2022
eeeeefe
Update Templates.Blazor.Tests.csproj
TanayParikh Jan 4, 2023
5a0e3b6
Revert App.Ref, add src in props
TanayParikh Jan 5, 2023
322e093
Config updates
TanayParikh Jan 5, 2023
a0bdfe8
Update RequiresDelayedBuildProjects.props
TanayParikh Jan 23, 2023
2e06f58
Update Templates.Blazor.Tests.csproj
TanayParikh Jan 23, 2023
09e9cb2
Merge branch 'main' into taparik/playwright
TanayParikh Jan 23, 2023
20ebf88
Skip failing tests
TanayParikh Feb 1, 2023
c2d7a88
Add https://github.com/dotnet/aspnetcore/issues/46430
TanayParikh Feb 3, 2023
a33acf3
Update Templates.Blazor.Tests.csproj
wtgodbe Feb 13, 2023
f60b141
Update BlazorWasmTemplateTest.cs
wtgodbe Feb 13, 2023
704a4e1
Update BlazorWasmTemplateTest.cs
wtgodbe Feb 14, 2023
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: 1 addition & 1 deletion .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ stages:
# Just uploading artifacts/logs/ files can take 15 minutes. Doubling the cancel timeout for this job.
cancelTimeoutInMinutes: 30
buildArgs: -all -pack -test -binaryLog /p:SkipHelixReadyTests=true /p:SkipIISNewHandlerTests=true /p:SkipIISTests=true
/p:SkipIISExpressTests=true /p:SkipIISNewShimTests=true /p:RunTemplateTests=false
/p:SkipIISExpressTests=true /p:SkipIISNewShimTests=true /p:RunTemplateTests=false /p:RunBlazorPlaywrightTemplateTests=true
Copy link
Member

Choose a reason for hiding this comment

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

Will setting this new variable (RunBlazorPlaywrightTemplateTests) to false result in the current behavior (as if we don't have this change in place)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fine to just omit RunBlazorPlaywrightTemplateTests in that case as it'll default to using the value of RunTemplateTests, but yes setting it to false would work as well.

<RunBlazorPlaywrightTemplateTests Condition="'$(RunBlazorPlaywrightTemplateTests)' == ''">$(RunTemplateTests)</RunBlazorPlaywrightTemplateTests>
<SkipTests Condition="'$(RunBlazorPlaywrightTemplateTests)' != 'true'">true</SkipTests>

$(_InternalRuntimeDownloadArgs)
beforeBuild:
- powershell: "& ./src/Servers/IIS/tools/UpdateIISExpressCertificate.ps1; & ./src/Servers/IIS/tools/update_schema.ps1"
Expand Down
1 change: 1 addition & 0 deletions eng/RequiresDelayedBuildProjects.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<RequiresDelayedBuild Include="$(RepoRoot)src\Grpc\JsonTranscoding\test\Microsoft.AspNetCore.Grpc.Swagger.Tests\Microsoft.AspNetCore.Grpc.Swagger.Tests.csproj" />
<RequiresDelayedBuild Include="$(RepoRoot)src\Grpc\JsonTranscoding\test\testassets\IntegrationTestsWebsite\IntegrationTestsWebsite.csproj" />
<RequiresDelayedBuild Include="$(RepoRoot)src\Grpc\JsonTranscoding\test\testassets\Sandbox\Sandbox.csproj" />
<RequiresDelayedBuild Include="$(RepoRoot)src\ProjectTemplates\test\Templates.Blazor.Tests\Templates.Blazor.Tests.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<NSwagApiDescriptionClientVersion>13.0.4</NSwagApiDescriptionClientVersion>
<PhotinoNETVersion>1.1.6</PhotinoNETVersion>
<MicrosoftPlaywrightVersion>1.17.3</MicrosoftPlaywrightVersion>
<MicrosoftPlaywrightVersion>1.28.0</MicrosoftPlaywrightVersion>
<PollyExtensionsHttpVersion>3.0.0</PollyExtensionsHttpVersion>
<PollyVersion>7.2.3</PollyVersion>
<SeleniumSupportVersion>4.7.0</SeleniumSupportVersion>
Expand Down
1 change: 1 addition & 0 deletions eng/tools/GenerateFiles/Directory.Build.props.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<DefaultNetCoreTargetFramework>${DefaultNetCoreTargetFramework}</DefaultNetCoreTargetFramework>
<ArtifactsShippingPackagesDir>${ArtifactsShippingPackagesDir}</ArtifactsShippingPackagesDir>
<TreatWarningsAsErrors Condition="'$(BuildingInsideVisualStudio)' != 'true'">true</TreatWarningsAsErrors>
<LibNetHostAppPackVersion Condition=" '$(LibNetHostAppPackVersion)' == '' ">${LibNetHostAppPackVersion}</LibNetHostAppPackVersion>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion eng/tools/GenerateFiles/GenerateFiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
MicrosoftPlaywrightCLIVersion=$(MicrosoftPlaywrightCLIVersion);
LibNetHostAppPackVersion=$(BundledNETCoreAppPackageVersion);
SupportedRuntimeIdentifiers=$(SupportedRuntimeIdentifiers.Trim())
SupportedRuntimeIdentifiers=$(SupportedRuntimeIdentifiers.Trim());
ArtifactsShippingPackagesDir=$(ArtifactsShippingPackagesDir)
</_TemplateProperties>
</PropertyGroup>

Expand Down
12 changes: 12 additions & 0 deletions src/ProjectTemplates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ Then, use one of:
previous step, it is NOT advised that you install templates created on your local machine using just
`dotnet new -i [nupkgPath]`.

#### Running Blazor Playwright Template Tests

1. From the root of the repo, build the templates: `.\eng\build.cmd -all -pack`
2. `cd .\src\ProjectTemplates\test\Templates.Blazor.Tests`
3. `dotnet test .\Templates.Blazor.Tests.csproj` with optional `--filter` arg to run a specific test.

The requisite browsers should be automatically installed. If you encounter browser errors, the browsers can be manually installed via the following script, replacing `[TFM]` with the current target TFM (ex. `net8.0`).

```cmd
.\bin\Debug\[TFM]\playwright.ps1 install
```

#### Conditional tests & skipping test platforms

Individual test methods can be decorated with attributes to configure them to not run ("skip running") on certain platforms. The `[ConditionalFact]` and `[ConditionalTheory]` attributes must be used on tests using the skip attributes in order for them to actually be skipped:
Expand Down
5 changes: 5 additions & 0 deletions src/ProjectTemplates/Shared/TemplatePackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ private static async Task InstallTemplatePackages(ITestOutputHelper output)
.Where(p => _templatePackages.Any(t => Path.GetFileName(p).StartsWith(t, StringComparison.OrdinalIgnoreCase)))
.ToArray();

if (builtPackages.Length == 0)
{
throw new InvalidOperationException($"Failed to find required templates in {packagesDir}. Please ensure the *Templates*.nupkg have been built.");
}

Assert.Equal(4, builtPackages.Length);

await VerifyCannotFindTemplateAsync(output, "web");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@

<Import Project="${ArtifactsBinDir}GenerateFiles\Directory.Build.props" />

<PropertyGroup>
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir)</RestoreAdditionalProjectSources>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.BrowserTesting;
using Microsoft.AspNetCore.Testing;
Expand All @@ -25,7 +26,7 @@ public BlazorServerTemplateTest(ProjectFactoryFixture projectFactory)

public override string ProjectType { get; } = "blazorserver";

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30761")]
[Theory]
[InlineData(BrowserKind.Chromium)]
public async Task BlazorServerTemplateWorks_NoAuth(BrowserKind browserKind)
{
Expand Down Expand Up @@ -77,11 +78,8 @@ await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo) :
}
}

public static IEnumerable<object[]> BlazorServerTemplateWorks_IndividualAuthData =>
BrowserManager.WithBrowsers(new[] { BrowserKind.Chromium }, true, false);

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[MemberData(nameof(BlazorServerTemplateWorks_IndividualAuthData))]
[InlineData(BrowserKind.Chromium)]
[Theory]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/30825", Queues = "All.OSX")]
public async Task BlazorServerTemplateWorks_IndividualAuth(BrowserKind browserKind)
{
Expand Down Expand Up @@ -134,29 +132,9 @@ public async Task BlazorServerTemplateWorks_IndividualAuth(BrowserKind browserKi

private async Task TestBasicNavigation(IPage page)
{
var socket = await page.WaitForWebSocketAsync();

var framesReceived = 0;
var framesSent = 0;

void FrameReceived(object sender, IWebSocketFrame frame) { framesReceived++; }
void FrameSent(object sender, IWebSocketFrame frame) { framesSent++; }

socket.FrameReceived += FrameReceived;
socket.FrameSent += FrameSent;
// Wait for the page to load, and the connection to idle for >500ms
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new() { Timeout = 60_000 });

// Receive render batch
await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesReceived == 1 });
await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesSent == 1 });

// JS interop call to intercept navigation
await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesReceived == 2 });
await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesSent == 2 });

socket.FrameReceived -= FrameReceived;
socket.FrameSent -= FrameSent;

await page.WaitForSelectorAsync("nav");
// <title> element gets project ID injected into it during template execution
Assert.Equal("Index", (await page.TitleAsync()).Trim());

Expand All @@ -168,10 +146,13 @@ private async Task TestBasicNavigation(IPage page)
await page.WaitForSelectorAsync("h1+p >> text=Current count: 0");

// Clicking the counter button works
await page.ClickAsync("p+button >> text=Click me");
await page.WaitForSelectorAsync("h1+p >> text=Current count: 1");
for (var i = 1; i <= 3; i++)
{
await page.ClickAsync("p+button >> text=Click me");
await page.WaitForSelectorAsync($"h1+p >> text=Current count: {i}");
}

// Can navigate to the 'fetch data' page
// Can navigate to the 'Fetch Data' page
await page.ClickAsync("a[href=fetchdata] >> text=Fetch data");
await page.WaitForSelectorAsync("h1 >> text=Weather forecast");

Expand All @@ -180,7 +161,7 @@ private async Task TestBasicNavigation(IPage page)
Assert.Equal(5, await page.Locator("p+table>tbody>tr").CountAsync());
}

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory(Skip="https://github.com/dotnet/aspnetcore/issues/46430")]
[InlineData("IndividualB2C", null)]
[InlineData("IndividualB2C", new [] { "--called-api-url \"https://graph.microsoft.com\"", "--called-api-scopes user.readwrite" })]
[InlineData("SingleOrg", null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class BlazorTemplateTest : BrowserTestBase
public BlazorTemplateTest(ProjectFactoryFixture projectFactory)
{
ProjectFactory = projectFactory;
Microsoft.Playwright.Program.Main(new[] { "install" });
}

public ProjectFactoryFixture ProjectFactory { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BlazorWasmTemplateTest(ProjectFactoryFixture projectFactory)

public override string ProjectType { get; } = "blazorwasm";

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory]
[InlineData(BrowserKind.Chromium)]
public async Task BlazorWasmStandaloneTemplate_Works(BrowserKind browserKind)
{
Expand Down Expand Up @@ -59,7 +59,7 @@ private static async Task<IPage> NavigateToPage(IBrowserContext browser, string
return page;
}

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory(Skip="https://github.com/dotnet/aspnetcore/issues/46430")]
[InlineData(BrowserKind.Chromium)]
public async Task BlazorWasmHostedTemplate_Works(BrowserKind browserKind)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ private static async Task AssertCompressionFormat(AspNetProcess aspNetProcess, s
Assert.Equal(expectedEncoding, response.Content.Headers.ContentEncoding.Single());
}

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/45736")]
Copy link
Member

Choose a reason for hiding this comment

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

The issue here was blocked on a Playwright issue, which they have resolved with the following comment:
image

Does that impact our decisions regarding this in any way?
I assume you're trying to wrap up your work already, and leaving this to be handled as part of the work on the linked issue is the right thing to do. So mostly wanted to note the progress on the dependency.

Copy link
Member

Choose a reason for hiding this comment

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

Going to try un-skipping this

Copy link
Member

Choose a reason for hiding this comment

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

Nope, still failing

[InlineData(BrowserKind.Chromium)]
public async Task BlazorWasmStandalonePwaTemplate_Works(BrowserKind browserKind)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task BlazorWasmStandalonePwaTemplate_Works(BrowserKind browserKind)
}
}

[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/45736")]
[InlineData(BrowserKind.Chromium)]
public async Task BlazorWasmHostedPwaTemplate_Works(BrowserKind browserKind)
{
Expand Down Expand Up @@ -212,15 +212,15 @@ private static void ValidatePublishedServiceWorker(Project project)
Assert.True(serviceWorkerContents.Contains($"/* Manifest version: {serviceWorkerAssetsManifestVersion} */", StringComparison.Ordinal));
}

[ConditionalTheory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[ConditionalTheory(Skip="https://github.com/dotnet/aspnetcore/issues/46430")]
[InlineData(BrowserKind.Chromium)]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithLocalDB(BrowserKind browserKind)
=> BlazorWasmHostedTemplate_IndividualAuth_Works(browserKind, true);

// This test depends on BlazorWasmTemplate_CreateBuildPublish_IndividualAuthNoLocalDb running first
[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/30882")]
[Theory(Skip="https://github.com/dotnet/aspnetcore/issues/46430")]
[InlineData(BrowserKind.Chromium)]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/30825", Queues = "All.OSX")]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB(BrowserKind browserKind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<TestGroupName>ProjectTemplates.Blazor.E2ETests</TestGroupName>
<DefineConstants>$(DefineConstants);XPLAT</DefineConstants>

<RequiresDelayedBuild>true</RequiresDelayedBuild>

<RunTemplateTests Condition="'$(RunTemplateTests)' == ''">true</RunTemplateTests>
<SkipTests Condition="'$(RunTemplateTests)' != 'true'">true</SkipTests>
<RunBlazorPlaywrightTemplateTests Condition="'$(RunBlazorPlaywrightTemplateTests)' == ''">$(RunTemplateTests)</RunBlazorPlaywrightTemplateTests>
<SkipTests Condition="'$(RunBlazorPlaywrightTemplateTests)' != 'true'">true</SkipTests>

<BaseOutputPath />
<OutputPath />

Expand Down Expand Up @@ -47,6 +51,7 @@
<Reference Include="Microsoft.Extensions.Configuration.Json" />
<Reference Include="AngleSharp" />
<Reference Include="System.Net.Http" />
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<Reference Include="Microsoft.Playwright" Condition="'$(IsPlaywrightAvailable)' == 'true'" />
<Reference Include="Microsoft.Playwright" ExcludeAssets="build" Condition="'$(IsPlaywrightAvailable)' != 'true'" />
<ProjectReference Include="$(RepoRoot)src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj"
Expand Down
16 changes: 0 additions & 16 deletions src/ProjectTemplates/test/Templates.Blazor.Tests/package.json

This file was deleted.

Loading