【问题标题】:Stop resetting simulator for tests停止重置模拟器进行测试
【发布时间】:2018-02-06 10:11:19
【问题描述】:

我在我的模拟器上运行 Calabash-IOS。如果我在应用程序已经运行时在终端中键入cucumber,它将关闭整个模拟器,并启动它的新实例,然后运行所有测试。它运行我所有的登录场景和大纲,只是为了在用户登录后测试一件事。

有没有办法禁用此功能,以便从我打开视图的位置运行测试?

【问题讨论】:

    标签: ruby automated-tests cucumber calabash calabash-ios


    【解决方案1】:

    来自Calabash::Cucumber::Launcher 文档

    附加到控制台中的当前启动器

    如果 Calabash 已经在运行并且您想附加到当前 启动器,使用 console_attach。这在黄瓜场景中很有用 已失败,您想查询应用的当前状态。

    理论上,这意味着您可以使用console_attach 连接到正在运行的calabash 实例。

    【讨论】:

    • 正确!当您启动 calabash-ios 控制台时,它将尝试连接到正在运行的 calabash 服务器。 console_attach 不应在您的测试中使用。我认为这并不能真正回答用户的问题。我认为用户需要使用黄瓜标签、Before、After 块或 Calabash 后门。
    • 是的。这并不能完全回答我的问题。我想从一个特定的视图开始运行我的测试,而不必为了测试一点而通过所有的测试。
    • 在这种情况下@jmoody 是正确的。您需要在应用程序中设置一个后门,以将您导航到正确的 ViewController。根据应用程序的复杂性和依赖性,编写这样的路由器可能非常困难。
    • 运行黄瓜时有没有简单的方法不只是重置模拟器?
    • 您可以尝试将环境变量RESET_BETWEEN_SCENARIOS 设置为"0"。如果退出应用也有问题,可以将QUIT_APP_AFTER_SCENARIO设置为"0"
    【解决方案2】:

    这是我在support 文件夹中的配置:

    01_launch.rb

    require 'calabash-cucumber/launcher'
    
    # You can find examples of more complicated launch hooks in these
    # two repositories:
    #
    # https://github.com/calabash/ios-smoke-test-app/blob/master/CalSmokeApp/features/support/01_launch.rb
    # https://github.com/calabash/ios-webview-test-app/blob/master/CalWebViewApp/features/support/01_launch.rb
    
    module Calabash::Launcher
      @@launcher = nil
    
      def self.launcher
        @@launcher ||= Calabash::Cucumber::Launcher.new
      end
    
      def self.launcher=(launcher)
        @@launcher = launcher
      end
    end
    
    
    $testServerRunning = false
    
    
    Before do |scenario|
      scenario_tags = scenario.source_tag_names
      if !$testServerRunning || scenario_tags.include?('@restart')
        if $testServerRunning
          shutdown_test_server
        end
    
        start_test_server_in_background
    
        $testServerRunning = true
      end
    end
    
    After do |scenario|
      Cucumber.wants_to_quit = false
      if scenario.failed?
        screenshot_embed
      end
    end
    

    env.rb

    require "calabash-cucumber"
    
    # Cucumber -d must pass, but support/env.rb is not eval'd on dry runs.
    # We must detect that the user wants to use pre-defined steps.
    dir = File.expand_path(File.dirname(__FILE__))
    env = File.join(dir, "env.rb")
    
    contents = File.read(env).force_encoding("UTF-8")
    
    contents.split($-0).each do |line|
    
      # Skip comments.
      next if line.chars[0] == "#"
    
      if line[/calabash-cucumber\/cucumber/, 0]
        require "calabash-cucumber/calabash_steps"
        break
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2012-06-03
      • 2011-03-12
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多