When writing my scenerios, is it possible to not have to hard code text in the steps?
Like say I am insert a username in a textbox field, and a password in the password field.
If I need to do this in many places, it would be a pain to fix.
Example:
Given I am the registered member "myusername"
And I am on the login page
When I fill in "email" with "email@example.com"
And I fill in "password" with "123"
And I press "Login"
Then I should see "Account Activity"
I don’t want my username, email, and password hard-coded.
Okay, you’re still using the older version of the
cucumber-railsgem which comes with the training wheels installed by default. Read this post by Aslak Hellesøy “The training wheels came off”.The gist of the post is that using
web_steps.rb, although it having been the “standard” for years is now terribly wrong and that we should feel bad for doing that.The purpose of Cucumber is to use it to make readable / understandable features for all people.
Writing a scenario like this is long and boring:
What you want to actually be testing is that you should be able to login and after that see something to do with being logged in. Whatever that something is shouldn’t be written in the scenario.
So ideally, your
Scenario(in a more exciting fashion) would look like this:Then the task of doing the legwork goes to some new step definitions. Those two steps aren’t defined automatically for you, like
web_steps.rbdoes, but rather need to have them written in a file withinfeature/step_definitions. What you call the file is up to you, but it’ll contain content similar to this:No more excessive
web_steps.rbfile and cleaner step definitions. Exactly what Cucumber should be.