1. What is the main purpose  to use Behavior Driven Development (BDD) framework ?

The main purpose of the BDD framework is to make various project roles such as Business Analysts, Quality Assurance, Developers, etc., understand the application without diving deep into the technical aspects.

2. What language is used by the Cucumber tool and what are the various keywords used ?

The Cucumber tool uses the Gherkin language, a simple English representation of the application behavior.

Some of the Keywords used in Cucumber are:

Scenario, Given, When, Then, And ,But, Background.

3. What is Feature File and Why it is used ?

1. Feature File : The feature file is the essential segment of cucumber tool, which is used to write acceptance steps for automation testing. It is used to include multiple scenarios within the same file.

(It is created with .feature extension) for example: LoginAction.feature

For example: Feature file looks like :

Feature: Login Action

Scenario: Successful Login with Valid Credentials

                Given User is on Home Page

                When User Navigate to LogIn Page

                And User enters User Name and Password

                Then Message displayed Login Successfully

4. What is Step Definition File and how to execute it ?

Step definition is nothing but the file which stores the mapping between each step of the scenario defined in the feature file with a code of function to be executed.

We need to use a Junit Test Runner class to execute the Step Definition file which has mapping of code and steps from Feature file:

Code snippet of Test Runner Class :

@RunWith(Cucumber.class)

@CucumberOptions(

 features = "Featurefilename",

 glue={"stepDefinitionfilename"}

 )

public class TestRunner {

}

5. What is Scenario Outline and write a sample structure for Scenario Outline ?

Scenario outline basically replaces variables with the values from the Examples table. Each row in the table is considered to be a scenario.

Example for Difference between Scenario and Scenario Outline:

Scenario: Eat 4 out of 12 pizza slices
Given there are 12 pizza slices
When I eat 4 pizza slices
Then I should have 8 pizza slices

Scenario: Eat 10 out of 20 pizza slices
Given there are 20 pizza slices
When I eat 10 pizza slices
Then I should have 10 pizza slices

Scenario Outline: Eating pizza slices
Given there are < Total > pizza slices
When I eat < Eat > pizza slices
Then I should have < Left > pizza slices

Examples:
| Total | Eat | Left |
| 12 | 4 | 8 |
| 20 | 10 | 10 |


6. What is Difference between Scenario Outline and Data Tables ?

Both are basically used for Data Driven Testing using Cucumber.

Differences are:
Scenario outline :

This uses Example keyword and works for the whole test.

Cucumber automatically run the complete test the number of times equal to the number of data in the Test Set.

Data table:

No keyword is used to define the test data

This works only for the single step, below which it is defined .

We need a write a separate code with raw() method in it to collect the data specified in the step.

For Eg:

Scenario: Login with Valid Credentials
Given User is on Home page
When User navigates to home page
And User enters Login Credentials
| testuser1 | Testuser@1 |
Then Message displayed Login Successfully.

Now @When method in Step Def File looks like below:
@When("^User enters Login Credentials$")
public User_enters_Login_Credentials (DataTable usercredentials) throws Throwable {
//Write the code to handle Data Table
List<List<String>> data = usercredentials.raw();
driver.findElement(By.id("log")).sendKeys(data.get(0).get(0));
driver.findElement(By.id("pwd")).sendKeys(data.get(0).get(1));
driver.findElement(By.id("login")).click();
}

7. What is difference between And & But Keywords ?

And:

And keyword is used to add conditions to your steps or add more detail to a step. It's an addition to previous statement. AND is used to add more conditions to Given, When and Then statements. It represent positive statement.

But:

But keyword is used to add negative type comments. It is good to use when your step describe condition which is not expected. For example : when you are expecting some text or element should not be present on the page.

Eg:

Scenario: Login with Valid Credentials
Given User is on Home page
When User navigates to home page
And User enters Login Credentials
Then Message displayed Login Successfully
But Login button should not be displayed

8. What is Background and Can we have multiple Background scenario ?

Background in Cucumber is used to define a step or series of steps that are common to all the tests in the feature file. A Background is much like a scenario containing a number of steps. But it runs before each and every scenario were for a feature in which it is defined.
We Cannot have multiple Background Scenarios in a Single Feature File.

For example : Below steps will execute before Every Scenario.

Background: User is Logged In

 Given I navigate to the login page

 When I submit username and password

 Then I should be logged in

9. What are Hooks ?

Hooks blocks of code that run before or after each scenario. It allows us to manage the code workflow and helps us to reduce the code redundancy.

There are only 2 hooks in Cucumber: @Before and @After.

As name suggests @Before will run before each scenario and @After will run after each scenario.

10. Explain the order concept of Hooks ?

To Execute the hooks in Order (For eg : if there are 2 @Before Hooks ) we can Specify the order like :

@Before(order=1)

public void Before_Second(){

System.out.println("This will execute second");

}

 @Before(order=0)

public void Before_First(){

System.out.println(“This will execute first-");

}

@After(order=0)

public void after_Second(){

System.out.println This will execute second ");

}

 @After(order=1)

public void after_first(){

System.out.println("This will execute first ");

}

The very important concept of order to note here is :

@Before(order = int) : This runs in increment order, means value 0 would run first and 1 would be after 0.

@After(order = int) : This runs in decrements order, means apposite of @Before. Value 1 would run first and 0 would be after 1

11. What is the use of Tags in Cucumber ?

Tags are used to group the scenarios based on some need ( For eg : If there are 3 scenarios in Feature file, we can tag 2 scenarios to SmokeTest and 1 scenarios to RegressionTest).

Feature: Featured Application

@SmokeTest

Scenario: Smoke 1

Given Smoke 1 execution

@RegressionTest

Scenario: Regression 1

Given Reg1 execution

@SmokeTest

Scenario: Smoke 2

Given Smoke 2 Execution

So, now if the tester wants to execute only Smoke test scenarios it would easy to call only @SmokeTest tag from the Feature file and specify it in Test Runner Class.

12. How to create a Report of Test execution in Cucumber ?

Cucumber gives us the capability to generate reports as well in the form of HTML, XML, JSON & TXT. Cucumber frameworks generate very good and detailed reports, which can be shared with all stakeholders.

For Example : To create a HTML report, add html:filepath to the @CucumberOptions plugin option in Test Runner Class.

So, we can store the pretty html report format in the specified file path . Below the code snippet.

@CucumberOptions(

features = "featurefilename",

glue= {"stepDefinitionsfilename"},

plugin = { "pretty", "html:output/reports " }, monochrome = true)


Tags


You may also like

Leave a Reply

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

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}