percy-appium-app 0.0.1 → 0.0.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
  SHA256:
3
- metadata.gz: ba54dc346521591705be68354e98b25018a98a1af988b9d05c7b3e6d6120b92f
4
- data.tar.gz: 5fe4abc08f138a09c1f5c95f327f9bebb8c9d4f7899cd0ffbe233d2d95cb5e86
3
+ metadata.gz: 977a7a790f27d4907f95f7fe43de80d9b22e755320f159a491615a642a836a1d
4
+ data.tar.gz: e9eb127a4f084f12bffc64aa4263928bf0931352a5ff60d408f91f9e955b0204
5
5
  SHA512:
6
- metadata.gz: 5434a1ce14329a48bf5411050de8c466ec40e77f3545fa159d566d077d28d88ce027a7ed87ea3a3cf0cc6a851350376a7218d93e6250de93cc165e5ba6179196
7
- data.tar.gz: 2a8f9febe81d0490ed25d4f8bca3a2b24851a62d5c51ea33527629e72e810de9a4e0e94593f88727ffe42c25237c43aab785529d1e7bb4d24b5fd81488fedd8e
6
+ metadata.gz: e50bd2ad6f3fda122ef560e6e264bb2eb1bde38d48d6fcef7a3a53193d1af021d19bd60e04c8785e29cbeb0b5db4372b86ef43779d4716fb6c1006e60c5ab1ed
7
+ data.tar.gz: 1ce875348fe37874f4fa9d2089a7a9159aedd0977b7f9e5aa1c3042218b0778b098becdcc0fcd5aeb3767c3f0284276dbe170221d7b2beef797fe39a9ed32863
data/percy/environment.rb CHANGED
@@ -4,22 +4,24 @@ require 'appium_lib'
4
4
  require 'appium_lib/version'
5
5
  require_relative 'version'
6
6
 
7
- class Environment
8
- @percy_build_id = nil
9
- @percy_build_url = nil
10
- @session_type = nil
7
+ module Percy
8
+ class Percy::Environment
9
+ @percy_build_id = nil
10
+ @percy_build_url = nil
11
+ @session_type = nil
11
12
 
12
- class << self
13
- attr_accessor :percy_build_id, :percy_build_url, :session_type
13
+ class << self
14
+ attr_accessor :percy_build_id, :percy_build_url, :session_type
14
15
 
15
- def get_client_info(flag = false)
16
- sdk_version = SDK_VERSION
17
- flag ? "percy-appium-app-ruby/#{sdk_version}" : "percy-appium-app/#{sdk_version}"
18
- end
16
+ def get_client_info(flag = false)
17
+ sdk_version = Percy::VERSION
18
+ flag ? "percy-appium-app-ruby/#{sdk_version}" : "percy-appium-app/#{sdk_version}"
19
+ end
19
20
 
20
- def get_env_info
21
- appium_version = Appium::VERSION # This assumes the 'appium_lib' gem provides a VERSION constant.
22
- ["appium/#{appium_version}", "ruby/#{RUBY_VERSION}"]
21
+ def get_env_info
22
+ appium_version = Appium::VERSION # This assumes the 'appium_lib' gem provides a VERSION constant.
23
+ ["appium/#{appium_version}", "ruby/#{RUBY_VERSION}"]
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class BaseException < StandardError; end
4
2
 
5
3
  class UnsupportedDevice < BaseException; end
@@ -6,50 +6,52 @@ require_relative 'percy_options'
6
6
  require_relative '../providers/provider_resolver'
7
7
  require_relative '../metadata/metadata_resolver'
8
8
 
9
- class AppPercy
10
- attr_accessor :metadata, :provider
9
+ module Percy
10
+ class AppPercy
11
+ attr_accessor :metadata, :provider
11
12
 
12
- def initialize(driver)
13
- raise DriverNotSupported unless driver.is_a?(Appium::Core::Base::Driver)
13
+ def initialize(driver)
14
+ raise DriverNotSupported unless driver.is_a?(Appium::Core::Base::Driver)
14
15
 
