class Object

Public Instance Methods

all_user_properties_as_json() click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 57
def all_user_properties_as_json
  raise 'ERROR: No properties file found' if ENV[K::PROPERTIES_PATH].nil?

  properties_absolute_path = File.expand_path(ENV[K::PROPERTIES_PATH])
  raise 'ERROR: Properties file not found' unless File.file?(
    properties_absolute_path
  )

  file = open(properties_absolute_path)
  content = file.read
  file.close
  JSON.parse(content)
end
current_process_id() click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 24
def current_process_id
  tag_process_id = @scenario_tags.grep(/@user/).first
  process_id = tag_process_id.delete_prefix('@user')
  return 'ERROR: User not foud for scenario' if process_id.nil?

  process_id
end
ensure_feature_has_unique_tags(file_path) click to toggle source
# File lib/kraken-mobile/helpers/feature_analyzer.rb, line 10
def ensure_feature_has_unique_tags file_path
  parser = Gherkin::Parser.new
  file = open(file_path)
  content = file.read
  gherkin_document = parser.parse(content)
  pickles = Gherkin::Pickles::Compiler.new.compile(gherkin_document)
  tag_hash = {}
  pickles.each do |scenario|
    raise "Scenario '#{scenario[:name]}' can't have more than one @user{int} tag." if scenario[:tags].select{ |tag| tag[:name].start_with? "@user" }.count > 1
    scenario[:tags].each do |tag|
      tag_name = tag[:name]
      if tag_hash[tag_name]
        raise "Tag #{tag_name} is duplicated. Each feature can only have one @user{:int} tag assigned to a scenario."
      else
        tag_hash[tag_name] = tag_name
      end
    end
  end
end
ensure_features_format(files) click to toggle source
# File lib/kraken-mobile/helpers/feature_analyzer.rb, line 4
def ensure_features_format files
  files.each do |file_path|
    ensure_feature_has_unique_tags file_path
  end
end
handle_faker(key) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 71
def handle_faker(key)
  faker = KrakenFaker.new(process_id: current_process_id)
  faker.generate_value_for_key(
    key: key
  )
end
handle_faker_reuse(key) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 78
def handle_faker_reuse(key)
  faker = KrakenFaker.new(process_id: current_process_id)
  faker.reuse_value_for_key(
    key: key
  )
end
handle_property(property) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 45
def handle_property(property)
  properties = all_user_properties_as_json
  process_id = current_process_id
  user_id = "@user#{process_id}"

  if !properties[user_id] || !properties[user_id][property]
    raise "Property <#{property}> not found for @user#{current_process_id}"
  end

  properties[user_id][property]
end
process_id() click to toggle source
# File lib/kraken-mobile/hooks/mobile_operations.rb, line 33
def process_id
  tag_process_id = @scenario_tags.grep(/@user/).first
  tag_process_id.delete_prefix('@user')
end
requested_protocol() click to toggle source
# File lib/kraken-mobile/runners/calabash/android/cucumber.rb, line 9
def requested_protocol
  case ENV["PROTOCOL"]
  when KrakenMobile::Constants::FILE_PROTOCOL
    KrakenMobile::Protocol::FileProtocol
  else
    raise "Invalid Kraken protocol."
  end
end
shutdown_test_kraken_server() click to toggle source
# File lib/kraken-mobile/hooks/mobile_operations.rb, line 18
def shutdown_test_kraken_server
  DeviceProcess.notify_process_state(
    process_id: process_id,
    state: K::PROCESS_STATES[:ready_to_finish]
  )

  Timeout.timeout(K::DEFAULT_FINISH_TIMEOUT_SECONDS, RuntimeError) do
    sleep(1) until TestScenario.ready_to_finish?
  end

  shutdown_test_server
end
start_test_kraken_server_in_background() click to toggle source
# File lib/kraken-mobile/hooks/mobile_operations.rb, line 5
def start_test_kraken_server_in_background
  start_test_server_in_background

  DeviceProcess.notify_process_state(
    process_id: process_id,
    state: K::PROCESS_STATES[:ready_to_start]
  )

  Timeout.timeout(K::DEFAULT_START_TIMEOUT_SECONDS, RuntimeError) do
    sleep(1) until TestScenario.ready_to_start?
  end
end
string_is_a_faker?(string) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 37
def string_is_a_faker?(string)
  string.start_with?('$')
end
string_is_a_faker_reuse?(string) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 41
def string_is_a_faker_reuse?(string)
  string.start_with?('$$')
end
string_is_a_property?(string) click to toggle source
# File lib/kraken-mobile/steps/general_steps.rb, line 32
def string_is_a_property?(string)
  string.start_with?('<') &&
    string.end_with?('>')
end