1

I am testing a feature on an app that requires the user to be a certain age. The only time you see the prompt that asks for your age is once you open the app for the first time and once you log out of the app. I don't want my test to only go through my steps to log in and then log out to be able to see this prompt, but I also don't want to manually reset the data in between tests either. Isn't this why we write scripts? Anyways, before I launch the test, I use the environment variable RESET_BETWEEN_SCENARIOS=1 cucumber features/my_feature.feature. Is there a way that I can use this variable INSIDE of my step definition so that it resets the data on its own once I run the script?

king_wayne
  • 222
  • 1
  • 9

1 Answers1

3

I'm not familiar with Calabash, but it appears to be using cucumber. If that is the case, you could handle the action in a before or after hook which would run before or after each scenario.

Within the features/support folder, add a file hooks.rb

Before() do
  if ENV['RESET_BETWEEN_SCENARIOS'] == '1'
    #code to reset data
  end
end

This could also be run after the scenario by using After() do. The same if/then could be used within a scenario step as well.

Jarod Adair
  • 419
  • 2
  • 8
  • Thank you for your response. I am still new to Calabash/Cucumber/Ruby so I forgot all about using hooks. Thanks again. – king_wayne Sep 04 '14 at 14:12
  • For a more complete answer see: http://stackoverflow.com/questions/24493634/reset-ios-app-in-calabash-ios/24521084?noredirect=1#comment39010690_24521084 – jmoody Sep 04 '14 at 16:16