Skip to content

Commit

Permalink
extra constant removed
Browse files Browse the repository at this point in the history
  • Loading branch information
yustasstar committed Jul 15, 2024
1 parent 5fc316f commit 6b493d2
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 162 deletions.
309 changes: 147 additions & 162 deletions PlaywrigthUITests/PageObjects/WebTablesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
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("[email protected]").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("[email protected]")).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
}
}
1 change: 1 addition & 0 deletions PlaywrigthUITests/Tests/WebTableTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Playwright;
using NUnit.Framework;
using PlaywrigthUITests.PageObjects;
using System.Threading.Tasks;

namespace PlaywrigthUITests.Tests
Expand Down

0 comments on commit 6b493d2

Please sign in to comment.