- Introduction to BDD with Selenium and Specflow
- Setting stage ready for BDD with Selenium and Specflow automation
- Writing simple BDD code with Selenium and Specflow
- Writing BDD Code using Selenium POM and Specflow
- BDD with Selenium POM Page Navigation and Specflow
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
Browser.Current is available in BaseClass.contrib library, just add the reference and the issue will be gone !!!
Thanks,
Karthik KK
Good information. Lucky me I discovered your site by accident (stumbleupon). I have saved it for later!
Thanks for reading articles in execute automation.
Thanks
Karthik
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();
}
}
}
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
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:
–>
@Browser tag is no more supported with latest versions of Specflow.
Ok….it worked for me with older version. Can you please let me know how we can do cross browser execution with the framework that you have explain in your video. Do we have any link???
Please reply….
Thanks,
Bishnu
Its there here https://www.udemy.com/creating-automation-reports-with-ears
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.
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
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.
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
Its exactly the same question you asked in NUnit post, you need to write your own custom library to make this happen 🙂
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.
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 ?
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
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
This video link is not working properly. please assist
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();
}
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();
}
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
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:
Its because of the @Browser:Chrome, you can most probabily write your own custom code for the browser.
Thanks,
Karthik KK
And my appconig contains:
Hi Karthik,
Could you have any video for Spec Flow configuration in vNext build definition or XAML build definition
Its there in this video series https://www.youtube.com/playlist?list=PL6tu16kXT9PobDD9CdXWBiidO-ewujxcT
Thanks,
Karthik KK
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?
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
This is fixed now
Great !!
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
Thanks for watching the videos !!!
Could you try to use submit() instead of click, may be the button type is submit (as postback)
Driver.Instance.FindElement(By.Name(“ctl00$AIContent$btnNext”)).Submit();
Thanks,
Karthik KK
There was some issue with the page loading ,worked with thread.sleep() .But it was so nice of you to reply instantly.I started off with automation by watching your videos.Can you suggest me some books that will help me with some advance knowledge on Selenium and C#.
You can watch the advanced course on Selenium and C# here https://www.udemy.com/framework-development-with-selenium-csharp-advanced
Karthik – Please let me know if you have some code that i can use for this course?
Most of the course source codes are available in the links itself. If not, you must go for Udemy course I released https://www.udemy.com/framework-development-with-selenium-csharp-advanced
Thanks,
Karthik KK
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
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
Hi Bishnu,
Your questions are answered in detailed in this course https://www.udemy.com/framework-development-with-selenium-csharp-advanced/, let me know if you are interested, I can send you discount coupon code.
Thanks,
Karthik KK
Hey Karthik,
It will be great help to my project. Please send me the coupon.
Looking forward to learn something new from you.
Regards,
Bishnu
Please check your inbox for coupon code.
Thanks,
Karthik KK
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
This project which you are using is not in development anymore, please do not use that for tagging with your scenario like @browser:Chrome etc You can see the developer has last committed his code in github repo 4 years before https://github.com/baseclass/Contrib.SpecFlow.Selenium.NUnit
Thanks,
Karthik KK
HI Karthik,
I want to buy your following course at UDEMY
https://www.udemy.com/bdd-with-specflow-and-selenium-csharp/
Could you please give me a special discount?
Thanks
You can learn this whole course for free from my youtube channel here https://www.youtube.com/watch?v=tfq9FlkyaUM&list=PL6tu16kXT9Pp3wrsaYyNRnK1QkvVv6qdI
Thanks,
Karthik KK
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
It should work, did you installed the plugin for Cucumber in your intelliJ ?
Yes it is installed,can you suggest the plugin version,because I think it may be because we have used an old one or something.
We have installed both cucumber for java and gherkin on our system,everything is working fine except one thing that we are not getting options to generate step definition for statements in feature file,could you please help me in resolving the issue.
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/
Its there in this course https://www.udemy.com/framework-development-with-cuit/
Thanks,
Karthik KK
Hi Karthik,
could you please help us with one issue, we are getting test ignored and none of the test are getting executed?Can you please help us in resolving the issue.
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.
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
Hi Malik,
You can checkout this complete details from either my basic free course in YouTube or from advanced course here to understand how to do what you are looking for
https://www.udemy.com/framework-development-with-selenium-csharp-advanced/
Thanks,
Karthik KK
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
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.
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
Please check your inbox for discount coupon code.
Thanks,
Karthik KK
Yeah I too need the coupon code for this course
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”
No it’s not possible, since the
--Where
condition is not applicable based FeatureTechnical details.
—————————-
NUnit runs based on tags, since it uses
[NUnit.Framework.CategoryAttribute("smoke")]
attribute in the code behind of Specflow and NUnit looks for categoryBut for feature name is created based on
[NUnit.Framework.DescriptionAttribute("Regression")]
which is not what NUnit can useHope it makes sense
Thanks,
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
I dont think there is any FREE tool, but may be SpecRunner https://specflow.org/plus/runner/ can come in handy, but its PAID.
Hi Karthik,
I’m trying to implement BDD using specflow. In that flow, I’m trying to follow your videos. Getting frequent build errors. Here is the error: https://github.com/baseclass/Contrib.SpecFlow.Selenium.NUnit/issues/15
Can you help me out of this?
Hi Karthik,
I’m getting number of errors in build. Here is the error: https://github.com/baseclass/Contrib.SpecFlow.Selenium.NUnit/issues/15
Can you help me out of this error?
thanks Khathik,
Please how do you determine relevant nugets for projects? Are there any suggested ones for projects?
Please I am new on this
It depends upon the usage of libraries
Hi Karthik
Your course is really helpful.
I am using ‘PageFactory’ class but getting a message that this class has been deprecated and will be removed from future releases. (though it is working with my current Selenium.Support Version 3.141.0).
Please let me know if there is any new class which suffice the same.
Thanks & Regards
Akanksha Gupta
Its here in DotNetExtra package https://github.com/DotNetSeleniumTools/DotNetSeleniumExtras
Hi Karthik kk
Pleas i am in need of the Framework Architecture Document for the BDD Spec Flow with Selenium if you can provide will be Helpful as saw it in the youtube
Hi Karthik, in my project solution I have implemented Extent Reports with Specflow. For this your articles and videos helped a lot. But on one thing I am stuck and tomorrow evening I have demo. I would be glad if you could help me.
Issue : There is hook.cs file, in which before scenario tagged method instantiates Extent report class and after scenario holds tag for given, when and then line that are displayed on html report. Followed steps provided in Specflow – Extent Report video – 31 yours on youtube.
Now my concern is that in step definition file, I am having some activity and retrieving data from SQL. so I want to display those extracted record on report.html page against that step like below –
Step Definition File.cs
[When(@”User database returns result”)]
public void UserDatabaseReturnsResult
{
Tuple <List, List> t = userDB();
var userName = t.Item1;
var empId = t.Item2;
}
Now Hook.cs file will call after test method and in result on html I will get – User Database Returns Result. But I want userName and empId to be also get print. Please guide me on this, as tomorrow is important day for me and demo will be decision taker for me.
You cannot rely on
AfterScenario
for this step, since thats called AFTER the scenario, rather you should do it inAfterStep
hook, All I can say is, instead of using these kind of steps in Hooks, do it in individual step, since hooks are generally for all the test steps and scenarios, but the one you have is very specific situation and its for the specific step, hence dont go with hooks.Using
scenario.CreateNode("PASS YOUR USERNAME AND EMPID HERE");
Thanks,
Karthik KK
Thanks Kartik 🙂
But now I am getting an error – “Project.exe came from another computer and was blocked to help protect this computer.” please find the below versions of package.
Specflow version is 2.3.1 / 2.3.2
Nunit 3.12
Nunit test adapter 3.10
Kindly guide me on this, as this error is killing me.
Regards,
Shruti
Hi kartik,
I am getting an error – “Project.exe came from another computer and was blocked to help protect this computer.” please find the below versions of package.
Specflow version is 2.3.1 / 2.3.2
Nunit 3.12
Nunit test adapter 3.10
Kindly guide me on this, as this error is killing me.
Regards,
Shruti
Very weird error, can you please search for project.exe in your folder, if such file does exist ?
Thanks,
Karthik KK
Here project.exe is just a sample name. There is one common solution, in which I am working on Supply.dll. Thats my project and yes my project has Supply.dll file in references folder.
Hi Karthik,
I am using latest Specflow version 3.1 and using Baseclass.Contrib.SpecFlow.Selenium.NUnit as you have mentioned in your videos. I am getting the below error “Message: OneTimeSetUp: System.TypeLoadException : Could not load type ‘TechTalk.SpecFlow.Infrastructure.RuntimePluginAttribute’ from assembly ”
Kindly help me to get rid of this error.