Module: Appium::Console

Defined in:
lib/appium_console.rb,
lib/appium_console/version.rb

Constant Summary collapse

VERSION =
'2.11.0'.freeze
DATE =
'2018-12-28'.freeze

Class Method Summary collapse

Class Method Details

.setup(appium_txt_path) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appium_console.rb', line 13

def setup(appium_txt_path)
  Pry.send(:define_singleton_method, :pry_load_appium_txt) do |opts = {}|
    verbose = opts.fetch :verbose, false
    path = appium_txt_path
    Appium.load_appium_txt file: path, verbose: verbose
  end

  Pry.send(:define_singleton_method, :reload) do
    parsed = Pry.pry_load_appium_txt
    return unless parsed && parsed[:appium_lib] && parsed[:appium_lib][:require]

    requires = parsed[:appium_lib][:require]
    requires.each do |file|
      # If a page obj is deleted then load will error.
      begin
        load file
      rescue LoadError => e
        puts e.message
      end
    end
  end
end

.startObject


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/appium_console.rb', line 36

def start
  start = File.expand_path 'start.rb', __dir__
  cmd = ['-r', start]

  parsed = Pry.pry_load_appium_txt verbose: true
  has_requires = parsed && parsed[:appium_lib] && parsed[:appium_lib][:require]
  if has_requires
    requires = parsed[:appium_lib][:require]

    unless requires.empty?
      load_files = requires.map { |f| %(require "#{f}";) }.join "\n"
      cmd += ['-e', load_files]
    end

    $stdout.puts "pry #{cmd.join(' ')}"
  end

  Pry.hooks.add_hook(:after_session, 'Release session hook') do |output, _binding, _pry|
    output.puts 'Closing appium session...'
    $driver.x
  end

  opts = Pry::CLI.parse_options cmd
  Pry::CLI.start(opts)
end