rudra 1.0.13 → 1.1.0

This diff has not been reviewed by any users.
Log in in order to be able to vote.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudra.rb +74 -32
  3. metadata +13 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a3a4f9fb5eee63f5a3f29102e0c1161256fb30b098c108ca3c415663b062113
4
- data.tar.gz: 72bf75e1a6bdd4913c944944b6f0a7427082ce38fe7800202710e72a3f012e23
3
+ metadata.gz: b59cfa6497e4560d80369dc076df45638ec043abe069b5f6665e5749aefdef87
4
+ data.tar.gz: 51e97a957330ffce97411d9f3ad40e01a4be439cc677306d5507ae0136577beb
5
5
  SHA512:
6
- metadata.gz: 7f6a25ab7afd10bdc21c73c3c09710791a69b7ffb3d887a285a2f94b6069d83c7ab07a0d1f62b541dfd7e20935661be94491f731c9a79a9d2f035a3b8e760538
7
- data.tar.gz: adc43a16f2f13f0a59acaa41de6c790ab88f9c19caf8372b9951c79ca8428d206cf13d9f80806dc7252acc05174b81880f8f3c411447aefefbfa92d896c6216b
6
+ metadata.gz: f7984dccb05ea056c716dd533c5d4662e83ea8711c62a2fc3f02f95d0d7a795914d16c2ceacd2ef2cf1eff26374ae9c8ed795a14797186f696356f3c02c687bf
7
+ data.tar.gz: 4bfb07ee8abe3ce212c85ca19ab052fb134b47c42e225e7160ea6463795e425e22a594998d2e89365709a3d2b1495a2c5cbbb0894b64bd1bfc073a190519ef8f
@@ -1,9 +1,5 @@
1
1
  require 'selenium-webdriver'
2
- require 'webdrivers/chromedriver'
3
- require 'webdrivers/geckodriver'
4
-
5
- # Selenium::WebDriver::Chrome::Service.driver_path = './webdrivers/chromedriver'
6
- # Selenium::WebDriver::Firefox::Service.driver_path = './webdrivers/geckodriver'
2
+ require 'webdrivers'
7
3
 
8
4
  # Selenium IDE-like WebDriver based upon Ruby binding
9
5
  # @author Aaron Chen
@@ -12,11 +8,16 @@ require 'webdrivers/geckodriver'
12
8
  # of the chosen browser
13
9
  # @attr_reader [String] install_dir The install directory of WebDrivers
14
10
  # @attr_reader [String] locale The browser locale
11
+ # @attr_reader [Boolean] headless Headless mode for Google Chrome
12
+ # @attr_reader [String] window_size Chrome window size when headless
13
+ # @attr_reader [String] screen_dir The screenshot directory of save_screenshot
14
+ # @attr_reader [String] log_prefix Prefix for logging descriptions and methods
15
15
  # @attr_reader [Integer] timeout The driver timeout
16
- # @attr_reader [Boolean] verbose Verbose mode
16
+ # @attr_reader [Boolean] verbose Turn on/off Verbose mode
17
+ # @attr_reader [Boolean] silent Turn off Turn on/off descriptions
17
18
  class Rudra
18
19
  # Supported Browsers
19
- BROWSERS = %i[chrome firefox safari].freeze
20
+ BROWSERS = %i[chrome firefox ie safari].freeze
20
21
 
21
22
  # Element Finder Methods
