webdrone 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64c654a025eb0472f1fb89926d62ca6e9c4de51d
4
- data.tar.gz: 8ae214fbe1d02a4a15e5bff878c0ade333e8db11
3
+ metadata.gz: 49628fa13c5065c1432da4106b3cc5f012f6b4ad
4
+ data.tar.gz: 3eca80c42e15e21a427580b35b93d856ca830fec
5
5
  SHA512:
6
- metadata.gz: 0d52f1d053cd9716e893a606d288b80ba5af59d8ba9b0a0be5a6f955fbce2252f3fe8f28da75ee19ecdfcad81fb13fb1f6be2c113e75e3226bda7b87e2c1c471
7
- data.tar.gz: 683117fff323a66d68c7dc6be27a3e2b7a61a60a4e7ea1e636efd77e66e060161fff93d87b8f570c956d7ecf5e31a70d91c266f60f7b7c50a33ecdba9d1a62bb
6
+ metadata.gz: 32822abff939fbb3e3ad74c5b8a433ec90809b582909755048766d7a184a91952af4d85e5cc082302240d5e516070ef01825098d8f27789cb6a06e9882b983a0
7
+ data.tar.gz: 46d5e8ffefd7b389efbbcb9439913239a9efea7bc063732278769534edd9fa42d526e26c8bf69b7b27a4f858cf1dfe4baad3dcd272ae81a886e17454e3839442
data/lib/webdrone.rb CHANGED
@@ -23,6 +23,7 @@ require 'irb'
23
23
  require 'fileutils'
24
24
  require 'binding_of_caller'
25
25
  require 'pathname'
26
+ require 'pry'
26
27
 
27
28
  module Webdrone
28
29
  def self.create(*args)
@@ -31,7 +32,7 @@ module Webdrone
31
32
  begin
32
33
  yield a0
33
34
  rescue => exception
34
- Webdrone.report_error(a0, exception, Kernel.caller_locations)
35
+ Webdrone.report_error(a0, exception)
35
36
  ensure
36
37
  a0.quit
37
38
  end
@@ -45,6 +46,11 @@ module Webdrone
45
46
  binding = Kernel.binding.of_caller(1) if binding == nil
46
47
  IRB.start_session(binding)
47
48
  end
49
+
50
+ def self.pry_console(binding = nil)
51
+ binding = Kernel.binding_of_caller(1) unless binding
52
+ binding.pry
53
+ end
48
54
  end
49
55
 
50
56
  module IRB
@@ -25,7 +25,22 @@ module Webdrone
25
25
  @@chrome_prefs
26
26
  end
27
27
 
28
- def initialize(browser: 'firefox', create_outdir: true, outdir: nil, timeout:, developer: false, maximize: true, error: :raise_report, chrome_prefs: nil, firefox_profile: nil)
28
+ def env_update(binding)
29
+ ENV.keys.select { |env| env.start_with? 'WEBDRONE_' }.each do |env|
30
+ v = env[9..-1].downcase.to_sym
31
+ if binding.local_variable_defined? v
32
+ o = binding.local_variable_get(v)
33
+ n = ENV[env]
34
+ binding.local_variable_set(v, n)
35
+ puts "Webdrone info: overriding #{v} from '#{o}' to '#{n}'."
36
+ else
37
+ puts "Webdrone warn: unknown environment #{env}."
38
+ end
39
+ end
40
+ end
41
+
42
+ def initialize(browser: 'firefox', create_outdir: true, outdir: nil, timeout:, developer: false, quit_at_exit: false, maximize: true, error: :raise_report, win_x: nil, win_y: nil, win_w: nil, win_h: nil, use_env: true, chrome_prefs: nil, firefox_profile: nil)
43
+ env_update(Kernel.binding) if use_env
29
44
  if create_outdir or outdir
30
45
  outdir ||= File.join("webdrone_output", Time.new.strftime('%Y%m%d_%H%M%S'))
31
46
  self.conf.outdir = outdir
@@ -43,10 +58,42 @@ module Webdrone
43
58
  else
44
59
  @driver = Selenium::WebDriver.for browser.to_sym
45
60
  end
