eyes_core 3.16.15 → 3.16.16

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
  SHA256:
3
- metadata.gz: e00bd1d272774a42a3cd33cebe385b3aa9a6e53cdb627f625f4503d7950fa822
4
- data.tar.gz: 6f7396c9774c8332c926dce7f62f0ba9573ad920294589af3c435a6588c3dc54
3
+ metadata.gz: b136d9d87a89f8d7de25d38d7a6597d4dce20866def4985ba735a39e7b6e3462
4
+ data.tar.gz: 8d5861b1392c336a75ca393ac20224493cc7fd26e40ebee43951ff479ce8f63c
5
5
  SHA512:
6
- metadata.gz: 7a78447c0ca43e4e3905fd0ef3068dc754461283a2defa0551c5fdef9583e8d3f783904acb4c35c86fc31878e190bf2b3929dd536369de1ba455283966ff1256
7
- data.tar.gz: 4a854afdcf564e0aca48cace6f77368ac315730659d2e85b871bddfd290eaff665c3226f3e6f558dff384c8de5d7c5ff088c98203c6e0e8e81f7b560571d3951
6
+ metadata.gz: c504140d557d1aac4516873f7c65149e293c10cde3c28f43bfbb31eee608b3ed5743b75e07a3674b51fe8a4ccde5a004b46ec986721957f342549575be345bc8
7
+ data.tar.gz: 53cff244c5b9290bf8baf58bb6f6d1e294183dc0f10097eb2c55273ca9301b31c6d0df21d97a1a404bd95835f5a5e5beb4b6b1afd095784703574154ca46c7d0
@@ -0,0 +1,21 @@
1
+ require_relative './screenshot.rb'
2
+ module Applitools
3
+ module Appium
4
+ class AndroidScreenshot < Applitools::Appium::Screenshot
5
+ def convert_region_location(region, from, to)
6
+ # converted_size = region.size.dup.scale_it!(1 / device_pixel_ratio)
7
+ # converted_location = region.location.dup.offset_negative(Applitools::Location.new(0, status_bar_height)).scale_it!(1 / device_pixel_ratio)
8
+ # Applitools::Region.from_location_size(converted_location, converted_size)
9
+ Applitools::Region.from_location_size(
10
+ convert_location(region.location, nil, nil),
11
+ region.size
12
+ ).scale_it!(1.to_f / device_pixel_ratio)
13
+ end
14
+
15
+ def convert_location(location, _from, _to)
16
+ location.offset_negative(Applitools::Location.new(0, status_bar_height))
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module Applitools::Appium
4
4
  class Driver < Applitools::Selenium::Driver
5
- attr_accessor :appium_driver
6
5
  def initialize(eyes, options)
7
- self.appium_driver = options.delete(:appium_driver)
8
6
  super(eyes, options)
9
7
  end
8
+ module AppiumLib
9
+ extend self
10
+ end
10
11
  end
11
12
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  class Applitools::Appium::Eyes < Applitools::Selenium::SeleniumEyes
4
+ attr_accessor :status_bar_height
4
5
  def perform_driver_settings_for_appium_driver
5
6
  self.region_visibility_strategy = Applitools::Selenium::NopRegionVisibilityStrategy.new
6
7
  self.force_driver_resolution_as_viewport_size = true
@@ -11,6 +12,7 @@ class Applitools::Appium::Eyes < Applitools::Selenium::SeleniumEyes
11
12
  self.dont_get_title = true
12
13
  self.runner = Applitools::ClassicRunner.new
13
14
  self.base_agent_id = "eyes.appium.ruby/#{Applitools::VERSION}".freeze
15
+ self.status_bar_height = 0
14
16
  end
15
17
 
16
18
  private :perform_driver_settings_for_appium_driver
@@ -76,7 +78,7 @@ class Applitools::Appium::Eyes < Applitools::Selenium::SeleniumEyes
76
78
  result = super do |screenshot|
77
79
  if scale_provider
78
80
  scaled_image = scale_provider.scale_image(screenshot.image)
