lineup 0.5.2 → 0.6.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: fef12db42af79b96ca8998beae02319bf95d47aa
4
- data.tar.gz: 080d552e625a913dd64a89fc55c2e5286833fe5f
3
+ metadata.gz: 4f3e24b0859c6f0c12ecf146e1564082f7f8a6a3
4
+ data.tar.gz: 08743eb9f69f2bd4b820c02a3799bd22e358acb5
5
5
  SHA512:
6
- metadata.gz: d42427ce1bb9db21d587e286645f4e8cb60020d22687910f620337cc4c55492b231c588d767d0810030c882c30f48e195f2904ae2a41f59130e975cbce0e0045
7
- data.tar.gz: 1601351d06b6149fd308ac935a13b65106e2985cd63a7f37c4c051a3b9b354e603d0ffbaa3058aebff958e6892d00101603459595c0978582810929ed3691674
6
+ metadata.gz: 259f123498f086d61fb790aec5b791d0a99b273f3eb7ee34aa3989b9a654c7cfe6b01f6bff25495f4227bff1c4104183fc92b468695474d1ecb51f15b540bf4b
7
+ data.tar.gz: 93f0f59e0ea444937fd85d0d9338be16bbfdb712186a4f69a1c8b2248a5b0a8c157c47c923be86931490b31bcc1b67814188ff44c4467d669f8f2c0cf5f37154
data/bin/lineup CHANGED
@@ -4,20 +4,28 @@ require '../lib/lineup'
4
4
 
5
5
  puts("This is an example. And a benchmark.")
6
6
 
7
- lineup = Lineup::Screenshot.new('https://uhr.ptb.de')
8
- lineup.wait_for_asynchron_pages(1)
9
- lineup.use_phantomjs true
7
+ lineup = Lineup::Screenshot.new('https://prelive.otto.de')
8
+ lineup.urls("/,multimedia,moebel,damenmode,mittesten")
9
+ lineup.cookies([{"name"=>"trackingDisabled","value"=>"true","secure"=>false,"path"=>"/","domain"=>".otto.de"},
10
+ {"name"=>"survey","value"=>"1","secure"=>false,"path"=>"/","domain"=>".otto.de"}])
11
+ lineup.localStorage(["us_customerServiceWidget"=>"{'customerServiceWidgetNotificationHidden':{'value':true,'timestamp':1467723066080}}"])
12
+ lineup.resolutions("600,800,1200")
13
+ lineup.use_phantomjs false
14
+ lineup.wait_for_asynchron_pages(2)
15
+
16
+ puts("Taking base screenshots")
10
17
  start = Time.now
11
- puts("Taking screenshots")
12
18
  lineup.record_screenshot('base')
13
19
  screenshots = Time.now
14
- sleep(2)
15
- lineup.record_screenshot('nun')
16
- screenshots2 = Time.now - 2
20
+
21
+ puts("Taking new screenshots")
22
+ lineup.record_screenshot('new')
23
+ screenshots2 = Time.now
24
+
17
25
  puts("Starting comparison")
18
- lineup.compare('base', 'nun')
26
+ lineup.compare('base', 'new')
19
27
  lineup.save_json(".")
20
- compare = Time.now - 2
28
+ compare = Time.now
21
29
 
22
30
  s_t = screenshots - start
23
31
  puts("Screenshots first run took #{s_t} seconds")
@@ -7,7 +7,7 @@ require_relative '../helper'
7
7
 
8
8
  class Browser
9
9
 
10
- def initialize(baseurl, urls, resolutions, path, headless, wait, cookies = [])
10
+ def initialize(baseurl, urls, resolutions, path, headless, wait, cookies = [], localStorage = [])
11
11
  @absolute_image_path = path
12
12
  FileUtils.mkdir_p @absolute_image_path
13
13
  @baseurl = baseurl
@@ -15,7 +15,18 @@ class Browser
15
15
  @resolutions = resolutions
16
16
  @headless = headless
17
17
  @wait = wait
18
- @cookies = cookies
18
+
19
+ if cookies
20
+ @cookies = cookies
21
+ else
22
+ @cookies = []
23
+ end
24
+
25
+ if localStorage
26
+ @localStorage = localStorage
27
+ else
28
+ @localStorage = []
29
+ end
19
30
  end
20
31
 
21
32
  def record(version)
@@ -53,14 +64,29 @@ class Browser
53
64
  @browser.driver.manage.window.resize_to(width, 1000)
54
65
 
55
66
  url = Helper.url(@baseurl, url)
56
- @browser.goto url
57
- if @cookies.any?
58
- @browser.cookies.clear
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
67
+
68
+ if @cookies.any? || @localStorage.any?
69
+ # load url first before setting cookies and/or localStorage values
62
70
  @browser.goto url
71
+
72
+ if @cookies.any?
73
+ @browser.cookies.clear
74
+ @cookies.each do |cookie|
75
+ @browser.cookies.add(cookie[:name], cookie[:value], domain: cookie[:domain], path: cookie[:path], expires: Time.now + 7200, secure: cookie[:secure])
76
+ end
77
+ end
78
+
79
+ if @localStorage.any?
80
+ @localStorage.each do |keyValue|
81
+ # Generate javascript for localStorage.setItem, escaping single quotes in key and value
82
+ stmt = "localStorage.setItem('" + keyValue.keys.first.gsub("'", "\\\\'") + "','" + keyValue.values.first.gsub("'", "\\\\'") + "')";
83
+ @browser.execute_script(stmt)
84
+ end
85
+ end
63
86
  end
87
+
88
+ @browser.goto url
89
+
64
90
  sleep @wait if @wait
65
91
  @browser.screenshot.save( File.expand_path(filename))
66
92
  end
data/lib/lineup.rb CHANGED
@@ -230,6 +230,36 @@ module Lineup
230
230
  end
231
231
 
232
232
 
233
+ def localStorage(localStorage)
234
+
235
+ # a hash for localStorage Key Value pair can be set here. this is optional.
236
+ #
237
+ # e.g {'key': 'value'}
238
+ #
239
+ # if it is not nil it has to be an array:
240
+
241
+ @localStorage = []
242
+ if localStorage
243
+ localStorage.each do |keyValue|
244
+ # generate :symbol => "value" hash map from "symbol" => "value"
245
+ #keyValue = keyValue.inject({}) { |element, (symbol, value)| element[symbol.to_sym] = value; element }
246
+
247
+ #Validation
248
+ (raise "LocalStorage Key Value pair must be a hash of format
249
+ {'key'=>'value'}
250
+ " unless keyValue.is_a? Hash)
251
+
252
+ raise "LocalStorage Key Value pair must have exactly one key" unless (keyValue.keys.length) == 1
253
+ raise "LocalStorage Key Value pair must have exactly one value" unless (keyValue.values.length) == 1
254
+ raise "LocalStorage Key Value pair must have a string as key" unless (keyValue.keys.first).is_a? String
255
+ raise "LocalStorage Key Value pair must have a string as value" unless (keyValue.values.first).is_a? String
256
+
257
+ @localStorage.push(keyValue)
258
+ end
259
+ end
260
+
261
+ end
262
+
233
263
  def wait_for_asynchron_pages(wait)
234
264
 
235
265
  # if required a wait time in seconds can be set. This may be needed, if after pageload some
@@ -265,6 +295,7 @@ module Lineup
265
295
  wait_for_asynchron_pages(configuration["wait_for_asynchron_pages"])
266
296
  cookie_for_experiment(configuration["cookie_for_experiment"])
267
297
  cookies(configuration["cookies"])
298
+ localStorage(configuration["localStorage"])
268
299
 
269
300
  if @cookies
270
301
  cookies_merged= @cookies.inject([]) { |a, element| a << element.dup }
@@ -278,7 +309,7 @@ module Lineup
278
309
  # the method calls set the variables for the parameters, we return an array with all of them.
279
310
  # for the example above it is:
280
311
  # [["/multimedia", "/sport"], [600, 800, 1200], "~/images/", true, "#/images/diff"]
281
- [@urls, @resolutions, @screenshots_path, @headless, @difference_path, @wait_for_asynchron_pages, cookies_merged]
312
+ [@urls, @resolutions, @screenshots_path, @headless, @difference_path, @wait_for_asynchron_pages, cookies_merged, @localStorage]
282
313
  end
283
314
 
284
315
 
@@ -303,7 +334,7 @@ module Lineup
303
334
  cookies_merged.push(@cookie_for_experiment)
304
335
  end
305
336
 
306
- browser = Browser.new(@baseurl, @urls, @resolutions, @screenshots_path, @headless, @wait_for_asynchron_pages, cookies_merged)
337
+ browser = Browser.new(@baseurl, @urls, @resolutions, @screenshots_path, @headless, @wait_for_asynchron_pages, cookies_merged, @localStorage)
307
338
  # the only argument missing is if this is the "base" or "new" screenshot, this can be
308
339
  # passed as an argument. The value does not need to be "base" or "new", but can be anything
309
340
  browser.record(version)
@@ -1,8 +1,8 @@
1
1
  module Lineup
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 5
5
- PATCH = 2
4
+ MINOR = 6
5
+ PATCH = 0
6
6
 
7
7
  class << self
8
8
  def to_s
@@ -6,21 +6,68 @@ require_relative '../../lib/lineup'
6
6
 
7
7
  describe '#screeshot_recorder' do
8
8
 
9
- BASE_URL = 'https://www.google.de/'
9
+ BASE_URL = 'https://www.google.de'
10
10
  SCREENSHOTS = "#{Dir.pwd}/screenshots/"
11
11
 
12
12
  after(:each) { FileUtils.rmtree SCREENSHOTS }
13
13
 
14
+ it 'loads minimum configuration from a json file' do
15
+ # Given
16
+ file = "#{Dir.pwd}/test_configuration.json"
17
+ FileUtils.rm file if (File.exists? file)
18
+ json = '{"urls":"page1",
19
+ "resolutions": "13",
20
+ "filepath_for_images":"screenshots/path",
21
+ "use_phantomjs":true,
22
+ "difference_path":"screenshots/path/difference",
23
+ "wait_for_asynchron_pages":5
24
+ }'
25
+ save_json(json, file)
26
+
27
+ # When
28
+ lineup = Lineup::Screenshot.new(BASE_URL)
29
+
30
+ # Then
31
+ expect(
32
+ lineup.load_json_config(file)
33
+ ).to eq([['page1'], [13], 'screenshots/path', true, 'screenshots/path/difference', 5, [], []])
34
+
35
+ # cleanup:
36
+ FileUtils.rm file if (File.exists? file)
37
+ end
38
+
14
39
  it 'loads all configuration from a json file' do
15
40
  # Given
16
41
  file = "#{Dir.pwd}/test_configuration.json"
17
42
  FileUtils.rm file if (File.exists? file)
18
43
  json = '{"urls":"page1, page2",
19
44
  "resolutions":"13,42",
20
- "filepath_for_images":"some/path",
45
+ "filepath_for_images":"screenshots/path",
21
46
  "use_phantomjs":true,
22
- "difference_path":"some/difference/image/path",
23
- "wait_for_asynchron_pages":5
47
+ "difference_path":"screenshots/path/difference",
48
+ "wait_for_asynchron_pages":5,
49
+ "cookie_for_experiment":{
50
+ "name":"cookie1",
51
+ "value":"11111",
52
+ "domain":".google.de",
53
+ "path":"/",
54
+ "secure":false
55
+ },
56
+ "cookies" : [{
57
+ "name":"cookie2",
58
+ "value":"22222",
59
+ "domain":".google.de",
60
+ "path":"/",
61
+ "secure":false
62
+ },
63
+ {
64
+ "name":"cookie3",
65
+ "value":"33333",
66
+ "domain":".google.de",
67
+ "path":"/",
68
+ "secure":false
69
+ }],
70
+ "localStorage":[{"myKey1":"myValue1"},{"myKey2":"myValue2"}]
24
71
  }'
25
72
  save_json(json, file)
26
73
 
@@ -30,7 +77,11 @@ describe '#screeshot_recorder' do
30
77
  # Then
31
78
  expect(
32
79
  lineup.load_json_config(file)
33
- ).to eq([['page1', 'page2'], [13,42], 'some/path', true, 'some/difference/image/path', 5, []])
80
+ ).to eq([['page1', 'page2'], [13,42], 'screenshots/path', true, 'screenshots/path/difference', 5,
81
+ [{:name=>"cookie2", :value=>"22222", :domain=>".google.de", :path=>"/", :secure=>false},
82
+ {:name=>"cookie3", :value=>"33333", :domain=>".google.de", :path=>"/", :secure=>false},
83
+ {:name=>"cookie1", :value=>"11111", :domain=>".google.de", :path=>"/", :secure=>false}],
84
+ [{"myKey1"=>"myValue1"}, {"myKey2"=>"myValue2"}]])
34
85
 
35
86
  # cleanup:
36
87
  FileUtils.rm file if (File.exists? file)
@@ -58,7 +109,30 @@ describe '#screeshot_recorder' do
58
109
 
59
110
  end
60
111
 
61
- it 'takes a screenshot a desired resolution' do
112
+ it 'opens a URL and takes mobile/tablet/desktop screenshots using firefox' do
113
+ # Given
114
+ lineup = Lineup::Screenshot.new(BASE_URL)
115
+ lineup.use_phantomjs false
116
+
117
+ # When
118
+ lineup.record_screenshot('base')
119
+
120
+ # Then
121
+ expect(
122
+ File.exist? ("#{Dir.pwd}/screenshots/frontpage_640_base.png")
123
+ ).to be(true)
124
+ # And
125
+ expect(
126
+ File.exist? ("#{Dir.pwd}/screenshots/frontpage_800_base.png")
127
+ ).to be(true)
128
+ # And
129
+ expect(
130
+ File.exist? ("#{Dir.pwd}/screenshots/frontpage_1180_base.png")
131
+ ).to be(true)
132
+
133
+ end
134
+
135
+ it 'takes a screenshot at desired resolution' do
62
136
  # Given
