test(WebsiteSearch) Adding tests for entity searching
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using TestAutomation.Shared;
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation.Pages;
|
||||
|
||||
public class DatabasePage : BaseElement
|
||||
{
|
||||
|
||||
private IWebElement FilterNameInput => Website.Find("filterName");
|
||||
|
||||
|
||||
private ReadOnlyCollection<IWebElement> EntityNames() =>
|
||||
Website.FindAll("entityName");
|
||||
|
||||
|
||||
private IWebElement EntityName(string entityType, string entityName) =>
|
||||
Website.Find("entityName",
|
||||
$"{entityType.ToLower()}-{entityName.ToLower()}");
|
||||
|
||||
|
||||
public DatabasePage(Website website) : base(website) { }
|
||||
|
||||
public DatabasePage FilterName(string name)
|
||||
{
|
||||
Website.EnterInput(FilterNameInput, name);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabasePage GetEntityName(string entityType, string entityName, out string result)
|
||||
{
|
||||
result = EntityName(entityType, entityName).Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabasePage GetEntityName(int index,out string result)
|
||||
{
|
||||
result = EntityNames()[index].Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,37 @@ namespace TestAutomation.Pages;
|
||||
|
||||
public class DatabaseSinglePage : BaseElement
|
||||
{
|
||||
private IWebElement EntityName => Website.Find("entityName");
|
||||
private IWebElement EntityHealth => Website.Find("entityHealth");
|
||||
|
||||
private IWebElement InvalidSearch => Website.Find("invalidSearch");
|
||||
private IWebElement ValidSearch => Website.Find("validSearch");
|
||||
|
||||
public DatabaseSinglePage(Website website) : base(website) { }
|
||||
|
||||
|
||||
public DatabaseSinglePage GetEntityName(out string result)
|
||||
{
|
||||
result = EntityName.Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabaseSinglePage GetEntityHealth(out string result)
|
||||
{
|
||||
result = EntityHealth.Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabaseSinglePage GetInvalidSearch(out string result)
|
||||
{
|
||||
result = InvalidSearch.Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabaseSinglePage GetValidSearch(out string result)
|
||||
{
|
||||
result = ValidSearch.Text;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,11 +25,9 @@ public class WebsiteSearchDialog : BaseElement
|
||||
return this;
|
||||
}
|
||||
|
||||
public void SelectSearchEntity(string throne)
|
||||
public DatabaseSinglePage SelectSearchEntity(string throne)
|
||||
{
|
||||
Website.Click(Website.FindButtonWithLabel(throne));
|
||||
//TODO Add DatabaseSinglePage
|
||||
//return Website.DatabaseSinglePage;
|
||||
|
||||
return Website.DatabaseSinglePage;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation;
|
||||
|
||||
[TestFixture]
|
||||
@@ -17,7 +19,6 @@ public class TestSearchFeatures : BaseTest
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Not completed")]
|
||||
public void DesktopSearchForThrone()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
@@ -27,9 +28,59 @@ public class TestSearchFeatures : BaseTest
|
||||
Website.NavigationBar
|
||||
.ClickSearchButton()
|
||||
.Search("Throne")
|
||||
.SelectSearchEntity("Throne");
|
||||
// .GetName(out var name);
|
||||
.SelectSearchEntity("Throne")
|
||||
.GetEntityName(out var name)
|
||||
.GetEntityHealth(out var health);
|
||||
|
||||
// TestReport.CheckPassed(name.Equals("Throne"), "Couldn't find Throne via search.");
|
||||
TestReport.CheckPassed(name.Equals("Throne"), new TestMessage(){ Description = "Couldn't find Throne via search."});
|
||||
TestReport.CheckPassed(!health.Trim().Equals(""), new TestMessage(){ Description = "Throne has no visible health!"});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DesktopFilterForThrone()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/database");
|
||||
|
||||
Website.DatabasePage
|
||||
.FilterName("Throne")
|
||||
.GetEntityName(0, out var name);
|
||||
|
||||
TestReport.CheckPassed(name.Equals("Throne"),
|
||||
new TestMessage(){ Description = "Couldn't find Throne via filter."});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeeThroneByDefault()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/database");
|
||||
|
||||
Website.DatabasePage
|
||||
.GetEntityName( "army", "throne", out var name);
|
||||
|
||||
TestReport.CheckPassed(name.Equals("Throne"),
|
||||
new TestMessage(){ Description = "Couldn't find Throne on the page by default."});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectLinkNotThroneFailure()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/database/not throne");
|
||||
|
||||
Website.DatabaseSinglePage
|
||||
.GetInvalidSearch(out var invalidSearch)
|
||||
.GetValidSearch(out var validSearch);
|
||||
|
||||
TestReport.CheckPassed(invalidSearch.Equals("not throne"),
|
||||
new TestMessage(){ Description = "Couldn't find invalid search text on the page."});
|
||||
TestReport.CheckPassed(validSearch.Equals("Throne"),
|
||||
new TestMessage(){ Description = "Couldn't find valid search text on the page."});
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/database/not throne");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using System.Collections.ObjectModel;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using TestAutomation.Enums;
|
||||
using TestAutomation.Shared;
|
||||
|
||||
@@ -12,14 +13,23 @@ public class Website
|
||||
{
|
||||
WebDriver = webDriver;
|
||||
|
||||
// Pages
|
||||
HarassCalculatorPage = new HarassCalculatorPage(this);
|
||||
DatabasePage = new DatabasePage(this);
|
||||
DatabaseSinglePage = new DatabaseSinglePage(this);
|
||||
|
||||
// Navigation
|
||||
NavigationBar = new NavigationBar(this);
|
||||
|
||||
// Dialogs
|
||||
WebsiteSearchDialog = new WebsiteSearchDialog(this);
|
||||
}
|
||||
|
||||
public IWebDriver WebDriver { get; }
|
||||
|
||||
public HarassCalculatorPage HarassCalculatorPage { get; }
|
||||
public DatabaseSinglePage DatabaseSinglePage { get; }
|
||||
public DatabasePage DatabasePage { get; }
|
||||
public NavigationBar NavigationBar { get; }
|
||||
public WebsiteSearchDialog WebsiteSearchDialog { get; }
|
||||
|
||||
@@ -39,6 +49,31 @@ public class Website
|
||||
}
|
||||
|
||||
|
||||
public IWebElement Find(string byId, string withParentId)
|
||||
{
|
||||
IWebElement parent;
|
||||
|
||||
try
|
||||
{
|
||||
parent = WebDriver.FindElement(By.Id(withParentId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Couldn't find parent {withParentId}. Element does not exist on current page. " +
|
||||
$"\n\nPerhaps an Id is missing.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return parent.FindElement(By.Id(byId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Couldn't find {byId}. Element does not exist on current page. " +
|
||||
$"\n\nPerhaps an Id is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
public IWebElement Find(string byId)
|
||||
{
|
||||
try
|
||||
@@ -52,11 +87,25 @@ public class Website
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<IWebElement> FindAll(string byId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return WebDriver.FindElements(By.Id(byId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Couldn't find {byId}. Element does not exist on current page. " +
|
||||
$"\n\nPerhaps an Id is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IWebElement FindButtonWithLabel(string label)
|
||||
{
|
||||
try
|
||||
{
|
||||
return WebDriver.FindElement(By.XPath($"button[@label='{label}']"));
|
||||
return WebDriver.FindElement(By.XPath($"//button[@label='{label}']"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user