Browse Source

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

main
Jonathan McCaffrey 4 years ago
parent
commit
b65dae0884
  1. 2
      .github/workflows/development.yml
  2. 25
      .github/workflows/test-development.yml
  3. 2
      Bot_Discord/.gitignore
  4. 1
      Bot_Discord/Procfile
  5. 11
      Bot_Discord/README.md
  6. 18
      Bot_Discord/commands/kick.js
  7. 5
      Bot_Discord/events/guildMemberAdd.js
  8. 7
      Bot_Discord/events/message.js
  9. 3
      Bot_Discord/events/ready.js
  10. 17
      Bot_Discord/index.js
  11. 5938
      Bot_Discord/package-lock.json
  12. 20
      Bot_Discord/package.json
  13. BIN
      IGP/Database.db
  14. 2
      IGP/wwwroot/generated/GitChangeModels.json
  15. 2
      IGP/wwwroot/generated/GitPatchModels.json
  16. 6
      TestAutomation/Pages/BasePage.cs
  17. 18
      TestAutomation/Pages/HarassCalculatorPage.cs
  18. 2
      TestAutomation/TestAutomation.csproj
  19. 119
      TestAutomation/UnitTest1.cs
  20. 141
      TestAutomation/UnitTests.cs
  21. 7
      TestAutomation/Utils/Test.cs
  22. 11
      TestAutomation/Utils/TestMessage.cs
  23. 57
      TestAutomation/Utils/TestReport.cs
  24. 2
      TestAutomation/Utils/Usings.cs
  25. 10
      TestAutomation/Utils/Website.cs

2
.github/workflows/development.yml

@ -47,3 +47,5 @@ jobs:
- run: dotnet restore
- run: dotnet build --no-restore
- run: dotnet test --no-build --verbosity normal
env:
TEST_HOOK: ${{ secrets.TEST_HOOK }}

25
.github/workflows/test-development.yml

@ -1,25 +0,0 @@
name: Run Development Tests
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
- name: Change Directory
run: cd TestAutomation | dotnet restore |dotnet build --no-restore | dotnet test --no-build --verbosity normal

2
Bot_Discord/.gitignore vendored

@ -0,0 +1,2 @@
node_modules
.env

1
Bot_Discord/Procfile

@ -0,0 +1 @@
worker: node index.js

11
Bot_Discord/README.md

