eyes_core 3.5.4 → 3.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60dfb90fc4e333a0418bb6303774911f4727ca95
4
- data.tar.gz: 72d6bc32da94dc2b3971051690cd1ed1cad58ab4
3
+ metadata.gz: 68baf2041ed67e8172284b1f19af46f53c13fce9
4
+ data.tar.gz: 1322f93d66d26b704a028619fe7cdaed92642f1f
5
5
  SHA512:
6
- metadata.gz: 3dfc94e4c741333627a7d792dd1e12e90007a89171f70499b561f7884cca4b074348beb2ec51cbbc84f96f8a6958ab821118e97bd49e87cb18a0a99373627487
7
- data.tar.gz: 66dc4259c574d5c4fce41e972f998fb89402061eb9eb5b64b6792537720f7b068f811018fda534e5e59ae87557f0356c5c1676ada68500e43203762a02bda4dd
6
+ metadata.gz: eb6c546e62d31ab27177debff341f5c127b462bb04bc2b58024d119004789715a5f0848d349c95414a2acb72e57b55745e45ff2668fd4a9f946614764b57e1c4
7
+ data.tar.gz: 86b3512f290b6b6cd5220285e7a19a31b0091600a67b08306aebd332a71035acd86c8cb9583490f2d4f21de4281a9fbabdb2c1557a0dadd0dfaadbc7e4ed7fe4
@@ -10,10 +10,12 @@ module Applitools::Connectivity
10
10
 
11
11
  DEFAULT_SERVER_URL = 'https://eyessdk.applitools.com'.freeze
12
12
 
13
+
13
14
  SSL_CERT = File.join(File.dirname(File.expand_path(__FILE__)), '../../../certs/cacert.pem').to_s.freeze
14
15
  DEFAULT_TIMEOUT = 300
15
16
 
16
17
  API_SESSIONS_RUNNING = '/api/sessions/running/'.freeze
18
+ API_SINGLE_TEST = '/api/sessions/'.freeze
17
19
 
