Class: Calabash::Cucumber::SimulatorLauncher

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/calabash-cucumber/launch/simulator_launcher.rb

Overview

Acts as a bridge to the sim_launcher SimLauncher and SdkDetector classes.

Runtime Environmental Variables

  • ‘PROJECT_DIR` (ENV) - the path to the .xcproject directory

  • ‘DEVICE_ENDPOINT` (localhost:37265/) - the ip:port of the device under test

  • ‘CALABASH_VERSION_PATH` (version) - the path to server version route

  • ‘MAX_CONNECT_RETRY` (2) the number of times retry establishing a connection to the server.

  • ‘CONNECT_TIMEOUT` (30) how long to wait for the server before timing out

Defined Under Namespace

Classes: TimeoutErr

Constant Summary collapse

DEFAULT_SIM_RETRY =

If ‘MAX_CONNECT_RETRY` is not set, try to launch the app this many times in the simulator before giving up

2

Instance Method Summary collapse

Methods included from Logging

#calabash_info, #calabash_warn

Constructor Details

#initializeSimulatorLauncher

Creates a new instance an sets the :simulator and :sdk_detector attributes.



68
69
70
71
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 68

def initialize
  @simulator = SimLauncher::Simulator.new
  @sdk_detector = SimLauncher::SdkDetector.new()
end

Instance Method Details

#find_preferred_dir(sim_dirs) ⇒ String

TODO:

find_preferred_dir is a bad name - preferred for what?

TODO:

sim_dirs arg is a bad name - we can be iterating over any directory

!@visibility private Finds the preferred(?) directory.

Parameters:

  • sim_dirs (Array<String>)

    eke! why sim_dirs? why not a list of any directories?

Returns:

  • (String)

    The first path in ‘sim_dirs` that contains a binary linked with Calabash server. Returns `nil` if there is no path in `sim_dirs` that contains a binary linked with Calabash server.



370
371
372
373
374
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 370

def find_preferred_dir(sim_dirs)
  sim_dirs.find do |d|
    linked_with_calabash?(d)
  end
end

#get_versionObject

Deprecated.

0.9.169 Calabash::Cucumber::Launcher.launcher.device instance methods

Raises:

  • (NotImplementedError)

    no longer implemented



537
538
539
540
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 537

def get_version
  _deprecated('0.9.169', 'use an instance Device class instead', :warn)
  raise(NotImplementedError, 'this method has been deprecated')
end

#ios_major_versionObject

Deprecated.

0.9.169 use Calabash::Cucumber::Launcher.launcher.ios_major_version

Raises:

  • (NotImplementedError)

    no longer implemented



551
552
553
554
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 551

def ios_major_version
  _deprecated('0.9.169', 'use an instance Device class instead', :warn)
  raise(NotImplementedError, 'this method has been deprecated')
end

#ios_versionObject

Deprecated.

0.9.169 Calabash::Cucumber::Launcher.launcher.device instance methods

Raises:

  • (NotImplementedError)

    no longer implemented



544
545
546
547
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 544

def ios_version
  _deprecated('0.9.169', 'use an instance Device class instead', :warn)
  raise(NotImplementedError, 'this method has been deprecated')
end

#ping_appString

TODO:

migrate DEVICE_ENDPOINT to environment_helpers

TODO:

migrate CALABASH_VERSION_PATH to environment_helpers

TODO:

this is an exact duplicate of Launcher ping method

Note:

Has the side effect of setting self.device attribute if successful.

!@visibility private Ping the version route of the calabash server embedded in the app,

Returns:

  • (String)

    returns the server status - ‘200’ is a success



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 386

def ping_app
  url = URI.parse(ENV['DEVICE_ENDPOINT']|| 'http://localhost:37265/')
  if full_console_logging?
    puts "Ping #{url}..."
  end

  http = Net::HTTP.new(url.host, url.port)
  res = http.start do |sess|
    # noinspection RubyResolve
    sess.request Net::HTTP::Get.new(ENV['CALABASH_VERSION_PATH'] || 'version')
  end

  status = res.code
  begin
    http.finish if http and http.started?
  rescue
    # nop
  end

  if status == '200'
    version_body = JSON.parse(res.body)
    self.device = Calabash::Cucumber::Device.new(url, version_body)
  end

  if full_console_logging?
    puts "ping status = '#{status}'"
  end
  status
end

#stopObject

Stops (quits) the simulator.



74
75
76
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 74

def stop
  RunLoop::SimControl.new.quit_sim
end

#version_check(version) ⇒ Object

Deprecated.

0.9.169 version checking is done in Launcher

Raises:

  • (NotImplementedError)

    no longer implemented



561
562
563
564
# File 'lib/calabash-cucumber/launch/simulator_launcher.rb', line 561

def version_check(version)
  _deprecated('0.9.169', 'check is now done in Launcher', :warn)
  raise(NotImplementedError, 'this method has been deprecated and will be removed')
end