test(Discord) Added test logs to discord and start of discord chat bot

This commit is contained in:
2022-04-28 12:56:49 -04:00
parent 156339786c
commit b65dae0884
25 changed files with 6277 additions and 181 deletions
+7
View File
@@ -0,0 +1,7 @@
namespace TestAutomation.Utils;
public class Test {
public string Name { get; set; } = "Name...";
public bool Result { get; set; } = true;
public IList<TestMessage> Messages { get; set; } = new List<TestMessage>();
}
+11
View File
@@ -0,0 +1,11 @@
namespace TestAutomation.Utils;
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) {
return new TestMessage { Title = "Check Failed", Description = description, Color = "FF0000" };
}
}
+57
View File
@@ -0,0 +1,57 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace TestAutomation.Utils;
public class TestReport {
private List<Test> Tests { get; } = new();
[MethodImpl(MethodImplOptions.NoInlining)]
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) {
if (passed) return;
Tests.Last().Result = false;
Tests.Last().Messages.Add(message);
}
public bool DidTestsPass() {
foreach (var test in Tests) {
if (test.Result) continue;
return false;
}
return true;
}
public List<object> GetMessages() {
if (DidTestsPass())
return new List<object> {
new {
title = "Passed",
color = int.Parse("00FF00", NumberStyles.HexNumber),
description = $"All {Tests.Count} tests passed."
}
};
var messageList = new List<object>();
foreach (var test in Tests)
foreach (var message in test.Messages)
messageList.Add(
new {
title = message.Title,
color = int.Parse(message.Color, NumberStyles.HexNumber),
description = message.Description
});
return messageList;
}
}
+7
View File
@@ -0,0 +1,7 @@
global using NUnit.Framework;
global using OpenQA.Selenium;
global using OpenQA.Selenium.Firefox;
global using OpenQA.Selenium.Chrome;
global using TestAutomation.Pages;
global using OpenQA.Selenium.Support.UI;
global using OpenQA.Selenium.Support;
+51
View File
@@ -0,0 +1,51 @@
namespace TestAutomation.Utils;
public class Website {
public Website(IWebDriver webDriver) {
WebDriver = webDriver;
HarassCalculatorPage = new HarassCalculatorPage(this);
}
public IWebDriver WebDriver { get; }
public HarassCalculatorPage HarassCalculatorPage { get; }
public IWebElement Find(string byId) {
return WebDriver.FindElement(By.Id(byId));
}
public IList<IWebElement> FindChildren(string ofId, string tagname) {
return WebDriver.FindElements(By.CssSelector($"#{ofId} {tagname}"));
}
public string FindText(string byId) {
return WebDriver.FindElement(By.Id(byId)).Text;
}
public int FindInt(string byId) {
return int.Parse(WebDriver.FindElement(By.Id(byId)).Text);
}
public IWebElement EnterInput<T>(IWebElement element, T input) {
element.Clear();
element.SendKeys(input!.ToString());
element.SendKeys(Keys.Enter);
return element;
}
public IWebElement EnterInput<T>(string byId, T input) {
var element = Find(byId);
element.Clear();
element.SendKeys(input!.ToString());
element.SendKeys(Keys.Enter);
return element;
}
public string GetLabel(string byId) {
return Find(byId).Text;
}
}