How to setup Specflow and Protractor
Behavior
Driven Development
In this article, we
are going to discuss Behavior-driven development and Specflow and Protractor
tools and some of the best tools present in the industry.
So, before going into
tools, what is behavior driven development? behavior-driven development (BDD)
is an Agile software development process that encourages collaboration between
developers, QA and non-technical or business participants of that project.
The tools serve to add automation to the ubiquitous language that is a central
theme of BDD.
1.First
Install these 3 tools mentioned below
·
node v6.11.3
·
protractor version
5.1.2
·
Visual
Studio 2017 Community Edition
2. Create
NUnit project by:
visual
studio > new Project > Visual C# > Test > Unit Test Project (.Net
Framework)
3.
then go to Solution Explorer > right click on “References” and select on “Manage
NuGet packages”
4. then Add packages
these packages mentioned below
·
Specflow
·
Nunit3
·
NUnit3TestAdapter
·
Protractor
·
Selenium.WebDriver
·
Selenium.Support
·
Selenium.WebDriver.ChromeDriver
5. Create a
Feature File by:
Again go to
“Solution Explorer” Right click on the project > Visual C# Items > select
“SpecFlow Feature File”
6. Write the
Feature file description with Gherkin notation (Given, When, Then)
Ex :
Ex :
Title: To maintain 20
iPhone 7 models in my inventory
- I am a Cell Phone Store Owner
- In order to address fresh orders
- I need to maintain 20 iPhone 7
models in my inventory
Scenario
1:
- Given that a customer has
purchased an iPhone 7
- Then my Inventory balance should
go down to 19
- When I transfer one model from the
Warehouse to Inventory
- Then the inventory balance should
go up by 1, to 20
Scenario
2:
- Given that a customer has
purchased an iPhone 7
- Then my Inventory balance should
go down to 19
- And the customer has decided to
return the model
- Then the inventory balance should go back to 20
Right Click
on the Feature title > select Generate Step Definitions
8. Copy the
methods to clip board
10. Create
“SpecFlow Step Definition” file
11. Paste
the copied Step Definitions in the SpecFlow Step Definition file.
·
Include the
necessary references
(NUnit.Framework, OpenQA.Selenium, OpenQA.Selenium.Chrome, Protractor,
TechTalk.SpecFlow)
·
Create an
instance of Protractor’s NgWebDriver as ngDriver.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using Protractor;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Threading;
namespace TestProject1
{
[Binding]
public sealed class SearchGoogle
{
// Create a Instence
NgWebDriver ngDriver = new NgWebDriver(new ChromeDriver());
[Given(@"Go to website")]
public void GivenGoToWebsite()
{
ngDriver.IgnoreSynchronization = true;
// Navigate to Url
ngDriver.Url = "https://www.fiverr.com";
// Maximize web browser
ngDriver.Manage().Window.Maximize();
// Hold page 3 seconds
Thread.Sleep(3000);
}
[Then(@"Search Article")]
public void ThenSearchArticle()
{
// Pass the data to search box
ngDriver.FindElement(By.XPath("//*[@id='main-wrapper']/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/form/input")).SendKeys("QA automation");
Thread.Sleep(3000);
// Click Search
ngDriver.FindElement(By.XPath("//*[@id='main-wrapper']/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/form/button")).Click();
Thread.Sleep(3000);
}
}
}
15. Right click and finally run particulate test
12. Write the
steps for:
·
load the page (given
statement)
·
navigating to new page
(then statement)
13. Finally the Steps file
code should be as using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using Protractor;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Threading;
namespace TestProject1
{
[Binding]
public sealed class SearchGoogle
{
// Create a Instence
NgWebDriver ngDriver = new NgWebDriver(new ChromeDriver());
[Given(@"Go to website")]
public void GivenGoToWebsite()
{
ngDriver.IgnoreSynchronization = true;
// Navigate to Url
ngDriver.Url = "https://www.fiverr.com";
// Maximize web browser
ngDriver.Manage().Window.Maximize();
// Hold page 3 seconds
Thread.Sleep(3000);
}
[Then(@"Search Article")]
public void ThenSearchArticle()
{
// Pass the data to search box
ngDriver.FindElement(By.XPath("//*[@id='main-wrapper']/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/form/input")).SendKeys("QA automation");
Thread.Sleep(3000);
// Click Search
ngDriver.FindElement(By.XPath("//*[@id='main-wrapper']/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/form/button")).Click();
Thread.Sleep(3000);
}
}
}
Download Project using below link
Download







Great article for all, thanks bro . . . . . . . .
ReplyDeleteSuch a helpful article, would love to explore more like this one.
ReplyDeleteCustom website development Melbourne
Wordpress website development Melbourne
Artificial Intelligence Melbourne
Hi, this is really very nice blog, your content is very interesting and engaging, worth reading it. I got to know a lot from your articles. Thanks for sharing your knowledge.
ReplyDeleteISO 9001 Certification in Bahrain
I just came to your blog and want to say that I enjoyed reading your blog post. I hope you will post again soon. We Appreciate your work. If you need any kind of information related toAutomate Software Testing, then you can contact us.
ReplyDeleteThis post is so usefull and informative.keep updating with more information...
ReplyDeleteSoftware Testing Courses in Mumbai
Software Testing Training in Ahmedabad
Software Testing Courses in Kochi
Software Testing Courses in Trivandrum
Software Testing Courses in Kolkata
I read your blog. It's very nice and very helpful. I learn something new every time from this website. Thanks for sharing this information with us.You can visit our services here
ReplyDeleteProduct Engineering Services Company
App Modernization Services
Enterprise App Development Services
Mobile App Development Services
Low Code Development Services
Mendix Development Services
Cloud Migration Services
Digital Assurance Services
Software testing services
Good article! I found some useful educational information in your blog, it was awesome to read, thanks for sharing this great content to my vision
ReplyDeleteadf training in ameerpet
adf Training In Hyderabad
best adf training institute in hyderabad
adf online Training in hyderabad
azure data factory Training in Hyderabad
Thank you for sharing this article. Visit our website for Automation Testing Jobs
ReplyDeleteBig data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important.Project Centres in Chennai
ReplyDeleteI appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Continue to publish more articles on
ReplyDeleteLow Code App Development Company
Mendix Solutions
Software Testing Services
Test Automation Services
Product Engineering Services
Great post. keep sharing such a worthy information.
ReplyDeleteUsually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me.
Training Institute in Electronic City Bangalore
Software Training Institute in Electronic City Bangalore
Devops Training in Electronic City Bangalore
Python Training in Electronic City Bangalore
Python Course in Electronic City Bangalore