46
- self.conf.error = error
61
+ if quit_at_exit
62
+ at_exit do
63
+ begin
64
+ @driver.quit
65
+ rescue
66
+ end
67
+ end
68
+ end
69
+ self.conf.error = error.to_sym
47
70
  self.conf.developer = developer
48
71
  self.conf.timeout = timeout if timeout
49
- self.maximize if maximize
72
+
73
+ if developer
74
+ win_x = win_y = 0
75
+ win_w = 0.5
76
+ win_h = 1.0
77
+ end
78
+ if win_x or win_y or win_w or win_h
79
+ x, y, w, h = self.exec.script 'return [window.screenLeft ? window.screenLeft : window.screenX, window.screenTop ? window.screenTop : window.screenY, window.screen.availWidth, window.screen.availHeight];'
80
+ win_x ||= x
81
+ win_y ||= y
82
+ if win_w.is_a? Float
83
+ win_w = (w * win_w).to_i
84
+ else
85
+ win_w ||= w
86
+ end
87
+ if win_h.is_a? Float
88
+ win_h = (h * win_h).to_i
89
+ else
90
+ win_h ||= h
91
+ end
92
+ @driver.manage.window.position= Selenium::WebDriver::Point.new win_x, win_y
93
+ @driver.manage.window.resize_to(win_w, win_h)
94
+ else
95
+ self.maximize if maximize
96
+ end
50
97
  end
51
98
 
52
99
  def maximize
data/lib/webdrone/clic.rb CHANGED
@@ -20,7 +20,7 @@ module Webdrone
20
20
  item.click
21
21
  end
22
22
  rescue => exception
23
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
23
+ Webdrone.report_error(@a0, exception)
24
24
  end
25
25
 
26
26
  alias_method :id, :clic
data/lib/webdrone/conf.rb CHANGED
@@ -18,21 +18,21 @@ module Webdrone
18
18
  @timeout = val
19
19
  @a0.driver.manage.timeouts.implicit_wait = val
20
20
  rescue => exception
21
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
21
+ Webdrone.report_error(@a0, exception)
22
22
  end
23
23
 
24
24
  def outdir=(val)
25
25
  @outdir = val
26
26
  FileUtils.mkdir_p val
27
27
  rescue => exception
28
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
28
+ Webdrone.report_error(@a0, exception)
29
29
  end
30
30
 
31
31
  def error=(val)
32
32
  raise "Invalid value '#{val}' for error" if not [:raise_report, :raise, :ignore].include? val
33
33
  @error = val
34
34
  rescue => exception
35
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
35
+ Webdrone.report_error(@a0, exception)
36
36
  end
37
37
  end
38
38
  end
data/lib/webdrone/ctxt.rb CHANGED
@@ -17,14 +17,14 @@ module Webdrone
17
17
  @a0.exec.script "function a0_ctx_create_tab() { var w = window.open(); w.document.open(); w.document.write('A0 CTXT CREATE TAB'); w.document.close(); } a0_ctx_create_tab();"
18
18
  @a0.driver.switch_to.window @a0.driver.window_handles.last
19
19
  rescue => exception
20
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
20
+ Webdrone.report_error(@a0, exception)
21
21
  end
22
22
 
23
23
  def close_tab
24
24
  @a0.driver.close
25
25
  @a0.driver.switch_to.window @a0.driver.window_handles.last
26
26
  rescue => exception
27
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
27
+ Webdrone.report_error(@a0, exception)
28
28
  end
29
29
 
30
30
  def with_frame(name)
@@ -41,14 +41,14 @@ module Webdrone
41
41
  end
42
42
  name
43
43
  rescue => exception
44
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
44
+ Webdrone.report_error(@a0, exception)
45
45
  end
46
46
 
47
47
  def reset
48
48
  @a0.driver.switch_to.default_content
49
49
  @framestack = []
50
50
  rescue => exception
51
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
51
+ Webdrone.report_error(@a0, exception)
52
52
  end
53
53
 
54
54
  def with_alert
@@ -56,13 +56,13 @@ module Webdrone
56
56
  yield @a0.driver.switch_to.alert
57
57
  end
58
58
  rescue => exception
59
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
59
+ Webdrone.report_error(@a0, exception)
60
60
  end
