diazolin88
diazolin88

Reputation: 125

Cucumber run scenario depends on another from different feature files

the question is it possible to run scenarios in custom order:

Imagine that we have 2 feature files (1st - to place an orders, 2nd is to create data for orders on the Back End side) In the first file I have scenarios with voucher code or without, so basically those scenarios that have to be triggered with voucher code should be triggered after back end (create voucher scenario is triggered). I expected to see the same behavior as we have for TestNG - dependsOnMethods. Is it possible to do for Cucumber ?

Thanks a lot.

Upvotes: 0

Views: 2574

Answers (2)

Thomas Sundberg
Thomas Sundberg

Reputation: 4343

I would avoid coupling features as you suggest as much as possible.

Your first feature is about creating data and validating that the creation process is correct.

Your second feature is about working with data that you expect are available in the system.

My approach would be to have support code that create the data for each scenario when needed. This support code would setup the system in the expected state before any execution.

This might lead to duplication. Personally I would accept duplication in favour for readability. This would also introduce flexibility in this case. The coupled executions you are asking for will force you to execute everything every time. You would not ba able to execute a single scenario easily when trouble shooting.

BDD and Cucumber is all about human readable communication.

Clarity trumps DRY.

Upvotes: 1

kfairns
kfairns

Reputation: 3067

You could create a step definition for the Scenario that it is dependant on, by taking the scenarios step functions and placing them all into a new step definition.

I personally work with the PHP dist (Behat), so I could give an example for PHP, and perhaps that will make it slightly easier for you to see what I mean:

 /**
 *
 * @Given /^I have completed some previous scenario$/
 */
public function iHaveCompletedSomePreviousScenario()
{
    $this->iEnterInTextboxWith();
    $this->wait(300);
    $this->iClickOn("button:contains('Continue')");
    $this->wait(500);
}

If there is some sort of way that in Java (which as far as I am aware, is what serenity uses), it could do something like this:

@Given /^I have completed some previous scenario$/
public void i_have_completed_some_previous_scenario() throws Throwable
{
    // Enter in here functions used in scenario you are emulating
}

Again, I am sorry that I do not know enough about the Java and Serenity dist of cucumber to know about the exact syntax of using the functions that are predefined, however, I do hope that you know how to do it, so that this is helpful to you.

Upvotes: 0

Related Questions