Emily
Emily

Reputation: 43

Cucumber - How can I run feature files in proper order?

I have 2 feature files such as Login.feature and Search.feature. When I run cucumber it always run the Search.feature file first.

Is it possible for me to run Login.fetaure first then Search.feature?

Upvotes: 2

Views: 4200

Answers (3)

Emjey
Emjey

Reputation: 2063

Rename the feature files as 01Login.feature and 02Search.feature

On a side note as @Thomas claimed, it is not advisable to run the feature files in order as it will lead to confusion when you have too many feature files and unwanted naming of it.

Upvotes: 0

Mr Cas
Mr Cas

Reputation: 668

You could put them in the same feature and place the Login scenario(s) before the Search scenario(s).

If we assume that the login is a prerequisite for the search, you could write the login part in the background:

Feature: Searching ..

Background: Given: I have logged into the system with user ..

Scenario: ... When And Then

Upvotes: 0

Thomas Sundberg
Thomas Sundberg

Reputation: 4323

Avoid the path of expecting features to be executed in an expected order. This will lead you to a situation where they depend on each other and the state they leave your system in. This will create a maintenance problem rather soon.

Instead, make sure that you recognize two distinct cases here.

It is important to be able to login. Use this feature to drive the implementation of login. Maybe create a helper object or method that makes it easy to login. It is common that steps are one or two lines and delegate to a helper immediately.

It is important to be able to search. This feature should use the helper, or helpers, from the previous feature to login and then perform the search. Logging in is a prerequisite that has to be done, but it isn't the main thing here. It is an incidental detail.

When developing a system and having a tool like Cucumber to help you drive out the functionality, you will create support methods that makes you steps small. These help methods can, and usually should, be reused in other cases where they are needed.

This approach is preferred compared to calling another scenario from a scenario or expect scenarios to be executed in a specific order.

Upvotes: 2

Related Questions