15
- @driver = driver
16
- @metadata = MetadataResolver.resolve(@driver)
17
- @provider = ProviderResolver.resolve(@driver)
18
- @percy_options = PercyOptions.new(@metadata.capabilities)
19
- end
16
+ @driver = driver
17
+ @metadata = Percy::MetadataResolver.resolve(@driver)
18
+ @provider = Percy::ProviderResolver.resolve(@driver)
19
+ @percy_options = Percy::PercyOptions.new(@metadata.capabilities)
20
+ end
20
21
 
21
- def screenshot(name, **kwargs)
22
- return nil unless @percy_options.enabled
22
+ def screenshot(name, **kwargs)
23
+ return nil unless @percy_options.enabled
23
24
 
24
- raise TypeError, 'Argument name should be a String' unless name.is_a?(String)
25
+ raise TypeError, 'Argument name should be a String' unless name.is_a?(String)
25
26
 
26
- device_name = kwargs[:device_name]
27
- raise TypeError, 'Argument device_name should be a String' if device_name && !device_name.is_a?(String)
27
+ device_name = kwargs[:device_name]
28
+ raise TypeError, 'Argument device_name should be a String' if device_name && !device_name.is_a?(String)
28
29
 
29
- fullscreen = kwargs[:full_screen]
30
- if fullscreen && !fullscreen.is_a?(TrueClass) && !fullscreen.is_a?(FalseClass)
31
- raise TypeError,
32
- 'Argument fullscreen should be a Boolean'
33
- end
30
+ fullscreen = kwargs[:full_screen]
31
+ if fullscreen && !fullscreen.is_a?(TrueClass) && !fullscreen.is_a?(FalseClass)
32
+ raise TypeError,
33
+ 'Argument fullscreen should be a Boolean'
34
+ end
34
35
 
35
- status_bar_height = kwargs[:status_bar_height]
36
- if status_bar_height && !status_bar_height.is_a?(Integer)
37
- raise TypeError,
38
- 'Argument status_bar_height should be an Integer'
39
- end
36
+ status_bar_height = kwargs[:status_bar_height]
37
+ if status_bar_height && !status_bar_height.is_a?(Integer)
38
+ raise TypeError,
39
+ 'Argument status_bar_height should be an Integer'
40
+ end
41
+
42
+ nav_bar_height = kwargs[:nav_bar_height]
43
+ raise TypeError, 'Argument nav_bar_height should be an Integer' if nav_bar_height && !nav_bar_height.is_a?(Integer)
40
44
 
41
- nav_bar_height = kwargs[:nav_bar_height]
42
- raise TypeError, 'Argument nav_bar_height should be an Integer' if nav_bar_height && !nav_bar_height.is_a?(Integer)
45
+ orientation = kwargs[:orientation]
46
+ if orientation && !orientation.is_a?(String)
47
+ raise TypeError,
48
+ 'Argument orientation should be a String and portrait/landscape'
49
+ end
43
50
 
44
- orientation = kwargs[:orientation]
45
- if orientation && !orientation.is_a?(String)
46
- raise TypeError,
47
- 'Argument orientation should be a String and portrait/landscape'
51
+ @provider.screenshot(name, **kwargs)
52
+ nil
48
53
  end
49
54
 
50
- @provider.screenshot(name, **kwargs)
51
- nil
55
+ attr_reader :percy_options
52
56
  end
53
-
54
- attr_reader :percy_options
55
57
  end
data/percy/lib/cache.rb CHANGED
@@ -1,53 +1,54 @@
1
1
  # frozen_string_literal: true
2
+ module Percy
3
+ class Cache
4
+ attr_reader :cache
5
+
6
+ @@cache = {}
7
+ CACHE_TIMEOUT = 5 * 60 # 5 * 60 seconds
8
+ TIMEOUT_KEY = 'last_access_time'
9
+
10
+ SESSION_DETAILS = 'session_details'
11
+ SYSTEM_BARS = 'system_bars'
12
+ WINDOW_SIZE = 'window_size'
13
+ VIEWPORT = 'viewport'
14
+ SESSION_CAPABILITIES = 'session_capabilities'
15
+ CAPABILITIES = 'capabilities'
16
+ COMMAND_EXECUTOR_URL = 'command_executor_url'
17
+
18
+ def cache
19
+ @@cache
20
+ end
2
21
 
