Sha256: 6e6f3c474cee570ee4819a201ba934d3db5649c5675b5be9cd62014176bc414a

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module KrakenAndroidMonkey
  def execute_kraken_monkey(number_of_events)
    number_of_events.times do |_i|
      execute_random_action
    end
  end

  def execute_random_action
    Timeout.timeout(K::MONKEY_DEFAULT_TIMEOUT, RuntimeError) do
      begin
        arr = [
          method(:random_click), method(:insert_random_text)
        ]
        arr.sample.call
      rescue StandardError => _e
        puts 'ERROR: Kraken monkey couldn\'t perfom action'
      end
    end
  end

  # Actions
  private

  def random_click
    elements = query('*')
    return if elements.nil?
    return if elements.none?

    element = elements.sample
    return if element['rect'].nil?

    x = element['rect']['x']
    y = element['rect']['y']
    perform_action('touch_coordinate', x, y)
  end

  def insert_random_text
    inputs = query('android.support.v7.widget.AppCompatEditText')
    return if inputs.nil?
    return if inputs.none?

    input = inputs.sample
    return if input['rect'].nil?

    x = input['rect']['x']
    y = input['rect']['y']
    perform_action('touch_coordinate', x, y)
    enter_text SecureRandom.hex
  end

  def input_texts
    query('android.support.v7.widget.AppCompatEditText')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kraken-mobile-1.0.9 lib/kraken-mobile/monkeys/mobile/kraken_android_monkey.rb
kraken-mobile-1.0.8 lib/kraken-mobile/monkeys/mobile/kraken_android_monkey.rb
kraken-mobile-1.0.5 lib/kraken-mobile/monkeys/mobile/kraken_android_monkey.rb