Skip to content

Commit 4546124

Browse files
authored
Add Playwright tests for read-only mode (#10673)
* Pull WebTestFramework assembly from package instead of GAC, this allows building in VS 2026 * Add playwright tests for ReadOnlyMode * Enable DEV configuration for local testing
1 parent c0e27c2 commit 4546124

16 files changed

Lines changed: 161 additions & 15 deletions

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<PackageVersion Include="Microsoft.Internal.NuGet.Testing.SignedPackages" Version="6.13.2-rc.1" />
8585
<PackageVersion Include="Microsoft.Net.Http" Version="2.2.29" />
8686
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
87+
<PackageVersion Include="Microsoft.Playwright.Xunit" Version="1.57.0" />
8788
<PackageVersion Include="Microsoft.Owin.Host.SystemWeb" Version="4.2.2" />
8889
<PackageVersion Include="Microsoft.Owin.Security.Cookies" Version="4.2.2" />
8990
<PackageVersion Include="Microsoft.Owin.Security.MicrosoftAccount" Version="4.2.2" />
@@ -93,6 +94,7 @@
9394
<PackageVersion Include="Microsoft.Rest.ClientRuntime" Version="2.3.24" />
9495
<PackageVersion Include="Microsoft.Security.Utilities.Core" Version="1.12.0" />
9596
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
97+
<PackageVersion Include="Microsoft.TestPlatform" Version="17.14.1" />
9698
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="1.8.24" />
9799
<PackageVersion Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
98100
<PackageVersion Include="Microsoft.Web.Xdt" Version="3.1.0" />

tests/NuGetGallery.FunctionalTests.Core/EnvironmentSettings.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -19,7 +19,19 @@ public static class EnvironmentSettings
1919
};
2020

2121
public const string ConfigurationFilePathVariableName = "ConfigurationFilePath";
22-
public static string ConfigurationFilePath => GetEnvironmentVariable(ConfigurationFilePathVariableName, required: true);
22+
23+
public static string ConfigurationFilePath
24+
{
25+
get
26+
{
27+
#if DEBUG
28+
bool required = false;
29+
#else
30+
bool required = true;
31+
#endif
32+
return GetEnvironmentVariable(ConfigurationFilePathVariableName, required) ?? "settings.DEV.json";
33+
}
34+
}
2335

