ExecuteAutomation

Writing simple BDD code with Selenium and Specflow

In last post we created all the necessary environment setup ready for testing our application using BDD with Selenium and Specflow, in this post, we will start to write a simple code starting with And write out a very simple Here is how feature file for our simple scenario looks Here is the complete video for our above discussion Here is the Step definition for the above feature file
		
	        IWebDriver currentDriver = null;

        [Given(@"I have navigated to Google page")]
        public void GivenIHaveNavigatedToGooglePage()
        {
            Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
            currentDriver = Browser.Current;
        }

        [Given(@"I see the Google page fully loaded")]
        public void GivenISeeTheGooglePageFullyLoaded()
        {
            if(currentDriver.FindElement(By.Name("q")).Displayed == true)
                Console.WriteLine("Page loaded fully");
            else
                Console.WriteLine("Page failed to load");
        }

        [When(@"I type search keyword as")]
        public void WhenITypeSearchKeywordAs(Table table)
        {
            dynamic tableDetail = table.CreateDynamicInstance();
            currentDriver.FindElement(By.Name("q")).SendKeys(tableDetail.Keyword);
        }

        [Then(@"I should see the result for keyword")]
        public void ThenIShouldSeeTheResultForKeyword(Table table)
        {
            dynamic tableDetail = table.CreateDynamicInstance();
            string key = tableDetail.Keyword;
            if (currentDriver.FindElement(By.PartialLinkText(key)).Displayed == true)
                Console.WriteLine("Control exist");
            else
                Console.WriteLine("Control not exist");
        }
Thanks for watching the video and reading the post !!! Please leave your comments and let me know if there is anything need to be improved in this post. Thanks, Karthik KK