【问题标题】:Reset iOS app in calabash-ios在 calabash-ios 中重置 iOS 应用
【发布时间】:2014-08-21 00:45:41
【问题描述】:

如何在特定场景下更改挂钩中的代码以重置 (iOS) 应用程序? 仅适用于标签提及为@reset

的情况

【问题讨论】:

    标签: calabash calabash-ios


    【解决方案1】:

    https://github.com/cucumber/cucumber/wiki/Hooks#tagged-hooks

    更新了 Calabash 0.17 和运行循环 2.0.2

    本项目包含一个示例,说明如何使用 Cucumber 标签和 Before hooks 重新安装应用程序并清除模拟器和设备上的应用程序数据。

    https://github.com/calabash/ios-smoke-test-app/

    具体看这两个文件:

    我不会在这里重现整个 01_launch.rb 示例,但这里是钩子:

    Before("@no_relaunch") do
      @no_relaunch = true
    end
    
    Before('@reset_app_btw_scenarios') do
      if xamarin_test_cloud? || LaunchControl.target_is_simulator?
        ENV['RESET_BETWEEN_SCENARIOS'] = '1'
      else
        LaunchControl.install_on_physical_device
      end
    end
    
    Before('@reset_device_settings') do
      if xamarin_test_cloud?
        ENV['RESET_BETWEEN_SCENARIOS'] = '1'
      elsif LaunchControl.target_is_simulator?
        target = LaunchControl.target
        instruments = RunLoop::Instruments.new
        xcode = instruments.xcode
        device = instruments.simulators.find do |sim|
          sim.udid == target || sim.instruments_identifier(xcode) == target
        end
    
        RunLoop::CoreSimulator.erase(device)
      else
        LaunchControl.install_on_physical_device
      end
    end
    
    Before do |scenario|
      launcher = LaunchControl.launcher
    
      options = {
        #:uia_strategy => :host
        #:uia_strategy => :shared_element
        :uia_strategy => :preferences
      }
    
      relaunch = true
    
      if @no_relaunch
        begin
          launcher.ping_app
          attach_options = options.dup
          attach_options[:timeout] = 1
          launcher.attach(attach_options)
          relaunch = launcher.device == nil
        rescue => e
          RunLoop.log_info2("Tag says: don't relaunch, but cannot attach to the app.")
          RunLoop.log_info2("#{e.class}: #{e.message}")
          RunLoop.log_info2("The app probably needs to be launched!")
        end
      end
    
      if relaunch
        launcher.relaunch(options)
        launcher.calabash_notify(self)
      end
    
      ENV['RESET_BETWEEN_SCENARIOS'] = '0'
    
      # Re-installing the app on a device does not clear the Keychain settings,
      # so we must clear them manually.
      if scenario.source_tag_names.include?('@reset_device_settings')
        if xamarin_test_cloud? || LaunchControl.target_is_physical_device?
          keychain_clear
        end
      end
    end
    

    关键是要认识到在模拟器和设备上进行测试与在测试云和本地进行测试之间的区别。

    您可以使用RESET_BETWEEN_SCENARIOS env 变量在每个场景之前重置应用程序设置和内容。

    $ RESET_BETWEEN_SCENARIOS=1 cucumber
    

    您还可以实施后门方法将您的应用重置为众所周知的状态。这个例子有点古怪和过时,但我过去使用它效果很好 - 它确实加快了测试速度 - briar-ios-example 你可以用后门做各种各样的事情:登录/注销用户,重置数据库,擦除用户首选项,从沙箱中添加/删除文件。

    【讨论】:

    • 这取决于你。如果您只想重置模拟器内容和设置,请尝试:reset_simulator_content_and_settings。虽然没有承诺 - 我不记得这是功能是否公开。您可能需要在 01_launch.rb 文件中添加一些文件。
    • 根据您的评论以及有关 calabash-ios google 组和 calabash-ios 问题的一些问题更新了我的答案。
    • 在calabash 0.10.0版本中会有一些基于这个pull request的变化:github.com/calabash/calabash-ios/pull/440
    • 在使用真实设备的 Xamarin 测试云上,设置 RESET_BETWEEN_SCENARIOS=1 将在每个场景之前重置应用沙箱。在本地,没有已知的方法可以在物理设备上重置应用程序的沙箱。你能接受我的回答正确吗?
    • 更新了 0.10.0.pre2 及以上版本的示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    相关资源
    最近更新 更多