webdrone 1.7.8 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/clic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def clic
|
@@ -6,7 +8,7 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Clic
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
@@ -24,8 +26,8 @@ module Webdrone
|
|
24
26
|
else
|
25
27
|
item.click
|
26
28
|
end
|
27
|
-
rescue =>
|
28
|
-
Webdrone.report_error(@a0,
|
29
|
+
rescue StandardError => error
|
30
|
+
Webdrone.report_error(@a0, error)
|
29
31
|
end
|
30
32
|
|
31
33
|
alias_method :id, :clic
|
data/lib/webdrone/conf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def conf
|
@@ -6,33 +8,34 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Conf
|
9
|
-
attr_accessor :
|
11
|
+
attr_accessor :developer, :logger
|
12
|
+
attr_reader :a0, :timeout, :outdir, :error
|
10
13
|
|
11
14
|
def initialize(a0)
|
12
15
|
@a0 = a0
|
13
|
-
@outdir =
|
16
|
+
@outdir = '.'
|
14
17
|
@error = :raise_report
|
15
18
|
end
|
16
19
|
|
17
20
|
def timeout=(val)
|
18
21
|
@timeout = val
|
19
22
|
@a0.driver.manage.timeouts.implicit_wait = val
|
20
|
-
rescue =>
|
21
|
-
Webdrone.report_error(@a0,
|
23
|
+
rescue StandardError => error
|
24
|
+
Webdrone.report_error(@a0, error)
|
22
25
|
end
|
23
26
|
|
24
27
|
def outdir=(val)
|
25
28
|
@outdir = val
|
26
29
|
FileUtils.mkdir_p val
|
27
|
-
rescue =>
|
28
|
-
Webdrone.report_error(@a0,
|
30
|
+
rescue StandardError => error
|
31
|
+
Webdrone.report_error(@a0, error)
|
29
32
|
end
|
30
33
|
|
31
34
|
def error=(val)
|
32
|
-
raise "Invalid value '#{val}' for error" if
|
35
|
+
raise "Invalid value '#{val}' for error" if !%i[raise_report raise ignore].include? val
|
33
36
|
@error = val
|
34
|
-
rescue =>
|
35
|
-
Webdrone.report_error(@a0,
|
37
|
+
rescue StandardError => error
|
38
|
+
Webdrone.report_error(@a0, error)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
data/lib/webdrone/ctxt.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def ctxt
|
@@ -6,29 +8,29 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Ctxt
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
13
15
|
@framestack = []
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
def create_tab
|
17
19
|
@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
20
|
@a0.driver.switch_to.window @a0.driver.window_handles.last
|
19
|
-
rescue =>
|
20
|
-
Webdrone.report_error(@a0,
|
21
|
+
rescue StandardError => error
|
22
|
+
Webdrone.report_error(@a0, error)
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
def close_tab
|
24
26
|
@a0.driver.close
|
25
27
|
@a0.driver.switch_to.window @a0.driver.window_handles.last
|
26
|
-
rescue =>
|
27
|
-
Webdrone.report_error(@a0,
|
28
|
+
rescue StandardError => error
|
29
|
+
Webdrone.report_error(@a0, error)
|
28
30
|
end
|
29
31
|
|
30
32
|
def with_frame(name)
|
31
|
-
@framestack << name
|
33
|
+
@framestack << name
|
32
34
|
@a0.driver.switch_to.frame name
|
33
35
|
if block_given?
|
34
36
|
begin
|
@@ -36,33 +38,33 @@ module Webdrone
|
|
36
38
|
ensure
|
37
39
|
@framestack.pop
|
38
40
|
@a0.driver.switch_to.default_content
|
39
|
-
@framestack.each { |frame| @a0.driver.switch_to.frame frame}
|
41
|
+
@framestack.each { |frame| @a0.driver.switch_to.frame frame }
|
40
42
|
end
|
41
43
|
end
|
42
44
|
name
|
43
|
-
rescue =>
|
44
|
-
Webdrone.report_error(@a0,
|
45
|
+
rescue StandardError => error
|
46
|
+
Webdrone.report_error(@a0, error)
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
def reset
|
48
50
|
@a0.driver.switch_to.default_content
|
49
51
|
@framestack = []
|
50
|
-
rescue =>
|
51
|
-
Webdrone.report_error(@a0,
|
52
|
+
rescue StandardError => error
|
53
|
+
Webdrone.report_error(@a0, error)
|
52
54
|
end
|
53
|
-
|
55
|
+
|
54
56
|
def with_alert
|
55
57
|
@a0.wait.for do
|
56
58
|
yield @a0.driver.switch_to.alert
|
57
59
|
end
|
58
|
-
rescue =>
|
59
|
-
Webdrone.report_error(@a0,
|
60
|
+
rescue StandardError => error
|
61
|
+
Webdrone.report_error(@a0, error)
|
60
62
|
end
|
61
63
|
|
62
64
|
def ignore_alert
|
63
65
|
@a0.exec.script 'alert = function(message){return true;};'
|
64
|
-
rescue =>
|
65
|
-
Webdrone.report_error(@a0,
|
66
|
+
rescue StandardError => error
|
67
|
+
Webdrone.report_error(@a0, error)
|
66
68
|
end
|
67
69
|
|
68
70
|
def with_conf(new_config)
|
@@ -74,8 +76,8 @@ module Webdrone
|
|
74
76
|
end
|
75
77
|
|
76
78
|
yield
|
77
|
-
rescue =>
|
78
|
-
Webdrone.report_error(@a0,
|
79
|
+
rescue StandardError => error
|
80
|
+
Webdrone.report_error(@a0, error)
|
79
81
|
ensure
|
80
82
|
current_config.each do |k, v|
|
81
83
|
@a0.conf.send "#{k}=", v
|
data/lib/webdrone/error.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class WebdroneError < RuntimeError
|
3
5
|
attr_reader :original, :a0, :binding
|
4
6
|
|
5
|
-
def initialize(msg, original
|
7
|
+
def initialize(msg, original, a0, bindings)
|
6
8
|
super(msg)
|
7
|
-
@original = original
|
9
|
+
@original = original || $!
|
8
10
|
@a0 = a0
|
9
11
|
@buffer = []
|
10
12
|
@binding = nil
|
@@ -12,17 +14,18 @@ module Webdrone
|
|
12
14
|
|
13
15
|
begin
|
14
16
|
# find location of user error
|
15
|
-
bindings[0..-1].
|
17
|
+
bindings[0..-1].each do |binding|
|
16
18
|
location = { path: binding.eval('__FILE__'), lineno: binding.eval('__LINE__') }
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
next unless Gem.path.none? { |path| location[:path].include? path }
|
20
|
+
|
21
|
+
@location = location
|
22
|
+
@binding = binding
|
23
|
+
break
|
22
24
|
end
|
23
25
|
|
24
26
|
report if a0.conf.error == :raise_report
|
25
|
-
rescue
|
27
|
+
rescue StandardError
|
28
|
+
nil
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -33,11 +36,12 @@ module Webdrone
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def write_title(title)
|
36
|
-
title = "#{title} " if title.length
|
39
|
+
title = "#{title} " if title.length.odd?
|
37
40
|
title = "== #{title} =="
|
38
41
|
filler = "="
|
39
42
|
length = (80 - title.length) / 2
|
40
|
-
|
43
|
+
filler_length = filler * length
|
44
|
+
title = "#{filler_length}#{title}#{filler_length}\n" if length > 1
|
41
45
|
write_line title
|
42
46
|
end
|
43
47
|
|
@@ -57,61 +61,58 @@ module Webdrone
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def report_script
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
write_line sprintf "%3d %s", lno, line
|
72
|
-
end
|
64
|
+
ini, fin = [@location[:lineno] - 10 - 1, @location[:lineno] + 10 - 1]
|
65
|
+
ini = 0 if ini.negative?
|
66
|
+
|
67
|
+
write_title "LOCATION OF ERROR"
|
68
|
+
write_line "#{@location[:path]} AT LINE #{sprintf '%3d', @location[:lineno]}"
|
69
|
+
File.readlines(@location[:path])[ini..fin].each_with_index do |line, index|
|
70
|
+
lno = index + ini + 1
|
71
|
+
if lno == @location[:lineno]
|
72
|
+
write_line sprintf "%3d ==> #{line}", lno
|
73
|
+
else
|
74
|
+
write_line sprintf "%3d #{line}", lno
|
73
75
|
end
|
74
|
-
|
75
|
-
dump_error_report
|
76
|
-
rescue
|
77
76
|
end
|
77
|
+
|
78
|
+
dump_error_report
|
79
|
+
rescue StandardError
|
80
|
+
nil
|
78
81
|
end
|
79
82
|
|
80
83
|
def report_screenshot
|
84
|
+
write_title "AUTOMATIC SCREENSHOT"
|
81
85
|
begin
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
write_line "Screenshot saved succesfully filename:"
|
87
|
-
write_line "#{File.expand_path(file.path)}"
|
88
|
-
end
|
89
|
-
rescue => exception
|
90
|
-
write_line "Error Saving screenshot, exception:"
|
91
|
-
write_line "#{exception}"
|
86
|
+
@a0.ctxt.with_conf error: :raise do
|
87
|
+
file = @a0.shot.screen 'a0_webdrone_error_report'
|
88
|
+
write_line "Screenshot saved succesfully filename:"
|
89
|
+
write_line File.expand_path(file.path).to_s
|
92
90
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
rescue StandardError => error
|
92
|
+
write_line "Error Saving screenshot, exception:"
|
93
|
+
write_line error.to_s
|
96
94
|
end
|
95
|
+
|
96
|
+
dump_error_report
|
97
|
+
rescue StandardError
|
98
|
+
nil
|
97
99
|
end
|
98
100
|
|
99
101
|
def report_exception
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
@
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
write_line sprintf "%02d: from %s", index, location
|
109
|
-
end
|
102
|
+
write_title "EXCEPTION DUMP"
|
103
|
+
|
104
|
+
write_line "#{@original.class}: #{@original.message}"
|
105
|
+
@original.backtrace_locations.each_with_index do |location, index|
|
106
|
+
if location.path == @location[:path] && location.lineno == @location[:lineno]
|
107
|
+
write_line sprintf "%02d: ==> from #{location}", index
|
108
|
+
else
|
109
|
+
write_line sprintf "%02d: from #{location}", index
|
110
110
|
end
|
111
|
-
|
112
|
-
dump_error_report
|
113
|
-
rescue
|
114
111
|
end
|
112
|
+
|
113
|
+
dump_error_report
|
114
|
+
rescue StandardError
|
115
|
+
nil
|
115
116
|
end
|
116
117
|
|
117
118
|
def report_os
|
@@ -124,7 +125,7 @@ module Webdrone
|
|
124
125
|
end
|
125
126
|
|
126
127
|
def report_time
|
127
|
-
write_title
|
128
|
+
write_title Time.new.to_s
|
128
129
|
|
129
130
|
dump_error_report
|
130
131
|
end
|
@@ -134,13 +135,13 @@ module Webdrone
|
|
134
135
|
return if a0.conf.error == :ignore
|
135
136
|
if exception.class != WebdroneError
|
136
137
|
exception = WebdroneError.new(exception.message, exception, a0, Kernel.binding.callers)
|
137
|
-
if a0.conf.developer
|
138
|
+
if a0.conf.developer && exception.binding
|
138
139
|
exception.write_title "STARTING DEVELOPER CONSOLE ON ERROR"
|
139
140
|
exception.dump_error_report
|
140
141
|
a0.console exception.binding
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
144
|
-
raise exception if
|
145
|
+
raise exception if %i[raise raise_report].include? a0.conf.error
|
145
146
|
end
|
146
147
|
end
|
data/lib/webdrone/exec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def exec
|
@@ -6,7 +8,7 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Exec
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
@@ -14,8 +16,8 @@ module Webdrone
|
|
14
16
|
|
15
17
|
def script(script, *more)
|
16
18
|
@a0.driver.execute_script(script, *more)
|
17
|
-
rescue =>
|
18
|
-
Webdrone.report_error(@a0,
|
19
|
+
rescue StandardError => error
|
20
|
+
Webdrone.report_error(@a0, error)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/webdrone/find.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webdrone
|
2
4
|
class Browser
|
3
5
|
def find
|
@@ -6,7 +8,7 @@ module Webdrone
|
|
6
8
|
end
|
7
9
|
|
8
10
|
class Find
|
9
|
-
|
11
|
+
attr_reader :a0
|
10
12
|
|
11
13
|
def initialize(a0)
|
12
14
|
@a0 = a0
|
@@ -17,8 +19,8 @@ module Webdrone
|
|
17
19
|
items = (parent || @a0.driver).find_elements :id, text
|
18
20
|
choose(items, n, all, visible, scroll)
|
19
21
|
end
|
20
|
-
rescue =>
|
21
|
-
Webdrone.report_error(@a0,
|
22
|
+
rescue StandardError => error
|
23
|
+
Webdrone.report_error(@a0, error)
|
22
24
|
end
|
23
25
|
|
24
26
|
def css(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
@@ -26,32 +28,32 @@ module Webdrone
|
|
26
28
|
items = (parent || @a0.driver).find_elements :css, text
|
27
29
|
choose(items, n, all, visible, scroll)
|
28
30
|
end
|
29
|
-
rescue =>
|
30
|
-
Webdrone.report_error(@a0,
|
31
|
+
rescue StandardError => error
|
32
|
+
Webdrone.report_error(@a0, error)
|
31
33
|
end
|
32
34
|
|
33
35
|
def link(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
34
|
-
|
35
|
-
rescue =>
|
36
|
-
Webdrone.report_error(@a0,
|
36
|
+
xpath Webdrone::XPath.link(text).to_s, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
37
|
+
rescue StandardError => error
|
38
|
+
Webdrone.report_error(@a0, error)
|
37
39
|
end
|
38
40
|
|
39
41
|
def button(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
40
|
-
|
41
|
-
rescue =>
|
42
|
-
Webdrone.report_error(@a0,
|
42
|
+
xpath Webdrone::XPath.button(text).to_s, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
43
|
+
rescue StandardError => error
|
44
|
+
Webdrone.report_error(@a0, error)
|
43
45
|
end
|
44
46
|
|
45
47
|
def on(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
46
|
-
|
47
|
-
rescue =>
|
48
|
-
Webdrone.report_error(@a0,
|
48
|
+
xpath Webdrone::XPath.link_or_button(text).to_s, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
49
|
+
rescue StandardError => error
|
50
|
+
Webdrone.report_error(@a0, error)
|
49
51
|
end
|
50
52
|
|
51
53
|
def option(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
52
|
-
|
53
|
-
rescue =>
|
54
|
-
Webdrone.report_error(@a0,
|
54
|
+
xpath Webdrone::XPath.option(text).to_s, n: n, all: all, visible: visible, scroll: scroll, parent: parent
|
55
|
+
rescue StandardError => error
|
56
|
+
Webdrone.report_error(@a0, error)
|
55
57
|
end
|
56
58
|
|
57
59
|
def xpath(text, n: 1, all: false, visible: true, scroll: false, parent: nil)
|
@@ -59,31 +61,32 @@ module Webdrone
|
|
59
61
|
items = (parent || @a0.driver).find_elements :xpath, text
|
60
62
|
choose(items, n, all, visible, scroll)
|
61
63
|
end
|
62
|
-
rescue =>
|
63
|
-
Webdrone.report_error(@a0,
|
64
|
+
rescue StandardError => error
|
65
|
+
Webdrone.report_error(@a0, error)
|
64
66
|
end
|
65
67
|
|
66
68
|
protected
|
67
|
-
def choose(list, n, all, visible, scroll)
|
68
|
-
list = list.select do |x|
|
69
|
-
if visible == true
|
70
|
-
x.displayed?
|
71
|
-
elsif visible == false
|
72
|
-
not x.displayed?
|
73
|
-
else
|
74
|
-
true
|
75
|
-
end
|
76
|
-
end
|
77
69
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
70
|
+
def choose(list, n, all, visible, scroll)
|
71
|
+
list = list.select do |x|
|
72
|
+
if visible == true
|
73
|
+
x.displayed?
|
74
|
+
elsif visible == false
|
75
|
+
!x.displayed?
|
84
76
|
else
|
85
|
-
|
77
|
+
true
|
86
78
|
end
|
87
79
|
end
|
80
|
+
|
81
|
+
if scroll && list.length.positive?
|
82
|
+
@a0.exec.script 'arguments[0].scrollIntoView()', list.first
|
83
|
+
end
|
84
|
+
|
85
|
+
if all
|
86
|
+
list
|
87
|
+
else
|
88
|
+
list[n - 1]
|
89
|
+
end
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|