79
- self.screenshot = Applitools::Appium::Screenshot.new(
81
+ self.screenshot = screenshot_class.new(
80
82
  Applitools::Screenshot.from_image(
81
83
  case scaled_image
82
84
  when ChunkyPNG::Image
@@ -86,7 +88,9 @@ class Applitools::Appium::Eyes < Applitools::Selenium::SeleniumEyes
86
88
  else
87
89
  raise Applitools::EyesError.new('Unknown image format after scale!')
88
90
  end
89
- )
91
+ ),
92
+ status_bar_height: Applitools::Utils::EyesSeleniumUtils.status_bar_height(driver),
93
+ device_pixel_ratio: Applitools::Utils::EyesSeleniumUtils.device_pixel_ratio(driver)
90
94
  )
91
95
  end
92
96
  end
@@ -115,17 +119,22 @@ class Applitools::Appium::Eyes < Applitools::Selenium::SeleniumEyes
115
119
 
116
120
  def viewport_screenshot
117
121
  logger.info 'Viewport screenshot requested...'
118
- self.screenshot = Applitools::Appium::Screenshot.new(
122
+
123
+ self.screenshot = screenshot_class.new(
119
124
  Applitools::Screenshot.from_datastream(driver.screenshot_as(:png))
120
125
  )
121
126
  end
122
127
 
123
128
  def element_screenshot
124
129
  logger.info 'Element screenshot requested...'
125
- self.screenshot = Applitools::Appium::Screenshot.new(
126
- Applitools::Screenshot.from_datastream(
127
- driver.element_screenshot_as(eyes_element_to_check, :png)
128
- )
130
+ self.screenshot = screenshot_class.new(
131
+ Applitools::Screenshot.from_datastream(driver.element_screenshot_as(eyes_element_to_check, :png))
129
132
  )
130
133
  end
134
+
135
+ def screenshot_class
136
+ return Applitools::Appium::IosScreenshot if Applitools::Utils::EyesSeleniumUtils.ios?(Applitools::Appium::Driver::AppiumLib)
137
+ return Applitools::Appium::AndroidScreenshot if Applitools::Utils::EyesSeleniumUtils.android?(Applitools::Appium::Driver::AppiumLib)
138
+ raise Applitools::EyesError, 'Unknown device type'
139
+ end
131
140
  end
@@ -0,0 +1,10 @@
1
+ require_relative './screenshot.rb'
2
+ module Applitools
3
+ module Appium
4
+ class IosScreenshot < Applitools::Appium::Screenshot
5
+ def convert_location(location, _from, _to)
6
+ location.offset_negative(Applitools::Location.new(0, status_bar_height))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -3,6 +3,16 @@
3
3
  module Applitools
4
4
  module Appium
5
5
  class Screenshot < Applitools::EyesScreenshot
6
+
7
+ attr_reader :status_bar_height, :device_pixel_ratio
8
+
9
+ def initialize(*args)
10
+ options = Applitools::Utils.extract_options!(args)
11
+ @status_bar_height = options[:status_bar_height] || 0
12
+ @device_pixel_ratio = options[:device_pixel_ratio] || 1
13
+ super
14
+ end
15
+
6
16
  def sub_screenshot(region, _coordinate_type, _throw_if_clipped = false, _force_nil_if_clipped = false)
7
17
  self.class.new(
8
18
  Applitools::Screenshot.from_image(
@@ -10,6 +20,11 @@ module Applitools
10
20
  )
11
21
  )
12
22
  end
23
+
24
+ def convert_location(location, _from, _to)
25
+ raise 'Applitools::Appium::Screenshot is an abstract class.' \
26
+ ' You should implement :convert_location method in a descendant class.'
27
+ end
13
28
  end
14
29
  end
15
30
  end
@@ -4,8 +4,7 @@ module Applitools
4
4
  module Appium
5
5
  class Target
6
6
  include Applitools::FluentInterface
7
-
8
- attr_accessor :region_to_check, :options
7
+ attr_accessor :region_to_check, :options, :ignored_regions, :floating_regions, :layout_regions, :content_regions, :strict_regions, :accessibility_regions
9
8
 
10
9
  class << self
11
10
  def window
@@ -19,6 +18,12 @@ module Applitools
19
18
 
20
19
  def initialize
21
20
  self.region_to_check = proc { Applitools::Region::EMPTY }
21
+ self.ignored_regions = []
22
+ self.floating_regions = []
23
+ self.layout_regions = []
24
+ self.content_regions = []
25
+ self.strict_regions = []
26
+ self.accessibility_regions = []
22
27
  self.options = {}
23
28
  end
24
29
 
@@ -34,9 +39,170 @@ module Applitools
34
39
  self
35
40
  end
36
41
 
42
+ def ignore(*args)
43
+ requested_padding = if args.last.is_a? Applitools::PaddingBounds
44
+ args.pop
45
+ else
46
+ Applitools::PaddingBounds::ZERO_PADDING
47
+ end
48
+ ignored_regions << case (first_argument = args.first)
49
+ when ::Selenium::WebDriver::Element
50
+ proc do
51
+ Applitools::Region
52
+ .from_location_size(first_argument.location, first_argument.size)
53
+ .padding(requested_padding)
54
+ end
55
+ when Applitools::Region
56
+ result = first_argument.padding(requested_padding)
57
+ if Applitools::Utils::EyesSeleniumUtils.ios?(Applitools::Appium::Driver::AppiumLib)
58
+ def result.converted?
59
+ true
60
+ end
61
+ end
62
+ result
63
+ else
64
+ proc do |driver|
65
+ element = driver.find_element(*args)
66
+ Applitools::Region
67
+ .from_location_size(element.location, element.size)
68
+ .padding(requested_padding)
69
+ end
70
+ end
71
+ self
72
+ end
73
+
74
+ def floating(*args)
75
+ value = case args.first
76
+ when Applitools::FloatingRegion
77
+ args.first
78
+ when Applitools::Region
79
+ result = Applitools::FloatingRegion.any(*args)
80
+ if Applitools::Utils::EyesSeleniumUtils.ios?(Applitools::Appium::Driver::AppiumLib)
81
+ def result.converted?
82
+ true
83
+ end
84
+ end
85
+ result
86
+ when ::Selenium::WebDriver::Element
87
+ args_dup = args.dup
88
+ Applitools::FloatingRegion.any(*args_dup)
89
+ else
90
+ proc do |driver|
91
+ args_dup = args.dup
92
+ region = driver.find_element(args_dup.shift, args_dup.shift)
93
+ Applitools::FloatingRegion.any(
94
+ region, *args_dup
95
+ )
96
+ end
97
+ end
98
+ floating_regions << value
99
+ self
100
+ end
101
+
102
+ def layout
103
+ return match_level(Applitools::MatchLevel::LAYOUT) if args.empty?
104
+ region = process_region(*args)
105
+ layout_regions << region
106
+ self
107
+
108
+ end
109
+
110
+ def content(*args)
111
+ return match_level(Applitools::MatchLevel::CONTENT) if args.empty?
112
+ region = process_region(*args)
113
+ content_regions << region
114
+ self
115
+ end
116
+
117
+ def strict(*args)
118
+ return match_level(Applitools::MatchLevel::STRICT) if args.empty?
119
+ region = process_region(*args)
120
+ strict_regions << region
121
+ self
122
+ end
123
+
124
+ def exact(*args)
125
+ match_level(Applitools::MatchLevel::EXACT, *args)
126
+ end
127
+
128
+ def accessibility(*args)
129
+ options = Applitools::Utils.extract_options! args
130
+ unless options[:type]
131
+ raise Applitools::EyesError,
132
+ 'You should call Target.accessibility(region, type: type). The region_type option is required'
133
+ end
134
+ unless Applitools::AccessibilityRegionType.enum_values.include?(options[:type])
135
+ raise Applitools::EyesIllegalArgument,
136
+ "The region type should be one of [#{Applitools::AccessibilityRegionType.enum_values.join(', ')}]"
137
+ end
138
+
139
+ accessibility_regions << case args.first
140
+ when ::Selenium::WebDriver::Element
141
+ element = args.first
142
+ Applitools::AccessibilityRegion.new(
143
+ element,
144
+ options[:type]
145
+ )
146
+ when Applitools::Region
147
+ result = Applitools::AccessibilityRegion.new(
148
+ args.first, options[:type]
149
+ )
150
+ if Applitools::Utils::EyesSeleniumUtils.ios?(Applitools::Appium::Driver::AppiumLib)
151
+ def result.converted?
152
+ true
153
+ end
154
+ end
155
+ result
156
+ when String
157
+ proc do |driver|
158
+ element = driver.find_element(name_or_id: args.first)
159
+ Applitools::AccessibilityRegion.new(
160
+ element,
161
+ options[:type]
162
+ )
163
+ end
164
+ else
165
+ proc do |driver|
166
+ elements = driver.find_elements(*args)
167
+ elements.map do |e|
168
+ Applitools::AccessibilityRegion.new(
169
+ e,
170
+ options[:type]
171
+ )
172
+ end
173
+ end
174
+ end
175
+ self
176
+ end
177
+
37
178
  def finalize
38
179
  self
39
180
  end
181
+
182
+ private
183
+
184
+ def process_region(*args)
185
+ r = args.first
186
+ case r
187
+ when ::Selenium::WebDriver::Element
188
+ proc do |driver|
189
+ Applitools::Region.from_location_size(r.location, r.size)
190
+ end
191
+ when Applitools::Region
192
+ if Applitools::Utils::EyesSeleniumUtils.ios?(Applitools::Appium::Driver::AppiumLib)
193
+ def r.converted?
194
+ true
195
+ end
196
+ end
197
+ r
198
+ else
199
+ proc do |driver|
200
+ element = driver.find_element(*args)
201
+ Applitools::Region.from_location_size(element.location, element.size)
202
+ end
203
+ end
204
+ end
205
+
40
206
  end
41
207
  end
42
208
  end
@@ -4,7 +4,9 @@ module Applitools::Appium
4
4
  module Utils
5
5
  # true if test is running on mobile device
6
6
  def mobile_device?(driver)
7
- defined?(Appium::Driver) && driver.respond_to?(:appium_driver) && driver.appium_driver
7
+ defined?(Appium::Driver) &&
8
+ defined?(Applitools::Appium::Driver::AppiumLib) &&
9
+ Applitools::Appium::Driver::AppiumLib
8
10
  end
9
11
 
10
12
  # true if test is running on Android device
@@ -19,18 +21,26 @@ module Applitools::Appium
19
21
 
20
22
  # @param [Applitools::Selenium::Driver] driver
21
23
  def platform_version(driver)
22
- driver.respond_to?(:caps) && driver.caps[:platformVersion]
24
+ driver.respond_to?(:platform_version) && driver.platform_version
23
25
  end
24
26
 
25
27
  # @param [Applitools::Selenium::Driver] executor
26
28
  def device_pixel_ratio(executor)
27
- if executor.respond_to? :session_capabilities
28
- session_info = executor.session_capabilities
29
- return session_info['pixelRatio'].to_f if session_info['pixelRatio']
30
- end
29
+ session_info = session_capabilities(executor)
30
+ return session_info['pixelRatio'].to_f if session_info['pixelRatio']
31
31
  Applitools::Selenium::Eyes::UNKNOWN_DEVICE_PIXEL_RATIO
32
32
  end
33
33
 
34
+ def status_bar_height(executor)
35
+ session_info = session_capabilities(executor)
36
+ return session_info['statBarHeight'].to_i if session_info['statBarHeight']
37
+ 0
38
+ end
39
+
40
+ def session_capabilities(executor)
41
+ executor.session_capabilities if executor.respond_to? :session_capabilities
42
+ end
43
+
34
44
  def current_scroll_position(driver)
35
45
  super
36
46
  rescue
@@ -4,6 +4,7 @@ module Applitools
4
4
  class MatchWindowData
5
5
  class << self
6
6
  def convert_coordinates(region, screenshot)
7
+ return region.with_padding.to_hash if region.respond_to?(:converted?) && region.converted?
7
8
  screenshot.convert_region_location(
8
9
  region.with_padding,
9
10
  Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module Applitools
4
- VERSION = '3.16.15'.freeze
4
+ VERSION = '3.16.16'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.15
4
+ version: 3.16.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Applitools Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oily_png
@@ -260,10 +260,12 @@ files:
260
260
  - ext/eyes_core/extconf.rb
261
261
  - ext/eyes_core/eyes_core.c
262
262
  - ext/eyes_core/eyes_core.h
263
+ - lib/applitools/appium/android_screenshot.rb
263
264
  - lib/applitools/appium/driver.rb
264
265
  - lib/applitools/appium/eyes.rb
265
266
  - lib/applitools/appium/initialize_1.9.rb
266
267
  - lib/applitools/appium/initialize_2.0.rb
268
+ - lib/applitools/appium/ios_screenshot.rb
267
269
  - lib/applitools/appium/region_provider.rb
268
270
  - lib/applitools/appium/screenshot.rb
269
271
  - lib/applitools/appium/target.rb