3
- class Cache
4
- attr_reader :cache
5
-
6
- @@cache = {}
7
- CACHE_TIMEOUT = 5 * 60 # 5 * 60 seconds
8
- TIMEOUT_KEY = 'last_access_time'
9
-
10
- SESSION_DETAILS = 'session_details'
11
- SYSTEM_BARS = 'system_bars'
12
- WINDOW_SIZE = 'window_size'
13
- VIEWPORT = 'viewport'
14
- SESSION_CAPABILITIES = 'session_capabilities'
15
- CAPABILITIES = 'capabilities'
16
- COMMAND_EXECUTOR_URL = 'command_executor_url'
17
-
18
- def cache
19
- @@cache
20
- end
22
+ def self.set_cache(session_id, property, value)
23
+ raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
24
+ raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
21
25
 
22
- def self.set_cache(session_id, property, value)
23
- raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
24
- raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
26
+ session = @@cache.fetch(session_id, {})
27
+ session[TIMEOUT_KEY] = Time.now.to_i
28
+ session[property] = value
29
+ @@cache[session_id] = session
30
+ end
25
31
 
26
- session = @@cache.fetch(session_id, {})
27
- session[TIMEOUT_KEY] = Time.now.to_i
28
- session[property] = value
29
- @@cache[session_id] = session
30
- end
32
+ def self.get_cache(session_id, property)
33
+ cleanup_cache
31
34
 
32
- def self.get_cache(session_id, property)
33
- cleanup_cache
35
+ raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
36
+ raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
34
37
 
35
- raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
36
- raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
38
+ session = @@cache.fetch(session_id, {})
39
+ session.fetch(property, nil)
40
+ end
37
41
 
38
- session = @@cache.fetch(session_id, {})
39
- session.fetch(property, nil)
40
- end
42
+ def self.cleanup_cache
43
+ now = Time.now.to_i
44
+ session_ids = []
41
45
 
42
- def self.cleanup_cache
43
- now = Time.now.to_i
44
- session_ids = []
46
+ @@cache.each do |session_id, session|
47
+ timestamp = session[TIMEOUT_KEY]
48
+ session_ids << session_id if now - timestamp >= CACHE_TIMEOUT
49
+ end
45
50
 
46
- @@cache.each do |session_id, session|
47
- timestamp = session[TIMEOUT_KEY]
48
- session_ids << session_id if now - timestamp >= CACHE_TIMEOUT
51
+ session_ids.each { |session_id| @@cache.delete(session_id) }
49
52
  end
50
-
51
- session_ids.each { |session_id| @@cache.delete(session_id) }
52
53
  end
53
54
  end
@@ -9,124 +9,126 @@ require_relative '../exceptions/exceptions'
9
9
  require_relative '../version'
10
10
  require_relative '../environment'
11
11
 
12
- CLIENT_INFO = "percy-appium-app/#{SDK_VERSION}"
13
- ENV_INFO = ["appium/#{Appium::VERSION}", "ruby/#{RUBY_VERSION}"].freeze
12
+ module Percy
13
+ CLIENT_INFO = "percy-appium-app/#{VERSION}"
14
+ ENV_INFO = ["appium/#{Appium::VERSION}", "ruby/#{RUBY_VERSION}"].freeze
14
15
 
15
- PERCY_CLI_API = ENV['PERCY_CLI_API'] || 'http://localhost:5338'
16
+ PERCY_CLI_API = ENV['PERCY_CLI_API'] || 'http://localhost:5338'
16
17
 
17
- class CLIWrapper
18
- def initialize; end
18
+ class CLIWrapper
19
+ def initialize; end
19
20
 
20
- def self.percy_enabled?
21
- @percy_enabled ||= begin
22
- uri = URI("#{PERCY_CLI_API}/percy/healthcheck")
23
- response = Net::HTTP.get_response(uri)
21
+ def self.percy_enabled?
22
+ @percy_enabled ||= begin
23
+ uri = URI("#{PERCY_CLI_API}/percy/healthcheck")
24
+ response = Net::HTTP.get_response(uri)
24
25
 
