Sha256: 50ef97eac7010878c7b7f08960d268f1aa34efec8f35b45c75793ecc76667ac1

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'json'
require 'colorize'
require_relative 'xcmonkey/describer'
require_relative 'xcmonkey/repeater'
require_relative 'xcmonkey/version'
require_relative 'xcmonkey/logger'
require_relative 'xcmonkey/driver'

class Xcmonkey
  attr_accessor :driver

  def initialize(params)
    params[:session_path] = Dir.pwd if params[:session_path].nil?
    params[:duration] = 60 if params[:duration].nil?
    params[:enable_simulator_keyboard] = true if params[:enable_simulator_keyboard].nil?
    ensure_required_params(params)
    self.driver = Driver.new(params)
  end

  def run
    driver.monkey_test(gestures)
  end

  def gestures
    taps = [:precise_tap, :blind_tap] * 10
    swipes = [:precise_swipe, :blind_swipe] * 5
    presses = [:precise_press, :blind_press]
    taps + swipes + presses
  end

  def ensure_required_params(params)
    Logger.error('UDID should be provided') if params[:udid].nil?

    Logger.error('Bundle identifier should be provided') if params[:bundle_id].nil?

    Logger.error('Session path should be a directory') if params[:session_path].nil? || !File.directory?(params[:session_path])

    if params[:duration].nil? || !params[:duration].kind_of?(Integer) || !params[:duration].positive?
      Logger.error('Duration must be Integer and not less than 1 second')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xcmonkey-1.2.0 lib/xcmonkey.rb
xcmonkey-1.1.0 lib/xcmonkey.rb