webdrone 1.2.2 → 1.3.0

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: 12d5f77489ba2ded5102586a7193da98399de127
4
- data.tar.gz: 200238d4b2e92a09db311aa2ca4aff02e419a372
3
+ metadata.gz: 84f21a7830d512ee51ce79b98399df8a9cbec93c
4
+ data.tar.gz: 524e702b1786541742a00043fdc41a7f79b52d3c
5
5
  SHA512:
6
- metadata.gz: a56fb22e5f839479299ce86057edd24bd125789558c92dd9a06e23ca9f41e14e8c0eb0137dec5fbf68342f8295ca87bed30818b328b87d9bfe29282435374c20
7
- data.tar.gz: a1e7c9b1f3b08da28a3f35a54737d54b76cdfc3bad2b003baee86bd958fae20d5efe5add1d9185933bbc951e4321c8b85159da306948d06fe2f518b49f6adbc5
6
+ metadata.gz: bda08bad9dddf2224b562942856e463583d99bf6398f74298c6dadb76342fc1028d132ef0c07fbac87e951b2349b4ed69993d84ea6d7739da03e9199b4a3f370
7
+ data.tar.gz: 65baa45b966b033cc6961390d71ce0708d40b3803a6b7974543b5d073f848ef3273b0d8a75696aa86b8a44cd8c872a9e607054f37f1db1f3aac5bacb49223144
data/lib/webdrone.rb CHANGED
@@ -1,3 +1,15 @@
1
+ require 'os'
2
+ require 'selenium-webdriver'
3
+ require 'xpath'
4
+ require 'rubyXL'
5
+ require 'irb'
6
+ require 'fileutils'
7
+ require 'binding_of_caller'
8
+ require 'pathname'
9
+ require 'pry'
10
+ require 'highline'
11
+ require 'csv'
12
+
1
13
  require 'webdrone/version'
2
14
  require 'webdrone/error'
3
15
  require 'webdrone/browser'
@@ -15,15 +27,7 @@ require 'webdrone/wait'
15
27
  require 'webdrone/text'
16
28
  require 'webdrone/vrfy'
17
29
  require 'webdrone/html'
18
- require 'os'
19
- require 'selenium-webdriver'
20
- require 'xpath'
21
- require 'rubyXL'
22
- require 'irb'
23
- require 'fileutils'
24
- require 'binding_of_caller'
25
- require 'pathname'
26
- require 'pry'
30
+ require 'webdrone/logg'
27
31
 
28
32
  module Webdrone
29
33
  def self.create(*args)
@@ -50,7 +50,7 @@ module Webdrone
50
50
  end
51
51
  end
52
52
 
53
- 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)
53
+ def initialize(browser: 'firefox', create_outdir: true, outdir: nil, timeout:, developer: false, logger: true, 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)
54
54
  env_update(Kernel.binding) if use_env
55
55
  if create_outdir or outdir
56
56
  outdir ||= File.join("webdrone_output", Time.new.strftime('%Y%m%d_%H%M%S'))
@@ -80,6 +80,7 @@ module Webdrone
80
80
  self.conf.error = error.to_sym
81
81
  self.conf.developer = developer
82
82
  self.conf.timeout = timeout.to_i if timeout
83
+ self.conf.logger = logger
83
84
 
84
85
  if developer
85
86
  win_x = win_y = 0
data/lib/webdrone/conf.rb CHANGED
@@ -6,7 +6,7 @@ module Webdrone
6
6
  end
7
7
 
8
8
  class Conf
9
- attr_accessor :a0, :timeout, :outdir, :error, :developer
9
+ attr_accessor :a0, :timeout, :outdir, :error, :developer, :logger
10
10
 
11
11
  def initialize(a0)
12
12
  @a0 = a0
@@ -1,20 +1,22 @@
1
1
  module Webdrone
2
2
  class WebdroneError < RuntimeError
3
- attr_reader :original, :a0, :caller_locations, :caller_location_index
3
+ attr_reader :original, :a0, :binding
4
4
 
5
- def initialize(msg, original = $!, a0, caller_locations)
5
+ def initialize(msg, original = $!, a0, bindings)
6
6
  super(msg)
7
7
  @original = original
8
8
  @a0 = a0
9
- @caller_locations = caller_locations
10
9
  @buffer = []
10
+ @binding = nil
11
+ @location = nil
11
12
 
12
13
  begin
13
14
  # find location of user error
14
- @caller_locations[0..-1].each_with_index do |location, index|
15
- if Gem.path.none? { |path| location.path.include? path }
15
+ bindings[0..-1].each_with_index do |binding, index|
16
+ location = { path: binding.eval('__FILE__'), lineno: binding.eval('__LINE__') }
17
+ if Gem.path.none? { |path| location[:path].include? path }
16
18
  @location = location