63
137
  width = '700'
64
138
  lineup = Lineup::Screenshot.new(BASE_URL)
@@ -99,7 +173,7 @@ describe '#screeshot_recorder' do
99
173
 
100
174
  end
101
175
 
102
- it 'raises and exception if, parameters are changed after the base screenshot' do
176
+ it 'raises and exception if parameters are changed after the base screenshot' do
103
177
  # Given
104
178
  lineup = Lineup::Screenshot.new(BASE_URL)
105
179
  lineup.urls('/')
@@ -144,11 +218,12 @@ describe '#screeshot_recorder' do
144
218
  # Given
145
219
  file = "#{Dir.pwd}/test_configuration.json"
146
220
  FileUtils.rm file if (File.exists? file)
221
+
147
222
  json = '{"urls":"page1, page2",
148
223
  "resolutions":"13,42",
149
- "filepath_for_images":"some/path",
224
+ "filepath_for_images":"screenshots/path",
150
225
  "use_phantomjs":true,
151
- "difference_path":"some/difference/image/path",
226
+ "difference_path":"screenshots/path/difference",
152
227
  "wait_for_asynchron_pages":5,
153
228
  "cookie_for_experiment":{
154
229
  "name":"CONSENT",
@@ -188,6 +263,64 @@ describe '#screeshot_recorder' do
188
263
 
189
264
  # cleanup:
190
265
  FileUtils.rm file if (File.exists? file)
266
+
267
+ end
268
+
269
+ it 'takes a screenshot when loading a json config and setting local storage key value pair containing single quotes' do
270
+ # Given
271
+ file = "#{Dir.pwd}/test_configuration.json"
272
+ FileUtils.rm file if (File.exists? file)
273
+
274
+ json = '{"urls":"page1",
275
+ "resolutions":"200",
276
+ "filepath_for_images":"screenshots/path",
277
+ "use_phantomjs":true,
278
+ "difference_path":"screenshots/path/difference",
279
+ "wait_for_asynchron_pages":5,
280
+ "localStorage":[{"{\'mySpecialKey\'}":"{\'customerServiceWidgetNotificationHidden\':{\'value\':true,\'timestamp\':1467723066092}}"}]
281
+ }'
282
+ save_json(json, file)
283
+ lineup = Lineup::Screenshot.new(BASE_URL)
284
+ lineup.load_json_config(file)
285
+
286
+ lineup.record_screenshot('base')
287
+ # expect: no exception
288
+
289
+ # cleanup:
290
+ FileUtils.rm file if (File.exists? file)
291
+
292
+ end
293
+
294
+ it 'compares a base and a new screenshot when loading a json config and setting local storage key value pairs' do
295
+ # Given
296
+ file = "#{Dir.pwd}/test_configuration.json"
297
+ FileUtils.rm file if (File.exists? file)
298
+
299
+ json = '{"urls":"page1",
300
+ "resolutions":"200",
301
+ "filepath_for_images":"screenshots/path",
302
+ "use_phantomjs":true,
303
+ "difference_path":"screenshots/path/difference",
304
+ "wait_for_asynchron_pages":5,
305
+ "localStorage":[{"us_customerServiceWidget":"{\'customerServiceWidgetNotificationHidden\':{\'value\':true,\'timestamp\':1467723066092}}"},{"myKey2":"myValue2"}]
306
+ }'
307
+ save_json(json, file)
308
+ lineup = Lineup::Screenshot.new(BASE_URL)
309
+ lineup.load_json_config(file)
310
+
311
+ lineup.record_screenshot('base')
312
+ lineup.record_screenshot('new')
313
+
314
+ expect(
315
+ # When
316
+ lineup.compare('base', 'new')
317
+
318
+ # Then
319
+ ).to eq([])
320
+
321
+ # cleanup:
322
+ FileUtils.rm file if (File.exists? file)
323
+
191
324
  end
192
325
 
193
326
  it 'compares a base and a new screenshot and returns the difference if the images are NOT the same as json log' do
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.5.2
4
+ version: 0.6.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-06-21 00:00:00.000000000 Z
12
+ date: 2016-07-05 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.8
183
+ rubygems_version: 2.5.1
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: lineup will help you in your automated design regression testing