|
| 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 | +} |
0 commit comments