eyes_selenium 3.2.2 → 3.3.2

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: 38109543a878245f5b8576910af990ede12cea75
4
- data.tar.gz: d41a05ad3914b018a74922f1502932512b8699d5
3
+ metadata.gz: e79fbaad2e65435471ba70672dd81c0765cb2e67
4
+ data.tar.gz: 030f097040e4f3ab96bf0cb00313724f1f22c3d1
5
5
  SHA512:
6
- metadata.gz: 86b7f6b18e4c951d025c7e7d603bc2795569a0da377fa9b9c5d5ede25f22d8b89170028a2c37d3e7a2d6aea1fe2fe313274b80011d19811bea3d970dc7468abb
7
- data.tar.gz: 46d7ce59515dd15ae5c40586c636c58b90da2c80ab401b473055f1e65bb92b86051634cb4d13df57baca7bb9f2dff345f63fbc7ee203b8236bbebaf595cf429a
6
+ metadata.gz: e8ac42ec51804f6a0a4624729d97ffa153ea6443d53ed7016ad6bffb964fba1a4a9cfb119fe8e200cf9db9170eda199e5ee83238ed9cb285db9e2c29a0a8ea41
7
+ data.tar.gz: 672c0e3a7af3c8207ed8018ca0c9ad3a6909f82398a4d10711fdc524039d0b3b386e5cf7c3a55890d1ee6aa3bf102e5e340eb4f22a80264c02f9245d195a994d
@@ -175,6 +175,15 @@ module Applitools::Selenium
175
175
  driver.execute_script format(JS_SCROLL_TO_FORMATTED_STR, location.x, location.y), self
176
176
  end
177
177
 
178
+ def to_hash
179
+ {
180
+ left: location.x.to_i,
181
+ top: location.y.to_i,
182
+ width: size.width.to_i,
183
+ height: size.height.to_i
184
+ }
185
+ end
186
+
178
187
  private
179
188
 
180
189
  attr_reader :driver
@@ -31,6 +31,8 @@ module Applitools::Selenium
31
31
  current_position
32
32
  end
33
33
 
34
+ alias force_offset state
35
+
34
36
  def restore_state(value)
35
37
  self.position = value
36
38
  end
@@ -217,6 +217,160 @@ module Applitools::Selenium
217
217
  Applitools::Utils::EyesSeleniumUtils.extract_viewport_size(driver)
218
218
  end
219
219
 
220
+ def check(name, target)
221
+ Applitools::ArgumentGuard.is_a? target, 'target', Applitools::Selenium::Target
222
+ original_overflow = nil
223
+ original_position_provider = position_provider
224
+
225
+ eyes_element = nil
226
+
227
+ self.eyes_screenshot_factory = lambda do |image|
228
+ Applitools::Selenium::EyesWebDriverScreenshot.new(
229
+ image, driver: driver, force_offset: position_provider.force_offset
230
+ )
231
+ end
232
+
233
+ check_in_frame target_frames: target.frames do
234
+ begin
235
+ eyes_element = target.region_to_check.call(driver)
236
+
237
+ region_visibility_strategy.move_to_region original_position_provider,
238
+ Applitools::Location.new(eyes_element.location.x.to_i, eyes_element.location.y.to_i)
239
+
240
+ check_window = false
241
+ if (!target.frames.empty?) && eyes_element.is_a?(Applitools::Region)
242
+ #check_current_frame
243
+ region_provider = region_provider_for_frame
244
+
245
+ elsif eyes_element.is_a? Applitools::Selenium::Element
246
+ #check_element
247
+ region_provider = Applitools::Selenium::RegionProvider.new(
248
+ region_for_element(eyes_element),
249
+ target.coordinate_type
250
+ )
251
+ else
252
+ #check_window
253
+ region_provider = Applitools::Selenium::RegionProvider.new(
254
+ region_for_element(eyes_element),
255
+ target.coordinate_type
256
+ )
257
+ check_window = true
258
+ end
259
+
260
+ if target.options[:stitch_content]
261
+ check_window ? self.force_full_page_screenshot = true : self.check_frame_or_element = true
262
+ if eyes_element.is_a? Applitools::Selenium::Element
263
+ self.position_provider = Applitools::Selenium::ElementPositionProvider.new driver, eyes_element
264
+
265
+ original_overflow = eyes_element.overflow
266
+ eyes_element.overflow = 'hidden'
267
+ end
268
+
269
+ self.region_to_check = region_provider
270
+
271
+ region_provider = Object.new.tap do |prov|
272
+ prov.instance_eval do
273
+ define_singleton_method :region do
274
+ Applitools::Region::EMPTY
275
+ end
276
+
277
+ define_singleton_method :coordinate_type do
278
+ nil
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ check_window_base(
285
+ region_provider, name, false, target.options[:timeout] || USE_DEFAULT_MATCH_TIMEOUT,
286
+ ignore: target.ignored_regions.map {|i| i.call(driver)},
287
+ trim: target.options[:trim]
288
+ )
289
+ ensure
290
+ eyes_element.overflow = original_overflow unless original_overflow.nil?
291
+ self.check_frame_or_element = false
292
+ self.force_full_page_screenshot = false
293
+ self.position_provider = original_position_provider
294
+ self.region_to_check = nil
295
+ region_visibility_strategy.return_to_original_position position_provider
296
+ end
297
+ end
298
+ end
299
+
300
+ def check_in_frame(options)
301
+ frames = options.delete :target_frames
302
+
303
+ Applitools::ArgumentGuard.is_a? options, 'options', Hash
304
+ Applitools::ArgumentGuard.is_a? frames, 'target_frames: []', Array
305
+
306
+ return yield if block_given? && frames.empty?
307
+
308
+ original_frame_chain = driver.frame_chain
309
+ logger.info 'Switching to target frame according to frames path...'
310
+ driver.switch_to.frames(frames_path: frames)
311
+ logger.info 'Done!'
312
+
313
+ yield if block_given?
314
+
315
+
316
+ logger.info 'Switching back into top level frame...'
317
+ driver.switch_to.default_content()
318
+ unless original_frame_chain
319
+ logger.info 'Switching back into original frame...'
320
+ driver.switch_to.frames frame_chain: original_frame_chain
321
+ end
322
+ end
323
+
324
+ def region_for_element(element)
325
+ return element if element.is_a? Applitools::Region
326
+
327
+ p = element.location
328
+ d = element.size
329
+
330
+ border_left_width = element.border_left_width
331
+ border_top_width = element.border_top_width
332
+ border_right_width = element.border_right_width
333
+ border_bottom_width = element.border_bottom_width
334
+
335
+ Applitools::Region.new(
336
+ p.x + border_left_width,
337
+ p.y + border_top_width,
338
+ d.width - border_left_width - border_right_width,
339
+ d.height - border_top_width - border_bottom_width
340
+ )
341
+ end
342
+
343
+ def region_provider_for_frame()
344
+ Object.new.tap do |provider|
345
+ current_frame_size = lambda do
346
+ frame_region = Applitools::Region.from_location_size(
347
+ Applitools::Location.new(0, 0), driver.frame_chain!.current_frame.size
348
+ )
349
+ begin
350
+ frame_region.intersect Applitools::Region.from_location_size(
351
+ Applitools::Location.new(0, 0),
352
+ Applitools::Utils::EyesSeleniumUtils.entire_page_size(driver)
353
+ )
354
+ frame_region
355
+ ensure
356
+ frame_region
357
+ end
358
+ end
359
+
360
+ provider.instance_eval do
361
+ define_singleton_method :region do
362
+ current_frame_size.call
363
+ end
364
+ define_singleton_method :coordinate_type do
365
+ Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
366
+ end
367
+ end
368
+ end
369
+ end
370
+
371
+ private :check_in_frame
372
+ private :region_for_element
373
+
220
374
  # Takes a snapshot of the application under test and matches a region of
221
375
  # a specific element with the expected region output.
222
376
  # @param [Applitools::Selenium::Element] element Represents a region to check.
@@ -397,12 +551,15 @@ module Applitools::Selenium
397
551
  options[:name_or_id] ||
398
552
  options[:frame_element] ||
399
553
  options[:frame_chain] ||
400
- options[:frames_path]
554
+ options[:frames_path] ||
555
+ options[:target_frames]
401
556
  raise Applitools::EyesIllegalArgument.new 'You must pass :index or :name_or_id or :frame_element option' /
402
557
  'or :frame_chain option or :frames_path option'
403
558
  end
404
559
 
405
- if (needed_keys = (options.keys & [:index, :name_or_id, :frame_element, :frame_chain, :frames_path])).length == 1
560
+ if (needed_keys = (
561
+ options.keys & [:index, :name_or_id, :frame_element, :frame_chain, :frames_path, :target_frames])
562
+ ).length == 1
406
563
  frame_key = needed_keys.first
407
564
  else
408
565
  raise Applitools::EyesIllegalArgument.new 'You\'ve passed some extra keys!' /
@@ -145,7 +145,7 @@ module Applitools::Selenium
145
145
  raise Applitools::EyesNoSuchFrame.new "No frame with name or id #{name_or_id} exists!" if frames.empty?
146
146
  end
147
147
  logger.info 'Done! Making preparations...'
148
- on_will_switch.will_switch_to_frame(:frame, frames.first).last
148
+ on_will_switch.will_switch_to_frame(:frame, frames.first)
149
149
  logger.info 'Done! Switching to frame...'
150
150
  __getobj__.frame frames.first
151
151
 
@@ -181,7 +181,16 @@ module Applitools::Selenium
181
181
  logger.info 'EyesTargetLocator.frames(:frames_path => a_chain)'
182
182
  frames_path.each do |frame_name_or_id|
183
183
  logger.info 'Switching to frame...'
184
- frame(name_or_id: frame_name_or_id)
184
+ logger.info frame_name_or_id
185
+ case frame_name_or_id
186
+ when String
187
+ frame(name_or_id: frame_name_or_id)
188
+ when Applitools::Selenium::Element
189
+ frame(frame_element: frame_name_or_id.reference)
190
+ else
191
+ Applitools::ArgumentGuard.raise_argument_error Applitools::EyesNoSuchFrame.new frame_name_or_id
192
+ end
193
+
185
194
  logger.info 'Done!'
186
195
  end
187
196
  logger.info 'Done switching into nested frames!'
@@ -25,6 +25,7 @@ module Applitools::Selenium
25
25
  end
26
26
 
27
27
  def return_to_original_position(position_provider)
28
+ return if original_position.nil?
28
29
  logger.info 'Returning to original position...'
29
30
  position_provider.restore_state original_position
30
31
  logger.info 'Done!'
@@ -0,0 +1,10 @@
1
+ module Applitools::Selenium
2
+ class RegionProvider
3
+ #он нам нужен в селениум?
4
+ attr_reader :region, :coordinate_type
5
+ def initialize(region, coordinate_type)
6
+ @region = region
7
+ @coordinate_type = coordinate_type
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,97 @@
1
+ module Applitools
2
+ module Selenium
3
+ class Target
4
+ class << self
5
+ def window
6
+ self.new()
7
+ end
8
+
9
+ def region(element)
10
+ self.new().region(element)
11
+ end
12
+ end
13
+
14
+ attr_accessor :element, :frames, :region_to_check, :coordinate_type, :options, :ignored_regions
15
+
16
+ def initialize()
17
+ self.frames = []
18
+ self.options = {}
19
+ reset_for_fullscreen
20
+ end
21
+
22
+ def ignore(*args)
23
+ if(args.first)
24
+ if args.first.is_a? Applitools::Selenium::Element
25
+ self.ignored_regions << proc do
26
+ args.first
27
+ end
28
+ else
29
+ self.ignored_regions << proc do |driver|
30
+ driver.find_element *args
31
+ end
32
+ end
33
+ else
34
+ reset_ignore
35
+ end
36
+ self
37
+ end
38
+
39
+ def float(*args)
40
+ self
41
+ end
42
+
43
+ def fully
44
+ options[:stitch_content] = true
45
+ self
46
+ end
47
+
48
+ def timeout(value)
49
+ options[:timeout] = value
50
+ self
51
+ end
52
+
53
+ def frame(element)
54
+ frames << element
55
+ reset_for_fullscreen
56
+ self
57
+ end
58
+
59
+ def region(*args)
60
+ if args.first.is_a? Applitools::Selenium::Element
61
+ self.region_to_check = proc do
62
+ args.first
63
+ end
64
+ else
65
+ self.region_to_check = proc do |driver|
66
+ driver.find_element *args
67
+ end
68
+ end
69
+ self.coordinate_type = Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
70
+ options[:timeout] = nil
71
+ reset_ignore
72
+ self
73
+ end
74
+
75
+ def trim
76
+ options[:trim] = true
77
+ self
78
+ end
79
+
80
+ private
81
+
82
+ def reset_for_fullscreen
83
+ self.coordinate_type = nil
84
+ self.region_to_check = proc { Applitools::Region::EMPTY }
85
+ reset_ignore
86
+ options[:stitch_content] = false
87
+ options[:timeout] = nil
88
+ options[:trim] = false
89
+ end
90
+
91
+ def reset_ignore
92
+ self.ignored_regions = []
93
+ end
94
+ end
95
+ end
96
+ end
97
+
@@ -1,3 +1,3 @@
1
1
  module Applitools
2
- VERSION = '3.2.2'.freeze
2
+ VERSION = '3.3.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Applitools Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eyes_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.2
19
+ version: 3.3.2
20
20
  type: :runtime
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: 3.2.2
26
+ version: 3.3.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: selenium-webdriver
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,9 +94,11 @@ files:
94
94
  - lib/applitools/selenium/mouse.rb
95
95
  - lib/applitools/selenium/move_to_region_visibility_strategy.rb
96
96
  - lib/applitools/selenium/nop_region_visibility_strategy.rb
97
+ - lib/applitools/selenium/region_provider.rb
97
98
  - lib/applitools/selenium/sauce/driver.rb
98
99
  - lib/applitools/selenium/scroll_position_provider.rb
99
100
  - lib/applitools/selenium/takes_screenshot_image_provider.rb
101
+ - lib/applitools/selenium/target.rb
100
102
  - lib/applitools/selenium/viewport_size.rb
101
103
  - lib/applitools/version.rb
102
104
  - lib/eyes_selenium.rb