using DryRunner;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace Calculator_SeleniumHQ.AcceptanceTests.StepHelpers
{
    [Binding]
    public static class WebBrowser
    {
        private static TestSiteManager _testSiteManager;

        public static IWebDriver Current
        {
            get
            {
                if (!ScenarioContext.Current.ContainsKey("browser"))
                    ScenarioContext.Current["browser"] = new ChromeDriver();
                return ScenarioContext.Current["browser"] as IWebDriver;
            }
        }

        [BeforeTestRun]
        public static void SetupIISExpress()
        {
            _testSiteManager = new TestSiteManager("Calculator_SeleniumHQ", new TestSiteOptions()
            {
                Port = 8888,
            });

            _testSiteManager.Start();
        }

        [AfterTestRun]
        public static void DestroyIISExpress()
        {
            _testSiteManager.Stop();
        }

        [AfterScenario]
        public static void DestroyIE()
        {
            Current.Quit();
            Current.Dispose();
        }
    }
}
