test(SearchTest) Added a test for opening and closing search dialog

This commit is contained in:
2022-04-30 00:50:46 -04:00
parent 06c0a976e8
commit 51e5bd8185
24 changed files with 476 additions and 154 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
namespace TestAutomation.Utils;
public class Test {
public class Test
{
public string Name { get; set; } = "Name...";
public bool Result { get; set; } = true;
public IList<TestMessage> Messages { get; set; } = new List<TestMessage>();
+4 -2
View File
@@ -1,11 +1,13 @@
namespace TestAutomation.Utils;
public class TestMessage {
public class TestMessage
{
public string Title { get; set; } = "Name...";
public string Description { get; set; } = "";
public string Color { get; set; } = "FFFFFF";
public static TestMessage CreateFailedMessage(string description) {
public static TestMessage CreateFailedMessage(string description)
{
return new TestMessage { Title = "Check Failed", Description = description, Color = "FF0000" };
}
}
+20 -9
View File
@@ -4,24 +4,31 @@ using System.Runtime.CompilerServices;
namespace TestAutomation.Utils;
public class TestReport {
public class TestReport
{
private List<Test> Tests { get; } = new();
[MethodImpl(MethodImplOptions.NoInlining)]
public Test CreateTest() {
public Test CreateTest()
{
var testName = new StackTrace().GetFrame(1)!.GetMethod()!.Name!;
Tests.Add(new Test { Name = testName });
return Tests.Last();
}
public void CheckPassed(bool passed, TestMessage message) {
public void CheckPassed(bool passed, TestMessage message)
{
if (passed) return;
Tests.Last().Result = false;
Tests.Last().Messages.Add(message);
throw new Exception(message.Description);
}
public bool DidTestsPass() {
foreach (var test in Tests) {
public bool DidTestsPass()
{
foreach (var test in Tests)
{
if (test.Result) continue;
return false;
@@ -31,10 +38,13 @@ public class TestReport {
return true;
}
public List<object> GetMessages() {
public List<object> GetMessages()
{
if (DidTestsPass())
return new List<object> {
new {
return new List<object>
{
new
{
title = "Passed",
color = int.Parse("00FF00", NumberStyles.HexNumber),
description = $"All {Tests.Count} tests passed."
@@ -45,7 +55,8 @@ public class TestReport {
foreach (var test in Tests)
foreach (var message in test.Messages)
messageList.Add(
new {
new
{
title = message.Title,
color = int.Parse(message.Color, NumberStyles.HexNumber),
description = message.Description
+91 -11
View File
@@ -1,35 +1,113 @@
namespace TestAutomation.Utils;
using OpenQA.Selenium.Interactions;
using TestAutomation.Enums;
using TestAutomation.Shared;
public class Website {
public Website(IWebDriver webDriver) {
namespace TestAutomation.Utils;
public class Website
{
public readonly ScreenType ScreenType = ScreenType.Desktop;
public Website(IWebDriver webDriver)
{
WebDriver = webDriver;
HarassCalculatorPage = new HarassCalculatorPage(this);
NavigationBar = new NavigationBar(this);
WebsiteSearchDialog = new WebsiteSearchDialog(this);
}
public IWebDriver WebDriver { get; }
public HarassCalculatorPage HarassCalculatorPage { get; }
public NavigationBar NavigationBar { get; }
public WebsiteSearchDialog WebsiteSearchDialog { get; }
public IWebElement Find(string byId) {
return WebDriver.FindElement(By.Id(byId));
public IWebElement FindScreenSpecific(string byId)
{
var screenSpecificId = $"{ScreenType.ToString().ToLower()}-{byId}";
try
{
return WebDriver.FindElement(By.Id(screenSpecificId));
}
catch (Exception e)
{
throw new Exception($"Couldn't find {screenSpecificId}. Element does not exist on current page. " +
$"\n\nPerhaps an Id is missing.");
}
}
public IList<IWebElement> FindChildren(string ofId, string tagname) {
public IWebElement Find(string byId)
{
try
{
return WebDriver.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 FindButtonWithLabel(string label)
{
try
{
return WebDriver.FindElement(By.XPath($"button[@label='{label}']"));
}
catch (Exception e)
{
throw new Exception($"Couldn't find with label: {label}. Element does not exist on current page. ");
}
}
//@FindBy(xpath = "//div[@label='First Name']")
public IList<IWebElement> FindChildren(string ofId, string tagname)
{
return WebDriver.FindElements(By.CssSelector($"#{ofId} {tagname}"));
}
public string FindText(string byId) {
public string FindText(string byId)
{
return WebDriver.FindElement(By.Id(byId)).Text;
}
public int FindInt(string byId) {
public int FindInt(string byId)
{
return int.Parse(WebDriver.FindElement(By.Id(byId)).Text);
}
public IWebElement EnterInput<T>(IWebElement element, T input) {
public void ClickTopLeft()
{
new Actions(WebDriver)
.MoveByOffset(32, 32)
.Click()
.Perform();
}
public IWebElement Click(IWebElement element)
{
try
{
element.Click();
}
catch
{
throw new Exception($"Couldn't click on {element.GetDomProperty("id")}. ");
}
return element;
}
public IWebElement EnterInput<T>(IWebElement element, T input)
{
element.Clear();
element.SendKeys(input!.ToString());
element.SendKeys(Keys.Enter);
@@ -37,7 +115,8 @@ public class Website {
}
public IWebElement EnterInput<T>(string byId, T input) {
public IWebElement EnterInput<T>(string byId, T input)
{
var element = Find(byId);
element.Clear();
element.SendKeys(input!.ToString());
@@ -45,7 +124,8 @@ public class Website {
return element;
}
public string GetLabel(string byId) {
public string GetLabel(string byId)
{
return Find(byId).Text;
}
}