Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
felixcicatt committed Dec 18, 2024
1 parent bc4d081 commit 483a335
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
113 changes: 43 additions & 70 deletions Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies/Scenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -118,34 +107,36 @@ 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);

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
{
Expand All @@ -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);
Expand All @@ -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
{
Expand All @@ -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<TimeoutException>(
() => 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]
Expand Down

0 comments on commit 483a335

Please sign in to comment.