-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathappium_console.rb
More file actions
63 lines (52 loc) · 1.7 KB
/
appium_console.rb
File metadata and controls
63 lines (52 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
61
62
63
# frozen_string_literal: true
require 'rubygems'
require 'pry'
require 'appium_lib'
# Silence gem warnings
Gem::Specification.class_eval do
def self.warn(args); end
end
module Appium
module Console
class << self
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.
load file
rescue LoadError => e
puts e.message
end
end
end
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...'
x
end
opts = Pry::CLI.parse_options cmd
Pry::CLI.start(opts)
end
end
end
end