rudra 1.0.16 → 1.0.17

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 +24 -15
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425842a9405ec0a244bca0e722f6eb25cdb881b355346f3d61318a2fde111a25
4
- data.tar.gz: 4ed27b935bd5a3192d421fad516fa024fc9783f1f10c2b75da85679717511a70
3
+ metadata.gz: a6b9b8353fbb965300bb0e6c9a96ef162717fc1b7e3afaa46192d414a0828584
4
+ data.tar.gz: 5ca513a1614e4c9fbae46dc5caf4636d5b579fd8e1fc74c6f745cc61d7d9ddcf
5
5
  SHA512:
6
- metadata.gz: 0aa62d7dcfa60e50e74fcc61a11a264a5e1b20f77355e4776e6821d75d06a4b3ecf9ff89c1a4197d72ace5175fe25163b7b68309f05d5ff64c60aa86e33f1aaa
7
- data.tar.gz: 8f4353692ce71ef0276786a0bad7a062c1d88095184947a1d2f682f5ddae0d515764bb958726fe9dfafcc704b9ac40b129659b1a0a277e673e38ffd3e8cf6edc
6
+ metadata.gz: e775d57a29612f265578c1ecfd665e093f837460b32012763ab88983d47a1b7ae674903e1e5169b30609e65cce59d621800ab20500013d506b4dd8120fa76f55
7
+ data.tar.gz: 98b306bd3f397ae54f53224fa88d57aacb5d6b6699a92706440626ddbe8dee4d75e3d7ff751fd71e2d64d0bd88a3e95852d1680720b7731fed6eccb22a7213bc
@@ -1,10 +1,5 @@
1
1
  require 'selenium-webdriver'
2
- require 'webdrivers/chromedriver'
3
- require 'webdrivers/geckodriver'
4
- require 'webdrivers/iedriver'
5
-
6
- # Selenium::WebDriver::Chrome::Service.driver_path = './webdrivers/chromedriver'
7
- # Selenium::WebDriver::Firefox::Service.driver_path = './webdrivers/geckodriver'
2
+ require 'webdrivers'
8
3
 
9
4
  # Selenium IDE-like WebDriver based upon Ruby binding
10
5
  # @author Aaron Chen
@@ -14,6 +9,7 @@ require 'webdrivers/iedriver'
14
9
  # @attr_reader [String] install_dir The install directory of WebDrivers
15
10
  # @attr_reader [String] locale The browser locale
16
11
  # @attr_reader [Boolean] headless Headless mode for Google Chrome
12
+ # @attr_reader [String] window_size Chrome window size when headless
17
13
  # @attr_reader [String] screen_dir The screenshot directory of save_screenshot
18
14
  # @attr_reader [String] log_prefix Prefix for logging executed methods
19
15
  # @attr_reader [Integer] timeout The driver timeout
@@ -31,13 +27,13 @@ class Rudra
31
27
  # Attributes
32
28
  ATTRIBUTES = %i[
33
29
  browser driver install_dir locale
34
- headless screen_dir log_prefix
35
- timeout verbose
30
+ headless window_size screen_dir
31
+ log_prefix timeout verbose
36
32
  ].freeze
37
33
 
38
34
  attr_reader :browser, :driver, :install_dir, :locale,
39
- :headless, :screen_dir, :log_prefix,
40
- :timeout, :verbose
35
+ :headless, :window_size, :screen_dir,
36
+ :log_prefix, :timeout, :verbose
41
37
 
42
38
  # Initialize an instance of Rudra
43
39
  # @param [Hash] options the options to initialize Rudra
@@ -47,6 +43,7 @@ class Rudra
47
43
  # directory of WebDrivers
48
44
  # @option options [Symbol] :locale (:en) the browser locale
49
45
  # @option options [Boolean] :headless (false) headless mode
46
+ # @option options [String] :window_size ('1280,720') window size when headless
50
47
  # @option options [String] :screen_dir ('./screens/') the location of screenshots
