在calabash-ios中重置iOS应用 [英] Reset iOS app in calabash-ios

查看:131
本文介绍了在calabash-ios中重置iOS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在特定情况下更改挂钩中的代码以重置(iOS)应用?
仅对标记提及为@reset

How to change code in hooks to reset (iOS) app at specific scenario ? means only to those scenario where tags mention as @reset

推荐答案

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

已针对Calabash 0.17和运行循环2.0.2更新

该项目包含如何使用Cucumber标签和Before挂钩在模拟器和设备上重新安装应用程序并清除应用程序数据。

This project contains an example of how to use Cucumber tags and Before hooks to re-install apps and clear application data on simulators and devices.

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

特别是,请参见以下两个文件:

In particular, see these two files:

  • ideviceinstaller wrapper
  • support/01_launch.rb

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

I won't reproduce the entire 01_launch.rb example here, but here are the hooks:

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

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

The key is recognize the difference between testing on simulators and devices and testing on the Test Cloud and locally.

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

You can reset the application settings and content before every Scenario using the RESET_BETWEEN_SCENARIOS env variable.

$ RESET_BETWEEN_SCENARIOS=1 cucumber

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

You can also implement a backdoor method to reset your app to a good known state. This example is a bit wonky and out of date, but I have used it to great effect in the past - it really speeds up tests - briar-ios-example You can do all kinds of things with backdoors: log users in/out, reset databases, wipe user preferences, add/remove files from the sandbox.

这篇关于在calabash-ios中重置iOS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