diff --git a/PlaywrigthUITests/PageObjects/WebTablesPage.cs b/PlaywrigthUITests/PageObjects/WebTablesPage.cs index 93ebc60..7ac9d2f 100644 --- a/PlaywrigthUITests/PageObjects/WebTablesPage.cs +++ b/PlaywrigthUITests/PageObjects/WebTablesPage.cs @@ -2,183 +2,168 @@ using NUnit.Framework; using System.Threading.Tasks; -internal class WebTablesPage(IPage page) +namespace PlaywrigthUITests.PageObjects { - #region TEST DATA: - //page: - private readonly IPage page = page; - private readonly string testPageUrl = "https://demoqa.com/webtables"; - //locators: - private readonly string tableLocator = ".ReactTable"; - private readonly string rowLocator = ".rt-tr-group"; - private readonly string headerLocator = ".rt-th"; - private readonly string cellLocator = ".rt-td"; - private readonly string addPopUpLocator = ".modal-content"; - //input placeholders: - private readonly string searchPlaceholder = "Type to search"; - private readonly string firstNamePlaceholder = "First Name"; - private readonly string lastNamePlaceholder = "Last Name"; - private readonly string emailPlaceholder = "name@example.com"; - private readonly string agePlaceholder = "Age"; - private readonly string salaryPlaceholder = "Salary"; - private readonly string departmentPlaceholder = "Department"; - #endregion - - public async Task GoToTestPageURL() + internal class WebTablesPage(IPage page) { - await page.GotoAsync(testPageUrl); - await page.WaitForURLAsync(testPageUrl); - } + private readonly IPage page = page; - public async Task IsPageH1Visible(string pageH1) - { - await Assertions.Expect(page.GetByRole(AriaRole.Heading, new() { Name = pageH1 })).ToBeVisibleAsync(); - } - - #region Table: - public async Task IsTableVisible() - { - await Assertions.Expect(page.Locator(tableLocator)).ToBeVisibleAsync(); - } - public async Task IsTableRowVisible() - { - await Assertions.Expect(page.Locator(rowLocator).First).ToBeVisibleAsync(); - } - public async Task VerifyTableHeadersContent(string headerName) - { - var headers = await page.Locator(headerLocator).AllInnerTextsAsync(); - var headerList = headers.ToList(); - Assert.That(headerList, Does.Contain(headerName), $"The header '{headerName}' was not found in the table headers."); - } - public async Task VerifyFirstRowContentIsPresent(string contentValue) - { - var row = page.Locator(rowLocator).First; - var cells = await row.Locator(cellLocator).AllInnerTextsAsync(); - var cellList = cells.ToList(); - Assert.That(cellList, Does.Contain(contentValue), $"The search value '{contentValue}' was not found in the table."); - } - public async Task VerifyFirstRowContentIsNotPresent(string contentValue) - { - var row = page.Locator(rowLocator).First; - var cells = await row.Locator(cellLocator).AllInnerTextsAsync(); - var cellList = cells.ToList(); - Assert.That(cellList, Does.Not.Contain(contentValue), $"The search value '{contentValue}' was not found in the table."); - } - public async Task VerifyTableContent(string headerName, string cellValue) - { - var table = page.Locator(tableLocator); - var headers = await table.Locator(headerLocator).AllInnerTextsAsync(); - var headerList = headers.ToList(); - int headerIndex = headerList.IndexOf(headerName); - - if (headerIndex == -1) + public async Task GoToTestPageURL() { - throw new Exception($"Header '{headerName}' not found."); + await page.GotoAsync("https://demoqa.com/webtables"); + await page.WaitForURLAsync("https://demoqa.com/webtables"); } - var rows = table.Locator(rowLocator); - var rowCount = await rows.CountAsync(); + public async Task IsPageH1Visible(string pageH1) + { + await Assertions.Expect(page.GetByRole(AriaRole.Heading, new() { Name = pageH1 })).ToBeVisibleAsync(); + } - bool isCellContentPresent = false; - for (int i = 0; i < rowCount; i++) + #region Table: + public async Task IsTableVisible() + { + await Assertions.Expect(page.Locator(".ReactTable")).ToBeVisibleAsync(); + } + public async Task IsTableRowVisible() + { + await Assertions.Expect(page.Locator(".rt-tr-group").First).ToBeVisibleAsync(); + } + public async Task VerifyTableHeadersContent(string headerName) + { + var headers = await page.Locator(".rt-th").AllInnerTextsAsync(); + var headerList = headers.ToList(); + Assert.That(headerList, Does.Contain(headerName), $"The header '{headerName}' was not found in the table headers."); + } + public async Task VerifyFirstRowContentIsPresent(string contentValue) + { + var row = page.Locator(".rt-tr-group").First; + var cells = await row.Locator(".rt-td").AllInnerTextsAsync(); + var cellList = cells.ToList(); + Assert.That(cellList, Does.Contain(contentValue), $"The search value '{contentValue}' was not found in the table."); + } + public async Task VerifyFirstRowContentIsNotPresent(string contentValue) { - var row = rows.Nth(i); - var cells = await row.Locator(cellLocator).AllInnerTextsAsync(); + var row = page.Locator(".rt-tr-group").First; + var cells = await row.Locator(".rt-td").AllInnerTextsAsync(); var cellList = cells.ToList(); + Assert.That(cellList, Does.Not.Contain(contentValue), $"The search value '{contentValue}' was not found in the table."); + } + public async Task VerifyTableContent(string headerName, string cellValue) + { + var table = page.Locator(".ReactTable"); + var headers = await table.Locator(".rt-th").AllInnerTextsAsync(); + var headerList = headers.ToList(); + int headerIndex = headerList.IndexOf(headerName); + + if (headerIndex == -1) + { + throw new Exception($"Header '{headerName}' not found."); + } + + var rows = table.Locator(".rt-tr-group"); + var rowCount = await rows.CountAsync(); - if (headerIndex < cellList.Count && cellList[headerIndex] == cellValue) + bool isCellContentPresent = false; + for (int i = 0; i < rowCount; i++) { - isCellContentPresent = true; - break; + var row = rows.Nth(i); + var cells = await row.Locator(".rt-td").AllInnerTextsAsync(); + var cellList = cells.ToList(); + + if (headerIndex < cellList.Count && cellList[headerIndex] == cellValue) + { + isCellContentPresent = true; + break; + } } + Assert.That(isCellContentPresent, Is.True, $"The cell value '{cellValue}' is not present under the header '{headerName}'."); } - Assert.That(isCellContentPresent, Is.True, $"The cell value '{cellValue}' is not present under the header '{headerName}'."); - } - #endregion + #endregion - #region Inputs: - public async Task FillSearchValue(string searchValue) - { - var searchInput = page.GetByPlaceholder(searchPlaceholder); + #region Inputs: + public async Task FillSearchValue(string searchValue) + { + var searchInput = page.GetByPlaceholder("Type to search"); - await searchInput.ClickAsync(); - await searchInput.FillAsync(searchValue); - await searchInput.FocusAsync(); - //await searchInput.PressAsync("Enter"); - } - public async Task FillFirstName(string fillText) - { - await page.GetByPlaceholder(firstNamePlaceholder).FillAsync(fillText); - } - public async Task FillLastName(string fillText) - { - await page.GetByPlaceholder(lastNamePlaceholder).FillAsync(fillText); - } - public async Task FillEmail(string fillText) - { - await page.GetByPlaceholder(emailPlaceholder).FillAsync(fillText); - } - public async Task FillAge(string fillText) - { - await page.GetByPlaceholder(agePlaceholder).FillAsync(fillText); - } - public async Task FillSalary(string fillText) - { - await page.GetByPlaceholder(salaryPlaceholder).FillAsync(fillText); - } - public async Task FillDepartment(string fillText) - { - await page.GetByPlaceholder(departmentPlaceholder).FillAsync(fillText); - } - #endregion + await searchInput.ClickAsync(); + await searchInput.FillAsync(searchValue); + await searchInput.FocusAsync(); + //await searchInput.PressAsync("Enter"); + } + public async Task FillFirstName(string fillText) + { + await page.GetByPlaceholder("First Name").FillAsync(fillText); + } + public async Task FillLastName(string fillText) + { + await page.GetByPlaceholder("Last Name").FillAsync(fillText); + } + public async Task FillEmail(string fillText) + { + await page.GetByPlaceholder("name@example.com").FillAsync(fillText); + } + public async Task FillAge(string fillText) + { + await page.GetByPlaceholder("Age").FillAsync(fillText); + } + public async Task FillSalary(string fillText) + { + await page.GetByPlaceholder("Salary").FillAsync(fillText); + } + public async Task FillDepartment(string fillText) + { + await page.GetByPlaceholder("Department").FillAsync(fillText); + } + #endregion - #region Buttons: - public async Task AddButtonClick() - { - await page.GetByRole(AriaRole.Button, new() { Name = "Add" }).ClickAsync(); - } - public async Task SubmitButtonCLick() - { - await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync(); - } - public async Task ClickEdit() - { - await page.Locator("#edit-record-2").GetByRole(AriaRole.Img).ClickAsync(); - } - public async Task ClickDelete() - { - await page.Locator("#delete-record-2").GetByRole(AriaRole.Img).ClickAsync(); - } - #endregion + #region Buttons: + public async Task AddButtonClick() + { + await page.GetByRole(AriaRole.Button, new() { Name = "Add" }).ClickAsync(); + } + public async Task SubmitButtonCLick() + { + await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync(); + } + public async Task ClickEdit() + { + await page.Locator("#edit-record-2").GetByRole(AriaRole.Img).ClickAsync(); + } + public async Task ClickDelete() + { + await page.Locator("#delete-record-2").GetByRole(AriaRole.Img).ClickAsync(); + } + #endregion - #region AddPopupVerifications: - public async Task VerifyAddPopupOpened() - { - await Assertions.Expect(page.Locator(addPopUpLocator)).ToBeVisibleAsync(); - } - public async Task VerifyFirstNameCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(firstNamePlaceholder)).ToHaveCSSAsync(cssOption, cssValue); - } - public async Task VerifyLastNameCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(lastNamePlaceholder)).ToHaveCSSAsync(cssOption, cssValue); - } - public async Task VerifyEmailCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(emailPlaceholder)).ToHaveCSSAsync(cssOption, cssValue); - } - public async Task VerifyAgeCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(agePlaceholder)).ToHaveCSSAsync(cssOption, cssValue); - } - public async Task VerifySalaryCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(salaryPlaceholder)).ToHaveCSSAsync(cssOption, cssValue); - } - public async Task VerifyDepartmentCssOption(string cssOption, string cssValue) - { - await Assertions.Expect(page.GetByPlaceholder(departmentPlaceholder)).ToHaveCSSAsync(cssOption, cssValue); + #region AddPopupVerifications: + public async Task VerifyAddPopupOpened() + { + await Assertions.Expect(page.Locator(".modal-content")).ToBeVisibleAsync(); + } + public async Task VerifyFirstNameCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("First Name")).ToHaveCSSAsync(cssOption, cssValue); + } + public async Task VerifyLastNameCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("Last Name")).ToHaveCSSAsync(cssOption, cssValue); + } + public async Task VerifyEmailCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("name@example.com")).ToHaveCSSAsync(cssOption, cssValue); + } + public async Task VerifyAgeCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("Age")).ToHaveCSSAsync(cssOption, cssValue); + } + public async Task VerifySalaryCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("Salary")).ToHaveCSSAsync(cssOption, cssValue); + } + public async Task VerifyDepartmentCssOption(string cssOption, string cssValue) + { + await Assertions.Expect(page.GetByPlaceholder("Department")).ToHaveCSSAsync(cssOption, cssValue); + } + #endregion } - #endregion -} +} \ No newline at end of file diff --git a/PlaywrigthUITests/Tests/WebTableTests.cs b/PlaywrigthUITests/Tests/WebTableTests.cs index e90e99e..1a72c34 100644 --- a/PlaywrigthUITests/Tests/WebTableTests.cs +++ b/PlaywrigthUITests/Tests/WebTableTests.cs @@ -1,5 +1,6 @@ using Microsoft.Playwright; using NUnit.Framework; +using PlaywrigthUITests.PageObjects; using System.Threading.Tasks; namespace PlaywrigthUITests.Tests