25
- raise CLIException, response.body unless response.is_a?(Net::HTTPSuccess)
26
+ raise CLIException, response.body unless response.is_a?(Net::HTTPSuccess)
26
27
 
27
- data = JSON.parse(response.body)
28
- raise CLIException, data['error'] unless data['success']
28
+ data = JSON.parse(response.body)
29
+ raise CLIException, data['error'] unless data['success']
30
+
31
+ Percy::Environment.percy_build_id = data['build']['id']
32
+ Percy::Environment.percy_build_url = data['build']['url']
33
+ Percy::Environment.session_type = data.fetch('type', nil)
29
34
 
30
- Environment.percy_build_id = data['build']['id']
31
- Environment.percy_build_url = data['build']['url']
32
- Environment.session_type = data.fetch('type', nil)
35
+ version = response['x-percy-core-version']
36
+ if version.split('.')[0] != '1'
37
+ log("Unsupported Percy CLI version, #{version}")
38
+ return false
39
+ end
40
+ return true unless version.split('.')[1].to_i < 27
33
41
 
34
- version = response['x-percy-core-version']
35
- if version.split('.')[0] != '1'
36
- log("Unsupported Percy CLI version, #{version}")
42
+ log('Please upgrade to the latest CLI version for using this SDK. Minimum compatible version is 1.27.0-beta.0')
43
+ return false
44
+ rescue StandardError => e
45
+ log('Percy is not running, disabling screenshots')
46
+ log(e, on_debug: true)
37
47
  return false
38
48
  end
39
- return true unless version.split('.')[1].to_i < 27
40
-
41
- log('Please upgrade to the latest CLI version for using this SDK. Minimum compatible version is 1.27.0-beta.0')
42
- return false
43
- rescue StandardError => e
44
- log('Percy is not running, disabling screenshots')
45
- log(e, on_debug: true)
46
- return false
47
49
  end
48
- end
49
50
 
50
- def post_screenshots(name, tag, tiles, external_debug_url = nil, ignored_elements_data = nil,
51
- considered_elements_data = nil)
52
- body = request_body(name, tag, tiles, external_debug_url, ignored_elements_data, considered_elements_data)
53
- body['client_info'] = Environment.get_client_info
54
- body['environment_info'] = Environment.get_env_info
51
+ def post_screenshots(name, tag, tiles, external_debug_url = nil, ignored_elements_data = nil,
52
+ considered_elements_data = nil)
53
+ body = request_body(name, tag, tiles, external_debug_url, ignored_elements_data, considered_elements_data)
54
+ body['client_info'] = Percy::Environment.get_client_info
55
+ body['environment_info'] = Percy::Environment.get_env_info
55
56
 
56
- uri = URI("#{PERCY_CLI_API}/percy/comparison")
57
- http = Net::HTTP.new(uri.host, uri.port)
58
- request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
59
- request.body = body.to_json
57
+ uri = URI("#{PERCY_CLI_API}/percy/comparison")
58
+ http = Net::HTTP.new(uri.host, uri.port)
59
+ request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
60
+ request.body = body.to_json
60
61
 
61
- response = http.request(request)
62
- data = JSON.parse(response.body)
62
+ response = http.request(request)
63
+ data = JSON.parse(response.body)
63
64
 
64
- raise CLIException, data.fetch('error', 'UnknownException') if response.code != '200'
65
+ raise CLIException, data.fetch('error', 'UnknownException') if response.code != '200'
65
66
 
66
- data
67
- end
68
-
69
- def self.post_failed_event(error)
70
- body = {
71
- 'clientInfo' => Environment.get_client_info(true),
72
- 'message' => error,
73
- 'errorKind' => 'sdk'
74
- }
67
+ data
68
+ end
75
69
 
76
- uri = URI("#{PERCY_CLI_API}/percy/events")
77
- response = Net::HTTP.post(uri, body.to_json, 'Content-Type' => 'application/json')
70
+ def self.post_failed_event(error)
71
+ body = {
72
+ 'clientInfo' => Percy::Environment.get_client_info(true),
73
+ 'message' => error,
74
+ 'errorKind' => 'sdk'
75
+ }
76
+
77
+ uri = URI("#{PERCY_CLI_API}/percy/events")
78
+ response = Net::HTTP.post(uri, body.to_json, 'Content-Type' => 'application/json')
79
+
80
+ # Handle errors
81
+ if response.code.to_i != 200
82
+ data = JSON.parse(response.body)
83
+ error_message = data.fetch('error', 'UnknownException')
84
+ raise CLIException, error_message
85
+ end
78
86
 
79
- # Handle errors
80
- if response.code.to_i != 200
81
- data = JSON.parse(response.body)
82
- error_message = data.fetch('error', 'UnknownException')
83
- raise CLIException, error_message
87
+ JSON.parse(response.body)
88
+ rescue StandardError => e
89
+ log(e.message, on_debug: true)
90
+ nil
84
91
  end
85
92
 
86
- JSON.parse(response.body)
87
- rescue StandardError => e
88
- log(e.message, on_debug: true)
89
- nil
90
- end
93
+ def post_poa_screenshots(name, session_id, command_executor_url, capabilities, desired_capabilities, options = nil)
94
+ body = {
95
+ 'sessionId' => session_id,
96
+ 'commandExecutorUrl' => command_executor_url,
97
+ 'capabilities' => capabilities.dup, # In Ruby, you can duplicate the hash with `dup`
98
+ 'sessionCapabilities' => desired_capabilities.dup,
99
+ 'snapshotName' => name,
100
+ 'options' => options
101
+ }
91
102
 
92
- def post_poa_screenshots(name, session_id, command_executor_url, capabilities, desired_capabilities, options = nil)
93
- body = {
94
- 'sessionId' => session_id,
95
- 'commandExecutorUrl' => command_executor_url,
96
- 'capabilities' => capabilities.dup, # In Ruby, you can duplicate the hash with `dup`
97
- 'sessionCapabilities' => desired_capabilities.dup,
98
- 'snapshotName' => name,
99
- 'options' => options
100
- }
103
+ body['client_info'] = Percy::Environment.get_client_info # Using class method without the underscore
104
+ body['environment_info'] = Percy::Environment.get_env_info
101
105
 
102
- body['client_info'] = Environment.get_client_info # Using class method without the underscore
103
- body['environment_info'] = Environment.get_env_info
106
+ uri = URI("#{PERCY_CLI_API}/percy/automateScreenshot")
107
+ response = Net::HTTP.post(uri, body.to_json, 'Content-Type' => 'application/json')
104
108
 
105
- uri = URI("#{PERCY_CLI_API}/percy/automateScreenshot")
106
- response = Net::HTTP.post(uri, body.to_json, 'Content-Type' => 'application/json')
109
+ # Handle errors
110
+ raise CLIException, "Error: #{response.message}" unless response.is_a?(Net::HTTPSuccess)
107
111
 
108
- # Handle errors
109
- raise CLIException, "Error: #{response.message}" unless response.is_a?(Net::HTTPSuccess)
112
+ data = JSON.parse(response.body)
110
113
 
111
- data = JSON.parse(response.body)
114
+ if response.code != '200'
115
+ error_message = data.fetch('error', 'UnknownException')
116
+ raise CLIException, error_message
117
+ end
112
118
 
113
- if response.code != '200'
114
- error_message = data.fetch('error', 'UnknownException')
115
- raise CLIException, error_message
119
+ data
116
120
  end
117
121
 
118
- data
119
- end
120
-
121
- def request_body(name, tag, tiles, external_debug_url, ignored_elements_data, considered_elements_data)
122
- tiles = tiles.map(&:to_h)
123
- {
124
- 'name' => name,
125
- 'tag' => tag,
126
- 'tiles' => tiles,
127
- 'ignored_elements_data' => ignored_elements_data,
128
- 'external_debug_url' => external_debug_url,
129
- 'considered_elements_data' => considered_elements_data
130
- }
122
+ def request_body(name, tag, tiles, external_debug_url, ignored_elements_data, considered_elements_data)
123
+ tiles = tiles.map(&:to_h)
124
+ {
125
+ 'name' => name,
126
+ 'tag' => tag,
127
+ 'tiles' => tiles,
128
+ 'ignored_elements_data' => ignored_elements_data,
129
+ 'external_debug_url' => external_debug_url,
130
+ 'considered_elements_data' => considered_elements_data
131
+ }
132
+ end
131
133
  end
132
134
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  # lib/ignore_region.rb
4
4
  require_relative 'region'
5
-
6
- class IgnoreRegion < Region
7
- # Inherits everything from Region; no additional code needed unless you want to extend or modify the behavior
5
+ module Percy
6
+ class IgnoreRegion < Percy::Region
7
+ # Inherits everything from Percy::Region; no additional code needed unless you want to extend or modify the behavior
8
+ end
8
9
  end
@@ -10,50 +10,52 @@ IGNORE_ELEMENT_ALT_KEY = 'ignoreRegionAppiumElements'
10
10
  CONSIDER_ELEMENT_KEY = 'consider_region_appium_elements'
11
11
  CONSIDER_ELEMENT_ALT_KEY = 'considerRegionAppiumElements'
12
12
 
13
- class PercyOnAutomate
14
- def initialize(driver)
15
- unless driver.is_a?(Appium::Core::Base::Driver)
16
- raise DriverNotSupported, 'The provided driver instance is not supported.'
13
+ module Percy
14
+ class PercyOnAutomate
15
+ def initialize(driver)
16
+ unless driver.is_a?(Appium::Core::Base::Driver)
17
+ raise DriverNotSupported, 'The provided driver instance is not supported.'
18
+ end
19
+
20
+ @driver = driver
21
+ @percy_options = Percy::PercyOptions.new(@driver.capabilities)
17
22
  end
18
23
 
19
- @driver = driver
20
- @percy_options = PercyOptions.new(@driver.capabilities)
21
- end
22
-
23
- def screenshot(name, **options)
24
- return nil unless @percy_options.enabled
25
- raise TypeError, 'Argument name should be a string' unless name.is_a?(String)
26
- raise KeyError, 'Please pass the last parameter as "options" key' unless options.key?(:options)
27
-
28
- metadata = DriverMetadata.new(@driver)
29
- options = options[:options] || {}
30
-
31
- begin
32
- options[IGNORE_ELEMENT_KEY] = options.delete(IGNORE_ELEMENT_ALT_KEY) if options.key?(IGNORE_ELEMENT_ALT_KEY)
33
- options[CONSIDER_ELEMENT_KEY] = options.delete(CONSIDER_ELEMENT_ALT_KEY) if options.key?(CONSIDER_ELEMENT_ALT_KEY)
34
-
35
- ignore_region_elements = options.fetch(IGNORE_ELEMENT_KEY, []).map(&:id)
36
- consider_region_elements = options.fetch(CONSIDER_ELEMENT_KEY, []).map(&:id)
37
- options.delete(IGNORE_ELEMENT_KEY)
38
- options.delete(CONSIDER_ELEMENT_KEY)
39
-
40
- additional_options = {
41
- 'ignore_region_elements' => ignore_region_elements,
42
- 'consider_region_elements' => consider_region_elements
43
- }
44
-
45
- CLIWrapper.new.post_poa_screenshots(
46
- name,
47
- metadata.session_id,
48
- metadata.command_executor_url,
49
- metadata.capabilities,
50
- metadata.session_capabilities,
51
- options.merge(additional_options)
52
- )
53
- rescue StandardError => e
54
- log("Could not take Screenshot '#{name}'")
55
- log(e.message, on_debug: true)
24
+ def screenshot(name, **options)
25
+ return nil unless @percy_options.enabled
26
+ raise TypeError, 'Argument name should be a string' unless name.is_a?(String)
27
+ raise KeyError, 'Please pass the last parameter as "options" key' unless options.key?(:options)
28
+
29
+ metadata = Percy::DriverMetadata.new(@driver)
30
+ options = options[:options] || {}
31
+
32
+ begin
33
+ options[IGNORE_ELEMENT_KEY] = options.delete(IGNORE_ELEMENT_ALT_KEY) if options.key?(IGNORE_ELEMENT_ALT_KEY)
34
+ options[CONSIDER_ELEMENT_KEY] = options.delete(CONSIDER_ELEMENT_ALT_KEY) if options.key?(CONSIDER_ELEMENT_ALT_KEY)
35
+
36
+ ignore_region_elements = options.fetch(IGNORE_ELEMENT_KEY, []).map(&:id)
37
+ consider_region_elements = options.fetch(CONSIDER_ELEMENT_KEY, []).map(&:id)
38
+ options.delete(IGNORE_ELEMENT_KEY)
39
+ options.delete(CONSIDER_ELEMENT_KEY)
40
+
41
+ additional_options = {
42
+ 'ignore_region_elements' => ignore_region_elements,
43
+ 'consider_region_elements' => consider_region_elements
44
+ }
45
+
46
+ Percy::CLIWrapper.new.post_poa_screenshots(
47
+ name,
48
+ metadata.session_id,
49
+ metadata.command_executor_url,
50
+ metadata.capabilities,
51
+ metadata.session_capabilities,
52
+ options.merge(additional_options)
53
+ )
54
+ rescue StandardError => e
55
+ log("Could not take Screenshot '#{name}'")
56
+ log(e.message, on_debug: true)
57
+ end
58
+ nil
56
59
  end