22
23
  HOWS = %i[
@@ -27,11 +28,13 @@ class Rudra
27
28
  # Attributes
28
29
  ATTRIBUTES = %i[
29
30
  browser driver install_dir locale
30
- headless log_prefix timeout verbose
31
+ headless window_size screen_dir
32
+ log_prefix timeout verbose silent
31
33
  ].freeze
32
34
 
33
35
  attr_reader :browser, :driver, :install_dir, :locale,
34
- :headless, :log_prefix, :timeout, :verbose
36
+ :headless, :window_size, :screen_dir,
37
+ :log_prefix, :timeout, :verbose, :silent
35
38
 
36
39
  # Initialize an instance of Rudra
37
40
  # @param [Hash] options the options to initialize Rudra
@@ -41,29 +44,27 @@ class Rudra
41
44
  # directory of WebDrivers
42
45
  # @option options [Symbol] :locale (:en) the browser locale
43
46
  # @option options [Boolean] :headless (false) headless mode
44
- # @option options [String] :log_prefix (' - ') log prefix
47
+ # @option options [String] :window_size ('1280,720') window size when headless
48
+ # @option options [String] :screen_dir ('./screens/') the location of screenshots
49
+ # @option options [String] :log_prefix (' - ') prefix for logging descriptions and methods
45
50
  # @option options [Integer] :timeout (30) implicit_wait timeout
46
- # @option options [Boolean] :verbose (true) verbose mode
51
+ # @option options [Boolean] :verbose (false) Turn on/off verbose mode
52
+ # @option options [Boolean] :silent (false) Turn on/off descriptions
47
53
  def initialize(options = {})
48
54
  self.browser = options.fetch(:browser, :chrome)
49
55
  self.install_dir = options.fetch(:install_dir, './webdrivers/')
50
56
  self.locale = options.fetch(:locale, :en)
51
57
  self.headless = options.fetch(:headless, false)
58
+ self.window_size = options.fetch(:window_size, '1280,720')
59
+ self.screen_dir = options.fetch(:screen_dir, './screens/')
52
60
  self.log_prefix = options.fetch(:log_prefix, ' - ')
53
- self.verbose = options.fetch(:verbose, true)
61
+ self.verbose = options.fetch(:verbose, false)
62
+ self.silent = options.fetch(:silent, false)
63
+ self.main_label = caller_locations(2, 1).first.label
54
64
 
55
65
  initialize_driver
56
66
 
57
67
  self.timeout = options.fetch(:timeout, 30)
58
-
59
- @main_label = caller_locations(2, 1).first.label
60
- @verbose && (
61
- puts %(
62
- ============ Rudra ============
63
- Browser: #{@browser}, Locale: #{@locale}
64
- ============ Log ============
65
- ).lines.map(&:strip).reject(&:empty?).join("\n")
66
- )
67
68
  end
68
69
 
69
70
  #
@@ -104,6 +105,7 @@ class Rudra
104
105
  end
105
106
 
106
107
  # Send keys to an alert
108
+ # @param [String] keys keystrokes to send
107
109
  def alert_send_keys(keys)
108
110
  switch_to_alert.send_keys(keys)
109
111
  end
@@ -208,7 +210,7 @@ class Rudra
208
210
 
209
211
  # Maximize the current window
210
212
  def maximize
211
- driver.manage.window.maximize
213
+ driver.manage.window.maximize unless headless
212
214
  end
213
215
 
214
216
  # Maximize the current window to the size of the screen
@@ -266,6 +268,12 @@ class Rudra
266
268
  driver.page_source
267
269
  end
268
270
 
271
+ # Print description in the console
272
+ # @param [String] description description to show
273
+ def puts(description)
274
+ $stdout.puts "#{log_prefix}#{description.chomp}" unless silent
275
+ end
276
+
269
277
  # Refresh the current pagef
270
278
  def refresh
271
279
  driver.navigate.refresh
@@ -278,11 +286,15 @@ class Rudra
278
286
  driver.manage.window.resize_to(width, height)
279
287
  end
280
288
 
281
- # Save a PNG screenshot to the given path
282
- # @param [String] png_path the path of PNG screenshot
283
- def save_screenshot(png_path)
289
+ # Save a PNG screenshot to file
290
+ # @param [String] filename the filename of PNG screenshot
291
+ def save_screenshot(filename)
292
+ mkdir(@screen_dir) unless Dir.exist?(@screen_dir)
284
293
  driver.save_screenshot(
285
- png_path.end_with?('.png') ? png_path : "#{png_path}.png"
294
+ File.join(
295
+ @screen_dir,
296
+ filename.end_with?('.png') ? filename : "#{filename}.png"
297
+ )
286
298
  )
287
299
  end
288
300
 
@@ -1066,9 +1078,7 @@ class Rudra
1066
1078
  end
1067
1079
 
1068
1080
  (instance_methods - superclass.instance_methods).map do |method_name|
1069
- if private_method_defined?(method_name) || ATTRIBUTES.include?(method_name)
1070
- next
1071
- end
1081
+ next if private_method_defined?(method_name) || ATTRIBUTES.include?(method_name) || method_name == :puts
1072
1082
 
1073
1083
  original_method = instance_method(method_name)
1074
1084
 
@@ -1080,6 +1090,9 @@ class Rudra
1080
1090
 
1081
1091
  private
1082
1092
 
1093
+ attr_accessor :main_label
1094
+ attr_writer :silent, :window_size
1095
+
1083
1096
  def browser=(brw)
1084
1097
  unless BROWSERS.include?(brw)
1085
1098
  browsers = BROWSERS.map { |b| ":#{b}" }.join(', ')
@@ -1105,6 +1118,10 @@ class Rudra
1105
1118
  @headless = true?(mode)
1106
1119
  end
1107
1120
 
1121
+ def screen_dir=(path)
1122
+ @screen_dir = File.join(path, @locale.to_s)
1123
+ end
1124
+
1108
1125
  def log_prefix=(prefix)
1109
1126
  @log_prefix = prefix.chomp
1110
1127
  end
@@ -1127,8 +1144,12 @@ class Rudra
1127
1144
  def initialize_driver
1128
1145
  @driver = if browser == :chrome
1129
1146
  Selenium::WebDriver.for(:chrome, options: chrome_options)
1147
+ # elsif browser == :edge
1148
+ # Selenium::WebDriver.for(:edge, options: edge_options)
1130
1149
  elsif browser == :firefox
1131
1150
  Selenium::WebDriver.for(:firefox, options: firefox_options)
1151
+ elsif browser == :ie
1152
+ Selenium::WebDriver.for(:ie, options: ie_options)
1132
1153
  else
1133
1154
  Selenium::WebDriver.for(:safari)
1134
1155
  end
@@ -1137,11 +1158,22 @@ class Rudra
1137
1158
  def chrome_options
1138
1159
  options = Selenium::WebDriver::Chrome::Options.new
1139
1160
  options.add_argument('--disable-notifications')
1140
- options.add_argument('--headless') if headless
1161
+ if headless
1162
+ options.add_argument('--headless')
1163
+ options.add_argument("--window-size=#{window_size}")
1164
+ end
1165
+ options.add_option(
1166
+ 'excludeSwitches',
1167
+ %w[enable-automation enable-logging]
1168
+ )
1141
1169
  options.add_preference('intl.accept_languages', locale)
1142
1170
  options
1143
1171
  end
1144
1172
 
1173
+ # def edge_options
1174
+ # Selenium::WebDriver::Edge::Options.new
1175
+ # end
1176
+
1145
1177
  def firefox_options
1146
1178
  options = Selenium::WebDriver::Firefox::Options.new
1147
1179
  options.add_preference('intl.accept_languages', locale)
@@ -1149,6 +1181,16 @@ class Rudra
1149
1181
  options
1150
1182
  end
1151
1183
 
1184
+ def ie_options
1185
+ options = Selenium::WebDriver::IE::Options.new
1186
+ options.ensure_clean_session = true
1187
+ options.full_page_screenshot = true
1188
+ options.ignore_protected_mode_settings = true
1189
+ options.ignore_zoom_level = true
1190
+ options.native_events = false
1191
+ options
1192
+ end
1193
+
1152
1194
  def parse_locator(locator)
1153
1195
  unmatched, how, what = locator.split(/^([A-Za-z]+)=(.+)/)
1154
1196
 
@@ -1170,11 +1212,11 @@ class Rudra
1170
1212
  end
1171
1213
 
1172
1214
  def log(method_name, *args)
1173
- return unless @verbose && caller_locations(2, 1).first.label == @main_label
1215
+ return unless verbose && caller_locations(2, 1).first.label == main_label
1174
1216
 
1175
1217
  arguments = args.map(&:to_s).join(', ')
1176
1218
 
1177
- puts @log_prefix + (
1219
+ puts log_prefix + (
1178
1220
  arguments.empty? ? method_name.to_s : "#{method_name}(#{arguments})"
1179
1221
  )
1180
1222
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-23 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.24
19
+ version: 0.9.25
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.24
26
+ version: 0.9.25
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: selenium-webdriver
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,24 +48,24 @@ dependencies:
48
48
  name: webdrivers
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 4.3.0
54
51
  - - "~>"
55
52
  - !ruby/object:Gem::Version
56
- version: '4.3'
53
+ version: '4.4'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 4.4.1
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 4.3.0
64
61
  - - "~>"
65
62
  - !ruby/object:Gem::Version
66
- version: '4.3'
63
+ version: '4.4'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 4.4.1
67
67
  description: Selenium IDE alternative using selenium-webdriver
68
- email: aaron@oobo.be
68
+ email: aaron@611b.com
69
69
  executables: []
70
70
  extensions: []
71
71
  extra_rdoc_files: []