61
61
 
62
62
  def ignore_alert
63
63
  @a0.exec.script 'alert = function(message){return true;};'
64
64
  rescue => exception
65
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
65
+ Webdrone.report_error(@a0, exception)
66
66
  end
67
67
 
68
68
  def with_conf(new_config)
@@ -75,7 +75,7 @@ module Webdrone
75
75
 
76
76
  yield
77
77
  rescue => exception
78
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
78
+ Webdrone.report_error(@a0, exception)
79
79
  ensure
80
80
  current_config.each do |k, v|
81
81
  @a0.conf.send "#{k}=", v
@@ -1,6 +1,7 @@
1
1
  module Webdrone
2
- class WebdroneError < StandardError
3
- attr_reader :original, :a0, :caller_locations, :consoled
2
+ class WebdroneError < RuntimeError
3
+ attr_reader :original, :a0, :caller_locations, :caller_location_index
4
+
4
5
  def initialize(msg, original = $!, a0, caller_locations)
5
6
  super(msg)
6
7
  @original = original
@@ -10,9 +11,10 @@ module Webdrone
10
11
 
11
12
  begin
12
13
  # find location of user error
13
- @caller_locations[0..-1].each do |location|
14
+ @caller_locations[0..-1].each_with_index do |location, index|
14
15
  if Gem.path.none? { |path| location.path.include? path }
15
16
  @location = location
17
+ @caller_location_index = index
16
18
  break
17
19
  end
18
20
  end
@@ -125,44 +127,17 @@ module Webdrone
125
127
 
126
128
  dump_error_report
127
129
  end
128
-
129
- def start_console
130
- return if @consoled
131
- @consoled = true
132
- while true do
133
- write_title "DEVELOPER CONSOLE"
134
- print "Enter stack index [#{@caller_index}] or 'exit': "
135
- input = gets.chomp
136
- break if input.include? 'exit'
137
- begin
138
- @caller_index = input.to_i if not input.empty?
139
- location = @original.backtrace_locations[@caller_index]
140
- raise '' if location == nil
141
- rescue => e
142
- puts "** INVALID STACK NUMBER **"
143
- next
144
- end
145
-
146
- @a0.ctxt.with_conf error: :raise, developer: false do
147
- begin
148
- index = Kernel.caller_locations.index do |item|
149
- item.path == location.path and item.lineno == location.lineno
150
- end
151
- Webdrone.irb_console Kernel.binding.of_caller(index + 1) if index != nil
152
- rescue => e
153
- puts "** INVALID STACK NUMBER #{e} **"
154
- end
155
- end
156
- report_exception
157
- end
158
- end
159
130
  end
160
131
 
161
- def self.report_error(a0, exception, caller_locations)
132
+ def self.report_error(a0, exception)
162
133
  return if a0.conf.error == :ignore
163
- exception = WebdroneError.new(exception.message, exception, a0, caller_locations) if exception.class != WebdroneError
134
+ if exception.class != WebdroneError
135
+ exception = WebdroneError.new(exception.message, exception, a0, Kernel.caller_locations)
136
+ if a0.conf.developer and not exception.caller_location_index.nil?
137
+ Kernel.binding.of_caller(exception.caller_location_index + 1).pry
138
+ end
139
+ end
164
140
 
165
- exception.start_console if a0.conf.developer
166
141
  raise exception if a0.conf.error == :raise or a0.conf.error == :raise_report
167
142
  end
168
143
  end
data/lib/webdrone/exec.rb CHANGED
@@ -15,7 +15,7 @@ module Webdrone
15
15
  def script(script, *more)
16
16
  @a0.driver.execute_script(script, *more)
17
17
  rescue => exception
18
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
18
+ Webdrone.report_error(@a0, exception)
19
19
  end
20
20
  end
21
21
  end
data/lib/webdrone/find.rb CHANGED
@@ -18,7 +18,7 @@ module Webdrone
18
18
  choose(items, n, all, visible)
19
19
  end
20
20
  rescue => exception
21
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
21
+ Webdrone.report_error(@a0, exception)
22
22
  end
23
23
 
24
24
  def css(text, n: 1, all: false, visible: true)
