On Tuesday, August 7, 2012 11:27:31 AM UTC-5, Andrey Botalov wrote:
Is there any benefit in existance of calling steps from step definitions? Maybe, it should be deprecated
We've actually used this concept where I work and have found it really nice, but it can offer some challenges. Unlike most people, I'm not either-or about it. It has positives and negatives. As an example, let's say I have a simple clause like this:
Scenario: The Lucid customer must exist
* the default customer exists
Obviously I'm making this contrived a little bit. But that might look like this behind the scenes:
Given (/^the default customer(?: exists)?$/) do
step %{I login as "clinical administrator"}
step %{I go to the customers list page}
step %{I filter on "Lucid"}
step %{I search the list for "Lucid"}
end
Here "the default customer" is and always will be Lucid by definition, which is why that information is hard-coded here. Further, only clinical administrators can do anything customers. Notice how first-person statements are only done in the test (step) definitions. Information at the scenario level is more generically stated. Each of those steps looks something like this:
When (/^I login as (?:a |the )?"([^"]*)"$/) do |role|
on_view(LoginPage).perform_login(user_data_for(role))
end
When (/^I go to the (.*) list page$/) do |entity|
on(Navigation).navigate_to(entity)
end
Given (/^I filter on "(.*?)"$/) do |text|
during(Filtering).start_filter
on(FilterPage).filter_by(text)
end
This has lead to a lot of success for us in terms allowing test writers to create composable sets of steps. We also have a little logic that can pull out all the "I do this" type stuff so that it outputs the exact steps that were taken if the scenario fails. Those steps are put into a bug report exactly as is and it reads just as if a manual tester had entered the steps in the report. We have also used this to train new testers on an application and for demonstrations given by marketing.
This may not be the "right" way that some people envisioned for Cucumber's use and I know there are different ways to do it that would require none of this. So I'm not putting this up here for people to tell me how wrong they think I am for doing it this way. Rather, I just wanted to give a specific example rather than "Yes, it's fine to do this" or "No, you shouldn't do this."
I think the benefit of a tool like Cucumber is that it (currently anyway) lets you work the way you want to work, even if that doesn't fit how others feel things "should" be. I hope that philosophy continues with Cucumber development.
- Jeff