@ -0,0 +1,11 @@
# Discord bot example
Read this [article](https://medium.freecodecamp.org/how-to-create-a-discord-bot-under-15-minutes-fb2fd0083844) to fully understand what this is about 😃
## Getting started
1. Clone this repository
2. Run `npm install`
3. Grab a token on [Discord's developer portal](https://discordapp.com/developers/applications)
4. Create a `.env` file and add a `BOT_TOKEN` environmental variable whose value is the token above.
5. Run `npm run dev`

18
Bot_Discord/commands/kick.js

@ -0,0 +1,18 @@
module.exports = message => {
const member = message.mentions.members.first();
if (!member) {
return message.reply(
`Who are you trying to kick? You must mention a user.`
);
}
if (!member.kickable) {
return message.reply(`I can't kick this user. Sorry!`);
}
return member
.kick()
.then(() => message.reply(`${member.user.tag} was kicked.`))
.catch(error => message.reply(`Sorry, an error occured.`));
};

5
Bot_Discord/events/guildMemberAdd.js

@ -0,0 +1,5 @@
module.exports = (client, member) => {
member.send(
`Welcome on the server! Please be aware that we won't tolerate troll, spam or harassment. Have fun 😀`
);
};

7
Bot_Discord/events/message.js

@ -0,0 +1,7 @@
const kick = require("../commands/kick");
module.exports = (client, message) => {
if (message.content.startsWith("!kick")) {
return kick(message);
}
};

3
Bot_Discord/events/ready.js

@ -0,0 +1,3 @@
module.exports = client => {
console.log(`Logged in as ${client.user.tag}!`);
};

17
Bot_Discord/index.js

@ -0,0 +1,17 @@
require("dotenv").config();
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client();
fs.readdir("./events/", (err, files) => {
files.forEach(file => {
const eventHandler = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.on(eventName, (...args) => eventHandler(client, ...args));
});
});
client.login(process.env.BOT_TOKEN);
client.channels.find(x=> x.id === "969297543538311248");

5938
Bot_Discord/package-lock.json generated

File diff suppressed because it is too large Load Diff

20
Bot_Discord/package.json

@ -0,0 +1,20 @@
{
"name": "discord-bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^11.4.2",
"dotenv": "^7.0.0"
},
"devDependencies": {
"nodemon": "^1.18.11"
}
}

BIN
IGP/Database.db

Binary file not shown.

2
IGP/wwwroot/generated/GitChangeModels.json

File diff suppressed because one or more lines are too long

2
IGP/wwwroot/generated/GitPatchModels.json

@ -1 +1 @@
[{"Id":1,"Name":"Database UX Patch","Date":"2022-03-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":2,"Name":"Thrum Stats Hotfix","Date":"2022-03-12T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":3,"Name":"Memory Tester Patch","Date":"2022-03-01T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":4,"Name":"Hide Pyre Hotfix","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":5,"Name":"Stream Patch 1","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":6,"Name":"Agile UI Hotfix","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":7,"Name":"Armor Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":8,"Name":"Home Page Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":9,"Name":"Mobile Menu Hotfix 2","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":10,"Name":"Mobile Menu Hotfix","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":11,"Name":"Mobile Menu Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":12,"Name":"0.0.6.8375a Patch","Date":"2022-02-18T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":13,"Name":"Google Tracking Hotfix","Date":"2022-02-18T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":14,"Name":"Privacy Policy Patch","Date":"2022-02-17T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":15,"Name":"Home Page Quick Hotfix","Date":"2022-02-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":16,"Name":"Early Agile Patch","Date":"2022-02-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":17,"Name":"Form Text Rendering Hotfix","Date":"2022-02-15T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":18,"Name":"Reducing Timing Interval Hotfix","Date":"2022-02-15T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":19,"Name":"Changelog Patch","Date":"2022-02-14T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":20,"Name":"SQL Patch","Date":"2022-03-26T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":21,"Name":"Stream Patch 2","Date":"2022-03-30T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":22,"Name":"0.0.6.8900a Patch","Date":"2022-03-30T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":23,"Name":"Database Links Patch","Date":"2022-04-01T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":24,"Name":"Open Source Patch","Date":"2022-04-03T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":25,"Name":"Stream Patch 3","Date":"2022-04-03T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":26,"Name":"Notes/Docs Patch","Date":"2022-04-10T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":27,"Name":"Stream Patch 4","Date":"2022-04-10T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":28,"Name":"Passive Patch","Date":"2022-04-12T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":29,"Name":"0.0.6.9121a Patch","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":30,"Name":"Stream Patch 5","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":31,"Name":"BuildCalc Hotfix","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":32,"Name":"Search Patch","Date":"2022-04-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":33,"Name":"Search Hotfix","Date":"2022-04-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":34,"Name":"Stream Patch 6","Date":"2022-04-17T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":35,"Name":"v0.0.6.9201a Patch","Date":"2022-04-18T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":36,"Name":"Build Calc Free Money Hotfix","Date":"2022-04-18T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":37,"Name":"BuildCalc Pyre Patch","Date":"2022-04-24T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":38,"Name":"Stream Patch 7","Date":"2022-04-24T00:00:00","GitChangeModels":[],"Important":"False"}]
[{"Id":1,"Name":"Database UX Patch","Date":"2022-03-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":2,"Name":"Thrum Stats Hotfix","Date":"2022-03-12T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":3,"Name":"Memory Tester Patch","Date":"2022-03-01T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":4,"Name":"Hide Pyre Hotfix","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":5,"Name":"Stream Patch 1","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":6,"Name":"Agile UI Hotfix","Date":"2022-02-20T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":7,"Name":"Armor Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":8,"Name":"Home Page Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":9,"Name":"Mobile Menu Hotfix 2","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":10,"Name":"Mobile Menu Hotfix","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":11,"Name":"Mobile Menu Patch","Date":"2022-02-19T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":12,"Name":"0.0.6.8375a Patch","Date":"2022-02-18T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":13,"Name":"Google Tracking Hotfix","Date":"2022-02-18T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":14,"Name":"Privacy Policy Patch","Date":"2022-02-17T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":15,"Name":"Home Page Quick Hotfix","Date":"2022-02-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":16,"Name":"Early Agile Patch","Date":"2022-02-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":17,"Name":"Form Text Rendering Hotfix","Date":"2022-02-15T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":18,"Name":"Reducing Timing Interval Hotfix","Date":"2022-02-15T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":19,"Name":"Changelog Patch","Date":"2022-02-14T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":20,"Name":"SQL Patch","Date":"2022-03-26T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":21,"Name":"Stream Patch 2","Date":"2022-03-30T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":22,"Name":"0.0.6.8900a Patch","Date":"2022-03-30T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":23,"Name":"Database Links Patch","Date":"2022-04-01T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":24,"Name":"Open Source Patch","Date":"2022-04-03T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":25,"Name":"Stream Patch 3","Date":"2022-04-03T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":26,"Name":"Notes/Docs Patch","Date":"2022-04-10T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":27,"Name":"Stream Patch 4","Date":"2022-04-10T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":28,"Name":"Passive Patch","Date":"2022-04-12T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":29,"Name":"0.0.6.9121a Patch","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":30,"Name":"Stream Patch 5","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":31,"Name":"BuildCalc Hotfix","Date":"2022-04-13T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":32,"Name":"Search Patch","Date":"2022-04-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":33,"Name":"Search Hotfix","Date":"2022-04-16T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":34,"Name":"Stream Patch 6","Date":"2022-04-17T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":35,"Name":"v0.0.6.9201a Patch","Date":"2022-04-18T00:00:00","GitChangeModels":[],"Important":"True"},{"Id":36,"Name":"Build Calc Free Money Hotfix","Date":"2022-04-18T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":37,"Name":"BuildCalc Pyre Patch","Date":"2022-04-24T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":38,"Name":"Stream Patch 7","Date":"2022-04-24T00:00:00","GitChangeModels":[],"Important":"False"},{"Id":39,"Name":"Infrastructure Patch","Date":"2022-05-20T00:00:00","GitChangeModels":[],"Important":"False"}]

6
TestAutomation/Pages/BasePage.cs

@ -1,13 +1,11 @@
using OpenQA.Selenium;
using TestAutomation.Utils;
namespace TestAutomation.Pages;
public class BasePage {
public Website website;
public Website website;
public BasePage(Website website) {
this.website = website;
}
}

18
TestAutomation/Pages/HarassCalculatorPage.cs

@ -1,13 +1,16 @@
namespace TestAutomation.Pages;
using TestAutomation.Utils;
namespace TestAutomation.Pages;
public class HarassCalculatorPage : BasePage {
public HarassCalculatorPage(Website website) : base(website) { }
private IWebElement NumberOfWorkersLostToHarass => website.Find("numberOfWorkersLostToHarass");
private IWebElement NumberOfTownHallsExisting => website.Find("numberOfTownHallsExisting");
private IList<IWebElement> OnTownHallTravelTimes => website.FindChildren("numberOfTownHallTravelTimes", "input");
private IWebElement NumberOfTownHallsExisting => website.Find("numberOfTownHallsExisting");
private IList<IWebElement> OnTownHallTravelTimes => website.FindChildren("numberOfTownHallTravelTimes", "input");
private int TotalAlloyHarassment => website.FindInt("totalAlloyHarassment");
private int WorkerReplacementCost => website.FindInt("workerReplacementCost");
private int WorkerReplacementCost => website.FindInt("workerReplacementCost");
private int DelayedMiningCost => website.FindInt("delayedMiningCost");
private int AverageTravelTime => website.FindInt("getAverageTravelTime");
private int AverageTravelTime => website.FindInt("getAverageTravelTime");
private int ExampleTotalAlloyLoss => website.FindInt("exampleTotalAlloyLoss");
private int ExampleWorkerCost => website.FindInt("exampleWorkerCost");
@ -16,8 +19,6 @@ public class HarassCalculatorPage : BasePage {
private int ExampleTotalAlloyLossAccurate => website.FindInt("exampleTotalAlloyLossAccurate");
private int ExampleTotalAlloyLossAccurateDifference => website.FindInt("exampleTotalAlloyLossAccurateDifference");
public HarassCalculatorPage(Website website) : base(website) { }
public HarassCalculatorPage SetWorkersLostToHarass(int number) {
website.EnterInput(NumberOfWorkersLostToHarass, number);
return this;
@ -53,10 +54,12 @@ public class HarassCalculatorPage : BasePage {
result = ExampleMiningTimeCost;
return this;
}
public HarassCalculatorPage GetExampleTotalAlloyLossAccurate(out int result) {
result = ExampleTotalAlloyLossAccurate;
return this;
}
public HarassCalculatorPage GetExampleTotalAlloyLossDifference(out int result) {
result = ExampleTotalAlloyLossDifference;
return this;
@ -66,5 +69,4 @@ public class HarassCalculatorPage : BasePage {
result = ExampleTotalAlloyLossAccurateDifference;
return this;
}
}

2
TestAutomation/TestAutomation.csproj

@ -9,6 +9,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net.Webhook" Version="3.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0-preview.2.22152.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />

119
TestAutomation/UnitTest1.cs

@ -1,119 +0,0 @@
namespace TestAutomation;
public class Tests
{
private IWebDriver _webDriver = default!;
private readonly string localhost = "https://localhost:7234";
private readonly string develop = "https://calm-mud-04916b210.1.azurestaticapps.net/";
private Website Website { get; }
public Tests() {
var options = new FirefoxOptions();
//var options = new ChromeOptions();
options.AcceptInsecureCertificates = true;
options.AddArgument("--headless");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--start-maximized");
options.AddArgument("--test-type");
options.AddArgument("--allow-running-insecure-content");
//_webDriver = new FirefoxDriver(options);
//_webDriver = new ChromeDriver(Environment.CurrentDirectory, options);
_webDriver = new FirefoxDriver(Environment.CurrentDirectory, options);
Website = new Website(_webDriver);
}
[OneTimeSetUp]
public void Setup()
{
_webDriver.Navigate().GoToUrl(develop);
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
}
[OneTimeTearDown]
public void TearDown()
{
_webDriver.Quit();
}
[Test]
public void HarassCalculator()
{
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
int expectedTotalAlloyHarassment = 240;
Website.HarassCalculatorPage
.SetWorkersLostToHarass(3)
.SetNumberOfTownHallsExisting(2)
.SetTownHallTravelTime(0, 30)
.GetTotalAlloyHarassment(out var foundTotalAlloyHarassment);
Assert.True(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment),
$"expectTotalAlloyHarassment of {expectedTotalAlloyHarassment} " +
"does not equal " +
$"foundTotalAlloyHarassment of {foundTotalAlloyHarassment} ");
}
[Test]
public void HarassCalculatorInformation()
{
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
int expectedExampleTotalAlloyLoss = 720;
int expectedExampleWorkerCost = 300;
int expectedExampleMiningTimeCost = 420;
int expectedExampleTotalAlloyLossDifference = 300;
int expectedExampleTotalAlloyLossAccurate = 450;
int expectedExampleTotalAlloyLossAccurateDifference = 270;
Website.HarassCalculatorPage
.GetExampleTotalAlloyLoss(out var foundTotalAlloyLoss)
.GetExampleWorkerCost(out var foundExampleWorkerCost)
.GetExampleMiningTimeCost(out var foundExampleMiningTimeCost)
.GetExampleTotalAlloyLossAccurate(out var foundExampleTotalAlloyLossAccurate)
.GetExampleTotalAlloyLossDifference(out var foundGetExampleTotalAlloyLossDifference)
.GetExampleTotalAlloyLossAccurateDifference(out var foundExampleTotalAlloyLossAccurateDifference);
Assert.True(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss),
$"expectedExampleTotalAlloyLoss of {expectedExampleTotalAlloyLoss} " +
"does not equal " +
$"foundTotalAlloyLoss of {foundTotalAlloyLoss} ");
Assert.True(expectedExampleWorkerCost.Equals(foundExampleWorkerCost),
$"expectedExampleWorkerCost of {expectedExampleWorkerCost} " +
"does not equal " +
$"foundExampleWorkerCost of {foundExampleWorkerCost} ");
Assert.True(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost),
$"expectedExampleMiningTimeCost of {expectedExampleMiningTimeCost} " +
"does not equal " +
$"foundExampleMiningTimeCost of {foundExampleMiningTimeCost} ");
Assert.True(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate),
$"expectedExampleTotalAlloyLossAccurate of {expectedExampleTotalAlloyLossAccurate} " +
"does not equal " +
$"foundExampleTotalAlloyLossAccurate of {foundExampleTotalAlloyLossAccurate} ");
Assert.True(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference),
$"expectedExampleTotalAlloyLossDifference of {expectedExampleTotalAlloyLossDifference} " +
"does not equal " +
$"foundGetExampleTotalAlloyLossDifference of {foundGetExampleTotalAlloyLossDifference} ");
Assert.True(expectedExampleTotalAlloyLossAccurateDifference.Equals(foundExampleTotalAlloyLossAccurateDifference),
$"expectedExampleTotalAlloyLossAccurateDifference of {expectedExampleTotalAlloyLossAccurateDifference} " +
"does not equal " +
$"foundExampleTotalAlloyLossAccurateDifference of {foundExampleTotalAlloyLossAccurateDifference} ");
}
}

