eyes_selenium 3.14.3 → 3.14.4
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 +5 -5
- data/lib/applitools/selenium/border_aware_element_content_location_provider.rb +2 -0
- data/lib/applitools/selenium/browser.rb +66 -56
- data/lib/applitools/selenium/context_based_scale_provider.rb +2 -0
- data/lib/applitools/selenium/css_transform/css_transform.rb +21 -0
- data/lib/applitools/selenium/css_translate_element_position_provider.rb +48 -0
- data/lib/applitools/selenium/css_translate_position_provider.rb +29 -10
- data/lib/applitools/selenium/dom_capture/dom_capture.rb +113 -0
- data/lib/applitools/selenium/dom_capture/dom_capture_script.rb +103 -0
- data/lib/applitools/selenium/driver.rb +9 -2
- data/lib/applitools/selenium/element.rb +2 -0
- data/lib/applitools/selenium/element_position_provider.rb +3 -1
- data/lib/applitools/selenium/entire_element_screenshot.rb +20 -0
- data/lib/applitools/selenium/eyes.rb +203 -396
- data/lib/applitools/selenium/eyes_screenshot.rb +60 -0
- data/lib/applitools/selenium/eyes_target_locator.rb +12 -24
- data/lib/applitools/selenium/fixed_cut_provider.rb +48 -0
- data/lib/applitools/selenium/frame.rb +11 -1
- data/lib/applitools/selenium/frame_chain.rb +9 -1
- data/lib/applitools/selenium/full_page_capture_algorithm.rb +85 -50
- data/lib/applitools/selenium/fullpage_screenshot.rb +37 -0
- data/lib/applitools/selenium/keyboard.rb +2 -0
- data/lib/applitools/selenium/mouse.rb +2 -0
- data/lib/applitools/selenium/move_to_region_visibility_strategy.rb +2 -0
- data/lib/applitools/selenium/nop_region_visibility_strategy.rb +2 -0
- data/lib/applitools/selenium/region_provider.rb +91 -0
- data/lib/applitools/selenium/sauce/driver.rb +2 -0
- data/lib/applitools/selenium/scroll_position_provider.rb +13 -2
- data/lib/applitools/selenium/takes_screenshot_image_provider.rb +5 -3
- data/lib/applitools/selenium/target.rb +32 -6
- data/lib/applitools/selenium/viewport_screenshot.rb +46 -0
- data/lib/applitools/selenium/viewport_size.rb +2 -0
- data/lib/applitools/version.rb +3 -1
- data/lib/eyes_selenium.rb +4 -9
- metadata +16 -27
- data/lib/applitools/capybara.rb +0 -8
- data/lib/applitools/poltergeist/applitools_compatible.rb +0 -32
- data/lib/applitools/poltergeist/driver.rb +0 -11
- data/lib/applitools/selenium/capybara/capybara_settings.rb +0 -23
- data/lib/applitools/selenium/capybara/driver.rb +0 -37
- data/lib/applitools/selenium/eyes_full_page_screenshot.rb +0 -47
- data/lib/applitools/selenium/eyes_web_driver_screenshot.rb +0 -341
data/lib/applitools/capybara.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# This module is used for compatibility with Applitools API.
|
2
|
-
# Should be extended by Poltergeist driver instance.
|
3
|
-
module Applitools::Poltergeist
|
4
|
-
module ApplitoolsCompatible
|
5
|
-
# Implementation of `screenshot_as` method for PhantomJS.
|
6
|
-
# Realisation uses Poltergeist binding to `renderBase64` PhantomJS method.
|
7
|
-
def screenshot_as(fmt)
|
8
|
-
Base64.decode64(browser.render_base64(fmt))
|
9
|
-
end
|
10
|
-
|
11
|
-
# Poltergeist driver does not have `manage` and `window` methods.
|
12
|
-
# In Applitools these methods are used in a chain to get size by `size` method call.
|
13
|
-
%w(manage window).each do |method_name|
|
14
|
-
define_method(method_name) { self }
|
15
|
-
end
|
16
|
-
|
17
|
-
# Method provides opened window size in Applitools format.
|
18
|
-
def size
|
19
|
-
size = window_size(current_window_handle)
|
20
|
-
Applitools::Base::Dimension.new(size[0], size[1])
|
21
|
-
end
|
22
|
-
|
23
|
-
# Method changes opened window size in a way how original Applitools::Selenium::Driver does.
|
24
|
-
def size=(new_size)
|
25
|
-
resize(new_size.width, new_size.height)
|
26
|
-
end
|
27
|
-
|
28
|
-
# def switch_to(*args)
|
29
|
-
# switch_to_frame(*args)
|
30
|
-
# end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# Applitools::Poltergeist::Driver is a small class implemented
|
2
|
-
# for compatibility with Applitools API.
|
3
|
-
# It gives required for Applitools methods to Poltergeist driver.
|
4
|
-
module Applitools::Poltergeist
|
5
|
-
class Driver < Applitools::Selenium::Driver
|
6
|
-
def initialize(eyes, options)
|
7
|
-
options[:driver].extend Applitools::Poltergeist::ApplitoolsCompatible
|
8
|
-
super(eyes, options)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Applitools
|
2
|
-
module Selenium
|
3
|
-
module Capybara
|
4
|
-
module CapybaraSettings
|
5
|
-
# Registers Capybara driver which will be used by eyes and sets it as default Capybara driver.
|
6
|
-
# The name of the driver is :eyes, and the driver is a descendant of class Capybara::Selenium::Driver.
|
7
|
-
# Options are eventually passed to drivers constructor
|
8
|
-
# @param [Hash] options
|
9
|
-
# @example
|
10
|
-
# Applitools.register_capybara_driver :browser => :chrome
|
11
|
-
# @example
|
12
|
-
# Applitools.register_capybara_driver :browser => :remote, :url => 'remote_url', :desired_capabilities => {}
|
13
|
-
def register_capybara_driver(options = {})
|
14
|
-
::Capybara.register_driver :eyes do |app|
|
15
|
-
Applitools::Selenium::Capybara::Driver.new app, options
|
16
|
-
end
|
17
|
-
::Capybara.default_driver = :eyes
|
18
|
-
::Capybara.javascript_driver = :eyes
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
if defined? Capybara::Selenium::Driver
|
2
|
-
module Applitools::Selenium::Capybara
|
3
|
-
# @!visibility private
|
4
|
-
class Driver < Capybara::Selenium::Driver
|
5
|
-
def driver_for_eyes(eyes)
|
6
|
-
browser eyes: eyes
|
7
|
-
end
|
8
|
-
|
9
|
-
def browser(options = {})
|
10
|
-
eyes = options.delete(:eyes)
|
11
|
-
@native_browser ||= super()
|
12
|
-
unless eyes.nil?
|
13
|
-
is_mobile_device = @browser.capabilities['platformName'] ? true : false
|
14
|
-
@browser = Applitools::Selenium::Driver.new eyes,
|
15
|
-
options.merge(driver: @browser, is_mobile_device: is_mobile_device)
|
16
|
-
end
|
17
|
-
@browser
|
18
|
-
end
|
19
|
-
|
20
|
-
def use_native_browser
|
21
|
-
@browser = @native_browser
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if defined? ::Capybara::Session
|
28
|
-
::Capybara::Session.class_eval do
|
29
|
-
def driver_for_eyes(eyes)
|
30
|
-
driver.driver_for_eyes eyes
|
31
|
-
end
|
32
|
-
|
33
|
-
def use_native_browser
|
34
|
-
driver.use_native_browser if driver.respond_to? :use_native_browser
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Applitools::Selenium
|
2
|
-
class EyesFullPageScreenshot < Applitools::EyesScreenshot
|
3
|
-
def initialize(*args)
|
4
|
-
super
|
5
|
-
end
|
6
|
-
|
7
|
-
def sub_screenshot(region, coordinate_type, throw_if_clipped = false, force_nil_if_clipped = false)
|
8
|
-
logger.info "get_subscreenshot(#{region}, #{coordinate_type}, #{throw_if_clipped})"
|
9
|
-
Applitools::ArgumentGuard.not_nil region, 'region'
|
10
|
-
Applitools::ArgumentGuard.not_nil coordinate_type, 'coordinate_type'
|
11
|
-
|
12
|
-
as_is_subscreenshot_region = intersected_region(
|
13
|
-
region, coordinate_type,
|
14
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
15
|
-
)
|
16
|
-
|
17
|
-
if as_is_subscreenshot_region.empty? || (throw_if_clipped && as_is_subscreenshot_region.size != region.size)
|
18
|
-
return nil if force_nil_if_clipped
|
19
|
-
raise Applitools::OutOfBoundsException.new "Region #{region} (#{coordinate_type}) is out" \
|
20
|
-
" of screenshot bounds [#{frame_window}]"
|
21
|
-
end
|
22
|
-
|
23
|
-
sub_screenshot_image = Applitools::Screenshot.from_image(
|
24
|
-
image.crop(
|
25
|
-
as_is_subscreenshot_region.left,
|
26
|
-
as_is_subscreenshot_region.top, as_is_subscreenshot_region.width,
|
27
|
-
as_is_subscreenshot_region.height
|
28
|
-
)
|
29
|
-
)
|
30
|
-
result = self.class.new sub_screenshot_image
|
31
|
-
logger.info 'Done!'
|
32
|
-
result
|
33
|
-
end
|
34
|
-
|
35
|
-
def intersected_region(region, _original_coordinate_types, _result_coordinate_types)
|
36
|
-
region.intersect Applitools::Region.new(0, 0, image.width, image.height)
|
37
|
-
end
|
38
|
-
|
39
|
-
def convert_location(location, _from, _to)
|
40
|
-
location
|
41
|
-
end
|
42
|
-
|
43
|
-
def location_in_screenshot(location, _coordinate_type)
|
44
|
-
location
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,341 +0,0 @@
|
|
1
|
-
module Applitools::Selenium
|
2
|
-
# @!visibility private
|
3
|
-
class EyesWebDriverScreenshot < Applitools::EyesScreenshot
|
4
|
-
SCREENSHOT_TYPES = {
|
5
|
-
viewport: 'VIEPORT',
|
6
|
-
entire_frame: 'ENTIRE_FRAME'
|
7
|
-
}.freeze
|
8
|
-
|
9
|
-
INIT_CALLBACKS = {
|
10
|
-
[:driver, :screenshot_type, :frame_location_in_screenshot].sort => :initialize_main,
|
11
|
-
[:driver, :force_offset].sort => :initialize_main,
|
12
|
-
[:driver].sort => :initialize_main,
|
13
|
-
[:driver, :position_provider].sort => :initialize_main,
|
14
|
-
[:driver, :position_provider, :force_offset].sort => :initialize_main,
|
15
|
-
[:driver, :entire_frame_size].sort => :initialize_for_element,
|
16
|
-
[:driver, :entire_frame_size, :frame_location_in_screenshot].sort => :initialize_for_element
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
attr_accessor :driver
|
20
|
-
attr_accessor :frame_chain
|
21
|
-
private :frame_chain=
|
22
|
-
|
23
|
-
class << self
|
24
|
-
alias _new new
|
25
|
-
|
26
|
-
# Creates new image.
|
27
|
-
#
|
28
|
-
# @param [Applitools::Screenshot] image
|
29
|
-
# @param [Hash] options
|
30
|
-
# @option options [Applitools::Selenium::Driver] :driver Applitools driver instance.
|
31
|
-
# @option options [Applitools::RectangleSize] :entire_frame_size The size of the entire frame.
|
32
|
-
# @option options [Applitools::Location] :frame_location_in_screenshot The location of the frame in the screenshot.
|
33
|
-
# @option options [String] :screenshot_type One of allowed types - 'VIEPORT' or 'ENTIRE_FRAME'
|
34
|
-
# @option options [Applitools::Location] :force_offset
|
35
|
-
|
36
|
-
# @return [Applitools::Screenshot] The image.
|
37
|
-
# @!parse def initialize(image, options); end
|
38
|
-
|
39
|
-
def new(*args)
|
40
|
-
image = args.shift
|
41
|
-
raise Applitools::EyesIllegalArgument.new 'image is expected to be Applitools::Screenshot!' unless
|
42
|
-
image.is_a? Applitools::Screenshot
|
43
|
-
|
44
|
-
options = args.first
|
45
|
-
if options.is_a? Hash
|
46
|
-
result = _new(image)
|
47
|
-
callback = INIT_CALLBACKS[options.keys.sort]
|
48
|
-
return result.tap { |o| o.send callback, options } if result.respond_to? callback
|
49
|
-
raise Applitools::EyesIllegalArgument.new 'Can\'t find an appropriate initializer!'
|
50
|
-
end
|
51
|
-
raise Applitools::EyesIllegalArgument.new "#{self.class}.initialize(): Hash is expected as an argument!"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Calculates the frame location in the screenshot.
|
55
|
-
#
|
56
|
-
# @param [Applitools::Selenium::FrameChain] frame_chain The driver's frame chain.
|
57
|
-
# @param [String] screenshot_type The type of the screenshot.
|
58
|
-
# @param [Logger] logger The logger instance.
|
59
|
-
# @return [Applitools::Location] The location in the screenshot.
|
60
|
-
def calc_frame_location_in_screenshot(frame_chain, screenshot_type, logger)
|
61
|
-
frame_chain = Applitools::Selenium::FrameChain.new other: frame_chain
|
62
|
-
logger.info 'Getting first frame...'
|
63
|
-
first_frame = frame_chain.shift
|
64
|
-
logger.info 'Done!'
|
65
|
-
location_in_screenshot = Applitools::Location.for first_frame.location
|
66
|
-
|
67
|
-
if screenshot_type == SCREENSHOT_TYPES[:viewport]
|
68
|
-
default_content_scroll = first_frame.parent_scroll_position
|
69
|
-
location_in_screenshot.offset_negative(
|
70
|
-
Applitools::Location.for(default_content_scroll.x, default_content_scroll.y)
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
logger.info 'Iterating over frames...'
|
75
|
-
frame_chain.each do |frame|
|
76
|
-
location_in_screenshot.offset(Applitools::Location.for(frame.location.x, frame.location.y))
|
77
|
-
.offset_negative(
|
78
|
-
Applitools::Location.for(
|
79
|
-
frame.parent_scroll_position.x, frame.parent_scroll_position.y
|
80
|
-
)
|
81
|
-
)
|
82
|
-
end
|
83
|
-
location_in_screenshot
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Initialize element.
|
88
|
-
#
|
89
|
-
# @param [Hash] options The options.
|
90
|
-
# @option options [Symbol] :driver Applitools driver instance.
|
91
|
-
# @option options [Symbol] :entire_frame_size The size of the entire frame.
|
92
|
-
# @option options [Symbol] :frame_location_in_screenshot The location of the frame in the screenshot.
|
93
|
-
def initialize_for_element(options = {})
|
94
|
-
Applitools::ArgumentGuard.not_nil options[:driver], 'options[:driver]'
|
95
|
-
Applitools::ArgumentGuard.not_nil options[:entire_frame_size], 'options[:entire_frame_size]'
|
96
|
-
entire_frame_size = options[:entire_frame_size]
|
97
|
-
self.driver = options[:driver]
|
98
|
-
self.frame_chain = driver.frame_chain
|
99
|
-
self.screenshot_type = SCREENSHOT_TYPES[:entire_frame]
|
100
|
-
self.scroll_position = Applitools::Location.new(0, 0)
|
101
|
-
self.scroll_position = Applitools::Location.new(0, 0).offset(options[:frame_location_in_screenshot]) if
|
102
|
-
options[:frame_location_in_screenshot].is_a? Applitools::Location
|
103
|
-
self.frame_location_in_screenshot = Applitools::Location.new(0, 0)
|
104
|
-
self.frame_window = Applitools::Region.new(0, 0, entire_frame_size.width, entire_frame_size.height)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Initializes class properties.
|
108
|
-
#
|
109
|
-
# @param [Hash] options The options.
|
110
|
-
# @option options [Symbol] :driver Wrapped Selenium driver instance.
|
111
|
-
# @option options [Symbol] :position_provider The ScrollPositionProvider.
|
112
|
-
# @option options [Symbol] :viewport The viewport instance.
|
113
|
-
# @option options [Symbol] :entire_frame The entire frame instance.
|
114
|
-
# @option options [Symbol] :screenshot_type The screenshot type.
|
115
|
-
# @option options [Symbol] :frame_location_in_screenshot The frame location in the screenshot.
|
116
|
-
# @option options [Symbol] :force_offset Whether to force offset or not.
|
117
|
-
def initialize_main(options = {})
|
118
|
-
# options = {screenshot_type: SCREENSHOT_TYPES[:viewport]}.merge options
|
119
|
-
|
120
|
-
Applitools::ArgumentGuard.hash options, 'options', [:driver]
|
121
|
-
Applitools::ArgumentGuard.not_nil options[:driver], 'options[:driver]'
|
122
|
-
|
123
|
-
self.driver = options[:driver]
|
124
|
-
self.position_provider = Applitools::Selenium::ScrollPositionProvider.new driver if
|
125
|
-
options[:position_provider].nil?
|
126
|
-
|
127
|
-
self.position_provider = if options[:position_provider].nil?
|
128
|
-
Applitools::Selenium::ScrollPositionProvider.new(driver)
|
129
|
-
else
|
130
|
-
options[:position_provider]
|
131
|
-
end
|
132
|
-
|
133
|
-
viewport_size = driver.default_content_viewport_size
|
134
|
-
|
135
|
-
self.frame_chain = driver.frame_chain
|
136
|
-
if !frame_chain.empty?
|
137
|
-
frame_size = frame_chain.current_frame_size
|
138
|
-
else
|
139
|
-
begin
|
140
|
-
frame_size = position_provider.entire_size
|
141
|
-
rescue
|
142
|
-
frame_size = viewport_size
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
begin
|
147
|
-
self.scroll_position = position_provider.current_position
|
148
|
-
rescue
|
149
|
-
self.scroll_position = Applitools::Location.new(0, 0)
|
150
|
-
end
|
151
|
-
|
152
|
-
if options[:screenshot_type].nil?
|
153
|
-
self.screenshot_type = if image.width <= viewport_size.width && image.height <= viewport_size.height
|
154
|
-
SCREENSHOT_TYPES[:viewport]
|
155
|
-
else
|
156
|
-
SCREENSHOT_TYPES[:entire_frame]
|
157
|
-
end
|
158
|
-
else
|
159
|
-
self.screenshot_type = options[:screenshot_type]
|
160
|
-
end
|
161
|
-
|
162
|
-
if options[:frame_location_in_screenshot].nil?
|
163
|
-
if !frame_chain.empty?
|
164
|
-
self.frame_location_in_screenshot = self.class.calc_frame_location_in_screenshot(
|
165
|
-
frame_chain, screenshot_type, logger
|
166
|
-
)
|
167
|
-
else
|
168
|
-
self.frame_location_in_screenshot = Applitools::Location.new(0, 0)
|
169
|
-
end
|
170
|
-
else
|
171
|
-
self.frame_location_in_screenshot = options[:frame_location_in_screenshot]
|
172
|
-
end
|
173
|
-
|
174
|
-
self.force_offset = Applitools::Location::TOP_LEFT
|
175
|
-
self.force_offset = options[:force_offset] if options[:force_offset]
|
176
|
-
|
177
|
-
logger.info 'Calculating frame window..'
|
178
|
-
self.frame_window = Applitools::Region.from_location_size(frame_location_in_screenshot, frame_size)
|
179
|
-
frame_window.intersect Applitools::Region.new(0, 0, image.width, image.height)
|
180
|
-
|
181
|
-
raise Applitools::EyesError.new 'Got empty frame window for screenshot!' if
|
182
|
-
frame_window.width <= 0 || frame_window.height <= 0
|
183
|
-
|
184
|
-
logger.info 'Done!'
|
185
|
-
end
|
186
|
-
|
187
|
-
# Convert the location.
|
188
|
-
#
|
189
|
-
# @param [Applitools::Location] location Location to convert
|
190
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] from Source.
|
191
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] to Destination.
|
192
|
-
# @return [Applitools::Location] The converted location.
|
193
|
-
def convert_location(location, from, to)
|
194
|
-
Applitools::ArgumentGuard.not_nil location, 'location'
|
195
|
-
Applitools::ArgumentGuard.not_nil from, 'from'
|
196
|
-
Applitools::ArgumentGuard.not_nil to, 'to'
|
197
|
-
|
198
|
-
result = Applitools::Location.for location
|
199
|
-
return result if from == to
|
200
|
-
# if frame_chain.size.zero? && screenshot_type == SCREENSHOT_TYPES[:entire_frame]
|
201
|
-
# if (from == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative] ||
|
202
|
-
# from == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_as_is]) &&
|
203
|
-
# to == Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
204
|
-
# result.offset frame_location_in_screenshot
|
205
|
-
# elsif from == Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is] &&
|
206
|
-
# (to == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative] ||
|
207
|
-
# to == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_as_is])
|
208
|
-
# result.offset_negative frame_location_in_screenshot
|
209
|
-
# end
|
210
|
-
# end
|
211
|
-
|
212
|
-
case from
|
213
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
|
214
|
-
case to
|
215
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
216
|
-
result.offset_negative scroll_position
|
217
|
-
result.offset frame_location_in_screenshot
|
218
|
-
else
|
219
|
-
raise Applitools::EyesCoordinateTypeConversionException.new "Can't convert coordinates from #{from} to #{to}"
|
220
|
-
end
|
221
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
222
|
-
case to
|
223
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
|
224
|
-
result.offset_negative frame_location_in_screenshot
|
225
|
-
result.offset scroll_position
|
226
|
-
else
|
227
|
-
raise Applitools::EyesCoordinateTypeConversionException.new "Can't convert coordinates from #{from} to #{to}"
|
228
|
-
end
|
229
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:context_as_is]
|
230
|
-
case to
|
231
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
232
|
-
result.offset_negative(frame_location_in_screenshot).offset(force_offset)
|
233
|
-
else
|
234
|
-
raise Applitools::EyesCoordinateTypeConversionException.new "Can't convert coordinates from #{from} to #{to}"
|
235
|
-
end
|
236
|
-
else
|
237
|
-
raise Applitools::EyesCoordinateTypeConversionException.new "Can't convert coordinates from #{from} to #{to}"
|
238
|
-
end
|
239
|
-
|
240
|
-
result
|
241
|
-
end
|
242
|
-
|
243
|
-
def frame_chain
|
244
|
-
Applitools::Selenium::FrameChain.new other: @frame_chain
|
245
|
-
end
|
246
|
-
|
247
|
-
# Returns the intersected region.
|
248
|
-
#
|
249
|
-
# @param [Applitools::Selenium::Region] region The relevant region.
|
250
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] original_coordinate_types The type of
|
251
|
-
# the original coordinates.
|
252
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] result_coordinate_types The type of the
|
253
|
-
# original coordinates.
|
254
|
-
# @return [Applitools::Region] The intersected region.
|
255
|
-
def intersected_region(region, original_coordinate_types, result_coordinate_types)
|
256
|
-
return Applitools::Region::EMPTY if region.empty?
|
257
|
-
intersected_region = convert_region_location(
|
258
|
-
region, original_coordinate_types, Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
259
|
-
)
|
260
|
-
case original_coordinate_types
|
261
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
|
262
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:context_as_is]
|
263
|
-
intersected_region.intersect frame_window
|
264
|
-
when Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
265
|
-
intersected_region.intersect(Applitools::Region.new(0, 0, image.width, image.height))
|
266
|
-
else
|
267
|
-
raise Applitools::EyesCoordinateTypeConversionException.new(
|
268
|
-
"Unknown coordinates type: #{original_coordinate_types}"
|
269
|
-
)
|
270
|
-
end
|
271
|
-
|
272
|
-
return intersected_region if intersected_region.empty?
|
273
|
-
convert_region_location(
|
274
|
-
intersected_region,
|
275
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is],
|
276
|
-
result_coordinate_types
|
277
|
-
)
|
278
|
-
end
|
279
|
-
|
280
|
-
# Returns the location in the screenshot.
|
281
|
-
#
|
282
|
-
# @param [Applitools::Location] location The location.
|
283
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] coordinate_type The type of the coordinate.
|
284
|
-
# @return [Applitools::Location] The location instance in the screenshot.
|
285
|
-
def location_in_screenshot(location, coordinate_type)
|
286
|
-
location = convert_location(
|
287
|
-
location, coordinate_type, Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
288
|
-
)
|
289
|
-
unless frame_window.contains?(location.x, location.y)
|
290
|
-
raise Applitools::OutOfBoundsException.new(
|
291
|
-
"Location #{location} (#{coordinate_type}) is not visible in screenshot!"
|
292
|
-
)
|
293
|
-
end
|
294
|
-
location
|
295
|
-
end
|
296
|
-
|
297
|
-
# Gets a sub-screenshot of a region.
|
298
|
-
#
|
299
|
-
# @param [Applitools::Region] region The relevant region for taking screenshot.
|
300
|
-
# @param [Applitools::EyesScreenshot::COORDINATE_TYPES] coordinate_type The coordinate type.
|
301
|
-
# @param [Boolean] throw_if_clipped Whether to throw if screenshot is out of bounds.
|
302
|
-
# @return [Applitools::Screenshot] The sub screenshot.
|
303
|
-
def sub_screenshot(region, coordinate_type, throw_if_clipped = false, force_nil_if_clipped = false)
|
304
|
-
logger.info "get_subscreenshot(#{region}, #{coordinate_type}, #{throw_if_clipped})"
|
305
|
-
Applitools::ArgumentGuard.not_nil region, 'region'
|
306
|
-
Applitools::ArgumentGuard.not_nil coordinate_type, 'coordinate_type'
|
307
|
-
|
308
|
-
region_to_check = Applitools::Region.from_location_size(
|
309
|
-
region.location.offset_negative(force_offset), region.size
|
310
|
-
)
|
311
|
-
|
312
|
-
as_is_subscreenshot_region = intersected_region region_to_check, coordinate_type,
|
313
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
|
314
|
-
|
315
|
-
if as_is_subscreenshot_region.empty? || (throw_if_clipped && !as_is_subscreenshot_region.size == region.size)
|
316
|
-
return nil if force_nil_if_clipped
|
317
|
-
raise Applitools::OutOfBoundsException.new "Region #{region} (#{coordinate_type}) is out" \
|
318
|
-
" of screenshot bounds [#{frame_window}]"
|
319
|
-
end
|
320
|
-
|
321
|
-
sub_screenshot_image = Applitools::Screenshot.from_image image.crop(as_is_subscreenshot_region.left,
|
322
|
-
as_is_subscreenshot_region.top, as_is_subscreenshot_region.width,
|
323
|
-
as_is_subscreenshot_region.height)
|
324
|
-
|
325
|
-
context_relative_region_location = convert_location as_is_subscreenshot_region.location,
|
326
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is],
|
327
|
-
Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
|
328
|
-
|
329
|
-
result = self.class.new sub_screenshot_image, driver: driver,
|
330
|
-
entire_frame_size: Applitools::RectangleSize.new(sub_screenshot_image.width, sub_screenshot_image.height),
|
331
|
-
frame_location_in_screenshot: context_relative_region_location
|
332
|
-
logger.info 'Done!'
|
333
|
-
result
|
334
|
-
end
|
335
|
-
|
336
|
-
private
|
337
|
-
|
338
|
-
attr_accessor :position_provider, :scroll_position, :screenshot_type, :frame_location_in_screenshot,
|
339
|
-
:frame_window, :force_offset
|
340
|
-
end
|
341
|
-
end
|