Google+ Followers

Friday, 24 January 2014

calabash: how to reset app for specific scenarios using cucumber

RESET_BETWEEN_SCENARIOS

$ RESET_BETWEEN_SCENARIOS=1 calabash-android run <apkfile>
if the value is set to 1 application is reset between each scenario, incase you have logged in then you will logged out as application data will be cleared, used it if its only neccessary.


  • lets looks at https://github.com/calabash/x-platform-example/blob/master/features/android/support/app_life_cycle_hooks.rb
This is run before feature files are run

Android

Before do |scenario|
  scenario_tags = scenario.source_tag_names
  if scenario_tags.include?('@reinstall') || !INSTALLATION_STATE[:installed]
      uninstall_apps
      install_app(ENV['TEST_APP_PATH'])
      install_app(ENV['APP_PATH'])
      INSTALLATION_STATE[:installed] = true
  end
  start_test_server_in_background
end


To reset or reinstall for only specific scenarios, tag them with @reinstall only those scenarios ill be reset


if its required to only reset app then use clear_app_data in place of uninstall , install apps command
scenario_tags = scenario.source_tag_names
    if scenario_tags.include?('@reset')
      clear_app_data
    end



for ios use this code 


Before do |scenario|
  initialize_all
  @calabash_launcher = Calabash::Cucumber::Launcher.new
  scenario_tags = scenario.source_tag_names
  if scenario_tags.include?('@reset')
    @calabash_launcher.reset_app_jail
  end
  unless @calabash_launcher.calabash_no_launch?
    @calabash_launcher.relaunch
    @calabash_launcher.calabash_notify(self)
  end
end


14 comments:

  1. Calabash:ios
    Hi everyone i am new to calabash-cucumber .. i have some questions :
    1> How to reuse a scenario in a feature file ...
    for example :
    in my_first.feature i have

    scenario1: submit_info
    When I do someting
    then I enter user name
    then I enter password
    then I click submit button

    scenario2: here i want to use scenario1 Before I do something in scenario 2
    Given submit_info ( here i want that my submit_ info steps should executes first to login)
    Then I should see home screen


    2> How can I reuse a feature file completely i.e if have a first.feature and second.feature then how can i call/use first.feature in second.feature

    Please comment and give your thoughts..
    Thanks in advance
    vikas

    ReplyDelete
  2. Group the steps and reuse them in code ..take a look at the below link
    http://makandracards.com/makandra/18905-how-to-not-repeat-yourself-in-cucumber-scenarios

    ReplyDelete
  3. The iOS code doesn't seem to work with simulator iOS 7.

    ReplyDelete
    Replies
    1. have you used @reset tag in cucumber feature file

      Delete
  4. Hi here, I have a few questions.
    Were put iOS code into 01_launch.rb or 02_pre_stop_hooks.rb

    If I put code on 02_pre_stop_hooks.rb and

    Scenario: @reset test something
    Then I should see that
    When I touch that
    Scenario: test thing
    Then I should see that
    When I touch that

    I got error like this:

    undefined local variable or method `initialize_all' for # (NameError)
    /Library/Ruby/Gems/2.0.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
    /Users/.../.../.../../projectx/features/support/02_pre_stop_hooks.rb:2:in `Before'

    If I put code on 02_pre_stop_hooks.rb and

    @reset Scenario: test something
    Then I should see that
    When I touch that
    Scenario: test thing
    Then I should see that
    When I touch that

    I got error like this:

    /Users/.../../.../projetctx/features/test0000.feature: Lexing error on line 6: '@reset Scenario: testing doc'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
    /Library/Ruby/Gems/2.0.0/gems/gherkin-2.12.2/lib/gherkin/lexer/i18n_lexer.rb:24:in `scan'
    /Library/Ruby/Gems/2.0.0/gems/gherkin-2.12.2/lib/gherkin/lexer/i18n_lexer.rb:24:in `scan'
    /Library/Ruby/Gems/2.0.0/gems/gherkin-2.12.2/lib/gherkin/parser/parser.rb:33:in `parse'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/feature_file.rb:37:in `parse'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime/features_loader.rb:28:in `block in load'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime/features_loader.rb:26:in `each'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime/features_loader.rb:26:in `load'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime/features_loader.rb:14:in `features'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:179:in `features'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:49:in `run!'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47:in `execute!'
    /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.10/bin/cucumber:13:in `'
    /usr/bin/cucumber:23:in `load'
    /usr/bin/cucumber:23:in `'


    How to fix it, what I'm doing wrong?

    ReplyDelete
  5. Gotta put tags in separate line
    like this:
    @broken @58 @no_real_device
    Scenario: Verify Added Equipment is visible on multiple phones for the same user

    ReplyDelete
  6. i have certain scenarios that run only the first time the app is run after it has been installed(user setup) the above method was not working for me- and i need some way to delete and reinstall the app when i run the test suite( maybe even automatically reset content and settings and then install the app before running the test scenarios. any help would be much appreciated.

    ReplyDelete
  7. Hello, I am new to calabash but have successfully run 2-3 features.. when I finished my 4th feature, it gives a lexing error and does not run any of my scenarios. is there any way to run my test cases successfully again ?

    ReplyDelete
  8. ping me on google plus with your feature files .. let me check.

    ReplyDelete
  9. You have to replace "if" instruction related to reinstall with this one:

    if scenario_tags.include? "@reinstall"
    @calabash_launcher.relaunch(:reset=>true)
    end

    ReplyDelete
  10. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
    Mobile App Development Company
    Mobile App Development Company in India
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete
  11. One of the most costly capital outlays for development companies can be the purchasing of testing and analysis equipment. Textile Testing Equipments

    ReplyDelete
  12. Looking for the best mobile phone tracker? Simply hit the https://www.toptrackingapps.com/ and check out the reviews of top tracking apps for both iOS and Android phones. This top-ranked site saves you time and helps you decide which one is the best.

    ReplyDelete
  13. I have added and shared your site to my social media accounts to send people back to your site because I am sure they will find it extremely helpful too. home phone and internet bundles

    ReplyDelete