So I've been trying for a few days now and it seems like I just can't really can't understand or find a solution to this whole process. I'm using Selenium so i can simulate a User Input on my 'Website'. Whenever i try to execute my testmethods it says that they both have not been executed, without any indication of errors.
What I have tried:
This is my Testing Code. I try to test the simulated user input in Chrome and in Edge, but it just wont execute it. The IDE also doesn't find any code error:
namespace EndToEnd
{
[TestClass]
public class BookingCreateUITest
{
private string _websiteURL = "https://localhost:44325/";
private RemoteWebDriver _browserDriver;
public Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext { get; set; }
[TestInitialize]
public void Initialize()
{
_websiteURL = (string)TestContext.Properties["webAppUrl"];
}
[TestMethod]
[TestCategory("Selenium")]
[DataRow("10.2", "100", "2021-06-15T13:45:09", "2021-06-16T13:45:09")]
[DataRow("200", "200", "2021-06-15T13:45:09", "2021-06-16T13:45:09")]
[DataRow("10.2", "100", null, "20021-06-16T13:45:09")]
public void CreateBookingChrome(string chargeState, string distance, string starttime, string endtime)
{
_browserDriver = new ChromeDriver();
_browserDriver.Manage().Window.Maximize();
_browserDriver.Navigate().GoToUrl(_websiteURL + "Booking/Create");
Thread.Sleep(1000);
_browserDriver.FindElementById("ChargeState").SendKeys(chargeState);
_browserDriver.FindElementById("Distance").SendKeys(distance);
_browserDriver.FindElementById("Starttime").SendKeys(starttime);
_browserDriver.FindElementById("Endtime").SendKeys(endtime);
var screenshot = _browserDriver.GetScreenshot();
var filename = $"{distance}.jpg";
screenshot.SaveAsFile(filename, OpenQA.Selenium.ScreenshotImageFormat.Jpeg);
TestContext.AddResultFile(filename);
_browserDriver.FindElementById("CreateButton").Click();
Thread.Sleep(1000);
Assert.IsTrue(_browserDriver.PageSource.Contains(chargeState));
Assert.IsTrue(_browserDriver.PageSource.Contains(distance));
Assert.IsTrue(_browserDriver.PageSource.Contains(starttime));
Assert.IsTrue(_browserDriver.PageSource.Contains(endtime));
}
[TestMethod]
[TestCategory("Selenium")]
[DataRow("10.2", "100", "2021-06-15T13:45:09", "2021-06-16T13:45:09")]
[DataRow("200", "200", "2021-06-15T13:45:09", "2021-06-16T13:45:09")]
[DataRow("10.2", "100", null, "2009-06-15T13:45:09")]
public void CreateBookingEdge(string chargeState, string distance, string starttime, string endtime)
{
_browserDriver = new EdgeDriver();
_browserDriver.Manage().Window.Maximize();
_browserDriver.Navigate().GoToUrl(_websiteURL + "Booking/Create");
Thread.Sleep(1000);
_browserDriver.FindElementById("ChargeState").SendKeys(chargeState);
_browserDriver.FindElementById("Distance").SendKeys(distance);
_browserDriver.FindElementById("Starttime").SendKeys(starttime);
_browserDriver.FindElementById("Endtime").SendKeys(endtime);
var screenshot = _browserDriver.GetScreenshot();
var filename = $"{distance}.jpg";
screenshot.SaveAsFile(filename, OpenQA.Selenium.ScreenshotImageFormat.Jpeg);
TestContext.AddResultFile(filename);
_browserDriver.FindElementById("CreateButton").Click();
Thread.Sleep(1000);
Assert.IsTrue(_browserDriver.PageSource.Contains(chargeState));
Assert.IsTrue(_browserDriver.PageSource.Contains(distance));
Assert.IsTrue(_browserDriver.PageSource.Contains(starttime));
Assert.IsTrue(_browserDriver.PageSource.Contains(endtime));
}
}
}
This is the View that it is reffering to:
@model Sopro.Models.BookingModel
@{
ViewData["Title"] = "Create";
}
<h3>Neue Buchung erstellen</h3>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="chargeState" class="control-label"></label>
<input asp-for="chargeState" class="form-control" id="ChargeState"/>
<span asp-validation-for="chargeState" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="distance" class="control-label"></label>
<input asp-for="distance" class="form-control" id="Distance"/>
<span asp-validation-for="distance" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="startTime" class="control-label"></label>
<input asp-for="startTime" class="form-control" type="datetime" id="Starttime" />
<span asp-validation-for="startTime" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="endTime" class="control-label"></label>
<input asp-for="endTime" class="form-control" type="datetime" id="Endtime"/>
<span asp-validation-for="endTime" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="connectorType" class="control-label"></label>
<select asp-for="connectorType" class="form-control">
<option value="Schuko_Socket">Schuko-Socket</option>
<option value="Type_1_Plug">Type 1-Plug</option>
<option value="Type_2_Plug">Type 2-Plug</option>
<option value="CHAdeMO_Plug">CHAdeMO-Plug</option>
<option value="Tesla_Supercharger">Tesla Supercharger</option>
<option value="CCS_Combo_2_Plug">CCS Combo 2-Plug</option>
</select>
<span asp-validation-for="connectorType" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Erstellen" class="btn btn-primary" id="CreateButton"/>
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Zurück zur Buchungsübersicht</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}