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 :


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
7.  Generate Step Definitions of the feature file by:
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.


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);

        }

    }

}

14. Now navigate to “Test > Windows > Test Explorer”

15. Right click and finally run particulate test




Download Project using below link

  Download 

Comments

  1. Great article for all, thanks bro . . . . . . . .

    ReplyDelete
  2. 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.
    ISO 9001 Certification in Bahrain

    ReplyDelete
  3. 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.

    ReplyDelete
  4. 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


    adf training in ameerpet

    adf Training In Hyderabad
    best adf training institute in hyderabad
    adf online Training in hyderabad
    azure data factory Training in Hyderabad

    ReplyDelete
  5. Thank you for sharing this article. Visit our website for Automation Testing Jobs

    ReplyDelete
  6. Big 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

    ReplyDelete
  7. I 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
    Low Code App Development Company
    Mendix Solutions
    Software Testing Services
    Test Automation Services
    Product Engineering Services

    ReplyDelete
  8. Great post. keep sharing such a worthy information.
    Usually 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

    ReplyDelete

Post a Comment

Popular posts from this blog

How to setup automation POM framework using selenium and C# language with Test Project

Page Object Model in Selenium C#