1

I am running Calabash-IOS on my simulator. If I type cucumber in the terminal while the application is already running, it will shutdown the whole simulator, and start a new instance of it, and then runs all the tests. It runs all my login scenarios and outlines just to test one thing after the user has logged in.

Is there a way to disable this so that tests run from where I left a view open?

sawa
  • 165,429
  • 45
  • 277
  • 381

2 Answers2

1

From the Calabash::Cucumber::Launcher documentation

Attaching to the current launcher in a console

If Calabash already running and you want to attach to the current launcher, use console_attach. This is useful when a cucumber Scenario has failed and you want to query the current state of the app.

In theory this means you could use console_attach to connect to a running calabash instance.

Community
  • 1
  • 1
Sander Saelmans
  • 831
  • 4
  • 13
  • Correct! When you start a calabash-ios console, it will attempt to attach to a running calabash server. `console_attach` should not be used in your tests. I think this does not really answer the user's question though. I think the user needs to use cucumber tags, Before, After blocks, or Calabash backdoors. – jmoody Feb 07 '18 at 09:08
  • Yes. This doesn't quite answer my question. Id like to start running my tests from a specific view without having to go through all the tests just to test one bit. – IhateMacsSad Feb 07 '18 at 09:44
  • In that case @jmoody is correct. You would need a backdoor in your application which navigates you to the correct ViewController. Depending on the complexity and dependencies of your application, writing a router like this can be quite difficult. – Sander Saelmans Feb 07 '18 at 10:54
  • Is there no simple way to not just reset simulator when running cucumber? – IhateMacsSad Feb 07 '18 at 12:06
  • You could try setting the environment variable `RESET_BETWEEN_SCENARIOS` to `"0"`. If quitting the app is also causing issues, you can set `QUIT_APP_AFTER_SCENARIO` to `"0"` – Sander Saelmans Feb 07 '18 at 12:26
0

That's my configuration in the support folder:

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
kubano
  • 633
  • 7
  • 10