Skip to content

Commit f5c1324

Browse files
authored
Add remote auth forms test (#196)
1 parent bb35430 commit f5c1324

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

Microsoft.AspNetCore.SystemWebAdapters.sln

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.System
5757
EndProject
5858
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.MVCApp.Tests", "test\Samples.MVCApp.Tests\Samples.MVCApp.Tests.csproj", "{C4F5601D-8D33-4C95-BCFD-EDEF1DC095B4}"
5959
EndProject
60+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.RemoteAuth.Forms.Tests", "test\Samples.RemoteAuth.Forms.Tests\Samples.RemoteAuth.Forms.Tests.csproj", "{7C994084-D425-487C-9266-413BB0C22695}"
61+
EndProject
6062
Global
6163
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6264
Debug|Any CPU = Debug|Any CPU
@@ -127,6 +129,10 @@ Global
127129
{C4F5601D-8D33-4C95-BCFD-EDEF1DC095B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
128130
{C4F5601D-8D33-4C95-BCFD-EDEF1DC095B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
129131
{C4F5601D-8D33-4C95-BCFD-EDEF1DC095B4}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{7C994084-D425-487C-9266-413BB0C22695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{7C994084-D425-487C-9266-413BB0C22695}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{7C994084-D425-487C-9266-413BB0C22695}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{7C994084-D425-487C-9266-413BB0C22695}.Release|Any CPU.Build.0 = Release|Any CPU
130136
EndGlobalSection
131137
GlobalSection(SolutionProperties) = preSolution
132138
HideSolutionNode = FALSE
@@ -152,6 +158,7 @@ Global
152158
{134659FA-F2BB-4E54-BB68-49E88EA2778F} = {25382551-D3BE-46C0-AAB5-8D2C64D4EDDD}
153159
{6931FEFB-DC18-4B3F-8AFC-EDA03063A518} = {F9DB9323-C919-49E8-8F96-B923D2F42E60}
154160
{C4F5601D-8D33-4C95-BCFD-EDEF1DC095B4} = {A1BDA50C-D70B-416C-97F1-74B0649797C5}
161+
{7C994084-D425-487C-9266-413BB0C22695} = {A1BDA50C-D70B-416C-97F1-74B0649797C5}
155162
EndGlobalSection
156163
GlobalSection(ExtensibilityGlobals) = postSolution
157164
SolutionGuid = {DABA3C65-9D74-4EB6-9B1C-730328710EAD}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Microsoft.Playwright.NUnit;
2+
using NUnit.Framework;
3+
4+
namespace PlaywrightTests;
5+
6+
[Parallelizable(ParallelScope.Self)]
7+
public class FormsSampleTest : PageTest
8+
{
9+
private const string FrameworkAppUrl = "https://localhost:44394/";
10+
private const string CoreAppUrl = "https://localhost:7080/";
11+
12+
[Test]
13+
public async Task CoreAppCanLogout()
14+
{
15+
var username = "User1";
16+
17+
await Page.GotoAsync(FrameworkAppUrl);
18+
await Expect(Page.Locator("text=My ASP.NET Application")).ToBeVisibleAsync();
19+
20+
// Login
21+
await Page.Locator("a:has-text(\"Log In\")").ClickAsync();
22+
await Page.Locator("input[name=\"ctl00\\$MainContent\\$UserName\"]").TypeAsync(username);
23+
await Page.Locator("input[name=\"ctl00\\$MainContent\\$Password\"]").TypeAsync("PasswordA");
24+
await Page.Locator(@"input:has-text(""Login"")").ClickAsync();
25+
await Expect(Page.Locator($"text=Welcome back, {username}!")).ToBeVisibleAsync();
26+
27+
// Make sure core app also logged in
28+
await Page.GotoAsync(CoreAppUrl);
29+
await Expect(Page.Locator($"text=Hello {username}!")).ToBeVisibleAsync();
30+
31+
// Logout on core app and make sure both logged out
32+
await Page.Locator(@"text=Log out").ClickAsync();
33+
await Expect(Page.Locator($"text=You have been logged out")).ToBeVisibleAsync();
34+
35+
// Note: Logout on core app doesn't logout framework app
36+
//await Page.GotoAsync(FrameworkAppUrl);
37+
//await Expect(Page.Locator(@"text=Login")).ToBeVisibleAsync();
38+
}
39+
40+
[Test]
41+
public async Task FrameworkCanLogoutBothApps()
42+
{
43+
var username = "User1";
44+
45+
// Login with core app
46+
await Page.GotoAsync(CoreAppUrl);
47+
await Expect(Page.Locator("text=ASP.NET Core")).ToBeVisibleAsync();
48+
49+
// Login
50+
await Page.Locator("a:has-text(\"Log In\")").ClickAsync();
51+
await Page.Locator("input[name=\"ctl00\\$MainContent\\$UserName\"]").TypeAsync(username);
52+
await Page.Locator("input[name=\"ctl00\\$MainContent\\$Password\"]").TypeAsync("PasswordA");
53+
await Page.Locator(@"input:has-text(""Login"")").ClickAsync();
54+
await Expect(Page.Locator($"text=Welcome back, {username}!")).ToBeVisibleAsync();
55+
56+
// Make sure framework app also logged in
57+
await Page.GotoAsync(FrameworkAppUrl);
58+
await Expect(Page.Locator($"text=Welcome back, {username}!")).ToBeVisibleAsync();
59+
60+
// Logout on framework app and make sure both logged out
61+
await Page.Locator(@"text=Logout").ClickAsync();
62+
await Expect(Page.Locator(@"text=Login")).ToBeVisibleAsync();
63+
await Page.GotoAsync(CoreAppUrl);
64+
await Expect(Page.Locator(@"text=Log in")).ToBeVisibleAsync();
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Playwright tests for samples/RemoteAuth/FormsAuth and FormsAuthCore
2+
3+
This project is meant to be used to verify functionality of the FormsAuth and FormsAuthCore sample apps using playwright.
4+
5+
## Set up
6+
7+
- These tests currently expect the sample apps to be run, i.e. run both FormsAuth and FormsAuthCore from the sln.
8+
- Run `dotnet test` to launch the playwright tests.
9+
- Set PWDEBUG=1 in the environment to enable the playwright debugger which is super helpful.
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
13+
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.25.0" />
14+
<PackageReference Include="NUnit" Version="3.13.3" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
16+
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
17+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
18+
</ItemGroup>
19+
20+
</Project>

0 commit comments

Comments
 (0)