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

 

35 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

    • 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

Leave a Reply

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