|
| 1 | +using Microsoft.Playwright; |
| 2 | +using Microsoft.Playwright.MSTest; |
| 3 | +using System.Text.RegularExpressions; |
| 4 | + |
| 5 | +namespace AudioCuesheetEditor.End2EndTests.Pages |
| 6 | +{ |
| 7 | + [TestClass] |
| 8 | + public class IndexTest : PageTest |
| 9 | + { |
| 10 | + [TestInitialize] |
| 11 | + public async Task TestInitialize() |
| 12 | + { |
| 13 | + await Context.Tracing.StartAsync(new() |
| 14 | + { |
| 15 | + Title = $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}", |
| 16 | + Screenshots = true, |
| 17 | + Snapshots = true, |
| 18 | + Sources = true |
| 19 | + }); |
| 20 | + } |
| 21 | + |
| 22 | + [TestCleanup] |
| 23 | + public async Task TestCleanup() |
| 24 | + { |
| 25 | + var failed = new[] { UnitTestOutcome.Failed, UnitTestOutcome.Error, UnitTestOutcome.Timeout, UnitTestOutcome.Aborted }.Contains(TestContext.CurrentTestOutcome); |
| 26 | + |
| 27 | + await Context.Tracing.StopAsync(new() |
| 28 | + { |
| 29 | + Path = failed ? Path.Combine( |
| 30 | + Environment.CurrentDirectory, |
| 31 | + "playwright-traces", |
| 32 | + $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip" |
| 33 | + ) : null, |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + public async Task HasTitle() |
| 39 | + { |
| 40 | + await Page.GotoAsync("http://localhost:5132/"); |
| 41 | + await Expect(Page).ToHaveTitleAsync("AudioCuesheetEditor"); |
| 42 | + await Expect(Page.GetByRole(AriaRole.Button, new() { Name = "AudioCuesheetEditor" })).ToBeVisibleAsync(); |
| 43 | + } |
| 44 | + |
| 45 | + [TestMethod] |
| 46 | + public async Task CheckSettings() |
| 47 | + { |
| 48 | + await Page.GotoAsync("http://localhost:5132/"); |
| 49 | + await Page.GetByRole(AriaRole.Toolbar).GetByRole(AriaRole.Button).Filter(new() { HasTextRegex = new Regex("^$") }).Nth(3).ClickAsync(); |
| 50 | + await Page.Locator("div").Filter(new() { HasTextRegex = new Regex("^Settings$") }).ClickAsync(); |
| 51 | + await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Settings" })).ToBeVisibleAsync(); |
| 52 | + } |
| 53 | + |
| 54 | + [TestMethod] |
| 55 | + public async Task Record() |
| 56 | + { |
| 57 | + await Page.GotoAsync("http://localhost:5132/"); |
| 58 | + await Page.GetByText("Record view").ClickAsync(); |
| 59 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Start recording" }).ClickAsync(); |
| 60 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Artist", Exact = true }).ClickAsync(); |
| 61 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Artist", Exact = true }).FillAsync("Test Track 1 Artist"); |
| 62 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Artist", Exact = true }).PressAsync("Tab"); |
| 63 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Title", Exact = true }).FillAsync("Test Track 1 Title"); |
| 64 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Title", Exact = true }).PressAsync("Tab"); |
| 65 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Add track" }).ClickAsync(); |
| 66 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Artist", Exact = true }).FillAsync("Test Track 2 Artist"); |
| 67 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Artist", Exact = true }).PressAsync("Tab"); |
| 68 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Title", Exact = true }).FillAsync("Test Track 2 Title"); |
| 69 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Title", Exact = true }).PressAsync("Tab"); |
| 70 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Add track" }).ClickAsync(); |
| 71 | + await Page.Locator(".mud-overlay").ClickAsync(); |
| 72 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Stop recording" }).ClickAsync(); |
| 73 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = "Test Track 1 Artist Clear" })).ToBeVisibleAsync(); |
| 74 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = "Test Track 1 Title Clear" })).ToBeVisibleAsync(); |
| 75 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = "Test Track 2 Artist Clear" })).ToBeVisibleAsync(); |
| 76 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = "Test Track 2 Title Clear" })).ToBeVisibleAsync(); |
| 77 | + } |
| 78 | + |
| 79 | + [TestMethod] |
| 80 | + public async Task Import() |
| 81 | + { |
| 82 | + await Page.GotoAsync("http://localhost:5132/"); |
| 83 | + await Page.GetByText("Import view").ClickAsync(); |
| 84 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Choose File" }).SetInputFilesAsync(new[] { "../../../../AudioCuesheetEditor/wwwroot/samples/Sample_Inputfile.txt" }); |
| 85 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Complete" }).ClickAsync(); |
| 86 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = "Sample Artist 1 Clear" })).ToBeVisibleAsync(); |
| 87 | + await Expect(Page.GetByRole(AriaRole.Cell, new() { Name = ":20:13" }).Nth(1)).ToBeVisibleAsync(); |
| 88 | + await Expect(Page.GetByRole(AriaRole.Textbox, new() { Name = "Cuesheet artist" })).ToHaveValueAsync("CuesheetArtist"); |
| 89 | + await Page.GetByRole(AriaRole.Textbox, new() { Name = "Cuesheet title" }).ClickAsync(); |
| 90 | + await Expect(Page.GetByRole(AriaRole.Group).Filter(new() { HasText = "AudiofileAudiofile Search" }).Locator("input[type=\"file\"]")).ToBeEmptyAsync(); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments