lineup 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ea9b6e95a25a526e1bb6317ec204a8518d4e4d
4
- data.tar.gz: 01f7795b66bb5b652c0f01925307b5fa6af6ea2e
3
+ metadata.gz: a9c1277997e4c9f112ae3a09071a8a54ff47ea66
4
+ data.tar.gz: 91015501ca8250b834c1473b121546a632f0d0b5
5
5
  SHA512:
6
- metadata.gz: 774b8f2777cd26e9609875e34a29336dcda9a5c254e3c78acf153a48d320b0a0587d2332c15090bdb8be10ed2daccec3c848f1fed0cbd8ccc1b662208aa5a5fb
7
- data.tar.gz: bfd830aa1e580998ba50c87bfbea26004a76202b97e46418607de0358bb22b52827bba433ef5d3af474ce3d52f785bc447b882d4b1564b345415cb1fe7d2d5c3
6
+ metadata.gz: 20cf39c0e193c0c1672fc717bdb8c326b8bce914835c566c3e77545c575c083e4c6685c958040853d63cb0c411cccbc2d5dd1da36c2bcfa17225e2cac6d46929
7
+ data.tar.gz: fc4a0df84e6779908648a52bd25e512c6ffe3d3c660079a61f9c28886cfbfbbdee0a949f08e0ba7227a5737f608efdb656f8007d99e8e4daefc6a4282c8579e5
@@ -7,7 +7,7 @@ require_relative '../helper'
7
7
 
8
8
  class Browser
9
9
 
10
- def initialize(baseurl, urls, resolutions, path, headless, wait, cookie = false)
10
+ def initialize(baseurl, urls, resolutions, path, headless, wait, cookies = [])
11
11
  @absolute_image_path = path
12
12
  FileUtils.mkdir_p @absolute_image_path
13
13
  @baseurl = baseurl
@@ -15,7 +15,7 @@ class Browser
15
15
  @resolutions = resolutions
16
16
  @headless = headless
17
17
  @wait = wait
18
- @cookie = cookie
18
+ @cookies = cookies
19
19
  end
20
20
 
21
21
  def record(version)
@@ -54,9 +54,11 @@ class Browser
54
54
 
55
55
  url = Helper.url(@baseurl, url)
56
56
  @browser.goto url
57
- if @cookie
57
+ if @cookies.any?
58
58
  @browser.cookies.clear
59
- @browser.cookies.add(@cookie[:name], @cookie[:value], domain: @cookie[:domain], path: @cookie[:path], expires: Time.now + 7200, secure: @cookie[:secure])
59
+ @cookies.each do |cookie|
60
+ @browser.cookies.add(cookie[:name], cookie[:value], domain: cookie[:domain], path: cookie[:path], expires: Time.now + 7200, secure: cookie[:secure])
61
+ end
60
62
  @browser.goto url
61
63
  end
62
64
  sleep @wait if @wait
@@ -82,7 +82,6 @@ module Lineup
82
82
  end
83
83
 
84
84
 
85
-
86
85
  def resolutions(resolutions)
87
86
 
88
87
  # all resolutions to be tested are defined here
@@ -109,7 +108,6 @@ module Lineup
109
108
  end
110
109
 
111
110
 
112
-
113
111
  def filepath_for_images(path)
114
112
 
115
113
  # if required an absolute path to store all images can be passed here.
@@ -127,12 +125,11 @@ module Lineup
127
125
  raise_base_screenshots_taken('The path')
128
126
 
129
127
  # the path is one string. we just assign the variable
130
-
128
+
131
129
  @screenshots_path = path
132
130
  end
133
131
 
134
-
135
-
132
+
136
133
  def use_phantomjs(boolean)
137
134
 
138
135
  # if required the headless environment can we skipped and firefox used for the screenshots
@@ -154,7 +151,6 @@ module Lineup
154
151
  end
155
152
 
156
153
 
157
-
158
154
  def difference_path(path)
159
155
 
160
156
  # if required an absolute path to store all difference images can be passed here.
@@ -201,6 +197,36 @@ module Lineup
201
197
  @cookie_for_experiment = cookie
202
198
  end
203
199
 
