Pages

Cucumber Scenario methods?

What are the methods available in the Cucumber Scenario?

Cucumber Scenario:
  • Scenario is a class provided in the io.cucumber.java package.
  • In Cucumber we will write our test cases using Scenario keyword.
  • While executing scenarios we need to know the information of executing scenarios like Status of scenario, scenario path, etc.,.
Below are Scenario methods which are frequently used in the framework:
  1. getName()
  2. getId()
  3. getUri()
  4. getLine()
  5. isFailed()
  6. getSourceTagNames()
  • getName(): It will return the name of the scenario.
  • getId():  It will return the id of scenario. (Syntax: <feature file uri>:<line number>)
  • getUri(): It will return the Uri of the Scenario.
  • getLine(): It will return the line number in the feature file of  the scenario.
  • isFailed(): It will return boolean value.Return True if scenario is failed.
  • getSourceTagName(): It will return tags of the current execution of scenario.
Demo program on Cucumber Scenario Methods:

Let's say I have a scenario like below:
Feature: Demo on cucumber framework
  Description: The purpose of this feature is to explain Scenario class in cucumber
  @smoke @regression
  Scenario: This is First Scenario
    Given I navigated to keeplearners blogspot
    And I search for Java
    And I search selenium
    And I search for cucumber
    Then I close the browser
cucumber scenario methods
cucumber scenario methods
Now we will execute the above scenario by using all the above methods in Hooks file.
getID(),getName(),getLine(),getUri(),getSourceTagNames(),isFailed()
Scenario methods in Cucumber

Cucumber getLine():

In case of Scenario Outline, it will return line number of Examples row.

Let's say I have a Scenario outline like below:
Cucumber Scenario outline getLine()
Cucumber Scenario outline getLine()
Execute above scenario:
Cucumber getLine() method
Cucumber Scenario getLine() method
So, generally in your cucumber framework, we can use scenario methods before and after the execution of a scenario.

Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.