In this series of articles and videos, we will start our discussion with introduction and march towards some of the advanced concepts without wasting our times on basics, since this series will be continuation of following series which is already discussed in ExecuteAutomation

Here are the list of topics discussed in this series

 

66 comments

  1. kishore says:

    Hi Karthik ,

    Thanks for the videos . They are really helpful .
    I am trying to setup BDD with selenium and specflow by following your tutorial “Writing simple BDD code with Selenium and Specflow” , i am getting following exception at Browser.Current
    “An exception of type ‘System.Collections.Generic.KeyNotFoundException’ occurred in mscorlib.dll but was not handled in user code”

    Little bit struggling to find out the problem , as i am very new to coding

    Many Thanks

    • karthik KK says:

      Browser.Current is available in BaseClass.contrib library, just add the reference and the issue will be gone !!!

      Thanks,
      Karthik KK

  2. Carl Christensen says:

    I am having a similar issue as above, I have the references of:
    Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings
    Baseclass.Contrib.SpecFlow.Selenium.NUnit

    below is the message I am getting. This is a replica of the code your tutorial instructed on.

    System.Collections.Generic.KeyNotFoundException was unhandled by user code
    HResult=-2146232969
    Message=The given key was not present in the dictionary.
    Source=mscorlib
    StackTrace:
    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    at Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings.Browser.get_Current()
    at EATestProject.Pages.LoginPage..ctor() in c:\Users\carlchristensen\Documents\Visual Studio 2012\Projects\EATestProject_Sol\EATestProject\Pages\LoginPage.cs:line 20
    at EATestProject.Steps.LoginSteps..ctor() in c:\Users\carlchristensen\Documents\Visual Studio 2012\Projects\EATestProject_Sol\EATestProject\Steps\LoginSteps.cs:line 22
    InnerException:

    Code is below:
    using Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Support.PageObjects;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Baseclass.Contrib;

    namespace EATestProject.Pages
    {
    class LoginPage
    {

    public LoginPage()
    {

    PageFactory.InitElements(Browser.Current, this);

    }

    [FindsBy(How = How.Name, Using = “UserName”)]
    public IWebElement txtUserName;

    [FindsBy(How = How.Name, Using = “Password”)]
    public IWebElement txtPassword;

    [FindsBy(How = How.Name, Using = “Login”)]
    public IWebElement btnLogin;

    public void Login(string userName, string password)
    {
    txtUserName.SendKeys(userName);
    txtPassword.SendKeys(password);
    }

    public EAPage ClickLogin()
    {
    btnLogin.Submit();
    return new EAPage();
    }

    }

    }

    • karthik KK says:

      I can see in your code, you have Browser.current, then please check two stuffs in your code

      1. @Browser tag in scenario
      2. check if the tag in app.config has this value

      Thanks,
      Karthik KK

      • Bishnu Prasad says:

        Hi Karthik,
        Can you please help me on what tag i need to add in App.config? I am still getting the KeyNotFound Exception. I have added the @Browser tag in scenario. Please find my app.config file below. And if any document available for understanding the app.config then please share with me.Please let me know if anything you want to see in my code and thanks for all your help.
        App.config

        <!– Example of using an injected RemoteDriver:

        –>

    • Tarik says:

      Hi,

      I’m getting this same error as mentioned above “System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.”

      Does anyone know how to fix this? My test run fine when I don’t have a browser (e.g. the calculator tests) as soon as I try to use a browser I get this error. Please help…

      Result StackTrace:
      at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
      at Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings.Browser.get_Current()

      System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

      • Karthik kk says:

        If you see this line of your exception

        it tell, that it could not get the current browser from your feature file.

        Meaning, you need to supply your browser name to it in @Browser:Chrome, this should work.

        Thanks,
        Karthik KK

  3. Ade Bakre says:

    I’m having exactly the same problem and I have the tag as specified in App config file and still getting the KeyNotFound exception. There must be step missing as I have the same issue using a similar tutorial as well.

  4. Sushma says:

    Hi Karthik,

    Currently We wrote a frame work where user can select the particular browser from excel sheet run the scripts based on selected browser,but now we need to run the scripts parallely in different browsers without manually changing the browser option in the excel sheet,

    Could you please suggest any plugIn/tool which helps to execute the scripts (selenium specflow) in diff browsers on one click.

    Thanks,
    Sushma

    • Karthik kk says:

      Its exactly the same question you asked in NUnit post, you need to write your own custom library to make this happen 🙂

  5. Srujan says:

    im using specflow v1.9.0 Baseclass.Contrib.SpecFlow.Selenium.NUnit v1.3.1 and when i try to build the project, im seeing the below error
    #error Generation error: Unable to find plugin in the plugin search path: Baseclass.Contrib.SpecFlow.Selenium.NUnit. Please check http://go.specflow.org/doc-plugins for details.

    and in the app.config, i see

    amd i see “Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin.dll” in the tools folder \packages\Baseclass.Contrib.SpecFlow.Selenium.NUnit.1.3.1\tools.

    • Karthik kk says:

      Seems like it couldn’t find the package you installed.

      Could you check the package.config and see if the installed Nuget package is available ?

      • Sandhya says:

        I too got the same error
        Error 30 #error: ‘Generation error: Unable to find plugin in the plugin search path: Baseclass.Contrib.SpecFlow.Selenium.NUnit. Please check http://go.specflow.org/doc-plugins for details.’ C:\GIT\ArgusOpenMarkets\AOM\AOMIntegrationTests\Features\Permissions\CounterpartyPermissions.feature.cs 1 8 AOMIntegrationTests

        Appconfgi:

        <!– –>

        Packages Config:

        I still couldnt find the where the issue is

  6. Hemang says:

    Hi Kartik
    Really nice videos..
    Shall we get code based to practice like c# class code which you used in video.. Not whole project but only code snippet of class which we can copy paste from blog and used in our practice application..

    Have you mentioned these steps in in your blogs which we can use for practice…

    Thanks

  7. Piku says:

    Hi Karthik,
    Thanks for the videos..they are very helpful.
    I am new to BDD/Specflow and I was trying to write a feature file with multiple scenario and one background. While generating step definitions, the methods for each scenario are not exactly sequentially placed . Is there any way to bound step definitions to each scenario ? Or , is there any way to set Priority /Sequence as annotation before each method .
    Feature:ValidateEngagementsPage
    Feature to validate various functionality of My Engagements Page

    Background: Till opening of the web page for My Engagements Page
    Given User provided credentials and click OK Button
    Then Web Page with already provisioned engagements should open

    Scenario: My Engagments page deafult content
    Then Search button should be visble

    Scenario Outline: Search with a Engagement name
    When user enters in the search box
    And click on Search button
    Then Engagements containing the search text should open
    Examples: |SearchText|
    | Black |
    | John |
    | AGI |
    [Given(@”User provided credentials and click OK Button”)]
    public void GivenUserProvidedCredentialsAndClickOKButton()
    {
    ScenarioContext.Current.Pending();
    }

    [Then(@”Web Page with already provisioned engagements should open”)]
    public void ThenWebPageWithAlreadyProvisionedEngagementsShouldOpen()
    {
    ScenarioContext.Current.Pending();
    }

    [Then(@”Search button should be visble”)]
    public void ThenSearchButtonShouldBeVisble()
    {
    ScenarioContext.Current.Pending();
    }

    [When(@”user enters (.*) in the search box”)]
    public void WhenUserEntersInTheSearchBox(string p0)
    {
    ScenarioContext.Current.Pending();
    }

    [When(@”click on Search button”)]
    public void WhenClickOnSearchButton()
    {
    ScenarioContext.Current.Pending();
    }

    [Then(@”Engagements containing the search text should open”)]
    public void ThenEngagementsContainingTheSearchTextShouldOpen()
    {
    ScenarioContext.Current.Pending();
    }

    • Piku says:

      Please ignore Previous code snippet. This is the actual code generated after Clicking “Generate Step Definitions”

      [Given(@”User provided credentials and click OK Button”)]
      public void GivenUserProvidedCredentialsAndClickOKButton()
      {
      ScenarioContext.Current.Pending();
      }

      [When(@”user enters (.*) in the search box”)]
      public void WhenUserEntersInTheSearchBox(string p0)
      {
      ScenarioContext.Current.Pending();
      }

      [When(@”click on Search button”)]
      public void WhenClickOnSearchButton()
      {
      ScenarioContext.Current.Pending();
      }

      [Then(@”Web Page with already provisioned engagements should open”)]
      public void ThenWebPageWithAlreadyProvisionedEngagementsShouldOpen()
      {
      ScenarioContext.Current.Pending();
      }

      [Then(@”Search button should be visble”)]
      public void ThenSearchButtonShouldBeVisble()
      {
      ScenarioContext.Current.Pending();
      }

      [Then(@”Engagements containing the search text should open”)]
      public void ThenEngagementsContainingTheSearchTextShouldOpen()
      {
      ScenarioContext.Current.Pending();
      }

    • Karthik kk says:

      You can do by prefixing the scenario name with 001_ValidateEngagementsPage, 002_ etc

      But the best practice of BDD is, making each scenario as independent as possible.

      Thanks,
      Karthik KK

      • Shazia says:

        I’m also having the same problem KeyNotFound exception.

        my feature files is:

        Feature: Login
        In order to avoid silly mistakes
        As a math idiot
        I want to be told the sum of two numbers

        @SmokeTest
        @Browse:Chrome
        Scenario:Verify login
        Given I have navigated to google
        And I see page loaded

        And my appconig contains:

        • Karthik kk says:

          Its because of the @Browser:Chrome, you can most probabily write your own custom code for the browser.

          Thanks,
          Karthik KK

  8. Dileep Kumar Verma says:

    Hi Karthik,

    Could you have any video for Spec Flow configuration in vNext build definition or XAML build definition

  9. Hi Kartik:
    I follow your video series for my integration test suite and I have successfully done with Smoke Test using specflow and selenium.Now I am started involving database in my project using hooks. I seed the data which I need for my test. I want to do it using transaction scope in hooks but when I inherit the hook class with step definition class,there is error “System.Collections.Generic.KeyNotFoundException was unhandled by user code HResult=-2146232969” on my PageFactory.InitElements(Browser.Current, this); I also have the reference for browser.Current.
    My basic approach is I don’t want to commit data in database. It works fine when I commit the data in database but I want to use in Transaction scope.
    Could you help me to solve this problem? Any guidelines?

  10. Santosh Kumar says:

    Hi Karthik,

    I was trying to setup SpecFlow with VS2015 during this drill I tried to write my first test in BDD unfortunately I couldn’t find the SpecFlow Feature File, SpecFlow Hooks and SpecFlow StepDefinition under Add new Item. Could you please help me on this.\

    Regards,
    Santosh

  11. Deepthi Karthikeyan says:

    Hi Karthik ,

    Your videos has helped me a lot to start with Automation.Appreciate your effort in creating these Videos.

    I had a query for you .Can you please help me ?

    While automating a webapp I’m encountering an issue – Not able to navigate to next page of the UI even after hitting Next button .
    Selenium is not throwing any error regarding the webelement

    HTML –

    Code : Driver.Instance.FindElement(By.Name(“ctl00$AIContent$btnNext”)).Click();

    I tried using explicit wait ,still not able to find a solution
    Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));

    Thanks in advance,
    Deepthi

  12. sushma says:

    Hi Karthik,

    I am using Scenario Outline , need to implement the method to kill the excel process at the end of each GWT execution by fetching all the excel instances of that GWT,Could you please help me on this.

    I used below which kills all the opened Excel sheets
    Process[] excelProcs = Process.GetProcessesByName(“EXCEL”);
    foreach (Process proc in excelProcs)
    {
    proc.Kill();
    }

    Thanks,
    Sushma

  13. Bishnu Prasad says:

    Hi Karthik,
    In your video series you have removed IWebDriver driver = null;. So lets say if in my program if i need IWebDriver object in some place then how to handle. I am facing issue while creating Action class object. Please help me as i am very new to Selenium C#.

    Thanks,
    Bishnu

  14. Bikas says:

    Can you please suggest as I m facing this issue when I click on Project build :-

    Custom tool error: Generation error: Method ‘Initialize’ in type ‘Baseclass.Contrib.SpecFlow.Selenium.NUnit.GeneratorPlugin’ from assembly ‘Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ does not have an implementation. c:\users\\documents\visual studio 2017\Projects\….Demo\Features\SpecFlowFeature1.feature

  15. Hi,
    We are trying to implement BDD using selenium,we are facing one issue that,after writing feature file,we are not getting suggestions on right click to
    Create step definition
    Create all steps definitions
    Kindly help us in resolving the issue.

    Attached the execute automation video URL which we referred.
    Thanks

  16. pandu raju says:

    Hi Kathik,
    I am trying to integrating Specflow with CodedUI API. but there is no proper solutions available in internet. Main problem with dll (plugins).
    Could you please provide the solution.
    Here is the useful links:
    https://specflow.org/documentation/Using-SpecFlow-with-CodedUI-API/
    http://blog.jessehouwing.nl/2013/04/creating-custom-unit-test-generator.html
    https://rburnham.wordpress.com/2011/03/15/bdd-ui-automation-with-specflow-and-coded-ui-tests/

  17. Kokilavani says:

    Hi Karthik,
    how to read data from multiple sheets in a excel, and store it in a dataTable initially, since if i try to access the FileStream for 2nd sheet, i am getting the excel is used by another processor error.

  18. waris says:

    Hello kartik,
    I find your blog very helpful but i need to develop the :

    Open your webbrowser
    Navigate to the Wikipedia site: https://www.wikipedia.org/
    Choose the English language
    Search for „Test Automation”
    Validate the following in this page:
    Unit testing text
    Existence of Test Automation Interface Model picture
    Search for the link of Behavior driven development and navigate to there.
    Tools you have to use for this task:

    C#
    Specflow
    Nunit3
    Selenium webdriver

  19. Subbu Pagadala says:

    Hi,

    How to show the ignored scenarios or feature files in the report with Extent report, And how to get the ignore tags information at the run time, i am using VS 2017 with NUnit Latest version.
    My Feature file Scenario

    @Ignore @”Test_purpose” @MainPage
    Scenario: Open Test Area From MainMenu
    Given the application is default
    When I open the test area page
    Then the test area page should be shown

    My designer file code should be
    [NUnit.Framework.TestAttribute()]
    [NUnit.Framework.DescriptionAttribute(“Open Test Area From MainMenu”)]
    [NUnit.Framework.IgnoreAttribute(“Ignored scenario”)]
    [NUnit.Framework.CategoryAttribute(“\”Test_purpose\””)]
    [NUnit.Framework.CategoryAttribute(“MainPage”)]
    public virtual void OpenTestAreaFromMainMenu()
    {
    TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo(“Open Test Area From MainMenu”, new string[] {
    “Ignore”,
    “\”Test_purpose\””,
    “MainPage”});
    #line 10
    this.ScenarioSetup(scenarioInfo);
    #line 11
    testRunner.Given(“the application is default”, ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), “Given “);
    #line 12
    testRunner.When(“I open the test area page”, ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), “When “);
    #line 13
    testRunner.Then(“the test area page should be shown”, ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), “Then “);
    #line hidden
    this.ScenarioCleanup();
    }

    I would like to show in my report 1 scenario is ignored if possible with custom message, For getting the ignore tags which Hook i can use and what are all the things i have to take care in specflow. Can you share some information on that

    Thanks & Regards
    SubbuP

  20. Sai says:

    Hi Karthik,

    I have followed your steps and started BDD but getting the following error:”Method ‘Initialize’ in type ‘Baseclass.Contrib.SpecFlow.Selenium.NUnit.GeneratorPlugin’ from assembly ‘Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ does not have an implementation.”

    how to deal with this?

    If we have to add any keyvalue pair in appconfig please let me know what and where to be added.

  21. Srabani says:

    Hi Karthik,
    I have gone through your course material for the above course material of selenium webdriver using c# and BDD. I want to enhance my knowledge for project purpose in building automation framework using BDD & Specflow following the POM.Which course is appropriate for me.
    Also please let me know any coupon code is available for the same.

    Thanks
    Srabani

  22. vijay says:

    HI Karthik, your video on Running Specflow Tags on nunit is working fine. However, i want to run a specific scenario

    can you please Help me how to execute a individual feature file?

    Commands I tried :

    B:\Koshervscode>nunit3-console.exe C:\Users\.\.\.\.\.\bin\Debug\test.dll –where “name=Regression.Feature”

    B:\Koshervscode>nunit3-console.exe C:\Users\.\.\.\.\.\bin\Debug\test.dll –test “name=Regression.Feature”

    • Karthik kk says:

      No it’s not possible, since the --Where condition is not applicable based Feature

      Technical details.
      —————————-
      NUnit runs based on tags, since it uses [NUnit.Framework.CategoryAttribute("smoke")] attribute in the code behind of Specflow and NUnit looks for category
      But for feature name is created based on [NUnit.Framework.DescriptionAttribute("Regression")] which is not what NUnit can use

      Hope it makes sense

      Thanks,

      • Vijay Bhargav says:

        Thanks for the Reply karthik 🙂

        So if i wanted to write tests with Specflow commands created by Visual studio professional 2015 using any Free tool, is it possible? I Have a nuget feed which updates the latest commands. Code is masked from implementation. does Visual studio code or any other free tool will be able to do this?

        Again, thanks for the Reply

Leave a Reply

Your email address will not be published. Required fields are marked *