200
+ def cookies(cookies)
201
+
202
+ # a hash for cookies can be set here. this is optional.
203
+ #
204
+ # e.g {name: 'experiment', value: 'experiment_value', domain: 'domain.com', path: '/', expires: <Time>, secure: false}
205
+ #
206
+ # if it is not nil it has to be an array:
207
+
208
+ @cookies = []
209
+ if cookies
210
+ cookies.each do |cookie|
211
+ # generate :symbol => "value" hash map from "symbol" => "value"
212
+ cookie = cookie.inject({}) { |element, (symbol, value)| element[symbol.to_sym] = value; element }
213
+
214
+ #Validation
215
+ (raise "Cookie must be a hash of format
216
+ {name: 'experiment', value: 'experiment_value', domain: 'domain.com', path: '/', expires: <Time>, secure: false}
217
+ " unless cookie.is_a? Hash)
218
+
219
+ raise "cookie must have value for :name" unless (cookie[:name]).is_a? String
220
+ raise "cookie must have value for :value" unless (cookie[:value]).is_a? String
221
+ raise "cookie must have value for :domain" unless (cookie[:domain]).is_a? String
222
+ raise "cookie must have value for :path" unless (cookie[:path]).is_a? String
223
+ raise "cookie must have value for :secure" if (cookie[:secure]) == nil
224
+
225
+ @cookies.push(cookie)
226
+ end
227
+ end
228
+ end
229
+
204
230
 
205
231
  def wait_for_asynchron_pages(wait)
206
232
 
@@ -236,15 +262,24 @@ module Lineup
236
262
  difference_path(configuration["difference_path"])
237
263
  wait_for_asynchron_pages(configuration["wait_for_asynchron_pages"])
238
264
  cookie_for_experiment(configuration["cookie_for_experiment"])
265
+ cookies(configuration["cookies"])
266
+
267
+ if @cookies
268
+ cookies_merged= @cookies.inject([]) { |a,element| a << element.dup }
269
+ else
270
+ cookies_merged = []
271
+ end
272
+ if @cookie_for_experiment
273
+ cookies_merged.push(@cookie_for_experiment)
274
+ end
239
275
 
240
276
  # the method calls set the variables for the parameters, we return an array with all of them.
241
277
  # for the example above it is:
242
278
  # [["/multimedia", "/sport"], [600, 800, 1200], "~/images/", true, "#/images/diff"]
243
- [@urls, @resolutions, @screenshots_path, @headless, @difference_path, @wait_for_asynchron_pages, @cookie_for_experiment]
279
+ [@urls, @resolutions, @screenshots_path, @headless, @difference_path, @wait_for_asynchron_pages, cookies_merged]
244
280
  end
245
281
 
246
282
 
247
-
248
283
  def record_screenshot(version)
249
284
 
250
285
  # to take a screenshot we have all parameters given from the methods above (or set to default values)
@@ -257,7 +292,15 @@ module Lineup
257
292
  # and saves the screenshot in the file
258
293
  # @screenshot_path
259
294
 
260
- browser = Browser.new(@baseurl, @urls, @resolutions, @screenshots_path, @headless, @wait_for_asynchron_pages, @cookie_for_experiment)
295
+ if @cookies
296
+ cookies_merged= @cookies.inject([]) { |a,element| a << element.dup }
297
+ else
298
+ cookies_merged = []
299
+ end
300
+ if @cookie_for_experiment
301
+ cookies_merged.push(@cookie_for_experiment)
302
+ end
303
+ browser = Browser.new(@baseurl, @urls, @resolutions, @screenshots_path, @headless, @wait_for_asynchron_pages, cookies_merged)
261
304
 
262
305
  # the only argument missing is if this is the "base" or "new" screenshot, this can be
263
306
  # passed as an argument. The value does not need to be "base" or "new", but can be anything
@@ -274,7 +317,6 @@ module Lineup
274
317
  end
275
318
 
276
319
 
277
-
278
320
  def compare(base, new)
279
321
 
280
322
  # this compares two previously taken screenshots
@@ -313,7 +355,7 @@ module Lineup
313
355
  end
314
356
 
315
357
  def clean(urls)
316
- urls.gsub(' ', '').gsub(';',',')
358
+ urls.gsub(' ', '').gsub(';', ',')
317
359
  end
318
360
 
319
361
  end
@@ -1,7 +1,7 @@
1
1
  module Lineup
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
 
7
7
  class << self
@@ -30,7 +30,7 @@ describe '#screeshot_recorder' do
30
30
  # Then
31
31
  expect(
32
32
  lineup.load_json_config(file)
33
- ).to eq([['page1', 'page2'], [13,42], 'some/path', true, 'some/difference/image/path', 5, nil])
33
+ ).to eq([['page1', 'page2'], [13,42], 'some/path', true, 'some/difference/image/path', 5, []])
34
34
 
35
35
  # cleanup:
36
36
  FileUtils.rm file if (File.exists? file)
@@ -156,7 +156,21 @@ describe '#screeshot_recorder' do
156
156
  "domain":".google.de",
157
157
  "path":"/",
158
158
  "secure":false
159
- }
159
+ },
160
+ "cookies" : [{
161
+ "name":"cookie2",
162
+ "value":"22222",
163
+ "domain":".google.de",
164
+ "path":"/",
165
+ "secure":false
166
+ },
167
+ {
168
+ "name":"cookie3",
169
+ "value":"33333",
170
+ "domain":".google.de",
171
+ "path":"/",
172
+ "secure":false
173
+ }]
160
174
  }'
161
175
  save_json(json, file)
162
176
  lineup = Lineup::Screenshot.new(BASE_URL)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lineup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-02 00:00:00.000000000 Z
12
+ date: 2016-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.4.5.1
183
+ rubygems_version: 2.2.2
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: lineup will help you in your automated design regression testing