@@ -27,31 +27,31 @@ module Webdrone
27
27
  choose(items, n, all, visible)
28
28
  end
29
29
  rescue => exception
30
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
30
+ Webdrone.report_error(@a0, exception)
31
31
  end
32
32
 
33
33
  def link(text, n: 1, all: false, visible: true)
34
34
  self.xpath XPath::HTML.link(text).to_s, n: n, all: all, visible: visible
35
35
  rescue => exception
36
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
36
+ Webdrone.report_error(@a0, exception)
37
37
  end
38
38
 
39
39
  def button(text, n: 1, all: false, visible: true)
40
40
  self.xpath XPath::HTML.button(text).to_s, n: n, all: all, visible: visible
41
41
  rescue => exception
42
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
42
+ Webdrone.report_error(@a0, exception)
43
43
  end
44
44
 
45
45
  def on(text, n: 1, all: false, visible: true)
46
46
  self.xpath XPath::HTML.link_or_button(text).to_s, n: n, all: all, visible: visible
47
47
  rescue => exception
48
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
48
+ Webdrone.report_error(@a0, exception)
49
49
  end
50
50
 
51
51
  def option(text, n: 1, all: false, visible: true)
52
52
  self.xpath XPath::HTML.option(text).to_s, n: n, all: all, visible: visible
53
53
  rescue => exception
54
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
54
+ Webdrone.report_error(@a0, exception)
55
55
  end
56
56
 
57
57
  def xpath(text, n: 1, all: false, visible: true)
@@ -60,7 +60,7 @@ module Webdrone
60
60
  choose(items, n, all, visible)
61
61
  end
62
62
  rescue => exception
63
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
63
+ Webdrone.report_error(@a0, exception)
64
64
  end
65
65
 
66
66
  protected
data/lib/webdrone/form.rb CHANGED
@@ -16,7 +16,7 @@ module Webdrone
16
16
  old_xpath, @xpath = @xpath, xpath
17
17
  instance_eval &block
18
18
  rescue => exception
19
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
19
+ Webdrone.report_error(@a0, exception)
20
20
  ensure
21
21
  @xpath = old_xpath
22
22
  end
@@ -31,32 +31,32 @@ module Webdrone
31
31
  item.send_keys(val)
32
32
  end
33
33
  rescue => exception
34
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
34
+ Webdrone.report_error(@a0, exception)
35
35
  end
36
36
 
37
37
  def get(key, n: 1, visible: true)
38
38
  self.find_item(key, n: n, visible: visible)[:value]
39
39
  rescue => exception
40
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
40
+ Webdrone.report_error(@a0, exception)
41
41
  end
42
42
 
43
43
  def clic(key, n: 1, visible: true)
44
44
  self.find_item(key, n: n, visible: visible).click
45
45
  rescue => exception
46
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
46
+ Webdrone.report_error(@a0, exception)
47
47
  end
48
48
 
49
49
  def mark(key, n: 1, visible: true, color: '#af1616', times: 3, sleep: 0.05)
50
50
  @a0.mark.mark_item self.find_item(key, n: n, visible: visible), color: color, times: times, sleep: sleep
51
51
  rescue => exception
52
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
52
+ Webdrone.report_error(@a0, exception)
53
53
  end
54
54
 
55
55
  def submit(key = nil, n: 1, visible: true)
56
56
  self.find_item(key, n: n, visible: visible) if key
57
57
  @lastitem.submit
58
58
  rescue => exception
59
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
59
+ Webdrone.report_error(@a0, exception)
60
60
  end
61
61
 
62
62
  def xlsx(sheet: nil, filename: nil)
@@ -64,7 +64,7 @@ module Webdrone
64
64
  self.set k, v
65
65
  end
66
66
  rescue => exception
67
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
67
+ Webdrone.report_error(@a0, exception)
68
68
  end
69
69
 
70
70
  protected
data/lib/webdrone/html.rb CHANGED
@@ -20,7 +20,7 @@ module Webdrone
20
20
  item.attribute 'innerHTML'
21
21
  end
22
22
  rescue => exception
23
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
23
+ Webdrone.report_error(@a0, exception)
24
24
  end
25
25
 
26
26
  alias_method :id, :find_html