2436
private static string GetEnvironmentVariable(string key, bool required)
2537
{

tests/NuGetGallery.FunctionalTests.Core/GalleryConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class GalleryConfiguration
1919
public string Slot { get; set; }
2020
public string ProductionBaseUrl { get; set; }
2121
public string StagingBaseUrl { get; set; }
22-
public string EmailServerHost { get; set; }
2322
public bool DefaultSecurityPoliciesEnforced { get; set; }
2423
public bool TestPackageLock { get; set; }
2524
public AccountConfiguration Account { get; set; }

tests/NuGetGallery.FunctionalTests.Core/NuGetGallery.FunctionalTests.Core.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\VisualStudioSearchPath.props" />
33
<PropertyGroup>
44
<TargetFramework>net472</TargetFramework>
55
<RootNamespace>NuGetGallery.FunctionalTests</RootNamespace>
66
</PropertyGroup>
77
<ItemGroup>
8-
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework" />
8+
<Reference Include="$(PkgMicrosoft_TestPlatform)\tools\net462\Common7\IDE\Extensions\TestPlatform\Microsoft.VisualStudio.QualityTools.WebTestFramework.dll" />
99
<Reference Include="System.IO.Compression" />
1010
</ItemGroup>
1111
<ItemGroup>
@@ -16,6 +16,8 @@
1616
Proper fix tracked here: https://github.com/NuGet/Engineering/issues/5669
1717
-->
1818
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="2.2.0" />
19+
<PackageReference Include="Microsoft.Playwright.Xunit" />
20+
<PackageReference Include="Microsoft.TestPlatform" GeneratePathProperty="true" />
1921
<PackageReference Include="Microsoft.Web.Xdt" />
2022
<PackageReference Include="NuGet.Core" />
2123
<PackageReference Include="NuGet.Services.Configuration" VersionOverride="2.94.0" />
@@ -26,4 +28,4 @@
2628
<PrivateAssets>all</PrivateAssets>
2729
</PackageReference>
2830
</ItemGroup>
29-
</Project>
31+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Threading.Tasks;
5+
using Microsoft.Playwright;
6+
using Microsoft.Playwright.Xunit;
7+
8+
#nullable enable
9+
10+
namespace NuGetGallery.FunctionalTests.Playwright
11+
{
12+
public class NuGetPageTest : PageTest
13+
{
14+
override public async Task InitializeAsync()
15+
{
16+
// Uncomment this to make Playwright run in headed mode (visible browser) for debugging.
17+
// Environment.SetEnvironmentVariable("HEADED", "1");
18+
await base.InitializeAsync();
19+
}
20+
21+
public async Task SignInAsync(string? email = null, string? password = null)
22+
{
23+
await Page.GotoAsync(UrlHelper.LogonPageUrl);
24+
25+
await Page.Locator("input[name='SignIn.UserNameOrEmail']").FillAsync(email ?? GalleryConfiguration.Instance.Account.Email);
26+
await Page.Locator("input[name='SignIn.Password']").FillAsync(password ?? GalleryConfiguration.Instance.Account.Password);
27+
await Page.Locator("input:has-text('Sign in')").ClickAsync();
28+
29+
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
30+
}
31+
}
32+
}

tests/NuGetGallery.FunctionalTests/NuGetGallery.FunctionalTests.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net472</TargetFramework>
44
</PropertyGroup>
@@ -24,10 +24,15 @@
2424
<StaticAssets Include="$(GalleryDirectory)\Scripts\**\*.js" Visible="false" />
2525
<StaticAssets Include="$(GalleryDirectory)\Content\**\*.css" Visible="false" />
2626
</ItemGroup>
27+
<ItemGroup>
28+
<None Update="settings.DEV.json">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
2732
<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
2833
<WriteLinesToFile File="StaticAssets\Data.g.txt" Lines="$(GalleryDirectory);@(StaticAssets)" Overwrite="true" />
2934
<ItemGroup>
3035
<EmbeddedResource Include="StaticAssets\Data.g.txt" />
3136
</ItemGroup>
3237
</Target>
33-
</Project>
38+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Net;
5+
using System.Threading.Tasks;
6+
using Microsoft.Playwright.Xunit;
7+
using Xunit;
8+
9+
namespace NuGetGallery.FunctionalTests.Playwright.BasicPages
10+
{
11+
public class HomePageValidationTest : NuGetPageTest
12+
{
13+
[Fact]
14+
[Category("P0Tests")]
15+
[Category("ReadOnlyModeTests")]
16+
public async Task HomePageLoads_ContainsExpectedText()
17+
{
18+
// Act
19+
var response = await Page.GotoAsync(UrlHelper.BaseUrl);
20+
21+
// Assert
22+
Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)response.Status);
23+
await Expect(Page.Locator(".what-is-nuget")).ToContainTextAsync(Constants.HomePageText);
24+
}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Net;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
8+
namespace NuGetGallery.FunctionalTests.Playwright.ReadOnlyMode
9+
{
10+
public class LogonInReadOnlyModeTest : NuGetPageTest
11+
{
12+
[Fact]
13+
[Category("ReadOnlyModeTests")]
14+
public async Task LoginPostToReadOnlyServer_Returns503_WithReadOnlyModeError()
15+
{
16+
// Act
17+
var responseTask = Page.WaitForResponseAsync(response => response.Url.Contains("SignIn"));
18+
await SignInAsync();
19+
20+
// Assert
21+
var response = await responseTask;
22+
await Expect(Page.Locator(".error-title")).ToContainTextAsync(Constants.ReadOnlyModeError);
23+
Assert.Equal(HttpStatusCode.ServiceUnavailable, (HttpStatusCode) response.Status);
24+
}
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
// Note to NuGet team members: Do not edit this file if you encounter authentication issues.
3+
// Instead, please check your access to the NuGetE2EVault Key Vault.
4+
"DefaultSecurityPoliciesEnforced": true,
5+
"TestPackageLock": true,
6+
"TyposquattingCheckAndBlockUsers": true,
7+
"Branding": {
8+
"BrandingMessage": "&#169; Microsoft {0}",
9+
"PrivacyPolicyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
10+
"TrademarksUrl": "https://www.microsoft.com/trademarks"
11+
},
12+
"Account": {
13+
"Name": "NugetTestAccount",
14+
"Email": "[email protected]",
15+
"Password": "$$Dev-GalleryFunc-Account-Password$$",
16+
"ApiKey": "$$Dev-GalleryFunc-Account-ApiKey$$",
17+
"ApiKeyPush": "$$Dev-GalleryFunc-Account-ApiKeyPush$$",
18+
"ApiKeyPushVersion": "$$Dev-GalleryFunc-Account-ApiKeyPushVersion$$",
19+
"ApiKeyUnlist": "$$Dev-GalleryFunc-Account-ApiKeyUnlist$$"
20+
},
21+
"AdminOrganization": {
22+
"Name": "NugetTestAdminOrganization",
23+
"ApiKey": "$$Dev-GalleryFunc-AdminOrganization-ApiKey$$"
24+
},
25+
"CollaboratorOrganization": {
26+
"Name": "NugetTestCollaboratorOrganization",
27+
"ApiKey": "$$Dev-GalleryFunc-CollaboratorOrganization-ApiKey$$"
28+
},
29+
"ProductionBaseUrl": "https://dev.nugettest.org",
30+
"StagingBaseUrl": "",
31+
"KeyVault_VaultName": "NuGetE2EVault",
32+
"KeyVault_UseManagedIdentity": "true"
33+
}

tests/NuGetGallery.WebUITests.P0/NuGetGallery.WebUITests.P0.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<IsTestProject>true</IsTestProject>
66
</PropertyGroup>
77
<ItemGroup>
8-
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework" />
8+
<Reference Include="$(PkgMicrosoft_TestPlatform)\tools\net462\Common7\IDE\Extensions\TestPlatform\Microsoft.VisualStudio.QualityTools.WebTestFramework.dll" />
99
<Reference Include="System.Web" />
1010
</ItemGroup>
1111
<ItemGroup>

0 commit comments

Comments
 (0)