17
- @caller_location_index = index
19
+ @binding = binding
18
20
  break
19
21
  end
20
22
  end
@@ -56,14 +58,14 @@ module Webdrone
56
58
 
57
59
  def report_script
58
60
  begin
59
- ini, fin = [@location.lineno - 10 - 1, @location.lineno + 10 - 1]
61
+ ini, fin = [@location[:lineno] - 10 - 1, @location[:lineno] + 10 - 1]
60
62
  ini = 0 if ini < 0
61
63
 
62
64
  write_title "LOCATION OF ERROR"
63
- write_line "#{@location.path} AT LINE #{sprintf '%3d', @location.lineno}"
64
- File.readlines(@location.path)[ini..fin].each_with_index do |line, index|
65
+ write_line "#{@location[:path]} AT LINE #{sprintf '%3d', @location[:lineno]}"
66
+ File.readlines(@location[:path])[ini..fin].each_with_index do |line, index|
65
67
  lno = index + ini + 1
66
- if lno == @location.lineno
68
+ if lno == @location[:lineno]
67
69
  write_line sprintf "%3d ==> %s", lno, line
68
70
  else
69
71
  write_line sprintf "%3d %s", lno, line
@@ -100,9 +102,8 @@ module Webdrone
100
102
 
101
103
  write_line "#{@original.class}: #{@original.message}"
102
104
  @original.backtrace_locations.each_with_index do |location, index|
103
- if location.path == @location.path and location.lineno == @location.lineno
105
+ if location.path == @location[:path] and location.lineno == @location[:lineno]
104
106
  write_line sprintf "%02d: ==> from %s", index, location
105
- @caller_index = index
106
107
  else
107
108
  write_line sprintf "%02d: from %s", index, location
108
109
  end
@@ -132,11 +133,11 @@ module Webdrone
132
133
  def self.report_error(a0, exception)
133
134
  return if a0.conf.error == :ignore
134
135
  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?
136
+ exception = WebdroneError.new(exception.message, exception, a0, Kernel.binding.callers)
137
+ if a0.conf.developer and exception.binding
137
138
  exception.write_title "STARTING DEVELOPER CONSOLE ON ERROR"
138
139
  exception.dump_error_report
139
- a0.console Kernel.binding.of_caller(exception.caller_location_index + 1)
140
+ a0.console exception.binding
140
141
  end
141
142
  end
142
143
 
