Sha256: 5b2423347f7e3c059c9a7f4f506af3b44de838e99c4996e13909e314e9be8486

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'kraken-mobile/utils/feature_reader'
require 'kraken-mobile/test_scenario'

class KrakenApp
  include Utils::FeatureReader

  #-------------------------------
  # Fields
  #-------------------------------

  attr_accessor :apk_path
  attr_accessor :scenarios_queue

  #-------------------------------
  # Constructors
  #-------------------------------
  def initialize(apk_path:, properties_path: nil, config_path: nil)
    @apk_path = apk_path
    @scenarios_queue = []
    save_path_in_environment_variable_with_name(
      name: K::PROPERTIES_PATH, path: properties_path
    )
    save_path_in_environment_variable_with_name(
      name: K::CONFIG_PATH, path: config_path
    )

    build_scenarios_queue
  end

  def start
    execute_next_scenario
  end

  #-------------------------------
  # Observers
  #-------------------------------
  def on_test_scenario_finished
    execute_next_scenario
  end

  private

  def build_scenarios_queue
    feature_files.each do |feature_path|
      scenarios_queue.unshift(
        TestScenario.new(
          kraken_app: self,
          feature_file_path: feature_path
        )
      )
    end
  end

  def execute_next_scenario
    return if scenarios_queue.count.zero?

    scenario = scenarios_queue.pop
    scenario.run
    scenario
  end

  def save_path_in_environment_variable_with_name(name:, path:)
    return if path.nil?

    absolute_path = File.expand_path(path)
    save_value_in_environmant_variable_with_name(
      name: name,
      value: absolute_path
    )
  end

  def save_value_in_environmant_variable_with_name(name:, value:)
    return if name.nil? || value.nil?

    ENV[name] = value
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kraken-mobile-1.0.5 lib/kraken_mobile.rb