gridium 0.1.21 → 0.2.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
2
  SHA1:
3
- metadata.gz: bf751acc7432fc7e919c8bc1d1f74f8b5a21029e
4
- data.tar.gz: 558a5a0eedbc3437dee61396a694269bb1e842d7
3
+ metadata.gz: 6756e4e593e9c99a266fe4bfb1c1c1f3a4412743
4
+ data.tar.gz: a7923e3514793d68fb2b60297a8792cfd0225d0e
5
5
  SHA512:
6
- metadata.gz: f39e4d62c68af7a47d4809d634305af954366dacdd2d24302bb54352295fc6d4581cf4255924f3d15dfa6ee0c287a99dbc8f17ae1da3ae6a8cb0a2ca8aec6d2f
7
- data.tar.gz: ac3e6e2828465e3934df04647f07e9f40182f03b1199494da87acd7f12f925a9824d12b8cb7e59da1db4482f0889bc48a1a19ec0069a3db8c0cf83554a218403
6
+ metadata.gz: e07a44f3e1b61c6799b1ff4e323c4ce78b80df02ec0415456e925cc00364baf1cfbc632f9a92380e5d30f7fab38d64c89bab7651d76ab459bb91a229930394b7
7
+ data.tar.gz: aa89e4c7e8fa3f84bff99f9adde4ba50850291a470457529fb02336d146ac141353b090ebb7270767b44d348aac27d39df6b5c4b79702f75360465679180427b
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in gridium.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rspec-mocks'
6
+ gem 'rspec-mocks'
7
+ gem 'aws-sdk', '~> 2'
data/lib/driver.rb CHANGED
@@ -11,6 +11,7 @@ class Driver
11
11
  driver.manage.timeouts.page_load = Gridium.config.page_load_timeout
12
12
  driver.manage.timeouts.implicit_wait = Gridium.config.element_timeout
13
13
 
14
+ # Ensure the browser is maximized to maximize visibility of element
14
15
  # Ensure the browser is maximized to maximize visibility of element
15
16
  # Currently doesn't work with chromedriver, but the following workaround does:
16
17
  if @browser_type.eql?(:chrome)
@@ -24,9 +25,9 @@ class Driver
24
25
  end
25
26
 
26
27
  def self.driver
27
- Log.debug("=====> Driver.driver: #{@@driver}")
28
28
  begin
29
29
  unless @@driver
30
+ Log.debug("=====> Driver.driver: instantiating new driver")
30
31
  @browser_type = Gridium.config.browser
31
32
  ##Adding support for remote browsers
32
33
  if Gridium.config.browser_source == :remote
@@ -40,6 +41,17 @@ class Driver
40
41
  else
41
42
  @@driver = Selenium::WebDriver.for(Gridium.config.browser)
42
43
  end
44
+ if Gridium.config.screenshots_to_s3
45
+ #do stuff
46
+ s3_project_folder = Gridium.config.project_name_for_s3
47
+ s3_subfolder = Gridium.config.subdirectory_name_for_s3
48
+ Log.debug("configuring s3 to save files to this directory: #{s3_project_folder} in addition to being saved locally")
49
+ @s3 = Gridium::GridiumS3.new(s3_project_folder, s3_subfolder)
50
+ Log.debug("s3 is #{@s3}")
51
+ else
52
+ Log.debug("s3 screenshots not enabled in spec_helper; they will be only be saved locally")
53
+ @s3 = nil
54
+ end
43
55
  reset
44
56
  end
45
57
  @@driver
@@ -51,6 +63,12 @@ class Driver
51
63
  end
52
64
  end
53
65
 
66
+
67
+ def self.s3
68
+ #TODO figure out why I can't just use attr_reader :s3
69
+ @s3
70
+ end
71
+
54
72
  def self.driver= driver
55
73
  @@driver.quit if @@driver
56
74
  @@driver = driver
@@ -180,9 +198,19 @@ class Driver
180
198
  timestamp = Time.now.strftime("%Y_%m_%d__%H_%M_%S")
181
199
  screenshot_path = File.join($current_run_dir, "screenshot__#{timestamp}__#{type}.png")
182
200
  driver.save_screenshot(screenshot_path)
201
+ _save_to_s3_if_configured(screenshot_path)
183
202
  SpecData.screenshots_captured.push("screenshot__#{timestamp}__#{type}.png") # used by custom_formatter.rb for embedding in report
203
+ screenshot_path
184
204
  end
185
205
 
206
+ def self._save_to_s3_if_configured(screenshot_path)
207
+ if Gridium.config.screenshots_to_s3
208
+ url = @s3.save_file(screenshot_path)
209
+ Log.info("#{screenshot_path} saved to #{url}")
210
+ end
211
+ end
212
+
213
+
186
214
  def self.list_open_windows
187
215
  handles = driver.window_handles
188
216
  Log.debug("List of active windows:")
data/lib/gridium.rb CHANGED
@@ -7,6 +7,7 @@ require 'element'
7
7
  require 'element_extensions'
8
8
  require 'element_verification'
9
9
  require 'page'
10
+ require 's3'
10
11
 
11
12
  module Gridium
12
13
  class << self
@@ -20,7 +21,7 @@ module Gridium
20
21
 
21
22
  class Config
