-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.Playwright; | ||
using Microsoft.Playwright.TestAdapter; | ||
|
||
namespace Testing.Browser.Base; | ||
|
||
public class PageTest : IAsyncLifetime | ||
{ | ||
private readonly PlaywrightFixture _fixture; | ||
public IPage Page => _fixture.Page; | ||
public IBrowser Browser => _fixture.Browser; | ||
public IBrowserContext Context => _fixture.Context; | ||
|
||
public PageTest() | ||
{ | ||
_fixture = new PlaywrightFixture(); | ||
} | ||
|
||
public ILocatorAssertions Expect(ILocator locator) => Assertions.Expect(locator); | ||
public IPageAssertions Expect(IPage page) => Assertions.Expect(page); | ||
public IAPIResponseAssertions Expect(IAPIResponse response) => Assertions.Expect(response); | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
await _fixture.InitializeAsync(); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await _fixture.DisposeAsync(); | ||
} | ||
} | ||
|
||
public class PlaywrightFixture : IAsyncLifetime | ||
{ | ||
public async Task InitializeAsync() | ||
{ | ||
PlaywrightInstance = await Playwright.CreateAsync(); | ||
Browser = await PlaywrightInstance.Chromium.LaunchAsync(); | ||
Context = await Browser.NewContextAsync(new BrowserNewContextOptions()); | ||
Page = await Context.NewPageAsync(); | ||
} | ||
|
||
public IPage Page { get; set; } | ||
public IBrowser Browser { get; set; } = null!; | ||
public IBrowserContext Context { get; set; } = null!; | ||
private IPlaywright PlaywrightInstance { get; set; } = null!; | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await Browser.DisposeAsync(); | ||
PlaywrightInstance.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.Playwright; | ||
using Testing.Browser.Base; | ||
|
||
namespace Testing.Browser; | ||
|
||
public class LoginPageTests: PageTest | ||
{ | ||
[Fact] | ||
public async Task CanLoginClicking() | ||
{ | ||
await Page.GotoAsync("https://staging.languagedepot.org/login"); | ||
|
||
await Page.GetByLabel("Email (or Send/Receive username)").ClickAsync(); | ||
|
||
await Page.GetByLabel("Email (or Send/Receive username)").FillAsync("KindLion"); | ||
|
||
await Page.GetByLabel("Password").ClickAsync(); | ||
|
||
await Page.GetByLabel("Password").FillAsync("pass"); | ||
|
||
await Page.GetByRole(AriaRole.Button, new() { Name = "Log in" }).ClickAsync(); | ||
|
||
await Expect(Page).ToHaveURLAsync("https://staging.languagedepot.org/admin"); | ||
} | ||
|
||
[Fact] | ||
public async Task CanLoginKeyboardNavigation() | ||
{ | ||
await Page.GotoAsync("https://staging.languagedepot.org/login"); | ||
|
||
await Page.GetByLabel("Email (or Send/Receive username)").FillAsync("KindLion"); | ||
|
||
await Page.GetByLabel("Email (or Send/Receive username)").PressAsync("Tab"); | ||
|
||
await Page.GetByLabel("Password").FillAsync("pass"); | ||
|
||
await Page.GetByLabel("Password").PressAsync("Enter"); | ||
|
||
await Expect(Page).ToHaveURLAsync("https://staging.languagedepot.org/admin"); | ||
} | ||
|
||
[Fact] | ||
public async Task ShowErrorWithoutUsername() | ||
{ | ||
await Page.GotoAsync("https://staging.languagedepot.org/login"); | ||
|
||
await Page.GetByRole(AriaRole.Button, new() { Name = "Log in" }).ClickAsync(); | ||
|
||
await Expect(Page).ToHaveURLAsync("https://staging.languagedepot.org/login"); | ||
await Expect(Page.GetByText("User info missing")).ToBeVisibleAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters