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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 79f6baed6b1b3a6dfa49139033fcf90ca441455f
4
- data.tar.gz: e6db81816ea558f73cb6345fcb21e4f35f6cc880
2
+ SHA256:
3
+ metadata.gz: 76c2f2e2bb45e0e189f030c402625b90b08e57e1628550a70e5415d7b109f489
4
+ data.tar.gz: 0714440a727a83fd63064acafc7c54e69b0803fd1b183f8e4033a3f07ff45eed
5
5
  SHA512:
6
- metadata.gz: 5dae707651daccdae02d26ebe4f8322c9eddac50049bce86f21a15bc085df3ca18146f2c5426a35ec4d60ae105b3e0317f69e600c7d4bda127b7b78754a1b64d
7
- data.tar.gz: aa2ba3f30b3c52ce3d62d0183397c93a64930e354f2f18ce1bbaad2a9d0ee44d67bd75e57e021e6f5dbaf571800b286ed328110ec5d5bc476e5c92f4f045ddf5
6
+ metadata.gz: 1c2396c6fa5fcd968b682221e1194cb5aa562cffa4408c28b41bc91c24a92a26adafeeb04d17ae5af12f53d0f81819046f3efb5c8b9e2f951efe11c72beebd61
7
+ data.tar.gz: bca0e11fc656f8a3d75ec7149dcc62937e38288c6aa8a7658b0ab9bfbab0675c2c89bcb050199302343ce3477cf2f4924faf8096c7262dd29e3e9c77921d5c9a
@@ -0,0 +1,165 @@
1
+ # Relaxed.Ruby.Style
2
+ ## Version 2.2
3
+
4
+ Style/Alias:
5
+ Enabled: false
6
+ StyleGuide: https://relaxed.ruby.style/#stylealias
7
+
8
+ Style/AsciiComments:
9
+ Enabled: false
10
+ StyleGuide: https://relaxed.ruby.style/#styleasciicomments
11
+
12
+ Style/BeginBlock:
13
+ Enabled: false
14
+ StyleGuide: https://relaxed.ruby.style/#stylebeginblock
15
+
16
+ Style/BlockDelimiters:
17
+ Enabled: false
18
+ StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
19
+
20
+ Style/CommentAnnotation:
21
+ Enabled: false
22
+ StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+ StyleGuide: https://relaxed.ruby.style/#styledocumentation
27
+
28
+ Layout/DotPosition:
29
+ Enabled: false
30
+ StyleGuide: https://relaxed.ruby.style/#layoutdotposition
31
+
32
+ Style/DoubleNegation:
33
+ Enabled: false
34
+ StyleGuide: https://relaxed.ruby.style/#styledoublenegation
35
+
36
+ Style/EndBlock:
37
+ Enabled: false
38
+ StyleGuide: https://relaxed.ruby.style/#styleendblock
39
+
40
+ Style/FormatString:
41
+ Enabled: false
42
+ StyleGuide: https://relaxed.ruby.style/#styleformatstring
43
+
44
+ Style/IfUnlessModifier:
45
+ Enabled: false
46
+ StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
47
+
48
+ Style/Lambda:
49
+ Enabled: false
50
+ StyleGuide: https://relaxed.ruby.style/#stylelambda
51
+
52
+ Style/ModuleFunction:
53
+ Enabled: false
54
+ StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
55
+
56
+ Style/MultilineBlockChain:
57
+ Enabled: false
58
+ StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
59
+
60
+ Style/NegatedIf:
61
+ Enabled: false
62
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedif
63
+
64
+ Style/NegatedWhile:
65
+ Enabled: false
66
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
67
+
68
+ Style/ParallelAssignment:
69
+ Enabled: false
70
+ StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
71
+
72
+ Style/PercentLiteralDelimiters:
73
+ Enabled: false
74
+ StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
75
+
76
+ Style/PerlBackrefs:
77
+ Enabled: false
78
+ StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
79
+
80
+ Style/Semicolon:
81
+ Enabled: false
82
+ StyleGuide: https://relaxed.ruby.style/#stylesemicolon
83
+
84
+ Style/SignalException:
85
+ Enabled: false
86
+ StyleGuide: https://relaxed.ruby.style/#stylesignalexception
87
+
88
+ Style/SingleLineBlockParams:
89
+ Enabled: false
90
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
91
+
92
+ Style/SingleLineMethods:
93
+ Enabled: false
94
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
95
+
96
+ Layout/SpaceBeforeBlockBraces:
97
+ Enabled: false
98
+ StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
99
+
100
+ Layout/SpaceInsideParens:
101
+ Enabled: false
102
+ StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
103
+
104
+ Style/SpecialGlobalVars:
105
+ Enabled: false
106
+ StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
107
+
108
+ Style/StringLiterals:
109
+ Enabled: false
110
+ StyleGuide: https://relaxed.ruby.style/#stylestringliterals
111
+
112
+ Style/TrailingCommaInArguments:
113
+ Enabled: false
114
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
115
+
116
+ Style/TrailingCommaInArrayLiteral:
117
+ Enabled: false
118
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
119
+
120
+ Style/TrailingCommaInHashLiteral:
121
+ Enabled: false
122
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
123
+
124
+ Style/WhileUntilModifier:
125
+ Enabled: false
126
+ StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
127
+
128
+ Style/WordArray:
129
+ Enabled: false
130
+ StyleGuide: https://relaxed.ruby.style/#stylewordarray
131
+
132
+ Lint/AmbiguousRegexpLiteral:
133
+ Enabled: false
134
+ StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
135
+
136
+ Lint/AssignmentInCondition:
137
+ Enabled: false
138
+ StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
139
+
140
+ Metrics/AbcSize:
141
+ Enabled: false
142
+
143
+ Metrics/BlockNesting:
144
+ Enabled: false
145
+
146
+ Metrics/ClassLength:
147
+ Enabled: false
148
+
149
+ Metrics/ModuleLength:
150
+ Enabled: false
151
+
152
+ Metrics/CyclomaticComplexity:
153
+ Enabled: false
154
+
155
+ Metrics/LineLength:
156
+ Enabled: false
157
+
158
+ Metrics/MethodLength:
159
+ Enabled: false
160
+
161
+ Metrics/ParameterLists:
162
+ Enabled: false
163
+
164
+ Metrics/PerceivedComplexity:
165
+ Enabled: false
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ inherit_from:
4
+ - .rubocop.relaxed.yml
5
+ Naming/UncommunicativeMethodParamName:
6
+ Enabled: false
7
+ Style/AccessModifierDeclarations:
8
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-2.5.1
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "webdrone"
3
+ require 'bundler/setup'
4
+ require 'webdrone'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "webdrone"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
data/lib/webdrone.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'os'
2
4
  require 'selenium-webdriver'
3
5
  require 'xpath'
@@ -28,59 +30,65 @@ require 'webdrone/text'
28
30
  require 'webdrone/vrfy'
29
31
  require 'webdrone/html'
30
32
  require 'webdrone/logg'
33
+ require 'webdrone/xpath'
31
34
 
32
35
  module Webdrone
33
- def self.create(*args)
34
- a0 = Webdrone::Browser.new *args
35
- if block_given?
36
- begin
37
- yield a0
38
- rescue => exception
39
- Webdrone.report_error(a0, exception)
40
- ensure
41
- a0.quit
36
+ class << self
37
+ attr_accessor :running_pry, :irb_setup_done
38
+
39
+ def create(*args)
40
+ a0 = Webdrone::Browser.new(*args)
41
+ if block_given?
42
+ begin
43
+ yield a0
44
+ rescue StandardError => error
45
+ Webdrone.report_error(a0, error)
46
+ ensure
47
+ a0.quit
48
+ end
49
+ else
50
+ a0
42
51
  end
43
- else
44
- a0
45
52
  end
46
53
  end
47
54
 
48
55
  def self.irb_console(binding = nil)
49
56
  puts "Webdrone: Webdrone.irb_console IS DEPRECATED, please use a0.console instead."
50
- return if IRB.CurrentContext and not binding
51
- binding = Kernel.binding.of_caller(1) if binding == nil
57
+ return if IRB.CurrentContext && !binding
58
+ binding ||= Kernel.binding.of_caller(1)
52
59
  IRB.start_session(binding)