@@ -0,0 +1,146 @@
1
+ module Webdrone
2
+ class MethodLogger < Module
3
+ def initialize(methods_0 = nil)
4
+ @methods_0 = methods_0
5
+ end
6
+
7
+ def included(base)
8
+ @methods_0 = base.instance_methods(false) if @methods_0 == nil
9
+ method_list = @methods_0
10
+ base.class_eval do
11
+ method_list.each do |method_name|
12
+ original_method = instance_method(method_name)
13
+ define_method method_name do |*args, &block|
14
+ caller_location = Kernel.caller_locations[0]
15
+ cl_path = caller_location.path
16
+ cl_line = caller_location.lineno
17
+ if @a0.conf.logger and Gem.path.none? { |path| cl_path.include? path }
18
+ $a0_webdrone_logger_last_time = Time.new unless $a0_webdrone_logger_last_time
19
+ ini = $a0_webdrone_logger_last_time
20
+ $a0_webdrone_screenshot = nil
21
+ begin
22
+ result = original_method.bind(self).call(*args, &block)
23
+ fin = $a0_webdrone_logger_last_time = Time.new
24
+ @a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, result, nil, $a0_webdrone_screenshot)
25
+ result
26
+ rescue => exception
27
+ fin = $a0_webdrone_logger_last_time = Time.new
28
+ @a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, nil, exception, $a0_webdrone_screenshot)
29
+ raise exception
30
+ end
31
+ else
32
+ original_method.bind(self).call(*args, &block)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ class Browser
41
+ def logs
42
+ @logs ||= Logs.new self
43
+ end
44
+ end
45
+
46
+ class Logs
47
+ attr_accessor :a0
48
+
49
+ def initialize(a0)
50
+ @a0 = a0
51
+ setup_format
52
+ setup_trace
53
+ end
54
+
55
+ def trace(ini, fin, from, lineno, base, method_name, args, result, exception, screenshot)
56
+ exception = "#{exception.class}: #{exception}" if exception
57
+ printf @format, (fin-ini), base, method_name, args, (result || exception)
58
+ CSV.open(@path, "a+") do |csv|
59
+ csv << [ini.strftime('%Y-%m-%d %H:%M:%S.%L %z'), (fin-ini), from, lineno, base, method_name, args, result, exception, screenshot]
60
+ end
61
+ end
62
+
63
+ def setup_format
64
+ cols, line = HighLine::SystemExtensions.terminal_size
65
+ total = 6 + 15 + 11 + 5
66
+ w = cols - total
67
+ w /= 2
68
+ w = 20 if w < 20
69
+ w1 = w
70
+ w2 = cols - total - w1
71
+ @format = "%5.3f %14.14s %10s %#{w1}.#{w1}s => %#{w2}.#{w2}s\n"
72
+ end
73
+
74
+ def setup_trace
75
+ @path = File.join(a0.conf.outdir, 'a0_webdrone_trace.csv')
76
+ CSV.open(@path, "a+") do |csv|
77
+ os = "Windows" if OS.windows?
78
+ os = "Linux" if OS.linux?
79
+ os = "OS X" if OS.osx?
80
+ bits = OS.bits
81
+ hostname = Socket.gethostname
82
+ browser_name = a0.driver.capabilities[:browser_name]
83
+ browser_version = a0.driver.capabilities[:version]
84
+ webdrone_version = Webdrone::VERSION
85
+
86
+ csv << %w.OS ARCH HOSTNAME BROWSER\ NAME BROWSER\ VERSION WEBDRONE\ VERSION.
87
+ csv << [os, bits, hostname, browser_name, browser_version, webdrone_version]
88
+ end
89
+ CSV.open(@path, "a+") do |csv|
90
+ csv << %w.DATE DUR FROM LINENO MODULE CALL PARAMS RESULT EXCEPTION SCREENSHOT.
91
+ end
92
+ end
93
+ end
94
+
95
+ class Clic
96
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
97
+ end
98
+
99
+ class Conf
100
+ include MethodLogger.new [:timeout=, :outdir=, :error=, :developer=, :logger=]
101
+ end
102
+
103
+ class Ctxt
104
+ include MethodLogger.new [:create_tab, :close_tab, :with_frame, :reset, :with_alert, :ignore_alert, :with_conf]
105
+ end
106
+
107
+ class Find
108
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
109
+ end
110
+
111
+ class Form
112
+ include MethodLogger.new [:with_xpath, :save, :set, :get, :clic, :mark, :submit, :xlsx]
113
+ end
114
+
115
+ class Html
116
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
117
+ end
118
+
119
+ class Mark
120
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
121
+ end
122
+
123
+ class Open
124
+ include MethodLogger.new [:url, :reload]
125
+ end
126
+
127
+ class Shot
128
+ include MethodLogger.new [:screen]
129
+ end
130
+
131
+ class Text
132
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
133
+ end
134
+
135
+ class Vrfy
136
+ include MethodLogger.new [:id, :css, :link, :button, :on, :option, :xpath]
137
+ end
138
+
139
+ class Wait
140
+ include MethodLogger.new [:for, :time]
141
+ end
142
+
143
+ class Xlsx
144
+ include MethodLogger.new [:dict, :rows, :both, :save, :reset]
145
+ end
146
+ end
data/lib/webdrone/shot.rb CHANGED
@@ -16,6 +16,7 @@ module Webdrone
16
16
  @counter = (@counter || 0) + 1
17
17
  filename = sprintf "screenshot-%04d-%s.png", @counter, name
18
18
  filename = File.join(@a0.conf.outdir, filename)
19
+ $a0_webdrone_screenshot = filename
19
20
  @a0.driver.save_screenshot filename
20
21
  rescue => exception
21
22
  Webdrone.report_error(@a0, exception)
@@ -1,3 +1,3 @@
1
1
  module Webdrone
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
data/webdrone.gemspec CHANGED
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_runtime_dependency "rubyXL"
39
39
  spec.add_runtime_dependency "binding_of_caller"
40
40
  spec.add_runtime_dependency "pry"
41
+ spec.add_runtime_dependency "highline"
41
42
  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.2.2
4
+ version: 1.3.0
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-15 00:00:00.000000000 Z
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: highline
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: See webpage for more info.
168
182
  email:
169
183
  - a@a0.cl
@@ -192,6 +206,7 @@ files:
192
206
  - lib/webdrone/find.rb
193
207
  - lib/webdrone/form.rb
194
208
  - lib/webdrone/html.rb
209
+ - lib/webdrone/logg.rb
195
210
  - lib/webdrone/mark.rb
196
211
  - lib/webdrone/open.rb
197
212
  - lib/webdrone/shot.rb