webdrone 1.7.8 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.relaxed.yml +165 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -1
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/webdrone.rb +35 -27
- data/lib/webdrone/browser.rb +96 -82
- data/lib/webdrone/clic.rb +5 -3
- data/lib/webdrone/conf.rb +12 -9
- data/lib/webdrone/ctxt.rb +23 -21
- data/lib/webdrone/error.rb +57 -56
- data/lib/webdrone/exec.rb +5 -3
- data/lib/webdrone/find.rb +39 -36
- data/lib/webdrone/form.rb +41 -35
- data/lib/webdrone/html.rb +6 -4
- data/lib/webdrone/logg.rb +50 -40
- data/lib/webdrone/mark.rb +9 -6
- data/lib/webdrone/open.rb +7 -5
- data/lib/webdrone/shot.rb +7 -5
- data/lib/webdrone/text.rb +7 -5
- data/lib/webdrone/version.rb +3 -1
- data/lib/webdrone/vrfy.rb +19 -19
- data/lib/webdrone/wait.rb +8 -5
- data/lib/webdrone/xlsx.rb +53 -38
- data/lib/webdrone/xpath.rb +168 -0
- data/webdrone.gemspec +27 -28
- metadata +55 -24
data/lib/webdrone/form.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def form
|
@@ -6,7 +8,8 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Form
|
9
|
-
attr_accessor :
|
11
|
+
attr_accessor :data
|
12
|
+
attr_reader :a0
|
10
13
|
|
11
14
|
def initialize(a0)
|
12
15
|
@a0 = a0
|
@@ -15,9 +18,9 @@ module Webdrone
|
|
15
18
|
|
16
19
|
def with_xpath(xpath = nil, &block)
|
17
20
|
old_xpath, @xpath = @xpath, xpath
|
18
|
-
instance_eval
|
19
|
-
rescue =>
|
20
|
-
Webdrone.report_error(@a0,
|
21
|
+
instance_eval(&block)
|
22
|
+
rescue StandardError => error
|
23
|
+
Webdrone.report_error(@a0, error)
|
21
24
|
ensure
|
22
25
|
@xpath = old_xpath
|
23
26
|
end
|
@@ -29,15 +32,15 @@ module Webdrone
|
|
29
32
|
|
30
33
|
yield
|
31
34
|
ensure
|
32
|
-
File.open(".#{filename}.lock", File::RDWR | File::CREAT,
|
35
|
+
File.open(".#{filename}.lock", File::RDWR | File::CREAT, 0o644) do
|
33
36
|
items = {}
|
34
37
|
items[item] = data
|
35
38
|
|
36
39
|
begin
|
37
40
|
workbook = RubyXL::Parser.parse(filename)
|
38
41
|
worksheet = workbook[sheet]
|
39
|
-
worksheet
|
40
|
-
rescue
|
42
|
+
worksheet ||= workbook.add_worksheet sheet
|
43
|
+
rescue StandardError
|
41
44
|
workbook = RubyXL::Workbook.new
|
42
45
|
worksheet = workbook[0]
|
43
46
|
worksheet.sheet_name = sheet
|
@@ -45,7 +48,7 @@ module Webdrone
|
|
45
48
|
|
46
49
|
rows = worksheet.sheet_data.rows.collect do |row|
|
47
50
|
row.cells.collect do |cell|
|
48
|
-
cell
|
51
|
+
cell&.value
|
49
52
|
end
|
50
53
|
end
|
51
54
|
heads = rows.shift || []
|
@@ -54,11 +57,11 @@ module Webdrone
|
|
54
57
|
key = nil
|
55
58
|
row.each_with_index do |val, i|
|
56
59
|
val = val.to_s if val
|
57
|
-
if i
|
60
|
+
if i.zero?
|
58
61
|
key = val
|
59
62
|
elsif key
|
60
63
|
items[key] = {} unless items[key]
|
61
|
-
items[key][heads[i]] = val if heads[i]
|
64
|
+
items[key][heads[i]] = val if !heads[i].nil? && items[key][heads[i]].nil?
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
@@ -88,10 +91,10 @@ module Webdrone
|
|
88
91
|
end
|
89
92
|
|
90
93
|
def set(key, val, n: 1, visible: true, scroll: false, parent: nil, mark: false)
|
91
|
-
item =
|
94
|
+
item = find_item(key, n: n, visible: visible, scroll: scroll, parent: parent)
|
92
95
|
@a0.mark.mark_item item if mark
|
93
96
|
if item.tag_name == 'select'
|
94
|
-
option = item.find_element :xpath, XPath
|
97
|
+
option = item.find_element :xpath, Webdrone::XPath.option(val).to_s
|
95
98
|
option.click
|
96
99
|
else
|
97
100
|
item.clear
|
@@ -99,56 +102,59 @@ module Webdrone
|
|
99
102
|
end
|
100
103
|
@data[key] = val if @data
|
101
104
|
nil
|
102
|
-
rescue =>
|
103
|
-
Webdrone.report_error(@a0,
|
105
|
+
rescue StandardError => error
|
106
|
+
Webdrone.report_error(@a0, error)
|
104
107
|
end
|
105
108
|
|
106
109
|
def get(key, n: 1, visible: true, scroll: false, parent: nil, mark: false)
|
107
|
-
item =
|
110
|
+
item = find_item(key, n: n, visible: visible, scroll: scroll, parent: parent)
|
108
111
|
@a0.mark.mark_item item if mark
|
109
112
|
item[:value]
|
110
|
-
rescue =>
|
111
|
-
Webdrone.report_error(@a0,
|
113
|
+
rescue StandardError => error
|
114
|
+
Webdrone.report_error(@a0, error)
|
112
115
|
end
|
113
116
|
|
114
117
|
def clic(key, n: 1, visible: true, scroll: false, parent: nil, mark: false)
|
115
|
-
item =
|
118
|
+
item = find_item(key, n: n, visible: visible, scroll: scroll, parent: parent)
|
116
119
|
@a0.mark.mark_item item if mark
|
117
120
|
item.click
|
118
|
-
rescue =>
|
119
|
-
Webdrone.report_error(@a0,
|
121
|
+
rescue StandardError => error
|
122
|
+
Webdrone.report_error(@a0, error)
|
120
123
|
end
|
121
124
|
|
122
125
|
def mark(key, n: 1, visible: true, scroll: false, parent: nil, color: '#af1616', times: nil, delay: nil, shot: nil)
|
123
|
-
@a0.mark.mark_item
|
124
|
-
rescue =>
|
125
|
-
Webdrone.report_error(@a0,
|
126
|
+
@a0.mark.mark_item find_item(key, n: n, visible: visible, scroll: scroll, parent: parent), color: color, times: times, delay: delay, shot: shot
|
127
|
+
rescue StandardError => error
|
128
|
+
Webdrone.report_error(@a0, error)
|
126
129
|
end
|
127
130
|
|
128
131
|
def submit(key = nil, n: 1, visible: true, scroll: false, parent: nil, mark: false)
|
129
|
-
|
132
|
+
item = find_item(key, n: n, visible: visible, scroll: scroll, parent: parent) if key
|
133
|
+
@a0.mark.mark_item item if mark
|
130
134
|
@lastitem.submit
|
131
|
-
rescue =>
|
132
|
-
Webdrone.report_error(@a0,
|
135
|
+
rescue StandardError => error
|
136
|
+
Webdrone.report_error(@a0, error)
|
133
137
|
end
|
134
138
|
|
135
139
|
def xlsx(sheet: nil, filename: nil)
|
136
140
|
@a0.xlsx.dict(sheet: sheet, filename: filename).each do |k, v|
|
137
|
-
|
141
|
+
set k, v
|
138
142
|
end
|
139
|
-
rescue =>
|
140
|
-
Webdrone.report_error(@a0,
|
143
|
+
rescue StandardError => error
|
144
|
+
Webdrone.report_error(@a0, error)
|
141
145
|
end
|
142
146
|
|
143
147
|
protected
|
144
|
-
|
148
|
+
|
149
|
+
def find_item(key, n: 1, visible: true, scroll: false, parent: nil)
|
150
|
+
@lastitem = \
|
145
151
|
if @xpath.respond_to? :call
|
146
|
-
@
|
147
|
-
elsif @xpath.is_a?
|
148
|
-
@
|
152
|
+
@a0.find.xpath @xpath.call(key).to_s, n: n, visible: visible, scroll: scroll, parent: parent
|
153
|
+
elsif @xpath.is_a?(String) && @xpath.include?('%s')
|
154
|
+
@a0.find.xpath sprintf(@xpath, key), n: n, visible: visible, scroll: scroll, parent: parent
|
149
155
|
else
|
150
|
-
@
|
156
|
+
@a0.find.xpath Webdrone::XPath.field(key).to_s, n: n, visible: visible, scroll: scroll, parent: parent
|
151
157
|
end
|
152
|
-
|
158
|
+
end
|
153
159
|
end
|
154
160
|
end
|
data/lib/webdrone/html.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def html
|
@@ -6,7 +8,7 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Html
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
@@ -15,12 +17,12 @@ module Webdrone
|
|
15
17
|
def find_html(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
16
18
|
item = @a0.find.send __callee__, text, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
17
19
|
if item.is_a? Array
|
18
|
-
item.collect { |x| x.attribute 'innerHTML'}
|
20
|
+
item.collect { |x| x.attribute 'innerHTML' }
|
19
21
|
else
|
20
22
|
item.attribute 'innerHTML'
|
21
23
|
end
|
22
|
-
rescue =>
|
23
|
-
Webdrone.report_error(@a0,
|
24
|
+
rescue StandardError => error
|
25
|
+
Webdrone.report_error(@a0, error)
|
24
26
|
end
|
25
27
|
|
26
28
|
alias_method :id, :find_html
|
data/lib/webdrone/logg.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class MethodLogger < Module
|
3
|
-
|
4
|
-
|
5
|
+
class << self
|
6
|
+
attr_accessor :last_time, :screenshot
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(methods = nil)
|
10
|
+
@methods = methods
|
5
11
|
end
|
6
12
|
|
7
13
|
def included(base)
|
8
|
-
@
|
9
|
-
method_list = @
|
14
|
+
@methods ||= base.instance_methods(false)
|
15
|
+
method_list = @methods
|
10
16
|
base.class_eval do
|
11
17
|
method_list.each do |method_name|
|
12
18
|
original_method = instance_method(method_name)
|
@@ -14,18 +20,17 @@ module Webdrone
|
|
14
20
|
caller_location = Kernel.caller_locations[0]
|
15
21
|
cl_path = caller_location.path
|
16
22
|
cl_line = caller_location.lineno
|
17
|
-
if @a0.conf.logger
|
18
|
-
|
19
|
-
|
20
|
-
$a0_webdrone_screenshot = nil
|
23
|
+
if @a0.conf.logger && Gem.path.none? { |path| cl_path.include? path }
|
24
|
+
ini = ::Webdrone::MethodLogger.last_time ||= Time.new
|
25
|
+
::Webdrone::MethodLogger.screenshot = nil
|
21
26
|
begin
|
22
27
|
result = original_method.bind(self).call(*args, &block)
|
23
|
-
fin =
|
24
|
-
@a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, result, nil,
|
28
|
+
fin = ::Webdrone::MethodLogger.last_time = Time.new
|
29
|
+
@a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, result, nil, ::Webdrone::MethodLogger.screenshot)
|
25
30
|
result
|
26
|
-
rescue => exception
|
27
|
-
fin =
|
28
|
-
@a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, nil, exception,
|
31
|
+
rescue StandardError => exception
|
32
|
+
fin = ::Webdrone::MethodLogger.last_time = Time.new
|
33
|
+
@a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, nil, exception, ::Webdrone::MethodLogger.screenshot)
|
29
34
|
raise exception
|
30
35
|
end
|
31
36
|
else
|
@@ -44,7 +49,7 @@ module Webdrone
|
|
44
49
|
end
|
45
50
|
|
46
51
|
class Logs
|
47
|
-
|
52
|
+
attr_reader :a0
|
48
53
|
|
49
54
|
def initialize(a0)
|
50
55
|
@a0 = a0
|
@@ -55,9 +60,9 @@ module Webdrone
|
|
55
60
|
|
56
61
|
def trace(ini, fin, from, lineno, base, method_name, args, result, exception, screenshot)
|
57
62
|
exception = "#{exception.class}: #{exception}" if exception
|
58
|
-
printf @format, (fin-ini), base, method_name, args, (result || exception)
|
63
|
+
printf @format, (fin - ini), base, method_name, args, (result || exception)
|
59
64
|
CSV.open(@path, "a+") do |csv|
|
60
|
-
csv << [ini.strftime('%Y-%m-%d %H:%M:%S.%L %z'), (fin-ini), from, lineno, base, method_name, args, result, exception, screenshot]
|
65
|
+
csv << [ini.strftime('%Y-%m-%d %H:%M:%S.%L %z'), (fin - ini), from, lineno, base, method_name, args, result, exception, screenshot]
|
61
66
|
end
|
62
67
|
@group_trace_count = @group_trace_count.map { |x| x + 1 }
|
63
68
|
end
|
@@ -72,28 +77,33 @@ module Webdrone
|
|
72
77
|
exception = nil
|
73
78
|
begin
|
74
79
|
yield
|
75
|
-
rescue => e
|
80
|
+
rescue StandardError => e
|
76
81
|
exception = e
|
77
82
|
bindings = Kernel.binding.callers
|
78
|
-
bindings[0..-1].
|
83
|
+
bindings[0..-1].each do |binding|
|
79
84
|
location = { path: binding.eval('__FILE__'), lineno: binding.eval('__LINE__') }
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
next unless Gem.path.none? { |path| location[:path].include? path }
|
86
|
+
|
87
|
+
result[:exception] = {}
|
88
|
+
result[:exception][:line] = location[:lineno]
|
89
|
+
result[:exception][:path] = location[:path]
|
90
|
+
|
91
|
+
break
|
92
|
+
end
|
87
93
|
end
|
88
94
|
result[:trace_count] = @group_trace_count.pop
|
89
95
|
fin = Time.new
|
90
96
|
trace(ini, fin, cl_path, cl_line, Logs, :with_group, [name, abort_error: abort_error], result, exception, nil)
|
91
97
|
puts "abort_error: #{abort_error} exception: #{exception}"
|
92
|
-
exit if abort_error == true
|
98
|
+
exit if abort_error == true && exception
|
93
99
|
end
|
94
100
|
|
95
101
|
def setup_format
|
96
|
-
|
102
|
+
begin
|
103
|
+
cols, _line = HighLine.default_instance.terminal.terminal_size
|
104
|
+
rescue StandardError
|
105
|
+
cols = 120
|
106
|
+
end
|
97
107
|
total = 6 + 15 + 11 + 5
|
98
108
|
w = cols - total
|
99
109
|
w /= 2
|
@@ -128,54 +138,54 @@ module Webdrone
|
|
128
138
|
end
|
129
139
|
|
130
140
|
class Clic
|
131
|
-
include MethodLogger.new [
|
141
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
132
142
|
end
|
133
143
|
|
134
144
|
class Conf
|
135
|
-
include MethodLogger.new [
|
145
|
+
include MethodLogger.new %i[timeout= outdir= error= developer= logger=]
|
136
146
|
end
|
137
147
|
|
138
148
|
class Ctxt
|
139
|
-
include MethodLogger.new [
|
149
|
+
include MethodLogger.new %i[create_tab close_tab with_frame reset with_alert ignore_alert with_conf]
|
140
150
|
end
|
141
151
|
|
142
152
|
class Find
|
143
|
-
include MethodLogger.new [
|
153
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
144
154
|
end
|
145
155
|
|
146
156
|
class Form
|
147
|
-
include MethodLogger.new [
|
157
|
+
include MethodLogger.new %i[with_xpath save set get clic mark submit xlsx]
|
148
158
|
end
|
149
159
|
|
150
160
|
class Html
|
151
|
-
include MethodLogger.new [
|
161
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
152
162
|
end
|
153
163
|
|
154
164
|
class Mark
|
155
|
-
include MethodLogger.new [
|
165
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
156
166
|
end
|
157
167
|
|
158
168
|
class Open
|
159
|
-
include MethodLogger.new [
|
169
|
+
include MethodLogger.new %i[url reload]
|
160
170
|
end
|
161
171
|
|
162
172
|
class Shot
|
163
|
-
include MethodLogger.new [
|
173
|
+
include MethodLogger.new %i[screen]
|
164
174
|
end
|
165
175
|
|
166
176
|
class Text
|
167
|
-
include MethodLogger.new [
|
177
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
168
178
|
end
|
169
179
|
|
170
180
|
class Vrfy
|
171
|
-
include MethodLogger.new [
|
181
|
+
include MethodLogger.new %i[id css link button on option xpath]
|
172
182
|
end
|
173
183
|
|
174
184
|
class Wait
|
175
|
-
include MethodLogger.new [
|
185
|
+
include MethodLogger.new %i[for time]
|
176
186
|
end
|
177
187
|
|
178
188
|
class Xlsx
|
179
|
-
include MethodLogger.new [
|
189
|
+
include MethodLogger.new %i[dict rows both save reset]
|
180
190
|
end
|
181
191
|
end
|
data/lib/webdrone/mark.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def mark
|
@@ -6,7 +8,8 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Mark
|
9
|
-
attr_accessor :
|
11
|
+
attr_accessor :default_times, :default_delay, :clear
|
12
|
+
attr_reader :a0
|
10
13
|
|
11
14
|
def initialize(a0)
|
12
15
|
@a0 = a0
|
@@ -18,8 +21,8 @@ module Webdrone
|
|
18
21
|
def mark(text, n: 1, all: false, visible: true, scroll: false, parent: nil, color: '#af1616', times: nil, delay: nil, shot: nil)
|
19
22
|
item = @a0.find.send __callee__, text, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
20
23
|
mark_item item, color: color, times: times, delay: delay, shot: shot, text: text
|
21
|
-
rescue =>
|
22
|
-
Webdrone.report_error(@a0,
|
24
|
+
rescue StandardError => error
|
25
|
+
Webdrone.report_error(@a0, error)
|
23
26
|
end
|
24
27
|
|
25
28
|
alias_method :id, :mark
|
@@ -41,7 +44,7 @@ module Webdrone
|
|
41
44
|
mark_item_border item, color
|
42
45
|
sleep delay
|
43
46
|
end
|
44
|
-
@a0.shot.screen shot.is_a?(String) ? shot : text
|
47
|
+
@a0.shot.screen shot.is_a?(String) ? shot : text if shot
|
45
48
|
mark_clear item if @clear
|
46
49
|
item
|
47
50
|
end
|
@@ -54,8 +57,8 @@ module Webdrone
|
|
54
57
|
style = color ? "'2px solid #{color}'" : "null"
|
55
58
|
set_outline = "arguments[0].style.outline = #{style}"
|
56
59
|
if item.is_a? Array
|
57
|
-
item.each do |
|
58
|
-
@a0.exec.script(set_outline,
|
60
|
+
item.each do |subitem|
|
61
|
+
@a0.exec.script(set_outline, subitem)
|
59
62
|
end
|
60
63
|
else
|
61
64
|
@a0.exec.script(set_outline, item)
|
data/lib/webdrone/open.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def open
|
@@ -6,7 +8,7 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Open
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
@@ -14,14 +16,14 @@ module Webdrone
|
|
14
16
|
|
15
17
|
def url(url)
|
16
18
|
@a0.driver.get url
|
17
|
-
rescue =>
|
18
|
-
Webdrone.report_error(@a0,
|
19
|
+
rescue StandardError => error
|
20
|
+
Webdrone.report_error(@a0, error)
|
19
21
|
end
|
20
22
|
|
21
23
|
def reload
|
22
24
|
@a0.driver.navigate.refresh
|
23
|
-
rescue =>
|
24
|
-
Webdrone.report_error(@a0,
|
25
|
+
rescue StandardError => error
|
26
|
+
Webdrone.report_error(@a0, error)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|