57
- nil
58
60
  end
59
61
  end
@@ -1,37 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class PercyOptions
4
- IGNORE_ERRORS = 'ignoreErrors'
5
- ENABLED = 'enabled'
6
- PERCY_OPTIONS = ['percy:options', 'percyOptions'].freeze
3
+ module Percy
4
+ class PercyOptions
5
+ IGNORE_ERRORS = 'ignoreErrors'
6
+ ENABLED = 'enabled'
7
+ PERCY_OPTIONS = ['percy:options', 'percyOptions'].freeze
7
8
 
8
- def initialize(capabilities)
9
- @capabilities = capabilities
10
- @capabilities = @capabilities.as_json unless @capabilities.is_a?(Hash)
11
- @percy_options = _parse_percy_options || {}
12
- end
9
+ def initialize(capabilities)
10
+ @capabilities = capabilities
11
+ @capabilities = @capabilities.as_json unless @capabilities.is_a?(Hash)
12
+ @percy_options = _parse_percy_options || {}
13
+ end
13
14
 
14
- def _parse_percy_options
15
- options = PERCY_OPTIONS.map { |key| @capabilities.fetch(key, nil) }
16
- options = if options.any? { |element| !element.nil? }
17
- options[0] || options[1]
18
- else
19
- {}
20
- end
15
+ def _parse_percy_options
16
+ options = PERCY_OPTIONS.map { |key| @capabilities.fetch(key, nil) }
17
+ options = if options.any? { |element| !element.nil? }
18
+ options[0] || options[1]
19
+ else
20
+ {}
21
+ end
21
22
 
22
- if options
23
- options[IGNORE_ERRORS] = @capabilities.fetch("percy.#{IGNORE_ERRORS}", true) unless options.key?(IGNORE_ERRORS)
24
- options[ENABLED] = @capabilities.fetch("percy.#{ENABLED}", true) unless options.key?(ENABLED)
25
- end
23
+ if options
24
+ options[IGNORE_ERRORS] = @capabilities.fetch("percy.#{IGNORE_ERRORS}", true) unless options.key?(IGNORE_ERRORS)
25
+ options[ENABLED] = @capabilities.fetch("percy.#{ENABLED}", true) unless options.key?(ENABLED)
26
+ end
26
27
 
27
- options
28
- end
28
+ options
29
+ end
29
30
 
30
- def ignore_errors
31
- @percy_options.fetch(IGNORE_ERRORS, true)
32
- end
31
+ def ignore_errors
32
+ @percy_options.fetch(IGNORE_ERRORS, true)
33
+ end
33
34
 
34
- def enabled
35
- @percy_options.fetch(ENABLED, true)
35
+ def enabled
36
+ @percy_options.fetch(ENABLED, true)
37
+ end
36
38
  end
37
- end
39
+ end