53
60
  end
54
61
 
55
- @@running_pry = false
62
+ Webdrone.running_pry = false
56
63
  def self.pry_console(binding = nil)
57
- if @@running_pry
64
+ if Webdrone.running_pry
58
65
  puts "Webdrone: pry console already running."
59
66
  else
60
- @@running_pry = true
61
- binding = Kernel.binding.of_caller(1) unless binding
67
+ Webdrone.running_pry = true
68
+ binding ||= Kernel.binding.of_caller(1)
62
69
  binding.pry
63
- @@running_pry = false
70
+ Webdrone.running_pry = false
64
71
  end
65
72
  end
66
73
  end
67
74
 
68
75
  module IRB
69
76
  def self.start_session(binding)
70
- unless $a0_irb_setup_done
77
+ unless Webdrone.irb_setup_done
71
78
  IRB.setup(nil)
72
- $a0_irb_setup_done = true
79
+ Webdrone.irb_setup_done = true
73
80
  end
74
81
 
75
82
  workspace = WorkSpace.new(binding)
76
83
 
77
- if @CONF[:SCRIPT]
78
- irb = Irb.new(workspace, @CONF[:SCRIPT])
79
- else
80
- irb = Irb.new(workspace)
81
- end
84
+ irb = \
85
+ if @CONF[:SCRIPT]
86
+ Irb.new(workspace, @CONF[:SCRIPT])
87
+ else
88
+ Irb.new(workspace)
89
+ end
82
90
 
83
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
91
+ @CONF[:IRB_RC]&.call(irb.context)
84
92
  @CONF[:MAIN_CONTEXT] = irb.context
85
93
 
86
94
  trap("SIGINT") do
@@ -95,4 +103,4 @@ module IRB
95
103
  IRB.irb_at_exit
96
104
  end
97
105
  end
98
- end
106
+ end
@@ -1,108 +1,82 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webdrone
2
4
  class Browser
3
- @@firefox_profile = @@chrome_options = nil
4
- attr_accessor :driver
5
-
6
- def self.firefox_profile
7
- if @@firefox_profile == nil
8
- @@firefox_profile = Selenium::WebDriver::Firefox::Profile.new
9
- @@firefox_profile['startup.homepage_welcome_url.additional'] = 'about:blank'
10
- @@firefox_profile['browser.download.folderList'] = 2
11
- @@firefox_profile['browser.download.manager.showWhenStarting'] = false
12
- @@firefox_profile['browser.helperApps.neverAsk.saveToDisk'] = "images/jpeg, application/pdf, application/octet-stream, application/download"
13
- end
14
- @@firefox_profile
15
- end
5
+ attr_reader :driver
16
6
 
17
- def self.firefox_profile=(firefox_profile)
18
- @@firefox_profile = firefox_profile
19
- end
7
+ class << self
8
+ attr_writer :firefox_profile, :chrome_options
20
9
 
21
- def self.chrome_options
22
- if @@chrome_options == nil
23
- @@chrome_options = Selenium::WebDriver::Chrome::Options.new
24
- @@chrome_options.add_preference 'download.prompt_for_download', false
25
- @@chrome_options.add_preference 'credentials_enable_service:', false
10
+ def firefox_profile
11
+ return @firefox_profile if defined? @firefox_profile
12
+
13
+ @firefox_profile = Selenium::WebDriver::Firefox::Profile.new
14
+ @firefox_profile['startup.homepage_welcome_url.additional'] = 'about:blank'
15
+ @firefox_profile['browser.download.folderList'] = 2
16
+ @firefox_profile['browser.download.manager.showWhenStarting'] = false
17
+ @firefox_profile['browser.helperApps.neverAsk.saveToDisk'] = "images/jpeg, application/pdf, application/octet-stream, application/download"
18
+
19
+ @firefox_profile
26
20
  end
27
- @@chrome_options
28
- end
29
21
 
30
- def env_update(binding)
31
- bool_vars = [:create_outdir, :developer, :quit_at_exit, :maximize]
32
- ENV.keys.select { |env| env.start_with? 'WEBDRONE_' }.each do |env|
33
- v = env[9..-1].downcase.to_sym
34
- if binding.local_variable_defined? v
35
- o = binding.local_variable_get(v)
36
- n = ENV[env]
37
- if bool_vars.include? v
38
- if n == "true"
39
- n = true
40
- elsif n == "false"
41
- n = false
42
- else
43
- puts "Webdrone: ignoring value '#{n}' for boolean parameter #{v}."
44
- next
45
- end
46
- end
47
- binding.local_variable_set(v, n)
48
- puts "Webdrone: overriding #{v} from '#{o}' to '#{n}'."
49
- elsif v == :mark_times
50
- n = ENV[env].to_i
51
- puts "Webdrone: setting mark times to #{n}"
52
- self.mark.default_times = n
53
- elsif v == :mark_sleep
54
- n = ENV[env].to_f
55
- puts "Webdrone: setting mark sleep to #{n}"
56
- self.mark.default_sleep = n
57
- else
58
- puts "Webdrone: ignoring unknown parameter #{env}."
59
- end
22
+ def chrome_options
23
+ return @chrome_options if defined? @chrome_options
24
+
25
+ @chrome_options = Selenium::WebDriver::Chrome::Options.new
26
+ @chrome_options.add_preference 'download.prompt_for_download', false
27
+ @chrome_options.add_preference 'credentials_enable_service:', false
28
+
29
+ @chrome_options
60
30
  end
61
31
  end
62
32
 
63
33
  def initialize(browser: 'firefox', create_outdir: true, outdir: nil, timeout: 30, developer: false, logger: true, quit_at_exit: true, maximize: true, error: :raise_report, win_x: nil, win_y: nil, win_w: nil, win_h: nil, use_env: true, chrome_options: nil, firefox_profile: nil, remote_url: nil, headless: false)
64
34
  env_update(Kernel.binding) if use_env
65
- if create_outdir or outdir
35
+
36
+ if create_outdir || outdir
66
37
  outdir ||= File.join("webdrone_output", Time.new.strftime('%Y%m%d_%H%M%S'))
67
- self.conf.outdir = outdir
38
+ conf.outdir = outdir
68
39
  end
69
- outdir = File.join(Dir.pwd, outdir) if outdir != nil and not Pathname.new(outdir).absolute?
40
+ outdir = File.join(Dir.pwd, outdir) if !outdir.nil? && !Pathname.new(outdir).absolute?
41
+
70
42
  if remote_url
71
43
  @driver = Selenium::WebDriver.for :remote, url: remote_url, desired_capabilities: browser.to_sym
72
- elsif outdir != nil and browser.to_sym == :chrome
73
- chrome_options = Browser.chrome_options if chrome_options == nil
44
+ elsif !outdir.nil? && browser.to_sym == :chrome
45
+ chrome_options ||= Browser.chrome_options
74
46
  chrome_options.add_preference 'download.default_directory', outdir
75
47
  chrome_options.add_argument '--disable-popup-blocking'
76
48
  chrome_options.add_argument '--headless' if headless
77
49
  @driver = Selenium::WebDriver.for browser.to_sym, options: chrome_options
78
- elsif outdir != nil and browser.to_sym == :firefox
79
- firefox_profile = Browser.firefox_profile if firefox_profile == nil
80
- downdir = OS.windows? ? outdir.gsub("/", "\\") : outdir
50
+ elsif !outdir.nil? && browser.to_sym == :firefox
51
+ firefox_profile ||= Browser.firefox_profile
52
+ downdir = OS.windows? ? outdir.tr("/", "\\") : outdir
81
53
  firefox_profile['browser.download.dir'] = downdir
82
54
  @driver = Selenium::WebDriver.for browser.to_sym, profile: firefox_profile
83
55
  else
84
56
  @driver = Selenium::WebDriver.for browser.to_sym
85
57
  end
58
+
86
59
  if quit_at_exit
87
60
  at_exit do
88
- begin
89
- @driver.quit
90
- rescue
91
- end
61
+ @driver.quit
62
+ rescue StandardError
63
+ nil
92
64
  end
93
65
  end
94
- self.conf.error = error.to_sym
95
- self.conf.developer = developer
96
- self.conf.timeout = timeout.to_i if timeout
97
- self.conf.logger = logger
98
-
66
+
67
+ conf.error = error.to_sym
68
+ conf.developer = developer
69
+ conf.timeout = timeout.to_i if timeout
70
+ conf.logger = logger
71
+
99
72
  if developer
100
73
  win_x = win_y = 0
101
74
  win_w = 0.5
102
75
  win_h = 1.0
103
76
  end
104
- if win_x or win_y or win_w or win_h
105
- 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];'
77
+
78
+ if win_x || win_y || win_w || win_h
79
+ x, y, w, h = exec.script 'return [window.screenLeft ? window.screenLeft : window.screenX, window.screenTop ? window.screenTop : window.screenY, window.screen.availWidth, window.screen.availHeight];'
106
80
  win_x ||= x
107
81
  win_y ||= y
108
82
  if win_w.is_a? Float
@@ -118,11 +92,11 @@ module Webdrone
118
92
  begin
119
93
  @driver.manage.window.position = Selenium::WebDriver::Point.new win_x, win_y
120
94
  @driver.manage.window.resize_to(win_w, win_h)
121
- rescue => e
95
+ rescue StandardError => e
122
96
  puts "Ignoring error on window position/resize: #{e}"
123
97
  end
124
- else
125
- self.maximize if maximize
98
+ elsif maximize
99
+ self.maximize
126
100
  end
127
101
  end
128
102
 
@@ -136,16 +110,56 @@ module Webdrone
136
110
 
137
111
  def console(binding = nil)
138
112
  return unless conf.developer
139
- binding = Kernel.binding.of_caller(1) unless binding
140
- old_error = self.conf.error
141
- old_developer = self.conf.developer
113
+ binding ||= Kernel.binding.of_caller(1)
114
+ old_error = conf.error
115
+ old_developer = conf.developer
142
116
  begin
143
- self.conf.error = :raise
144
- self.conf.developer = false
117
+ conf.error = :raise
118
+ conf.developer = false
145
119
  Webdrone.pry_console binding
146
120
  ensure
147
- self.conf.error = old_error
148
- self.conf.developer = old_developer
121
+ conf.error = old_error
122
+ conf.developer = old_developer
123
+ end
124
+ end
125
+
126
+ protected
127
+
128
+ def env_update_bool(binding, var, val_old, val_new)
129
+ if val_new == "true"
130
+ elsif val_new == "false"
131
+ else
132
+ puts "Webdrone: ignoring value '#{val_new}' for boolean parameter #{var}."
133
+ return
134
+ end
135
+ binding.local_variable_set(var, val_new)
136
+ puts "Webdrone: overriding #{var} from '#{val_old}' to '#{val_new}'."
137
+ end
138
+
139
+ def env_update(binding)
140
+ bool_vars = %i[create_outdir developer quit_at_exit maximize]
141
+ ENV.keys.select { |env| env.start_with? 'WEBDRONE_' }.each do |env|
142
+ var = env[9..-1].downcase.to_sym
143
+ if binding.local_variable_defined? var
144
+ val_old = binding.local_variable_get(var)
145
+ val_new = ENV[env]
146
+ if bool_vars.include? var
147
+ env_update_bool(binding, var, val_old, val_new)
148
+ else
149
+ binding.local_variable_set(var, val_new)
150
+ puts "Webdrone: overriding #{var} from '#{val_old}' to '#{val_new}'."
151
+ end
152
+ elsif v == :mark_times
153
+ n = ENV[env].to_i
154
+ puts "Webdrone: setting mark times to #{n}"
155
+ mark.default_times = n
156
+ elsif v == :mark_sleep
157
+ n = ENV[env].to_f
158
+ puts "Webdrone: setting mark sleep to #{n}"
159
+ mark.default_sleep = n
160
+ else
161
+ puts "Webdrone: ignoring unknown parameter #{env}."
162
+ end
149
163
  end
150
164
  end
151
165
  end