18
20
  HTTP_STATUS_CODES = {
19
21
  created: 201,
@@ -31,6 +33,7 @@ module Applitools::Connectivity
31
33
  " (#{@server_url.class} is passed)"
32
34
  end
33
35
  @endpoint_url = URI.join(@server_url, API_SESSIONS_RUNNING).to_s
36
+ @single_check_endpoint_url = URI.join(@server_url, API_SINGLE_TEST).to_s
34
37
  end
35
38
 
36
39
  def set_proxy(uri, user = nil, password = nil)
@@ -49,13 +52,24 @@ module Applitools::Connectivity
49
52
  # Notice that this does not include the screenshot.
50
53
  json_data = Oj.dump(Applitools::Utils.camelcase_hash_keys(data.to_hash)).force_encoding('BINARY')
51
54
  body = [json_data.length].pack('L>') + json_data + data.screenshot
52
- # Applitools::EyesLogger.debug json_data
53
55
  Applitools::EyesLogger.debug 'Sending match data...'
56
+ #Applitools::EyesLogger.debug json_data
54
57
  res = post(URI.join(endpoint_url, session.id.to_s), content_type: 'application/octet-stream', body: body)
55
58
  raise Applitools::EyesError.new("Request failed: #{res.status} #{res.headers}") unless res.success?
56
59
  Applitools::MatchResult.new Oj.load(res.body)
57
60
  end
58
61
 
62
+ def match_single_window(data)
63
+ # Notice that this does not include the screenshot.
64
+ json_data = Oj.dump(data.to_hash).force_encoding('BINARY')
65
+ body = [json_data.length].pack('L>') + json_data + data.screenshot
66
+ # Applitools::EyesLogger.debug json_data
67
+ Applitools::EyesLogger.debug 'Sending match data...'
68
+ res = long_post(@single_check_endpoint_url, content_type: 'application/octet-stream', body: body)
69
+ raise Applitools::EyesError.new("Request failed: #{res.status} #{res.headers} #{res.body}") unless res.success?
70
+ Applitools::TestResults.new Oj.load(res.body)
71
+ end
72
+
59
73
  def start_session(session_start_info)
60
74
  res = post(endpoint_url, body: Oj.dump(startInfo:
61
75
  Applitools::Utils.camelcase_hash_keys(session_start_info.to_hash)))
@@ -11,10 +11,10 @@ module Applitools
11
11
 
12
12
  def to_hash
13
13
  {
14
- os: @os,
15
- hosting_app: @hosting_app,
16
- display_size: @display_size.to_hash,
17
- inferred: @inferred
14
+ 'os' => @os,
15
+ 'hostingApp' => @hosting_app,
16
+ 'displaySize' => @display_size.to_hash,
17
+ 'inferred' => @inferred
18
18
  }
19
19
  end
20
20
 
@@ -10,9 +10,9 @@ module Applitools
10
10
 
11
11
  def to_hash
12
12
  {
13
- id: @id,
14
- name: @name,
15
- started_at: @started_at.iso8601
13
+ 'id' => @id,
14
+ 'name' => @name,
15
+ 'startedAt' => @started_at.iso8601
16
16
  }
17
17
  end
18
18
 
@@ -54,6 +54,7 @@ module Applitools
54
54
  @user_inputs = UserInputArray.new
55
55
  self.app_output_provider = Object.new
56
56
  self.verbose_results = false
57
+ self.failed = false
57
58
  @inferred_environment = nil
58
59
 
59
60
  get_app_output_method = ->(r, s) { get_app_output_with_screenshot r, s }
@@ -172,7 +173,7 @@ module Applitools
172
173
  raise e
173
174
  end
174
175
 
175
- def check_window_base(region_provider, tag, ignore_mismatch, retry_timeout, options = {})
176
+ def check_window_base(region_provider, retry_timeout, match_window_data)
176
177
  if disabled?
177
178
  logger.info "#{__method__} Ignored"
178
179
  result = Applitools::MatchResults.new
@@ -183,7 +184,7 @@ module Applitools
183
184
  raise Applitools::EyesError.new 'Eyes not open' unless open?
184
185
  Applitools::ArgumentGuard.not_nil region_provider, 'region_provider'
185
186
 
186
- logger.info "check_window_base(#{region_provider}, #{tag}, #{ignore_mismatch}, #{retry_timeout})"
187
+ logger.info "check_window_base(#{region_provider}, #{match_window_data.tag}, #{match_window_data.ignore_mismatch}, #{retry_timeout})"
187
188
 
188
189
  tag = '' if tag.nil?
189
190
 
@@ -200,18 +201,11 @@ module Applitools
200
201
  end
201
202
 
202
203
  logger.info 'Calling match_window...'
203
- result = @match_window_task.match_window(
204
- user_inputs: user_inputs,
204
+ result = @match_window_task.match_window(match_window_data,
205
205
  last_screenshot: last_screenshot,
206
206
  region_provider: region_provider,
207
- tag: tag,
208
207
  should_match_window_run_once_on_timeout: should_match_window_run_once_on_timeout,
209
- ignore_mismatch: ignore_mismatch,
210
208
  retry_timeout: retry_timeout,
211
- ignore: options[:ignore],
212
- trim: options[:trim],
213
- match_level: options[:match_level],
214
- exact: options[:exact]
215
209
  )
216
210
  logger.info 'match_window done!'
217
211
 
@@ -219,13 +213,13 @@ module Applitools
219
213
  clear_user_inputs
220
214
  self.last_screenshot = result.screenshot
221
215
  else
222
- unless ignore_mismatch
216
+ unless match_window_data.ignore_mismatch
223
217
  clear_user_inputs
224
218
  self.last_screenshot = result.screenshot
225
219
  end
226
220
 
227
221
  self.should_match_window_run_once_on_timeout = true
228
-
222
+ self.failed = true
229
223
  logger.info "Mistmatch! #{tag}" unless running_session.new_session?
230
224
 
231
225
  if failure_reports == :immediate
@@ -238,6 +232,77 @@ module Applitools
238
232
  result
239
233
  end
240
234
 
235
+
236
+ def check_single_base(region_provider, retry_timeout, match_window_data)
237
+ if disabled?
238
+ logger.info "#{__method__} Ignored"
239
+ result = Applitools::MatchResults.new
240
+ result.as_expected = true
241
+ return result
242
+ end
243
+
244
+ raise Applitools::EyesError.new 'Eyes not open' unless open?
245
+ Applitools::ArgumentGuard.not_nil region_provider, 'region_provider'
246
+
247
+ logger.info "check_single_base(#{region_provider}, #{match_window_data.tag}, #{match_window_data.ignore_mismatch}, #{retry_timeout})"
248
+
249
+ tag = '' if tag.nil?
250
+
251
+ session_start_info = SessionStartInfo.new agent_id: base_agent_id, app_id_or_name: app_name,
252
+ scenario_id_or_name: test_name, batch_info: batch,
253
+ env_name: baseline_name, environment: app_environment,
254
+ default_match_settings: default_match_settings,
255
+ branch_name: branch_name, parent_branch_name: parent_branch_name
256
+
257
+ match_window_data.start_info = session_start_info
258
+ match_window_data.update_baseline_if_new = save_new_tests
259
+ match_window_data.update_baseline_if_different = save_failed_tests
260
+ match_window_task = Applitools::MatchSingleTask.new(
261
+ logger,
262
+ match_timeout,
263
+ app_output_provider
264
+ )
265
+
266
+ logger.info 'Calling match_window...'
267
+ result = match_window_task.match_window(match_window_data,
268
+ last_screenshot: last_screenshot,
269
+ region_provider: region_provider,
270
+ should_match_window_run_once_on_timeout: should_match_window_run_once_on_timeout,
271
+ retry_timeout: retry_timeout,
272
+ ) do |match_results|
273
+ results = match_results.original_results
274
+ not_aborted = !results['isAborted']
275
+ new_and_saved = results['isNew'] && save_new_tests
276
+ different_and_saved = results['isDifferent'] && save_failed_tests
277
+ not_a_mismatch = !results['isDifferent'] && !results['isNew']
278
+
279
+ not_aborted && (new_and_saved || different_and_saved || not_a_mismatch)
280
+ end
281
+ logger.info 'match_window done!'
282
+
283
+ if result.as_expected?
284
+ clear_user_inputs
285
+ self.last_screenshot = result.screenshot
286
+ else
287
+ unless match_window_data.ignore_mismatch
288
+ clear_user_inputs
289
+ self.last_screenshot = result.screenshot
290
+ end
291
+
292
+ self.should_match_window_run_once_on_timeout = true
293
+
294
+ logger.info "Mistmatch! #{tag}"
295
+
296
+ if failure_reports == :immediate
297
+ raise Applitools::TestFailedException.new "Mistmatch found in #{session_start_info.scenario_id_or_name}" \
298
+ " of #{session_start_info.app_id_or_name}"
299
+ end
300
+ end
301
+
302
+ logger.info 'Done!'
303
+ result.original_results
304
+ end
305
+
241
306
  # Closes eyes
242
307
  # @param [Boolean] throw_exception If set to +true+ eyes will trow [Applitools::TestFailedError] exception,
243
308
  # otherwise the test will pass. Default is true
@@ -267,7 +332,7 @@ module Applitools
267
332
 
268
333
  logger.info 'Ending server session...'
269
334
 
270
- save = is_new_session && save_new_tests || !is_new_session && save_failed_tests
335
+ save = is_new_session && save_new_tests || !is_new_session && failed && save_failed_tests
271
336
 
272
337
  logger.info "Automatically save test? #{save}"
273
338
 
@@ -305,7 +370,7 @@ module Applitools
305
370
  private
306
371
 
307
372
  attr_accessor :running_session, :last_screenshot, :current_app_name, :test_name, :session_type,
308
- :scale_provider, :session_start_info, :should_match_window_run_once_on_timeout, :app_output_provider
373
+ :scale_provider, :session_start_info, :should_match_window_run_once_on_timeout, :app_output_provider, :failed
309
374
 
310
375
  attr_reader :user_inputs
311
376
 
@@ -0,0 +1,87 @@
1
+ require_relative 'match_window_data'
2
+ module Applitools
3
+ class MatchSingleCheckData < MatchWindowData
4
+ class << self
5
+ def default_data
6
+ {
7
+ 'startInfo' => {
8
+ 'agentId' => nil,
9
+ 'appIdOrName' => nil,
10
+ 'verId' => nil,
11
+ 'scenarioIdOrName' => nil,
12
+ 'batchInfo' => {},
13
+ 'envName' => nil,
14
+ 'environment' => {},
15
+ 'defaultMatchSettings' => nil,
16
+ 'branchName' => nil,
17
+ 'parentBranchName' => nil
18
+ },
19
+ 'IgnoreMismatch' => false,
20
+ 'MismatchWait' => 0,
21
+ 'Options' => {
22
+ 'Name' => nil,
23
+ 'UserInputs' => [],
24
+ 'ImageMatchSettings' => {
25
+ 'MatchLevel' => 'None',
26
+ 'SplitTopHeight' => 0,
27
+ 'SplitBottomHeight' => 0,
28
+ 'IgnoreCaret' => false,
29
+ 'Ignore' => [],
30
+ 'Exact' => {
31
+ 'MinDiffIntensity' => 0,
32
+ 'MinDiffWidth' => 0,
33
+ 'MinDiffHeight' => 0,
34
+ 'MatchThreshold' => 0
35
+ }
36
+ },
37
+ 'IgnoreExpectedOutputSettings' => false,
38
+ 'ForceMatch' => false,
39
+ 'ForceMismatch' => false,
40
+ 'IgnoreMatch' => false,
41
+ 'IgnoreMismatch' => false,
42
+ 'Trim' => {
43
+ 'Enabled' => false,
44
+ 'ForegroundIntensity' => 0,
45
+ 'MinEdgeLength' => 0
46
+ }
47
+ },
48
+ 'Id' => nil,
49
+ 'UserInputs' => [],
50
+ 'AppOutput' => {
51
+ 'Screenshot64' => nil,
52
+ 'ScreenshotUrl' => nil,
53
+ 'Title' => nil,
54
+ 'IsPrimary' => false,
55
+ 'Elapsed' => 0
56
+ },
57
+ 'Tag' => nil,
58
+ 'updateBaselineIfDifferent' => false,
59
+ 'updateBaselineIfNew' => false
60
+ }
61
+ end
62
+ end
63
+
64
+ def start_info=(value)
65
+ Applitools::ArgumentGuard.is_a? value, 'value', Applitools::SessionStartInfo
66
+ hash_value = value.to_hash
67
+ current_data['startInfo']['batchInfo'] = hash_value[:batch_info]
68
+ current_data['startInfo']['environment'] = hash_value[:environment]
69
+ current_data['startInfo']['agentId'] = hash_value[:agent_id]
70
+ current_data['startInfo']['appIdOrName'] = hash_value[:app_id_or_name]
71
+ current_data['startInfo']['verId'] = hash_value[:ver_id]
72
+ current_data['startInfo']['scenarioIdOrName'] = hash_value[:scenario_id_or_name]
73
+ current_data['startInfo']['envName'] = hash_value[:env_name]
74
+ current_data['startInfo']['defaultMatchSettings'] = hash_value[:default_match_settings]
75
+ current_data['startInfo']['branchName'] = hash_value[:branch_name]
76
+ current_data['startInfo']['parentBranchName'] = hash_value[:parent_branch_name]
77
+ end
78
+
79
+ def update_baseline_if_different=(value)
80
+ current_data['updateBaselineIfDifferent'] = value ? true : false
81
+ end
82
+
83
+ def update_baseline_if_new=(value)
84
+ current_data['updateBaselineIfNew'] = value ? true : false
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,16 @@
1
+ require 'base64'
2
+ require_relative 'match_window_task'
3
+ module Applitools
4
+ class MatchSingleTask < MatchWindowTask
5
+ def initialize(logger, retry_timeout, app_output_provider)
6
+ super(logger, 'nil', retry_timeout, app_output_provider)
7
+ end
8
+
9
+ private
10
+
11
+ def perform_match(match_window_data)
12
+ Applitools::ArgumentGuard.is_a? match_window_data, 'match_window_data', Applitools::MatchSingleCheckData
13
+ Applitools::Connectivity::ServerConnector.match_single_window match_window_data
14
+ end
15
+ end
16
+ end
@@ -1,34 +1,171 @@
1
1
  module Applitools
2
2
  class MatchWindowData
3
+ class << self
4
+ def convert_coordinates(region, screenshot)
5
+ screenshot.convert_region_location(
6
+ Applitools::Region.from_location_size(region.location, region.size),
7
+ Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
8
+ Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
9
+ ).to_hash
10
+ end
11
+
12
+ def default_data
13
+ {
14
+ 'IgnoreMismatch' => false,
15
+ 'MismatchWait' => 0,
16
+ 'Options' => {
17
+ 'Name' => nil,
18
+ 'UserInputs' => [],
19
+ 'ImageMatchSettings' => {
20
+ 'MatchLevel' => 'None',
21
+ 'SplitTopHeight' => 0,
22
+ 'SplitBottomHeight' => 0,
23
+ 'IgnoreCaret' => false,
24
+ 'Ignore' => [],
25
+ 'Exact' => {
26
+ 'MinDiffIntensity' => 0,
27
+ 'MinDiffWidth' => 0,
28
+ 'MinDiffHeight' => 0,
29
+ 'MatchThreshold' => 0
30
+ }
31
+ },
32
+ 'IgnoreExpectedOutputSettings' => false,
33
+ 'ForceMatch' => false,
34
+ 'ForceMismatch' => false,
35
+ 'IgnoreMatch' => false,
36
+ 'IgnoreMismatch' => false,
37
+ 'Trim' => {
38
+ 'Enabled' => false,
39
+ }
40
+ },
41
+ 'Id' => nil,
42
+ 'UserInputs' => [],
43
+ 'AppOutput' => {
44
+ 'Screenshot64' => nil,
45
+ 'ScreenshotUrl' => nil,
46
+ 'Title' => nil,
47
+ 'IsPrimary' => false,
48
+ 'Elapsed' => 0
49
+ },
50
+ 'Tag' => nil
51
+ }
52
+ end
53
+
54
+ def valid_region(r)
55
+ true
56
+ end
57
+
58
+ def valid_input(i)
59
+ true
60
+ end
61
+ end
62
+
3
63
  attr_accessor :app_output, :user_inputs, :tag, :options, :ignore_mismatch
4
64
 
5
- def initialize(user_inputs, app_output, tag, ignore_mismatch, options = {})
6
- self.user_inputs = user_inputs
7
- self.app_output = app_output
8
- self.tag = tag
9
- self.ignore_mismatch = ignore_mismatch
10
- self.options = options
65
+ def initialize
66
+ @app_output = nil
67
+ @ignored_regions = []
68
+ @need_convert_ignored_regions_coordinates = false
11
69
  end
12
70
 
13
71
  def screenshot
14
72
  app_output.screenshot.image.to_blob
15
73
  end
16
74
 
17
- alias appOutput app_output
18
- alias userInputs user_inputs
19
- alias ignoreMismatch ignore_mismatch
75
+ def ignore_mismatch=(value)
76
+ current_data['IgnoreMismatch'] = value ? true : false
77
+ current_data['Options']['IgnoreMismatch'] = current_data['IgnoreMismatch']
78
+ end
79
+
80
+ def tag=(value)
81
+ current_data['Tag'] = value
82
+ current_data['Options']['Name'] = value
83
+ end
84
+
85
+ def user_inputs=(value)
86
+ Applitools::ArgumentGuard.is_a? value, 'value', Array
87
+ value.each do |i|
88
+ current_data['UserInputs'] << i if self.class.valid_input(i)
89
+ end
90
+ current_data['Options']['UserInputs'] = current_data['UserInputs']
91
+ end
92
+
93
+ def ignored_regions=(value)
94
+ Applitools::ArgumentGuard.is_a? value, 'value', Array
95
+ value.each do |r|
96
+ current_data['Options']['ImageMatchSettings']['Ignore'] << r.to_hash if self.class.valid_region(r)
97
+ end
98
+ end
99
+
100
+ def app_output=(value)
101
+ Applitools::ArgumentGuard.is_a? value, 'value', Applitools::AppOutputWithScreenshot
102
+ @app_output = value
103
+ hash_value = value.to_hash
104
+ %w(Screenshot64 ScreenshotUrl Title IsPrimary Elapsed).each do |key|
105
+ current_data['AppOutput'][key] = hash_value[key] unless hash_value[key].nil?
106
+ end
107
+ end
108
+
109
+ def match_level=(value)
110
+ current_data['Options']['ImageMatchSettings']['MatchLevel'] = value
111
+ end
112
+
113
+ def read_target(target, driver)
114
+ #options
115
+ %w(trim).each do |field|
116
+ send("#{field}=", target.options[field.to_sym])
117
+ end
118
+ #ignored regions
119
+ target.ignored_regions.each do |r|
120
+ case r
121
+ when Proc
122
+ region = r.call(driver)
123
+ @ignored_regions << Applitools::Region.from_location_size(region.location, region.size)
124
+ @need_convert_ignored_regions_coordinates = true
125
+ when Applitools::Region
126
+ @ignored_regions << r
127
+ @need_convert_ignored_regions_coordinates = true
128
+ end
129
+ end
130
+ end
131
+
132
+ def ignore_mismatch
133
+ current_data['IgnoreMismatch']
134
+ end
135
+
136
+ def tag
137
+ current_data['Tag']
138
+ end
139
+
140
+ def screenshot
141
+ app_output.screenshot.image.to_blob
142
+ end
143
+
144
+ def trim=(value)
145
+ current_data['Options']['Trim']['Enabled'] = value ? true : false
146
+ end
147
+
148
+ def convert_ignored_regions_coordinates
149
+ return unless @need_convert_ignored_regions_coordinates
150
+ self.ignored_regions = @ignored_regions.map do |r|
151
+ self.class.convert_coordinates(r, app_output.screenshot)
152
+ end
153
+ @need_convert_ignored_regions_coordinates = false
154
+ end
20
155
 
21
156
  def to_hash
22
- ary = [:userInputs, :appOutput, :tag, :ignoreMismatch, :options].map do |field|
23
- result = send(field)
24
- result = result.to_hash if result.respond_to? :to_hash
25
- [field, result] if [String, Symbol, Hash, Array, FalseClass, TrueClass].include? result.class
26
- end.compact
27
- Hash[ary]
157
+ raise Applitools::EyesError.new 'You should convert coordinates for ignored_regions!' if @need_convert_ignored_regions_coordinates
158
+ current_data.dup
28
159
  end
29
160
 
30
161
  def to_s
31
162
  to_hash
32
163
  end
164
+
165
+ private
166
+
167
+ def current_data
168
+ @current_data ||= self.class.default_data
169
+ end
33
170
  end
34
171
  end
@@ -6,18 +6,6 @@ module Applitools
6
6
 
7
7
  attr_reader :logger, :running_session, :default_retry_timeout, :app_output_provider
8
8
 
9
- class << self
10
- def convert_coordinates(regions, screenshot)
11
- regions.map do |r|
12
- screenshot.convert_region_location(
13
- Applitools::Region.from_location_size(r.location, r.size),
14
- Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
15
- Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
16
- ).to_hash
17
- end
18
- end
19
- end
20
-
21
9
  def initialize(logger, running_session, retry_timeout, app_output_provider)
22
10
  @logger = logger
23
11
  @running_session = running_session
@@ -35,18 +23,11 @@ module Applitools
35
23
  ' respond to :app_output'
36
24
  end
37
25
 
38
- def match_window(options = {})
39
- user_inputs = options[:user_inputs]
26
+ def match_window(match_window_data, options = {})
40
27
  last_screenshot = options[:last_screenshot]
41
28
  region_provider = options[:region_provider]
42
- tag = options[:tag]
43
- should_match_window_run_once_on_timeout = options[:should_match_window_run_once_on_timeout]
44
- ignore_mismatch = options[:ignore_mismatch]
45
29
  retry_timeout = options[:retry_timeout]
46
- ignore = options[:ignore] || []
47
- trim = options[:trim] || false
48
- match_level = options[:match_level]
49
- exact = options[:exact]
30
+ should_match_window_run_once_on_timeout = options[:should_match_window_run_once_on_timeout]
50
31
 
51
32
  retry_timeout = default_retry_timeout if retry_timeout < 0
52
33
 
@@ -55,60 +36,42 @@ module Applitools
55
36
 
56
37
  if retry_timeout.zero? || should_match_window_run_once_on_timeout
57
38
  sleep retry_timeout if should_match_window_run_once_on_timeout
58
- app_output = app_output_provider.app_output region_provider, last_screenshot
59
- match_result = perform_match(
60
- user_inputs: user_inputs,
61
- app_output: app_output,
62
- tag: tag,
63
- ignore_mismatch: ignore_mismatch,
64
- ignore: self.class.convert_coordinates(ignore, app_output.screenshot),
65
- trim: trim,
66
- match_level: match_level,
67
- exact: exact
68
- )
39
+ app_output = app_output_provider.app_output(region_provider, last_screenshot)
40
+ match_window_data.app_output = app_output
41
+ match_window_data.convert_ignored_regions_coordinates
42
+ match_result = perform_match(match_window_data)
69
43
  else
70
- app_output = app_output_provider.app_output region_provider, last_screenshot
44
+ passed_ignore_mismatch = match_window_data.ignore_mismatch
45
+ app_output = app_output_provider.app_output(region_provider, last_screenshot)
46
+ match_window_data.app_output = app_output
47
+ match_window_data.convert_ignored_regions_coordinates
48
+ match_window_data.ignore_mismatch = true
71
49
  start = Time.now
72
- match_result = perform_match(
73
- user_inputs: user_inputs,
74
- app_output: app_output,
75
- tag: tag,
76
- ignore_mismatch: true,
77
- ignore: self.class.convert_coordinates(ignore, app_output.screenshot),
78
- trim: trim,
79
- match_level: match_level,
80
- exact: exact
81
- )
50
+ match_result = perform_match(match_window_data)
82
51
  retry_time = Time.now - start
83
52
 
84
- while retry_time < retry_timeout && !match_result.as_expected?
53
+ if block_given?
54
+ block_retry = yield(match_result)
55
+ else
56
+ block_retry = false
57
+ end
58
+
59
+ while retry_time < retry_timeout && !(block_retry || match_result.as_expected?)
85
60
  sleep MATCH_INTERVAL
86
- app_output = app_output_provider.app_output region_provider, last_screenshot
87
- match_result = perform_match(
88
- user_inputs: user_inputs,
89
- app_output: app_output,
90
- tag: tag,
91
- ignore_mismatch: true,
92
- ignore: self.class.convert_coordinates(ignore, app_output.screenshot),
93
- trim: trim,
94
- match_level: match_level,
95
- exact: exact
96
- )
61
+ app_output = app_output_provider.app_output(region_provider, last_screenshot)
62
+ match_window_data.app_output = app_output
63
+ match_window_data.convert_ignored_regions_coordinates
64
+ match_window_data.ignore_mismatch = true
65
+ match_result = perform_match(match_window_data)
97
66
  retry_time = Time.now - start
98
67
  end
99
68
 
100
- unless match_result.as_expected?
101
- app_output = app_output_provider.app_output region_provider, last_screenshot
102
- match_result = perform_match(
103
- user_inputs: user_inputs,
104
- app_output: app_output,
105
- tag: tag,
106
- ignore_mismatch: ignore_mismatch,
107
- ignore: self.class.convert_coordinates(ignore, app_output.screenshot),
108
- trim: trim,
109
- match_level: match_level,
110
- exact: exact
111
- )
69
+ unless block_retry || match_result.as_expected?
70
+ app_output = app_output_provider.app_output(region_provider, last_screenshot)
71
+ match_window_data.app_output = app_output
72
+ match_window_data.convert_ignored_regions_coordinates
73
+ match_window_data.ignore_mismatch = passed_ignore_mismatch
74
+ match_result = perform_match(match_window_data)
112
75
  end
113
76
  end
114
77
 
@@ -120,24 +83,9 @@ module Applitools
120
83
 
121
84
  private
122
85
 
123
- def perform_match(options = {})
124
- user_inputs = options[:user_inputs]
125
- app_output = options[:app_output]
126
- tag = options[:tag]
127
- ignore_mismatch = options[:ignore_mismatch]
128
- data = Applitools::MatchWindowData.new user_inputs, app_output, tag, ignore_mismatch,
129
- name: tag, user_inputs: user_inputs.to_hash, ignore_mismatch: ignore_mismatch, ignore_match: false,
130
- force_mistmatch: false, force_match: false,
131
- image_match_settings: {
132
- matchLevel: options[:match_level],
133
- ignore: options[:ignore],
134
- ignoreCaret: options[:ignore_caret].nil? ? true : options[:ignore_caret],
135
- exact: options[:exact]
136
- },
137
- trim: {
138
- enabled: options[:trim]
139
- }
140
- Applitools::Connectivity::ServerConnector.match_window running_session, data
86
+ def perform_match(match_window_data)
87
+ Applitools::ArgumentGuard.is_a? match_window_data, 'match_window_data', Applitools::MatchWindowData
88
+ Applitools::Connectivity::ServerConnector.match_window running_session, match_window_data
141
89
  end
142
90
  end
143
91
  end
@@ -2,7 +2,7 @@ require 'yaml'
2
2
 
3
3
  module Applitools
4
4
  class TestResults
5
- attr_accessor :is_new, :url
5
+ attr_accessor :is_new, :url, :screenshot
6
6
  attr_reader :steps, :matches, :mismatches, :missing, :original_results
7
7
 
8
8
  def initialize(results = {})
@@ -16,17 +16,15 @@ module Applitools
16
16
  end
17
17
 
18
18
  def passed?
19
- return !(mismatches > 0) && !(missing > 0) unless new?
20
- false
19
+ !(original_results['isAborted'] || original_results['isDifferent'] || original_results['isNew'])
21
20
  end
22
21
 
23
22
  def failed?
24
- return (mismatches > 0) || (missing > 0) unless new?
25
- false
23
+ original_results['isDifferent'] && !(original_results['isAborted'] || original_results['isNew'])
26
24
  end
27
25
 
28
26
  def new?
29
- is_new
27
+ original_results['isNew']
30
28
  end
31
29
 
32
30
  def ==(other)
@@ -42,6 +40,8 @@ module Applitools
42
40
 
43
41
  alias is_passed passed?
44
42
 
43
+ alias as_expected? passed?
44
+
45
45
  def to_s(advanced = false)
46
46
  is_new_str = ''
47
47
  is_new_str = is_new ? 'New test' : 'Existing test' unless is_new.nil?
@@ -62,21 +62,48 @@ module Applitools::Images
62
62
  Applitools::ArgumentGuard.not_nil(name, 'name')
63
63
  region_provider = get_region_provider(target)
64
64
 
65
+ match_window_data = Applitools::MatchWindowData.new
66
+ match_window_data.tag = name
67
+ match_window_data.match_level = default_match_settings[:match_level]
68
+ match_window_data.read_target(target, nil)
69
+
65
70
  image = target.image
66
71
  self.viewport_size = Applitools::RectangleSize.new image.width, image.height if viewport_size.nil?
67
72
  self.screenshot = EyesImagesScreenshot.new image
68
73
 
69
74
  mr = check_window_base(
70
- region_provider, name, false,
75
+ region_provider,
71
76
  target.options[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT,
72
- ignore: target.ignored_regions,
73
- trim: target.options[:trim],
74
- match_level: default_match_settings[:match_level],
75
- exact: default_match_settings[:exact]
77
+ match_window_data
76
78
  )
77
79
  mr.as_expected?
78
80
  end
79
81
 
82
+ def check_single(name, target, options = {})
83
+ open_base(options) unless options.empty?
84
+ Applitools::ArgumentGuard.not_nil(name, 'name')
85
+ region_provider = get_region_provider(target)
86
+
87
+ match_window_data = Applitools::MatchSingleCheckData.new
88
+ match_window_data.tag = name
89
+
90
+ match_window_data.ignore_mismatch = options[:ignore_mismatch] ? true : false
91
+ match_window_data.match_level = default_match_settings[:match_level]
92
+
93
+ match_window_data.read_target(target, nil)
94
+
95
+ image = target.image
96
+ self.viewport_size = Applitools::RectangleSize.new image.width, image.height if viewport_size.nil?
97
+ self.screenshot = EyesImagesScreenshot.new image
98
+
99
+ mr = check_single_base(
100
+ region_provider,
101
+ target.options[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT,
102
+ match_window_data
103
+ )
104
+ mr
105
+ end
106
+
80
107
  def get_region_provider(target)
81
108
  if (region_to_check = target.region_to_check).nil?
82
109
  Object.new.tap do |prov|
@@ -124,6 +151,10 @@ module Applitools::Images
124
151
  # eyes.check_image(image: my_image, tag: 'My Test', ignore_mismatch: true)
125
152
  def check_image(options)
126
153
  options = { tag: nil, ignore_mismatch: false }.merge options
154
+ match_data = Applitools::MatchWindowData.new
155
+ match_data.tag = options[:tag]
156
+ match_data.ignore_mismatch = options[:ignore_mismatch]
157
+ match_data.match_level = default_match_settings[:match_level]
127
158
 
128
159
  if disabled?
129
160
  logger.info "check_image(image, #{options[:tag]}, #{options[:ignore_mismatch]}): Ignored"
@@ -148,8 +179,7 @@ module Applitools::Images
148
179
  nil
149
180
  end
150
181
  end
151
- mr = check_window_base region_provider, options[:tag], options[:ignore_mismatch],
152
- Applitools::EyesBase::USE_DEFAULT_TIMEOUT, options.merge(match_level: default_match_settings[:match_level])
182
+ mr = check_window_base region_provider, Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_data
153
183
  mr.as_expected?
154
184
  end
155
185
 
@@ -170,6 +200,10 @@ module Applitools::Images
170
200
  # eyes.check_region(image_bytes: string_represents_image, tag: 'My Test', region: my_region)
171
201
  def check_region(options)
172
202
  options = { tag: nil, ignore_mismatch: false }.merge options
203
+ match_data = Applitools::MatchWindowData.new
204
+ match_data.tag = options[:tag]
205
+ match_data.ignore_mismatch = options[:ignore_mismatch]
206
+ match_data.match_level = default_match_settings[:match_level]
173
207
 
174
208
  if disabled?
175
209
  logger.info "check_region(image, #{options[:tag]}, #{options[:ignore_mismatch]}): Ignored"
@@ -196,8 +230,9 @@ module Applitools::Images
196
230
  Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
197
231
  end
198
232
  end
199
- mr = check_window_base region_provider, options[:tag], options[:ignore_mismatch],
200
- Applitools::EyesBase::USE_DEFAULT_TIMEOUT, options.merge(match_level: default_match_settings[:match_level])
233
+ # mr = check_window_base region_provider, options[:tag], options[:ignore_mismatch],
234
+ # Applitools::EyesBase::USE_DEFAULT_TIMEOUT, options.merge(match_level: default_match_settings[:match_level])
235
+ mr = check_window_base region_provider, Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_data
201
236
  mr.as_expected?
202
237
  end
203
238
 
@@ -1,3 +1,3 @@
1
1
  module Applitools
2
- VERSION = '3.5.4'.freeze
2
+ VERSION = '3.6.4'.freeze
3
3
  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.5.4
4
+ version: 3.6.4
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-05-02 00:00:00.000000000 Z
11
+ date: 2017-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oily_png
@@ -222,6 +222,8 @@ files:
222
222
  - lib/applitools/core/location.rb
223
223
  - lib/applitools/core/match_result.rb
224
224
  - lib/applitools/core/match_results.rb
225
+ - lib/applitools/core/match_single_check_data.rb
226
+ - lib/applitools/core/match_single_task.rb
225
227
  - lib/applitools/core/match_window_data.rb
226
228
  - lib/applitools/core/match_window_task.rb
227
229
  - lib/applitools/core/mouse_trigger.rb