51
48
  # @option options [String] :log_prefix (' - ') prefix for logging executed methods
52
49
  # @option options [Integer] :timeout (30) implicit_wait timeout
@@ -56,6 +53,7 @@ class Rudra
56
53
  self.install_dir = options.fetch(:install_dir, './webdrivers/')
57
54
  self.locale = options.fetch(:locale, :en)
58
55
  self.headless = options.fetch(:headless, false)
56
+ self.window_size = options.fetch(:window_size, '1280,720')
59
57
  self.screen_dir = options.fetch(:screen_dir, './screens/')
60
58
  self.log_prefix = options.fetch(:log_prefix, ' - ')
61
59
  self.verbose = options.fetch(:verbose, true)
@@ -104,6 +102,7 @@ class Rudra
104
102
  end
105
103
 
106
104
  # Send keys to an alert
105
+ # @param [String] keys keystrokes to send
107
106
  def alert_send_keys(keys)
108
107
  switch_to_alert.send_keys(keys)
109
108
  end
@@ -208,7 +207,7 @@ class Rudra
208
207
 
209
208
  # Maximize the current window
210
209
  def maximize
211
- driver.manage.window.maximize
210
+ driver.manage.window.maximize unless headless
212
211
  end
213
212
 
214
213
  # Maximize the current window to the size of the screen
@@ -1082,7 +1081,8 @@ class Rudra
1082
1081
 
1083
1082
  private
1084
1083
 
1085
- attr_writer :main_label
1084
+ attr_accessor :main_label
1085
+ attr_writer :window_size
1086
1086
 
1087
1087
  def browser=(brw)
1088
1088
  unless BROWSERS.include?(brw)
@@ -1135,6 +1135,8 @@ class Rudra
1135
1135
  def initialize_driver
1136
1136
  @driver = if browser == :chrome
1137
1137
  Selenium::WebDriver.for(:chrome, options: chrome_options)
1138
+ # elsif browser == :edge
1139
+ # Selenium::WebDriver.for(:edge, options: edge_options)
1138
1140
  elsif browser == :firefox
1139
1141
  Selenium::WebDriver.for(:firefox, options: firefox_options)
1140
1142
  elsif browser == :ie
@@ -1147,7 +1149,10 @@ class Rudra
1147
1149
  def chrome_options
1148
1150
  options = Selenium::WebDriver::Chrome::Options.new
1149
1151
  options.add_argument('--disable-notifications')
1150
- options.add_argument('--headless') if headless
1152
+ if headless
1153
+ options.add_argument('--headless')
1154
+ options.add_argument("--window-size=#{window_size}")
1155
+ end
1151
1156
  options.add_option(
1152
1157
  'excludeSwitches',
1153
1158
  %w[enable-automation enable-logging]
@@ -1156,6 +1161,10 @@ class Rudra
1156
1161
  options
1157
1162
  end
1158
1163
 
1164
+ # def edge_options
1165
+ # Selenium::WebDriver::Edge::Options.new
1166
+ # end
1167
+
1159
1168
  def firefox_options
1160
1169
  options = Selenium::WebDriver::Firefox::Options.new
1161
1170
  options.add_preference('intl.accept_languages', locale)
@@ -1194,11 +1203,11 @@ class Rudra
1194
1203
  end
1195
1204
 
1196
1205
  def log(method_name, *args)
1197
- return unless @verbose && caller_locations(2, 1).first.label == @main_label
1206
+ return unless verbose && caller_locations(2, 1).first.label == main_label
1198
1207
 
1199
1208
  arguments = args.map(&:to_s).join(', ')
1200
1209
 
1201
- puts @log_prefix + (
1210
+ puts log_prefix + (
1202
1211
  arguments.empty? ? method_name.to_s : "#{method_name}(#{arguments})"
1203
1212
  )
1204
1213
  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.16
4
+ version: 1.0.17
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-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard