eyes_appium 3.16.15 → 3.16.16

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
  SHA256:
3
- metadata.gz: '0970f43b3ff2defd33a4e30b28256dd661f29fa701cbe69390f8bf501ed527ea'
4
- data.tar.gz: c2306285a527ae1e56d939b200ae16f8ea52d8db7bdbf3b183d49f7e3b08f48c
3
+ metadata.gz: a72a3916818c3f7df9bb9539c5ae5e425ab21a4eceae8709654833719074110c
4
+ data.tar.gz: 6ad28f38fc32a47807ab1255504fd37301a7a964100185ff5aeb31a95b65d6bd
5
5
  SHA512:
6
- metadata.gz: 61cd0579986df5f0453ba062ffe8ac351554ff1d5f2111ea4d87d5dac457eeae1fffb8a044d4aed0ecc4a94c5af56dc7588f9028eb1d0e8d011e2151a8a9540e
7
- data.tar.gz: 29956067a8bfbe493460107331507a805f547fe4457bf6d783965a9734f64b47f566309efe70c1f817b4d46b9f8051d332479c28150e7b70ffeb11bc9b958fb4
6
+ metadata.gz: b11c47d661f8815724ef8eb9ade6ce176103f7446d5556b46cf1fd2b3be879c1f9762f68cece87e79572aaf90003b458ca2151831bd1109d097a61845b91c794
7
+ data.tar.gz: ea86ba7eb7a9b8947bf674c5c261749ec5d8aff1e627d9069440b7268207c108d488049e723c82e875dc8583189cad1a82ba986c24199148fbcaf6ba3343a193
@@ -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
@@ -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
@@ -22,9 +22,13 @@ else
22
22
  end
23
23
 
24
24
  if defined? Appium::Driver
25
- Appium::Driver.class_eval do
25
+ Appium::Core::Base::Driver.class_eval do
26
26
  def driver_for_eyes(eyes)
27
- Applitools::Appium::Driver.new(eyes, driver: driver || start_driver, is_mobile_device: true, appium_driver: self)
27
+ if defined? Appium
28
+ Appium.promote_appium_methods Applitools::Appium::Driver::AppiumLib
29
+ end
30
+ Applitools::Appium::Driver.new(eyes, driver: self, is_mobile_device: true)
28
31
  end
29
32
  end
30
33
  end
34
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_appium
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: eyes_selenium
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.16.15
19
+ version: 3.16.16
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.16.15
26
+ version: 3.16.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: appium_lib
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,10 +45,12 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - lib/applitools/appium/android_screenshot.rb
48
49
  - lib/applitools/appium/driver.rb
49
50
  - lib/applitools/appium/eyes.rb
50
51
  - lib/applitools/appium/initialize_1.9.rb
51
52
  - lib/applitools/appium/initialize_2.0.rb
53
+ - lib/applitools/appium/ios_screenshot.rb
52
54
  - lib/applitools/appium/region_provider.rb
53
55
  - lib/applitools/appium/screenshot.rb
54
56
  - lib/applitools/appium/target.rb