Unit tests for the controller and context

Create a new class in the tests project called: SprintsControllerTest


Create a new class in the tests project called: SprintTrackerWebContextTest.cs


Empty database test and code

Add below method to AverageActualPointsModelTests.cs


Update the GetAveragePoints method in Statistics.cs


Driver Class

 public class Driver
    {
        public static IWebDriver Browser { get; set; }
        public static string EnvironmentUrl { get; } = ConfigurationManager.AppSettings["url"];



        public static void InitializeDriver()
        {
            string browser = ConfigurationManager.AppSettings["browser"];
            ChromeOptions options = new ChromeOptions();
            options.AddArguments("headless", "disable-gpu");

            // Needed for running on the Hosted VS2017 box
            String chromePath = Environment.GetEnvironmentVariable("ChromeWebDriver");

            switch (browser)
            {
                case "chrome":
                    if (chromePath != null)
                    {
                        Browser = new ChromeDriver(chromePath);
                    }
                    else
                    {
                        Browser = new ChromeDriver();
                    }
                    break;
                case "headless":
                    if (chromePath != null)
                    {
                        Browser = new ChromeDriver(chromePath, options);
                    }
                    else
                    {
                        Browser = new ChromeDriver(options);
                    }
                    break;
                default:
                    if (chromePath != null)
                    {
                        Browser = new ChromeDriver(chromePath);
                    }
                    else
                    {
                        Browser = new ChromeDriver();
                    }
                    break;
            }
        }


        public static void OpenWebApp()
        {
            Browser.Navigate().GoToUrl(EnvironmentUrl);
        }

        public static void CloseBrowser()
        {
            Browser.Close();
            Browser.Dispose();
        }

        public static IWebElement WaitForElement(By locator)
        {
            // Here we set the timeout as 5 second, 0 minutes and 0 hours
            WebDriverWait wait = new WebDriverWait(Browser, new TimeSpan(0, 0, 5));
            // Here we set the `Until` condition as until the browser finds the element.If it find the element in 5 seconds, it will return it.
            return wait.Until(Browser => Browser.FindElement(locator));
        }

    }

Locators

public class SprintsPageLocators
    {
        // Locators for deleting a sprint
        // 'Delete' Link Locator
        public By DeleteLinkLocator { get; } = By.LinkText("Delete");
        // 'Delete' Button Locator
        public By DeleteButtonLocator { get; } = By.XPath(".//input[@value='Delete']");
        // Locators for adding a sprint
        // 'Create New' link locator.
        public By CreateNewLinkLocator { get; } = By.LinkText("Create New");
        // 'Sprint Name' field locator
        public By SprintNameFieldLocator { get; } = By.Id("SprintName");
        // 'Predicted Points' field locator
        public By PredictedPointsFieldLocator { get; } = By.Id("PredictedPoints");
        // 'Actual Points' field locator
        public By ActualPointsFieldLocator { get; } = By.Id("ActualPoints");
        // 'Create' button locator
        public By CreateButtonLocator { get; } = By.XPath(".//input[@value='Create']");
        // Sprint Average Points Locator
        public By AveragePointsLocator { get; } = By.XPath(".//h4[contains(text(),'Average Sprint Points')]");
    }

Pipeline YAML

IMPORTANT:

YAML is sensitive to spaces and indents, it’s very important that the indenting shown below is followed. Tools such as Notepad++ or VS code can help check the formatting

azure-pipeline.yml content:


Reporting

NUnit xml report

nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" SprintTracker.AcceptanceTests\bin\Debug\SprintTracker.AcceptanceTests.dll
 

Specflow report

specflow.exe nunitexecutionreport --ProjectFile SprintTracker.AcceptanceTests\SprintTracker.AcceptanceTests.csproj