Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we call one scenario inside another scenario in cucumber?

Tags:

cucumber

I started working with behavior driven tool cucumber. Its a fun tool to use. While i was working on a problem. I came across that most of time, I am not reusing my code.

That's why I want to call a scenario from another scenario. I have searched but found nothing helpful. Can I do that ?

Another same question posted here on github

like image 463
Adil Malik Avatar asked Jun 28 '16 11:06

Adil Malik


People also ask

Can we call a scenario from another scenario in Cucumber?

Not really.. but you can use "background" and "scenario outline" in features..

How do you make one scenario dependent on another scenario in Cucumber?

There is no support for creating a scenario that depends on another scenario in Cucumber-JVM. I think still is supported in the Ruby implementation in Cucumber. It is, however, a practice that is dangerous. The support for calling a scenario from another scenario will not be supported in future versions of Cucumber.

How do you run two scenarios in Cucumber?

Cucumber can be executed in parallel using TestNG and Maven test execution plugins by setting the dataprovider parallel option to true. In TestNG the scenarios and rows in a scenario outline are executed in multiple threads. One can use either Maven Surefire or Failsafe plugin for executing the runners.

How do you call one scenario from another feature file?

You need to extract that Scenario into a separate *. feature file and then re-use it using the call keyword.


Video Answer


1 Answers

This may be what you're looking for: https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions

So there are a couple of things you can do. If you have a step you want to reuse like the following:

Given /^I log in as (.*)$/ do |name|
  # ...
end

You can call it within another step like so:

Given /^(.*) is logged in$/ do |name|
  step "I log in as #{name}"
end

You can also do the following within a step definition:

steps %Q{
    Given I log in as #{name}
  }
like image 168
Mallory Avatar answered Sep 29 '22 17:09

Mallory