gpt4 book ai didi

calabash - 在 calabash-ios 中重置 iOS 应用

转载 作者:行者123 更新时间:2023-12-04 17:19:41 25 4
gpt4 key购买 nike

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

最佳答案

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/

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

  • ideviceinstaller wrapper
  • support/01_launch.rb

  • 我不会在这里重现整个 01_launch.rb 示例,但这里是钩子(Hook):
    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 重置应用程序设置和内容环境变量。
    $ RESET_BETWEEN_SCENARIOS=1 cucumber

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

    关于calabash - 在 calabash-ios 中重置 iOS 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24493634/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com