22
23
  attr_accessor :report_dir, :browser_source, :target_environment, :browser, :url, :page_load_timeout, :element_timeout, :visible_elements_only, :log_level
23
- attr_accessor :highlight_verifications, :highlight_duration, :screenshot_on_failure
24
+ attr_accessor :highlight_verifications, :highlight_duration, :screenshot_on_failure, :screenshots_to_s3, :project_name_for_s3, :subdirectory_name_for_s3
24
25
 
25
26
  def initialize
26
27
  @report_dir = Dir.home
@@ -35,6 +36,9 @@ module Gridium
35
36
  @highlight_verifications = false
36
37
  @highlight_duration = 0.100
37
38
  @screenshot_on_failure = false
39
+ @screenshots_to_s3 = false
40
+ @project_name_for_s3 = 'gridium'
41
+ @subdirectory_name_for_s3 = '' #rely on GridiumS3 default
38
42
  end
39
43
  end
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module Gridium
2
- VERSION = "0.1.21"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/log.rb CHANGED
@@ -86,6 +86,7 @@ module Gridium
86
86
  @@devices ||= []
87
87
  log.attach(device)
88
88
  @@devices << device
89
+ log.add(log.level, "device added: #{File.absolute_path(device)}")
89
90
  end
90
91
 
91
92
  def close
@@ -134,7 +135,6 @@ module Gridium
134
135
  "#{base_msg} X #{msg}\n"
135
136
  end
136
137
  end
137
-
138
138
  logger
139
139
  end # initialize_logger
140
140
  end # class << self
data/lib/s3.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'aws-sdk'
2
+ module Gridium
3
+
4
+
5
+ class GridiumS3
6
+
7
+ ACCESS_KEY_ID = ENV['S3_ACCESS_KEY_ID']
8
+ SECRET_ACCESS_KEY = ENV['S3_SECRET_ACCESS_KEY']
9
+ DEFAULT_REGION = ENV['S3_DEFAULT_REGION']
10
+ ROOT_BUCKET = ENV['S3_ROOT_BUCKET']
11
+ DELIMITER = "/"
12
+
13
+
14
+ def initialize(project_name, subdirectory_name='screenshots')
15
+ Log.debug("initializing GridiumS3 with #{project_name} and #{subdirectory_name}")
16
+ Aws.config.update({ credentials: Aws::Credentials.new(ACCESS_KEY_ID, SECRET_ACCESS_KEY) ,region: DEFAULT_REGION})
17
+ _validate_string(project_name)
18
+ _validate_string(subdirectory_name)
19
+ @project_name = _sanitize_string(project_name)
20
+ @subdirectory_name = _sanitize_string(subdirectory_name)
21
+ @bucket = Aws::S3::Resource.new().bucket(ROOT_BUCKET)
22
+ end
23
+
24
+ def save_file(absolute_path_of_file)
25
+ Log.debug("attempting to save #{absolute_path_of_file} to s3")
26
+ _validate_path(absolute_path_of_file)
27
+ file_name = File.basename(absolute_path_of_file)
28
+ destination_name = create_s3_name(file_name)
29
+ @bucket.object(destination_name).upload_file(absolute_path_of_file)
30
+ @bucket.object(destination_name).wait_until_exists
31
+ _verify_upload(destination_name, absolute_path_of_file)
32
+ # @bucket.object(s3_name).presigned_url(:get, expires_in: 3600) #uncomment this if public url ends up not working out OPREQ-83850
33
+ @bucket.object(destination_name).public_url
34
+ end
35
+
36
+ def create_s3_name(file_name)
37
+ _validate_string(file_name)
38
+ file_name = _sanitize_string(file_name)
39
+ joined_name = [@project_name, @subdirectory_name, file_name].join(DELIMITER)
40
+ joined_name
41
+ end
42
+
43
+ def _sanitize_string(input_string)
44
+ #remove left/right whitespace, split and join to collapse contiguous white space, replace whitespace and non-period special chars with underscore
45
+ input_string = input_string.strip().split.join(" ").gsub(/[^\w.]/i, '_')
46
+ input_string
47
+ end
48
+
49
+ def _validate_string(input_string)
50
+ Log.debug("attempting to validate #{input_string} for use as a name")
51
+ if input_string.empty? or input_string.strip().empty? then
52
+ raise(ArgumentError, "empty and/or whitespace file names are not wanted here.")
53
+ end
54
+ end
55
+
56
+ def _validate_path(path_to_file)
57
+ Log.debug("attmepting to validate #{path_to_file} as a legitimate path")
58
+ if not File.exist? path_to_file then
59
+ raise(ArgumentError, "this path doesn't resolve #{path_to_file}")
60
+ end
61
+ end
62
+
63
+ def _verify_upload(s3_name, local_absolute_path)
64
+ upload_size = @bucket.object(s3_name).content_length
65
+ local_size = File.size local_absolute_path
66
+ Log.debug("file upload verified: #{upload_size == local_size}. upload size is #{upload_size} and local size is #{local_size}")
67
+ upload_size == local_size
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Urban
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,6 +116,7 @@ files:
116
116
  - lib/gridium/version.rb
117
117
  - lib/log.rb
118
118
  - lib/page.rb
119
+ - lib/s3.rb
119
120
  - lib/spec_data.rb
120
121
  homepage: http://github.com/sethuster/gridium
121
122
  licenses: