0% found this document useful (0 votes)
12 views

eBook .NET 4 L1 BDD With Selenium and SpecFlow

Uploaded by

Arkadeep Roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

eBook .NET 4 L1 BDD With Selenium and SpecFlow

Uploaded by

Arkadeep Roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 121

BDD with Selenium and SpecFlow

A Day in the Life of a .NET Full Stack Developer

Joe has been assigned a task where he needs to use LINQ to generate
some data.

Joe has to generate statistics for the school on their student's


performance using LINQ. The school wants to analyze the current
database to generate the statistics.

In this lesson, we will learn how to solve this real-world scenario to help
Joe complete his task effectively and quickly.
Learning Objectives

By the end of this lesson, you will be able to:

Describe automation testing

Explain Selenium IDE, architecture, remote control, and grid

Describe XPath, its types, xpath functions, and Axes methods

Illustrate BDD, SpecFlow, Gherkin, and Scenario

Explain parallel execution, Excel plug-in, and cross-browser testing


Getting Started with Selenium
Automation with C#

C# is an object-oriented programming language that combines the features of Java and C++.

Structured
Component Rich
oriented library

C#
Simple Features Interoperable

Scalable Upgradeable

Fast
Different Tools for Automation

C# uses Visual Studio to build and automate applications.


A few examples are given below:

Cake Build Allows to compile codes and run unit tests by invoking MSuild and Xunit

MSBuild Builds multiple configurations for multiple platforms

Final Builder Provides visual debugging without editing XML or writing scripts

SpecFlow Uses the Gherkin syntax to build readable tests written in plain english

Selenium Tests web applications across browsers and platforms


Selenium

Selenium is an open source framework for testing web applications.

Following are some of the main features of Selenium:

01
Supports various operating systems, browsers, and languages

02
Supports parallel test execution

03
Works with external frameworks such as TestNG, Ant, and Maven

04
Offers simpler commands as compared to other tools

05
Performs web-based automated testing
Benefits of Selenium Testing

Extends compatibility across multiple


Supports major languages such as .Net, C#,
operating systems such as Windows, Linux,
Perl, Java, or Python
or Mac

Offers multi browser support, such as Google Allows integration with JUnit and TestNG that
Chrome, Internet Explorer, Mozilla Firefox, or aids in generating reports and managing test
Safari cases

Allows integration with Docker, Jenkins, and


Maven that helps in continuous testing
Applications of Selenium

Automation Regression
testing testing

Performance
Browser testing
testing

Smartphone app
testing
Selenium Setup

01 Install Java 02 03
Install Eclipse IDE for Install Selenium Java
Development Kit
Java Developers Client Driver
(JDK)

06 05 04
Add a new package Create a new project Configure Eclipse
and its details and add its details IDE with WebDriver

07 08
Create a new class
Install Driver Server
and add its details
Basics of Selenium IDE
Selenium IDE

Selenium IDE (Integrated Development Environment) is a record-and-run tool to quickly create test
cases. It is implemented as a Firefox extension.

Below are a few features of Selenium IDE and their functions:


Speed Control Controls the speed of test cases

Run All Allows execution of the entire test suite

Run Runs currently selected test

Pause/Resume Allows users to pause and resume a particular test case

Step Helps in debugging the test cases

Rollup Groups all the commands and executes it as a single operation


Selenium Remote Control

Selenium Remote Control (RC) is a test tool to write automated web application user interface tests in any
programming language.

Web Server Web Server Web Server Web Server Web Server

Remote Control Server

Java/Ruby/Python/.Net
Selenium Grid

Selenium Grid distributes the tests on multiple machines, allowing simultaneous testing across
machines. It reduces testing time and gives quick feedback to users.

The different components of Selenium grid are:

● Takes instructions from the WebDriver client and executes them remotely on the parallel
Hub nodes
● A central server with only one hub in the grid

● Multiple machines with different operating systems and browsers


Node
● Selenium instances that execute tests loaded on the hub
Selenium Setup with Visual Studio

Duration: 20 min.

Problem Statement:
Create an application to set up Selenium with Visual Studio.
Assisted Practice: Guidelines to Set Up Selenium with Visual Studio

1. Create a unit test project to test Selenium.


2. Install Selenium framework and drivers.
3. Run a test case to load a web page.
4. Build the project.
5. Run all the tests in test explorer.
6. Push the code to your GitHub repositories.
Basic Architecture of Selenium WebDriver
Basic Architecture of Selenium WebDriver

Selenium WebDriver architecture controls the browser from the operating system level. It requires only the
programming language IDE and a browser.
HTTP over HTTP Server

Selenium Language Browser Drivers Browsers


Bindings
Chrome driver
Chrome
Java
IE driver
Internet Explorer
C#
JSON Wire Firefox driver
Firefox
Python Protocol
Opera driver
Opera
JavaScript
Safari driver
Safari
Ruby
HTTP over HTTP Server
XPath Functions
What Is XPath?

XPath, or XML Path, is a query language used to navigate through XML documents. It is used to find a
web element in a web page.

Select current node Select attributes Attribute value

Xpath = //tagname[@Attribute = ‘Value’]

Tag name. Can be


img, input, etc. Attribute name
Types of XPath

XPath query is used to navigate through XML documents to select individual elements and attributes.

There are two types of XPath:

● A direct way to locate an element in a web page


Absolute
● Begins with a single forward slash (/) to select the element from the root

● Can search an element in the middle of the HTML Document Object Model (DOM)
Relative structure
● Begins with a double slash (//) to search anywhere in the web page
Handling Complex and Dynamic Web Elements

XPath functions are used to identify multiple elements having same names or buttons having same IDs and
names.

Common functions used to handle complex and dynamic web elements:

Basic XPath Finds node or set of nodes based on attributes such as ID and name

contains() Extracts all the values matching a particular text value

Finds elements whose value dynamically changes on refresh or other operations


starts-with() such as click, submit, etc.

text() Finds an element with exact text match

OR Finds an element by matching any one of the conditions

AND Finds an element by matching all the conditions


Axes Methods in XPath

XPath Axes methods are used to find the complex or dynamic web elements on the web page.

Following are some of the most commonly used XPath Axes methods:

Following Selects all elements in the document of the current node

Ancestor Selects all previous elements of the current node

Child Selects all children elements of the current node

Parent Selects all elements immediately prior to the current node

Following-Sibling Selects all elements that are in the same level as the current node

Preceding Selects all nodes before the current node

Self Selects the current node


Wait

The Wait method informs Selenium that the program would like to wait for a certain amount of time
before throwing an exception when it cannot find an element in a web page.

Find element.
Tests Web Driver Wait and loop for Browser
given time.
Types of Wait

Selenium wait helps resolve issues that may occur due to loading of different elements on the web page
at different time intervals.

Implicit Wait Waits for certain time before throwing an exception

Explicit Wait Waits for certain conditions or maximum time gets exceeded

Waits for an element at regular intervals until certain conditions are


Fluent Wait
met or the element is found
Locating Elements
Locating Techniques

Locating techniques are used to find elements. It informs the Selenium IDE about the GUI element that
needs to be located, using the keyword findElement.

Types of Locators:

findElement(By.id("IdName")) ID locator is used to search an element by its unique identifier

findElement(By.name("Name")) Name locator is used to search an element by its name

findElement(By.tagName("Tag")) Tag name locator is used to search an element by its tag name

Link text locator is used to search an element by using <a> tag in the
findElement(By.linkText("LinkText")) HTML links

findElement(By.cssSelector(tag#id)) CSS locator is used to search elements by the CSS tags

XPath locator is used to search an element by the XML expressions in


findElement(By.xpath("XPath")) the HTML document
Locating Web Elements

Duration: 40 min.

Problem Statement:
Create an application to locate web elements.
Assisted Practice: Guidelines to Locate Web Elements

1. Create a unit test project to locate web elements in a page.


2. Install Selenium framework and drivers.
3. Run a test case to load a web page and find elements with various methods.
4. Build the project.
5. Run all the tests in test explorer.
6. Push the code to your GitHub repositories.
Advance Automation
Iframes

Iframe, or inline frame, is an HTML page embedded in another HTML page. It may be content from
another source, such as an advertisement.

SwitchTo().frame() method is used to enable the browser to switch between


multiple frames.

SwitchTo().frame() method can be implemented in following ways:

By Index The browser will switch to the frame with the specified index number

By Name or ID The browser will switch to the frame with the specified name or ID

By Web Element The browser will switch to the frame with the specified web element
Alerts

Alert is a message or a notification that displays on a small window over the current window to provide
information, to seek confirmation, or to warn.

Types of alerts:
Simple Alert Displays an information or warning on the screen

Prompt Alert Prompts user to enter something

Confirmation Alert Asks permission to perform an operation


Pop-ups

A Pop-up is a window that displays on screen when the alerts are triggered.

Types of pop-up alerts:

Alerts generated by Windows such as authentication pop-up or print pop-up.


Windows-based
Selenium uses third-party tools to handle these pop-ups.

Alerts that come up with options for users to go ahead, cancel, or input
Web-based
something.
Changing Windows

Selenium WebDriver lets users switch browser windows, or open new windows by clicking on links or buttons. It
keeps track of all the opened windows by their unique IDs, called window handles.
Syntax:

public static void main(String[] args) throws InterruptedException


{ WebDriver driver = new ChromeDriver();
driver.get("<link to other window>");
String parentWindowHandle = driver.getWindowHandle();
System.out.println("Parent window's handle -> " + parentWindowHandle);
WebElement clickElement = driver.findElement(By.id("button1"));

for(int i = 0; i < 3; i++)


{ clickElement.click();
Thread.sleep(3000);
}

Set<String> allWindowHandles = driver.getWindowHandles();


for(String handle : allWindowHandles)
{
System.out.println("Switching to window - > " + handle);
driver.switchTo().window(handle);
driver.get("<link to another window>");
}
}
Screenshots

Screenshots are used to analyze test case failures and in bug analysis. Selenium automatically takes snapshots
during test execution.

Syntax:

File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);


String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
Advance Automation

Duration: 40 min.

Problem Statement:
Demonstrate the use of Iframes in a web page.
Assisted Practice: Guidelines to Use Iframes in a Web Page

1. Create a unit test project to perform advance automation with Selenium.


2. Install Selenium framework and drivers.
3. Run a test case to test Iframes and capture the screenshot with Selenium.
4. Build the project.
5. Run all the tests in test explorer.
6. Push the code to your GitHub repositories.
Selenium Web Grid on Multiple Browsers
Selenium Web Grid on Multiple Browsers

Selenium Grid allows running multiple tests on different browsers and operating systems in parallel. it
consists of a single Hub as a server and multiple nodes as test machines.

Node
Node
Node

Node
Node

Hub
Advanced User Interactions and Cross Browser Testing
Advanced User Interactions

Advanced User Interactions API describes complex actions that a user can do on a web page, such as
drag and drop, clicking of multiple options while holding control key.

Following are some methods for mouse and keyboard interactions:

ButtonReleaseAction ClickAction

DoubleClickAction ClickAndHoldAction

MoveToOffsetAction KeyDownAction

SendKeysAction KeyUpAction

MoveMouseAction ContextClickAction
Advanced User Interaction Methods

Advanced User Interactions API handles special keyboard and mouse events using actions and action
classes.

Interaction methods and their respective actions are given below:

Method Action
doubleClick() Double-click at the current mouse location
contextClick() Right-click at the current mouse location
clickAndHold() Click without releasing at the current mouse location
dragAndDrop(source, target) Click and hold at source element, move to the target, release the mouse
dragAndDropBy(source, x-offset, Click and hold at the source element, move by a given offset, release mouse
y-offset)
keyDown(modifier_key) Press Modifier key without releasing it
keyUp(modifier _key) Release Modifier key
release() Release the depressed left mouse button at the current mouse location
sendKeys(onElement, Send a series of keystrokes onto the element
charsequence)
Cross Browser Testing

Cross Browser Testing is a technique in Selenium that allows users to test web applications in different
browsers. Selenium integrates with TestNG to perform multi-browser testing.

Cross Browser Testing


Executing Tests in Chrome

Google Chrome supports many browser extensions that can be tested through the Selenium
automation capability.

Steps to execute tests in Chrome:

01 Download ChromeDriver server and extract the .exe file

02 Run the program for Selenium WebDriver in Chrome

03 Specify ChromeDriver path if there is an exception

04 Set system properties

05 Set property in environment variables

06 Run a sample program to launch Chrome using Selenium WebDriver


Executing Tests in Firefox
Firefox is the default browser for all previous versions of selenium 3 and can be tested through the
selenium automation capabality.

Steps to execute tests in Firefox:

01 Create a new Java project and give it a name

02 Add downloaded .jar files in the library

03 Add the Selenium standalone server

04 Create a Java class

05 Specify the package and class names

06 Use FireFoxDriver class to implement all methods of WebDriver interface

Create WebDriver reference and run the program


07
Automation Framework
Introduction to Maven

Maven is a build management and automation tool that is used to make builds consistent with other projects.

Steps for setting up Maven project for Selenium:

Set up Maven by unzipping it to a


01 folder. Create an environment 04 Create group ID to create pom.xml
variable for Maven.

02 Install Maven IDE in Eclipse 04 Add dependencies for Selenium

Build the project using IDE or


03 Create a Maven project 05
command prompt

NOTE: Maven downloads all dependency jars into the local repository. If
not done automatically, jars can be populated manually.
Page Object Model Design

Page Object Model (POM) is an XML file containing default values, project information, and configuration
details that Maven uses to build the project.

Login Test script Driver

Page object

Login page Main page Menu bar Header section

Page containing Selenium


operations
Page Factory

Page Factory is a class that is an extension of the POM design pattern. It is used to initialize page object
elements and instantiate the objects.

Page

Page Object Model


Page Factory

Test Scenarios Page Class


Automation Framework

Duration: 90 min.

Problem Statement:
Create an application using Maven.
Assisted Practice: Guidelines to Create an Application Using Maven

1. Create a unit test project to show usage of Page Object Model.


2. Install Selenium framework and drivers.
3. Create a POM class for homepage.
4. Create a POM class for about us page.
5. Run a test case to test POM .
6. Build the project.
7. Run all the tests in test explorer.
8. Push the code to your GitHub repositories.
Introduction to Testing, BDD, and SpecFlow
What Is Testing?

Testing refers to the process of executing a program or running a software application with an
intent of identifying bugs, errors, or missing technical requirements in the program.

Following are the types of testing:

Functional
Testing

Responsive
UI Testing
Testing

Regression
Smoke Testing Testing
Testing

Integration Sanity Testing


Testing
Cross Browser
Testing
SpecFlow

SpecFlow is an open source testing framework supporting Behavior Driven Development (BDD)
practices in .NET. It defines application behavior in plain text using Gherkin language.

Features:

SpecFlow scenarios have a name, and can consist of multiple scenario steps

Generates executable unit tests from the scenarios that represent acceptance criteria

Generates a unit test method for each scenario, with the method name derived from the scenario
name

Generates a unit test class for the feature element, with the class name derived from the feature name

Generates row-based tests from scenario outlines if the testing framework supports it
Behavior Driven Development (BDD)

Behavioral Driven Development (BDD) is a set of software development practices developed using simple
scripting language.

BDD Practices:

Specification by Uses examples to describe business rules and the behavior


Example (SbE) of the software to be built

Test Driven Turns examples into human readable and executable


Development (TDD) specifications
BDD: Importance and Application

BDD specifications are written in plain english, defined by Gherkin language, and supported by the Cucumber test
framework.

✔Allows everyone to engage in the


product development cycle

✔Provides high visibility due to its ⮚End-to-end testing


easily understandable language
⮚Checking of unwanted
✔Focuses on business value to provide Applications
behavior using integration
Benefits
better results tests

✔Focuses on code behavior for ⮚Developing and testing


stronger impact of the application code from a business point
of view
✔Reduces costs as language simplicity
reduces the learning curve of
developers
BDD and SpecFlow
Gherkin

Gherkin is a domain-specific and line oriented language to describe business behavior without going into the details
of implementation. Each line or statement in a Gherkin script starts with a special keyword.

Keywords and its uses:

Feature Describes what the software is supposed to do

Background Allows addition of more context to scenarios in a feature

Scenario Contains examples

Given Describes something that took place in the past

When Action step that describes an event

Then Outcome step that describes what the system must do

And, But Keeps the documentation organized and readable


Features of Gherkin

Line-oriented language like Python and Java

Each scenario has a separate execution

Simple to understand

Easy to reuse code in other tests

Acceptance tests are directly linked to automated tests


Gherkin

Gherkin uses indentation define structure. Gherkin text acts as the documentation and
skeleton of automated tests.
Gherkin syntax:

Feature: Some descriptive text of what is required


I want to gain some outcome which furthers the goal

Scenario: Some business situation


Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too

Scenario: Another situation


Given …

NOTE: Comments can be added anywhere in the Gherkin scripts by prefixing the comment
statement with #.
Gherkin

Following Gherkin script is an example of a login functionality:

Feature: User Authentication Background:


Given the user is already registered to the website

Scenario: Given the user is on the login page


When the user inputs the correct email address
And the user inputs the correct password
And the user clicks the Login button
Then the user should be authenticated
And the user should be redirected to their dashboard
And the user should be presented with a success message

This script can be used to redirect the user to their dashboard if the specified conditions
(statements starting with and keyword in the script) are met.
Gherkin Feature Keyword

Feature keyword is used to describe a software feature and group the related scenarios.

Elements in a feature:

The keyword ‘Feature’

Name of the feature

An optional description
Gherkin Step Definitions

Step Definition is a Java or C# method in a class with an annotation attached to it. The annotation with a
pattern is used to link Step Definition to all the matching steps that are executed.

Syntax of step definition:


[Binding]
public class CallingStepsFromStepDefinitionSteps : Steps
{
[Given(@"the username (.*) exists")]
public void GivenTheUserNameExists(string name)
{
// ...
}

[Given(@“Userid is (.*)")]
public void GivenUserIDAs(string name)
{
// ...
}

[Given(@"(.*) is logged in")]


public void GivenIsLoggedIn(string name)
{
Given(string.Format("the user name exists", name));
Given(string.Format(“User ID is {0}", name));
}
}
Gherkin Step Definitions

Step Definitions file is a place where the automation code is written.


The steps of Gherkin file directly map to the Step Definitions.

Alternate Syntax:
Step 1:
Given (/^ I am on google.com$/) do
Browser.goto "http://google.com"
end

Step 2:
When (/^ click on gmail menu$/) do
Browser.text (:name, " google mail" ).click
end

Step 3:
Then (/^ I should see gmail page$/) do
Browser.goto "https://mail.google.com"
end
SpecFlow Setup

Duration: 20 min.

Problem Statement:
You are given a project to set up SpecFlow.
Assisted Practice: Guidelines to Set Up SpecFlow

1. Create a unit test project to set up SpecFlow.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
Working with Multiple Data Using Tables

Duration: 20 min.

Problem Statement:
Create an application to work with multiple data using tables.
Assisted Practice: Guidelines to Work with Multiple Data Using Tables

1. Create a unit test project to use data tables in SpecFlow.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
Scenario Outline
Scenario Context

Scenario Context is a class to store data relative to the current scenario state. It is mainly used to pass values
between steps.

Syntax of Scenario Context:

// step1.cs
[Given(@"an employee exists by the name of Xxyy Aabb")]
public void s1(){
var emp = new Employee{ Name = "Xxyy Aabb"};
ScenarioContext.Current["AEmployee"] = emp;
}

// step2.cs
[Then(@"his name should be Xxyy Aabb"]
public void s2(){
var emp = ScenarioContext.Current["AEmployee"];
emp.Name.ShouldEqual("Xxyy Aabb");
}
SpecFlow.Assist.Dynamics Package

SpecFlow.Assist.Dynamic is used in SpecFlow Table object to reduce code size.

Syntax without Assist.Dynamic:

[Binding]
public class StepsUsingStaticType Syntax with Assist.Dynamic:
{ private Person _person;

[Given(@"Create an instance from this table")]


public void GivenCreateAnInstanceFromThisTable(Table table) [Binding]
{ _person = table.CreateInstance<Person>(); public class StepsUsingDynamic
} { private dynamic _instance;

[Then(@"Name property on Person should equal '(.*)'")] [Given(@"Create an instance from this table")]
public void PersonNameShouldBe(string expectedValue) public void c(dynamic instance) { _instance = instance; }
{ Assert.AreEqual(expectedValue, _person.Name);
} [Then(@"Name property should equal '(.*)'")]
} public void NameShouldBe(string expectedValue)
{ Assert.AreEqual(expectedValue, _instance.Name); }
public class Person }
{ public string Name { get; set; }
public int Age { get; set; }
public DateTime BirthDate { get; set; }
public double LengthInMeters { get; set; }
}
Scenario Context

Duration: 15 min.

Problem Statement:
Develop an application to create scenarios.
Assisted Practice: Guidelines to Create Scenarios

1. Create a unit test project to use ScenarioContext.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
SpecFlow Bindings

Duration: 15 min.

Problem Statement:
Develop an application to create SpecFlow bindings.
Assisted Practice: Guidelines to Create SpecFlow Bindings

1. Create a unit test project to use SpecFlow bindings.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
SpecFlow Context Injections

Duration: 15 min.

Problem Statement:
Create an application to use SpecFlow context injections.
Assisted Practice: Guidelines to Use SpecFlow Context Injections

1. Create a unit test project to use SpecFlow context injection.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Create a custom class for injection.
6. Build the project.
7. Run all the tests in test explorer.
8. Push the code to your GitHub repositories.
Scoped Bindings

Duration: 15 min.

Problem Statement:
Create an application to use scoped bindings.
Assisted Practice: Guidelines to Use Scoped Bindings

1. Create a unit test project to use SpecFlow context injection.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Create a custom class for doing binding.
6. Build the project.
7. Run all the tests in test explorer.
8. Push the code to your GitHub repositories.
Step Argument Transformation

Duration: 15 min.

Problem Statement:
Demonstrate the use of step argument transformation.
Assisted Practice: Guidelines to Use Step Argument Transformation

1. Create a unit test project to use SpecFlow argument transformation.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
Dynamic Table Conversion
What Is Dynamic Table Conversion?

Dynamic Table Conversion (DTC) is the automatic conversion between the table class and a collection of
user-defined classes by using SpecFlow.Assist.Dynamic.

Steps to perform DTC:

Install NuGet package

Create a .feature file with a table in it

Create binding

Run the unit test


Dynamic Table Conversation

Duration: 20 min.

Problem Statement:
Demonstrate the conversion between table class and user-defined class.
Assisted Practice: Guidelines to Convert Between Table Class and User-Defined Class

1. Create a unit test project to use SpecFlow dynamic table conversion.


2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
SpecFlow + Excel Plug-in
Setup and Configuration

SpecFlow + Excel is used to define requirements and example sets in MS Excel, similar to the plain text files in
Gherkin.
Steps to install and configure SpecFlow + Excel:

Install Visual Studio extension

Install SpecFlow+ Excel and SpecFlow+ Runner packages

Create an Excel file that contains the test scenario

Bind the test to application code and generate the step definitions

Build the application and run test from the test explorer

Implement the automation and application code

Add a class and reference it

Bind the Given, When, or Then statements

Run the program and execute the test


Step Definition
Introduction

Step Definition class is a Java class to store step definition methods. The methods are linked to scenario steps in
the feature file.

Steps to create step definition:

Identify the step definition methods to be added

Create a new step definition class

Add step definition methods to the class

Add import statements for Given, When, and Then

Add the path of the step definition class in the test runner

Run Cucumber test runner class


Getting Feature, Step, and Scenario Info (BDD and Specflow
Series)

Duration: 15 min.

Problem Statement:
Create an application for getting feature, step, and scenario info (BDD and SpecFlow series).
Assisted Practice: Guidelines to Get Feature, Step, and Scenario Info (BDD and SpecFlow Series)

1. Create a unit test project to get feature, step, and scenario info.
2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Build the project.
6. Run all the tests in test explorer.
7. Push the code to your GitHub repositories.
Calling Step Definitions from One Project to Another
Project in Specflow

Duration: 20 min.

Problem Statement:
Create an application for calling step definitions from one project to another project in SpecFlow.
Assisted Practice: Guidelines to Call Step Definitions of One Project to Another in SpecFlow

1. Create a unit test project to set up a sample feature and step file.
2. Install Specflow and related libraries.
3. Create a sample feature file.
4. Create a sample steps file.
5. Create a second unit test project to call the step definitions from the first project.
6. Install Specflow and related libraries.
7. Create a sample steps file.
8. Build the project.
9. Run all the tests in test explorer.
10.Push the code to your GitHub repositories.
SpecFlow Parallel Execution
Introduction

Parallel testing, along with remote testing, reduces the duration of an automated test run.

Considerations for parallel execution:

With Memory (AppDomain) Isolation When the application architecture depends on a static state

Without Memory Isolation When the application architecture does not depend on a static state
Running SpecFlow Test in Parallel with SpecFlow 2.0 and
NUnit 3

Duration: 20 min.

Problem Statement:
Demonstrate running of SpecFlow test in parallel with SpecFlow 2.0 and NUnit 3.
Assisted Practice: Guidelines to Run SpecFlow Test

1. Create a unit test project to show parallel execution in SpecFlow and NUnit.
2. Install SpecFlow, NUnit, and related libraries.
3. Create a feature file for login.
4. Create a steps file for login.
5. Create a feature file for UserForm.
6. Create a steps file for UserForm.
7. Change AssemblyInfo.cs.
8. Build the project.
9. Run all the tests in test explorer.
10.Push the code to your GitHub repositories.
Parallel Execution with SpecFlow 2.0 + Selenium + NUnit

Duration: 20 min.

Problem Statement:
Demonstrate parallel execution with SpecFlow 2.0 + Selenium + NUnit.
Assisted Practice: Guidelines for Parallel Execution with SpecFlow 2.0 + Selenium + NUnit

1. Create a unit test project to show parallel execution in SpecFlow and NUnit.
2. Install SpecFlow, NUnit, and related libraries.
3. Create a feature file for Yahoo.
4. Create a steps file for Yahoo.
5. Create a feature file for Google.
6. Create a steps file for Google.

7. Create a WebHooks class.

8. Change AssemblyInfo.cs.

9. Build the project.

10. Run all the tests in test explorer.

11. Push the code to your GitHub repositories.


Extent Reporting with SpecFlow
Introduction

Extent Reports are used to create HTML reports from tests. It is an Application Program Interface (API)
written for Java and .Net.

Steps to create extent reports:

Install extent report plug-in from NuGet tool of Visual Studio

Create an object of ExtentHtmlReporter()

Set a theme for the report

Create an object of ExtentReports() and attach the report

Add feature file title in the report

Add scenario title in feature file

Add test definitions such as Like, Given, When, or Then

Find error if test fails

Add Step Definition in the report after the error is cleared


Generate Report Dynamically with Extent Reporting

Duration: 15 min.

Problem Statement:
Demonstrate how to generate a report dynamically with extent reporting.
Assisted Practice: Guidelines to Generate a Report Dynamically with Extent Reporting

1. Create a unit test project to generate extent reports.


2. Install SpecFlow, NUnit, and related libraries.
3. Create a feature file.
4. Create a steps file.
5. Build the project.
6. Run all the tests in test explorer.

7. View the reports.

8. Push the code to your GitHub repositories.


Generate Report with SpecFlow Steps

Duration: 15 min.

Problem Statement:
Demonstrate how to generate a report with SpecFlow steps.
Assisted Practice: Guidelines to Generate a Report with SpecFlow Steps

1. Create a unit test project to generate extent reports.


2. Install SpecFlow, extent reports, and related libraries.
3. Create a feature file.
4. Create a steps file.
5. Build the project.
6. Run all the tests in test explorer.

7. View the reports.

8. Push the code to your GitHub repositories.


Historical Extent Report Using KLOV Reporting

Duration: 15 min.

Problem Statement:
Demonstrate historical extent report using KLOV reporting.
Assisted Practice: Guidelines for Historical Extent Report Using KLOV Reporting

1. Set up MongoDB server.


2. Set up KLOV server.
3. Create a unit test project to generate historical extent reports.
4. Install SpecFlow, extent reports, and related libraries.
5. Create a feature file.
6. Create a steps file.
7. Build the project.
8. Run all the tests in test explorer.
9. View the reports.
10.Push the code to your GitHub repositories.
BDD with Selenium C# and SpecFlow
Introduction

Selenium Webdriver can be used to perform Specflow based BDD tests

Steps to create Specflow based BDD tests:

Create a unit test project

Install Selenium WebDriver for the browser

Install Selenium WebDriver libraries and Selenium WaitHelpers to add ExpectedCondition waits

Remove the auto-created test.cs file from the project

Create folders for features and step definitions to store their respective implementation files
Setting Stage Ready for BDD with Selenium and SpecFlow

Duration: 20 min.

Problem Statement:
Set the stage ready for BDD with Selenium and SpecFlow.
Assisted Practice: Guidelines to Set Stage Ready for BDD with Selenium and SpecFlow
1. Create a unit test project to use Selenium with SpecFlow.
2. Install SpecFlow, Selenium, and related libraries.
3. Create a feature file.
4. Create a steps file.
5. Create a Hook file to set up Selenium browser object.
6. Build the project.
7. Run all the tests in test explorer.
8. View the reports.
9. Push the code to your GitHub repositories.
Writing Simple BDD Code with Selenium

Duration: 20 min.

Problem Statement:
Write simple BDD code with Selenium.
Assisted Practice: Guidelines to Write Simple BDD Code with Selenium

1. Create a unit test project to use Selenium with SpecFlow for BDD.
2. Install SpecFlow, Selenium, and related libraries.
3. Create a feature file.
4. Create a steps file.
5. Create a Hook file to set up Selenium browser object.
6. Build the project.
7. Run all the tests in test explorer.
8. View the reports.
9. Push the code to your GitHub repositories.
BDD with Selenium POM and SpecFlow

Duration: 20 min.

Problem Statement:
Demonstrate BDD with Selenium POM and SpecFlow.
Assisted Practice: Guidelines to Demonstrate BDD with Selenium POM and SpecFlow

1. Create a unit test project to use Selenium with SpecFlow using POM.
2. Install SpecFlow, Selenium, and related libraries.
3. Create a POM file.
4. Create a test feature file.
5. Create a test steps file.
6. Create a Hook file to set up Selenium browser object.
7. Build the project.
8. Run all the tests in test explorer.
9. View the reports.
10.Push the code to your GitHub repositories.
BDD with Selenium POM (Page Navigation) and SpecFlow

Duration: 20 min.

Problem Statement:
Demonstrate BDD with Selenium POM (Page Navigation) and SpecFlow.
Assisted Practice: Guidelines to Demonstrate BDD with Selenium POM and SpecFlow

1. Create a unit test project to use Selenium with SpecFlow using POM for page navigation.
2. Install SpecFlow, Selenium, and related libraries.
3. Create a home POM file.
4. Create a search POM file.
5. Create a test feature file.
6. Create a test steps file.
7. Create a Hook file to set up Selenium browser object.
8. Build the project.
9. Run all the tests in test explorer.
10.View the reports.
11.Push the code to your GitHub repositories.
Using Generics for Pages in BDD with Selenium and SpecFlow

Duration: 20 min.

Problem Statement:
Use Generics for Pages in BDD with Selenium and SpecFlow.
Assisted Practice: Guidelines to Use Generics for Pages in BDD

1. Create a unit test project to use Selenium with SpecFlow using POM and page generics.
2. Install SpecFlow, Selenium, and related libraries.
3. Create a POM file.
4. Create a BasePage generic class.
5. Create a PropsCollection class to use the generic class.
6. Create a test feature file.
7. Create a test steps file.
8. Create a Hook file to set up Selenium browser object.
9. Build the project.
10.Run all the tests in test explorer.
11.View the reports.
12.Push the code to your GitHub repositories.
Key Takeaways

Testing automation uses tools such as SpecFlow and MSBuild.

Selenium is an open source testing framework that supports multiple


languages and platforms.

Selenium Grid is used to run multiple tests in parallel on different


browsers and operating systems.

XPath is a query language used to navigate XML pages and find


dynamic elements having similar names.

BDD is a set of specifications supported by Cucumber, and it is


written in an english-like simple language called Gherkin.
Use Selenium, NUnit, and SpecFlow to Test a UI Prototype of a Bank Web App
Duration: 20 min.
Problem Statement:
Build an ASP.NET website comprising of two pages – a login page and a
dashboard page. Create test suites to test the pages from an end-user
perspective.

You might also like