diff --git a/.github/workflows/playwright.yaml b/.github/workflows/playwright.yaml index 807745ce5..34d347b1a 100644 --- a/.github/workflows/playwright.yaml +++ b/.github/workflows/playwright.yaml @@ -25,7 +25,7 @@ jobs: run: pwsh bin/Debug/net8.0/playwright.ps1 install --with-deps - name: Run your tests id: e2e - run: dotnet test + run: dotnet test --logger trx env: 'TestSettings:TEST_USERNAME': ${{ secrets.PLAYWRIGHT_USERNAME }} 'TestSettings:TEST_PASSWORD': '${{ secrets.PLAYWRIGHT_PASSWORD }}' diff --git a/Kiss.Bff.EndToEndTest/Infrastructure/BaseTestInitializer.cs b/Kiss.Bff.EndToEndTest/Infrastructure/BaseTestInitializer.cs index f659faa46..5dc90828e 100644 --- a/Kiss.Bff.EndToEndTest/Infrastructure/BaseTestInitializer.cs +++ b/Kiss.Bff.EndToEndTest/Infrastructure/BaseTestInitializer.cs @@ -18,6 +18,7 @@ public class BaseTestInitializer : PageTest [TestInitialize] public virtual async Task TestInitialize() { + Console.WriteLine("!!Scenario: " + TestContext.TestName); var username = GetRequiredConfig("TestSettings:TEST_USERNAME"); var password = GetRequiredConfig("TestSettings:TEST_PASSWORD"); diff --git a/Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies/Scenarios.cs b/Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies/Scenarios.cs index ae5aded26..1d3e0edba 100644 --- a/Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies/Scenarios.cs +++ b/Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies/Scenarios.cs @@ -49,7 +49,7 @@ public async Task Scenario3() And("there is a nieuws item"); await Expect(body).ToBeVisibleAsync(); - When("navigates through the HOME Page "); + When("navigates through the HOME Page"); await Page.GotoAsync("/"); And("clicks on the book icon next to the news icon"); @@ -63,16 +63,10 @@ public async Task Scenario3() await Expect(body).ToBeHiddenAsync(); } - /* - Given I am on the "News" tab - And there are at least 20 articles - When I click on the "Next" button to go to the next page - Then I should see 10 new articles on the next page - And the current page number should be 2 - */ [TestMethod] public async Task Scenario4() { + Given("there are at least 20 news articles"); var berichtRequests = Enumerable.Range(1, 20) .Select(x => new CreateBerichtRequest { @@ -81,35 +75,30 @@ public async Task Scenario4() await using var berichten = await Page.CreateBerichten(berichtRequests); + When("navigates through the HOME Page"); await Page.GotoAsync("/"); - // Given user is on "News" tab // Locate the 'Nieuws' section await Expect(Page.GetNieuwsSection()).ToBeVisibleAsync(); - // Locate the 'Next' page button using the pagination structure var nextPageButton = Page.GetNieuwsSection().Locator("[rel='next']").First; - // When I click on the "Next" button to go to the next page + And("clicks on the \"Next\" button to go to the next page"); await nextPageButton.ClickAsync(); - // And the current page number should be 2 + Then("should see 10 new articles on the next page"); + await Expect(Page.GetNieuwsSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); + + And("the current page number should be 2"); var currentPageButton = Page.GetNieuwsSection().Locator("[aria-current=page]"); var page2Button = Page.GetNieuwsSection().GetByLabel("Pagina 2"); await Expect(currentPageButton.And(page2Button)).ToBeVisibleAsync(); } - /* - Precondition: 20 news articles should be created and displayed on the "News" tab - Given I am on the "News" tab - And I am on page 2 with 10 articles displayed - When I click on the "Previous" button - Then I should see 10 articles on the first page - And the current page number should be 1 - */ [TestMethod] public async Task Scenario5() { + Given("there are at least 20 news articles"); var berichtRequests = Enumerable.Range(1, 20) .Select(x => new CreateBerichtRequest { @@ -118,21 +107,25 @@ public async Task Scenario5() await using var berichten = await Page.CreateBerichten(berichtRequests); + And("is on the HOME Page"); await Page.GotoAsync("/"); - // Given user is on "News" tab - // Locate the 'Nieuws' section await Expect(Page.GetNieuwsSection()).ToBeVisibleAsync(); // Locate the 'Next' page button using the pagination structure var nextPageButton = Page.GetNieuwsSection().Locator("[rel='next']").First; - // When I click on the "Next" button to go to the next page + And("is on page 2 with 10 articles displayed"); await nextPageButton.ClickAsync(); + await Expect(Page.GetNieuwsSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); - // And the current page number should be 2 + When("clicks on the \"Previous\" button"); var previousPageButton = Page.GetNieuwsSection().Locator("[rel='prev']").First; await previousPageButton.ClickAsync(); + Then("should see 10 new articles on the next page"); + await Expect(Page.GetNieuwsSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); + + And("the current page number should be 1"); var currentPageButton = Page.GetNieuwsSection().Locator("[aria-current=page]"); var page1Button = Page.GetNieuwsSection().GetByLabel("Pagina 1"); var currentPageButtonWithPage1Text = currentPageButton.And(page1Button); @@ -140,12 +133,10 @@ public async Task Scenario5() await Expect(currentPageButtonWithPage1Text).ToBeVisibleAsync(); } - /* - - */ [TestMethod] public async Task Scenario6() { + Given("there are at least 20 werkinstructies"); var berichtRequests = Enumerable.Range(1, 20) .Select(x => new CreateBerichtRequest { @@ -155,21 +146,24 @@ public async Task Scenario6() await using var berichten = await Page.CreateBerichten(berichtRequests); + And("is on the HOME Page"); await Page.GotoAsync("/"); - - // Given user is on "News" tab - // Locate the 'Nieuws' section await Expect(Page.GetWerkinstructiesSection()).ToBeVisibleAsync(); // Locate the 'Next' page button using the pagination structure var nextPageButton = Page.GetWerkinstructiesSection().Locator("[rel='next']").First; - // When I click on the "Next" button to go to the next page + And("is on page 2 with 10 articles displayed"); await nextPageButton.ClickAsync(); + await Expect(Page.GetWerkinstructiesSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); - // And the current page number should be 2 + When("clicks on the \"Previous\" button"); var previousPageButton = Page.GetWerkinstructiesSection().Locator("[rel='prev']").First; await previousPageButton.ClickAsync(); + Then("should see 10 new articles on the next page"); + await Expect(Page.GetWerkinstructiesSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); + + And("the current page number should be 1"); var currentPageButton = Page.GetWerkinstructiesSection().Locator("[aria-current=page]"); var page1Button = Page.GetWerkinstructiesSection().GetByLabel("Pagina 1"); var currentPageButtonWithPage1Text = currentPageButton.And(page1Button); @@ -180,6 +174,7 @@ public async Task Scenario6() [TestMethod] public async Task Scenario7() { + Given("there are at least 20 werkinstructies"); var berichtRequests = Enumerable.Range(1, 20) .Select(x => new CreateBerichtRequest { @@ -189,54 +184,32 @@ public async Task Scenario7() await using var berichten = await Page.CreateBerichten(berichtRequests); + And("is on the HOME Page"); await Page.GotoAsync("/"); - - // Given user is on "News" tab - // Locate the 'Nieuws' section await Expect(Page.GetWerkinstructiesSection()).ToBeVisibleAsync(); // Locate the 'Next' page button using the pagination structure var nextPageButton = Page.GetWerkinstructiesSection().Locator("[rel='next']").First; - // When I click on the "Next" button to go to the next page - await nextPageButton.ClickAsync(); - - // And the current page number should be 2 - var previousPageButton = Page.GetWerkinstructiesSection().Locator("[rel='prev']").First; - await previousPageButton.ClickAsync(); + And("is on the last page with 10 articles displayed"); + var werkinstructies = Page.GetWerkinstructiesSection().GetByRole(AriaRole.Article); - var currentPageButton = Page.GetWerkinstructiesSection().Locator("[aria-current=page]"); - var page1Button = Page.GetWerkinstructiesSection().GetByLabel("Pagina 1"); - var currentPageButtonWithPage1Text = currentPageButton.And(page1Button); - - await Expect(currentPageButtonWithPage1Text).ToBeVisibleAsync(); - } - - //[TestMethod] - //public async Task Als_ik_op_de_paginering_links_klik_navigeer_ik_naar_een_nieuwe_pagina() - //{ - - - // await Expect(nextPageButton).ToBeVisibleAsync(); - - // // Click the 'Next' page button - // await nextPageButton.ClickAsync(); + // keep clicking on the next page button until it's disabled + while (!await IsDisabledPage(nextPageButton)) + { + await nextPageButton.ClickAsync(); + await werkinstructies.First.WaitForAsync(); + } - // // Wait for the button to ensure the page navigation has started - // await nextPageButton.WaitForAsync(); + await Expect(Page.GetWerkinstructiesSection().GetByRole(AriaRole.Article)).ToHaveCountAsync(10); - // // Verify that the first page button is still visible after navigation - // var firstPageButton = NieuwsSection.GetByLabel("Pagina 1"); - // // TODO fix the pagination component. numbers should always have an aria label with the number in it - // //await Expect(firstPageButton).ToBeVisibleAsync(); + When("clicks on the \"Next\" button"); - // // Verify that the current page button reflects the correct page number - // var currentPageButton = NieuwsSection.Locator("[aria-current=page]"); - // var page2Button = NieuwsSection.GetByLabel("Pagina 2"); - // var page2ButtonWithAriaCurrentPage = currentPageButton.And(page2Button); + await Assert.ThrowsExceptionAsync( + () => nextPageButton.ClickAsync(new() { Timeout = 1000 }), + "Expected the button to not be clickable, but it was"); - // // Ensure the current page button's aria-label attribute is 'Pagina 2' - // await Expect(page2ButtonWithAriaCurrentPage).ToBeVisibleAsync(); - //} + Then("should remain on the last page"); + } //[TestMethod]