data/lib/webdrone/mark.rb CHANGED
@@ -16,7 +16,7 @@ module Webdrone
16
16
  item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
17
17
  mark_item item, color: color, times: times, sleep: sleep
18
18
  rescue => exception
19
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
19
+ Webdrone.report_error(@a0, exception)
20
20
  end
21
21
 
22
22
  alias_method :id, :mark
data/lib/webdrone/open.rb CHANGED
@@ -15,13 +15,13 @@ module Webdrone
15
15
  def url(url)
16
16
  @a0.driver.get url
17
17
  rescue => exception
18
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
18
+ Webdrone.report_error(@a0, exception)
19
19
  end
20
20
 
21
21
  def reload
22
22
  @a0.driver.navigate.refresh
23
23
  rescue => exception
24
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
24
+ Webdrone.report_error(@a0, exception)
25
25
  end
26
26
  end
27
27
  end
data/lib/webdrone/shot.rb CHANGED
@@ -18,7 +18,7 @@ module Webdrone
18
18
  filename = File.join(@a0.conf.outdir, filename)
19
19
  @a0.driver.save_screenshot filename
20
20
  rescue => exception
21
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
21
+ Webdrone.report_error(@a0, exception)
22
22
  end
23
23
  end
24
24
  end
data/lib/webdrone/text.rb CHANGED
@@ -20,7 +20,7 @@ module Webdrone
20
20
  item.text
21
21
  end
22
22
  rescue => exception
23
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
23
+ Webdrone.report_error(@a0, exception)
24
24
  end
25
25
 
26
26
  alias_method :id, :text
@@ -34,7 +34,7 @@ module Webdrone
34
34
  def page_title
35
35
  @a0.driver.title
36
36
  rescue => exception
37
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
37
+ Webdrone.report_error(@a0, exception)
38
38
  end
39
39
 
40
40
  protected :text
@@ -1,3 +1,3 @@
1
1
  module Webdrone
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.6"
3
3
  end
data/lib/webdrone/wait.rb CHANGED
@@ -26,13 +26,13 @@ module Webdrone
26
26
  yield
27
27
  end
28
28
  rescue => exception
29
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
29
+ Webdrone.report_error(@a0, exception)
30
30
  end
31
31
 
32
32
  def time(val)
33
33
  sleep val
34
34
  rescue => exception
35
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
35
+ Webdrone.report_error(@a0, exception)
36
36
  end
37
37
  end
38
38
  end
data/lib/webdrone/xlsx.rb CHANGED
@@ -30,7 +30,7 @@ module Webdrone
30
30
  end
31
31
  @dict
32
32
  rescue => exception
33
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
33
+ Webdrone.report_error(@a0, exception)
34
34
  end
35
35
 
36
36
  def rows(sheet: nil, filename: nil)
@@ -47,7 +47,7 @@ module Webdrone
47
47
  end
48
48
  @rows
49
49
  rescue => exception
50
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
50
+ Webdrone.report_error(@a0, exception)
51
51
  end
52
52
 
53
53
  def both(sheet: nil, filename: nil)
@@ -72,7 +72,7 @@ module Webdrone
72
72
  end
73
73
  @both
74
74
  rescue => exception
75
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
75
+ Webdrone.report_error(@a0, exception)
76
76
  end
77
77
 
78
78
 
@@ -117,13 +117,13 @@ module Webdrone
117
117
  k = workbook.write(@filename)
118
118
  reset
119
119
  rescue => exception
120
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
120
+ Webdrone.report_error(@a0, exception)
121
121
  end
122
122
 
123
123
  def reset()
124
124
  @dict = @rows = @both = nil
125
125
  rescue => exception
126
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
126
+ Webdrone.report_error(@a0, exception)
127
127
  end
128
128
 
129
129
  protected
data/webdrone.gemspec CHANGED
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_runtime_dependency "xpath"
38
38
  spec.add_runtime_dependency "rubyXL"
39
39
  spec.add_runtime_dependency "binding_of_caller"
40
+ spec.add_runtime_dependency "pry"
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldrin Martoq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-01 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: See webpage for more info.
154
168
  email:
155
169
  - a@a0.cl