141
TestAutomation/UnitTests.cs

@ -0,0 +1,141 @@
using System.Text;
using Newtonsoft.Json;
using TestAutomation.Utils;
namespace TestAutomation;
public class Tests {
private readonly IWebDriver _webDriver = default!;
private readonly string develop = "https://calm-mud-04916b210.1.azurestaticapps.net/";
private readonly HttpClient httpClient = new();
private readonly string localhost = "https://localhost:7234";
private readonly TestReport testReport = new();
public Tests() {
var options = new FirefoxOptions();
options.AcceptInsecureCertificates = true;
options.AddArgument("--headless");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--start-maximized");
options.AddArgument("--test-type");
options.AddArgument("--allow-running-insecure-content");
_webDriver = new FirefoxDriver(Environment.CurrentDirectory, options);
Website = new Website(_webDriver);
}
private Website Website { get; }
[OneTimeSetUp]
public void Setup() {
_webDriver.Navigate().GoToUrl(develop);
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
}
[OneTimeTearDown]
public void TearDown() {
_webDriver.Quit();
var message = new {
content = "Test Report " + DateTime.Now.ToString("dd/MM/yyyy"),
embeds = testReport.GetMessages()
};
var content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json");
httpClient.PostAsync(Environment.GetEnvironmentVariable("TEST_HOOK"), content).Wait();
}
[Test]
public void HarassCalculator() {
testReport.CreateTest();
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
var expectedTotalAlloyHarassment = 240;
try {
Website.HarassCalculatorPage
.SetWorkersLostToHarass(3)
.SetNumberOfTownHallsExisting(2)
.SetTownHallTravelTime(0, 30)
.GetTotalAlloyHarassment(out var foundTotalAlloyHarassment);
testReport.CheckPassed(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment),
TestMessage.CreateFailedMessage($"expectTotalAlloyHarassment of {expectedTotalAlloyHarassment} " +
"does not equal " +
$"foundTotalAlloyHarassment of {foundTotalAlloyHarassment} "));
}
catch (Exception e) {
testReport.CheckPassed(false,
TestMessage.CreateFailedMessage(e.StackTrace!));
}
}
[Test]
public void HarassCalculatorInformation() {
testReport.CreateTest();
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
var expectedExampleTotalAlloyLoss = 720;
var expectedExampleWorkerCost = 300;
var expectedExampleMiningTimeCost = 420;
var expectedExampleTotalAlloyLossDifference = 300;
var expectedExampleTotalAlloyLossAccurate = 450;
var expectedExampleTotalAlloyLossAccurateDifference = 270;
Website.HarassCalculatorPage
.GetExampleTotalAlloyLoss(out var foundTotalAlloyLoss)
.GetExampleWorkerCost(out var foundExampleWorkerCost)
.GetExampleMiningTimeCost(out var foundExampleMiningTimeCost)
.GetExampleTotalAlloyLossAccurate(out var foundExampleTotalAlloyLossAccurate)
.GetExampleTotalAlloyLossDifference(out var foundGetExampleTotalAlloyLossDifference)
.GetExampleTotalAlloyLossAccurateDifference(out var foundExampleTotalAlloyLossAccurateDifference);
testReport.CheckPassed(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss),
TestMessage.CreateFailedMessage($"expectedExampleTotalAlloyLoss of {expectedExampleTotalAlloyLoss} " +
"does not equal " +
$"foundTotalAlloyLoss of {foundTotalAlloyLoss} "));
testReport.CheckPassed(expectedExampleWorkerCost.Equals(foundExampleWorkerCost),
TestMessage.CreateFailedMessage($"expectedExampleWorkerCost of {expectedExampleWorkerCost} " +
"does not equal " +
$"foundExampleWorkerCost of {foundExampleWorkerCost} "));
testReport.CheckPassed(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost),
TestMessage.CreateFailedMessage($"expectedExampleMiningTimeCost of {expectedExampleMiningTimeCost} " +
"does not equal " +
$"foundExampleMiningTimeCost of {foundExampleMiningTimeCost} "));
testReport.CheckPassed(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate),
TestMessage.CreateFailedMessage(
$"expectedExampleTotalAlloyLossAccurate of {expectedExampleTotalAlloyLossAccurate} " +
"does not equal " +
$"foundExampleTotalAlloyLossAccurate of {foundExampleTotalAlloyLossAccurate} "));
testReport.CheckPassed(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference),
TestMessage.CreateFailedMessage(
$"expectedExampleTotalAlloyLossDifference of {expectedExampleTotalAlloyLossDifference} " +
"does not equal " +
$"foundGetExampleTotalAlloyLossDifference of {foundGetExampleTotalAlloyLossDifference} "));
testReport.CheckPassed(
expectedExampleTotalAlloyLossAccurateDifference.Equals(foundExampleTotalAlloyLossAccurateDifference),
TestMessage.CreateFailedMessage(
$"expectedExampleTotalAlloyLossAccurateDifference of {expectedExampleTotalAlloyLossAccurateDifference} " +
"does not equal " +
$"foundExampleTotalAlloyLossAccurateDifference of {foundExampleTotalAlloyLossAccurateDifference} "));
}
}

7
TestAutomation/Utils/Test.cs

@ -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
TestAutomation/Utils/TestMessage.cs

@ -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
TestAutomation/Utils/TestReport.cs

@ -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;
}
}

2
TestAutomation/Usings.cs → TestAutomation/Utils/Usings.cs

@ -1,9 +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;

10
TestAutomation/Website.cs → TestAutomation/Utils/Website.cs

@ -1,16 +1,16 @@
namespace TestAutomation;
namespace TestAutomation.Utils;
public class Website {
public IWebDriver WebDriver { get; }
public HarassCalculatorPage HarassCalculatorPage { get; }
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));
}
Loading…
Cancel
Save