using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;
using Calculator_SeleniumHQ.AcceptanceTests.StepHelpers;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace Calculator_SeleniumHQ.AcceptanceTests.SharedSteps
{
    [Binding]
    public class PageInteraction
    {
        [Then("the page contains a \"(.*)\" element with id \"(.*)\"")]
        public void ThePageContainsAnElementWithId(string element, string id)
        {
            // Arrange

            // Act
            IWebElement pageElement = WebBrowser.Current.FindElement(By.Id(id));

            // Assert
            Assert.AreEqual(element.ToLower(), pageElement.TagName.ToLower(), string.Format("Element with id \"{0}\" was expected to be of type \"{1}\", but instead was of type \"{2}\".", id, element.ToLower(), pageElement.TagName.ToLower()));
        }

        [When("the user clicks the \"(.*)\" element with the id \"(.*)\"")]
        public void TheUserClicksTheElementWithId(string element, string id)
        {
            // Arrange

            // Act
            IWebElement clickElement = WebBrowser.Current.FindElement(By.Id(id));

            // Assert
            Assert.AreEqual(element.ToLower(), clickElement.TagName.ToLower(), string.Format("Element with id \"{0}\" was expected to be of type \"{1}\", but instead was of type \"{2}\".", id, element.ToLower(), clickElement.TagName.ToLower()));

            // Click the element (e.g. 'a', 'button', or 'input[type="button"]')
            clickElement.Click();
        }
    }
}
