Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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) 
        {
            //Arrange
            _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);
            //_browserDriver.FindElementById("ConnectorType").SendKeys(connectorType);

            //create Screenshot (optional)
            var screenshot = _browserDriver.GetScreenshot();
            var filename = $"{distance}.jpg";
            screenshot.SaveAsFile(filename, OpenQA.Selenium.ScreenshotImageFormat.Jpeg);
            TestContext.AddResultFile(filename);

            //Act
            _browserDriver.FindElementById("CreateButton").Click();
            Thread.Sleep(1000);
             

            //Assert
            Assert.IsTrue(_browserDriver.PageSource.Contains(chargeState));
            Assert.IsTrue(_browserDriver.PageSource.Contains(distance));
            Assert.IsTrue(_browserDriver.PageSource.Contains(starttime));
            Assert.IsTrue(_browserDriver.PageSource.Contains(endtime));
            //Assert.IsTrue(_browserDriver.PageSource.Contains(connectorType));
        }

        [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)
        {
            //Arrange
            _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);
            //_browserDriver.FindElementById("ConnectorType").SendKeys(connectorType);

            //create Screenshot (optional)
            var screenshot = _browserDriver.GetScreenshot();
            var filename = $"{distance}.jpg";
            screenshot.SaveAsFile(filename, OpenQA.Selenium.ScreenshotImageFormat.Jpeg);
            TestContext.AddResultFile(filename);

            //Act
            _browserDriver.FindElementById("CreateButton").Click();
            Thread.Sleep(1000);

            //Assert
            Assert.IsTrue(_browserDriver.PageSource.Contains(chargeState));
            Assert.IsTrue(_browserDriver.PageSource.Contains(distance));
            Assert.IsTrue(_browserDriver.PageSource.Contains(starttime));
            Assert.IsTrue(_browserDriver.PageSource.Contains(endtime));
            //Assert.IsTrue(_browserDriver.PageSource.Contains(connectorType));
        }
    }
}


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");}
Posted
Updated 30-May-20 11:22am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900