percy-appium-app 0.0.1 → 0.0.2.pre.beta.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,154 +6,158 @@ require_relative '../lib/tile'
6
6
  require_relative 'generic_provider'
7
7
  require_relative '../environment'
8
8
 
9
- class AppAutomate < GenericProvider
10
- def self.supports(remote_url)
11
- r_index = remote_url.rindex(ENV['AA_DOMAIN'].nil? ? 'browserstack' : ENV['AA_DOMAIN'])
12
- if r_index
13
- r_index > -1
14
- else
15
- false
9
+ module Percy
10
+ class AppAutomate < Percy::GenericProvider
11
+ def self.supports(remote_url)
12
+ r_index = remote_url.rindex(ENV['AA_DOMAIN'].nil? ? 'browserstack' : ENV['AA_DOMAIN'])
13
+ if r_index
14
+ r_index > -1
15
+ else
16
+ false
17
+ end
16
18
  end
17
- end
18
19
 
19
- def screenshot(name, **kwargs)
20
- session_details = execute_percy_screenshot_begin(name)
20
+ def screenshot(name, **kwargs)
21
+ session_details = execute_percy_screenshot_begin(name)
21
22
 
22
- if session_details
23
- metadata.device_name = session_details['deviceName']
24
- metadata.os_version = session_details['osVersion']
25
- set_debug_url(session_details)
26
- end
23
+ if session_details
24
+ metadata.device_name = session_details['deviceName']
25
+ metadata.os_version = session_details['osVersion']
26
+ set_debug_url(session_details)
27
+ end
27
28
 
28
- begin
29
- response = super(name, **kwargs)
30
- percy_screenshot_url = response.fetch('link', '')
31
- execute_percy_screenshot_end(name, percy_screenshot_url, 'success')
32
- rescue StandardError => e
33
- execute_percy_screenshot_end(name, percy_screenshot_url, 'failure', e.message)
34
- raise e
29
+ begin
30
+ response = super(name, **kwargs)
31
+ percy_screenshot_url = response.fetch('link', '')
32
+ execute_percy_screenshot_end(name, percy_screenshot_url, 'success', kwargs.fetch('sync', nil))
33
+ response['data']
34
+ rescue StandardError => e
35
+ execute_percy_screenshot_end(name, percy_screenshot_url, 'failure', kwargs.fetch('sync', nil), e.message)
36
+ raise e
37
+ end
35
38
  end
36
- end
37
39
 
38
- def set_debug_url(session_details)
39
- build_hash = session_details['buildHash'].to_s
40
- session_hash = session_details['sessionHash'].to_s
41
- @debug_url = "https://app-automate.browserstack.com/dashboard/v2/builds/#{build_hash}/sessions/#{session_hash}"
42
- end
43
-
44
- def _get_tiles(**kwargs)
45
- fullpage_ss = kwargs[:fullpage] || false
46
- if ENV['PERCY_DISABLE_REMOTE_UPLOADS'] == 'true'
47
- puts("Full page screenshots are only supported when 'PERCY_DISABLE_REMOTE_UPLOADS' is not set") if fullpage_ss
48
- return super(**kwargs) unless fullpage_ss
40
+ def set_debug_url(session_details)
41
+ build_hash = session_details['buildHash'].to_s
42
+ session_hash = session_details['sessionHash'].to_s
43
+ @debug_url = "https://app-automate.browserstack.com/dashboard/v2/builds/#{build_hash}/sessions/#{session_hash}"
49
44
  end
50
- screenshot_type = fullpage_ss ? 'fullpage' : 'singlepage'
51
- screen_lengths = kwargs[:screen_lengths] || 4
52
- scrollable_xpath = kwargs[:scollable_xpath]
53
- scrollable_id = kwargs[:scrollable_id]
54
- top_scrollview_offset = kwargs[:top_scrollview_offset]
55
- bottom_scrollview_offset = kwargs[:top_scrollview_offset]
56
45
 
57
- data = execute_percy_screenshot(
58
- metadata.device_screen_size.fetch('height', 1),
59
- screenshot_type,
60
- screen_lengths,
61
- scrollable_xpath,
62
- scrollable_id,
63
- metadata.scale_factor,
64
- top_scrollview_offset,
65
- bottom_scrollview_offset
66
- )
67
- tiles = []
68
- status_bar_height = metadata.status_bar_height
69
- nav_bar_height = metadata.navigation_bar_height
46
+ def _get_tiles(**kwargs)
47
+ fullpage_ss = kwargs[:fullpage] || false
48
+ if ENV['PERCY_DISABLE_REMOTE_UPLOADS'] == 'true'
49
+ puts("Full page screenshots are only supported when 'PERCY_DISABLE_REMOTE_UPLOADS' is not set") if fullpage_ss
50
+ return super(**kwargs) unless fullpage_ss
51
+ end
52
+ screenshot_type = fullpage_ss ? 'fullpage' : 'singlepage'
53
+ screen_lengths = kwargs[:screen_lengths] || 4
54
+ scrollable_xpath = kwargs[:scollable_xpath]
55
+ scrollable_id = kwargs[:scrollable_id]
56
+ top_scrollview_offset = kwargs[:top_scrollview_offset]
57
+ bottom_scrollview_offset = kwargs[:top_scrollview_offset]
70
58
 
71
- JSON.parse(data['result']).each do |tile_data|
72
- tiles << Tile.new(
73
- status_bar_height,
74
- nav_bar_height,
75
- tile_data['header_height'],
76
- tile_data['footer_height'],
77
- sha: tile_data['sha'].split('-')[0]
59
+ data = execute_percy_screenshot(
60
+ metadata.device_screen_size.fetch('height', 1),
61
+ screenshot_type,
62
+ screen_lengths,
63
+ scrollable_xpath,
64
+ scrollable_id,
65
+ metadata.scale_factor,
66
+ top_scrollview_offset,
67
+ bottom_scrollview_offset
78
68
  )
79
- end
69
+ tiles = []
70
+ status_bar_height = metadata.status_bar_height
71
+ nav_bar_height = metadata.navigation_bar_height
80
72
 
81
- tiles
82
- end
73
+ JSON.parse(data['result']).each do |tile_data|
74
+ tiles << Percy::Tile.new(
75
+ status_bar_height,
76
+ nav_bar_height,
77
+ tile_data['header_height'],
78
+ tile_data['footer_height'],
79
+ sha: tile_data['sha'].split('-')[0]
80
+ )
81
+ end
83
82
 
84
- def execute_percy_screenshot_begin(name)
85
- request_body = {
86
- action: 'percyScreenshot',
87
- arguments: {
88
- state: 'begin',
89
- percyBuildId: Environment.percy_build_id,
90
- percyBuildUrl: Environment.percy_build_url,
91
- name: name
83
+ tiles
84
+ end
85
+
86
+ def execute_percy_screenshot_begin(name)
87
+ request_body = {
88
+ action: 'percyScreenshot',
89
+ arguments: {
90
+ state: 'begin',
91
+ percyBuildId: Percy::Environment.percy_build_id,
92
+ percyBuildUrl: Percy::Environment.percy_build_url,
93
+ name: name
94
+ }
92
95
  }
93
- }
94
- command = "browserstack_executor: #{request_body.to_json}"
95
- begin
96
- response = metadata.execute_script(command)
97
- JSON.parse(response)
98
- rescue StandardError => e
99
- log('Could not set session as Percy session')
100
- log('Error occurred during begin call', on_debug: true)
101
- log(e, on_debug: true)
102
- nil
96
+ command = "browserstack_executor: #{request_body.to_json}"
97
+ begin
98
+ response = metadata.execute_script(command)
99
+ JSON.parse(response)
100
+ rescue StandardError => e
101
+ log('Could not set session as Percy session')
102
+ log('Error occurred during begin call', on_debug: true)
103
+ log(e, on_debug: true)
104
+ nil
105
+ end
103
106
  end
104
- end
105
107
 
106
- def execute_percy_screenshot_end(name, percy_screenshot_url, status, status_message = nil)
107
- request_body = {
108
- action: 'percyScreenshot',
109
- arguments: {
110
- state: 'end',
111
- percyScreenshotUrl: percy_screenshot_url,
112
- name: name,
113
- status: status
108
+ def execute_percy_screenshot_end(name, percy_screenshot_url, status, sync = nil, status_message = nil)
109
+ request_body = {
110
+ action: 'percyScreenshot',
111
+ arguments: {
112
+ state: 'end',
113
+ percyScreenshotUrl: percy_screenshot_url,
114
+ name: name,
115
+ status: status,
116
+ sync: sync
117
+ }
114
118
  }
115
- }
116
- request_body[:arguments][:statusMessage] = status_message if status_message
117
- command = "browserstack_executor: #{request_body.to_json}"
118
- begin
119
- metadata.execute_script(command)
120
- rescue StandardError => e
121
- log('Error occurred during end call', on_debug: true)
122
- log(e, on_debug: true)
119
+ request_body[:arguments][:statusMessage] = status_message if status_message
120
+ command = "browserstack_executor: #{request_body.to_json}"
121
+ begin
122
+ metadata.execute_script(command)
123
+ rescue StandardError => e
124
+ log('Error occurred during end call', on_debug: true)
125
+ log(e, on_debug: true)
126
+ end
123
127
  end
124
- end
125
128
 
126
- def execute_percy_screenshot(device_height, screenshotType, screen_lengths, scrollable_xpath = nil,
127
- scrollable_id = nil, scale_factor = 1, top_scrollview_offset = 0,
128
- bottom_scrollview_offset = 0)
129
- project_id = ENV['PERCY_ENABLE_DEV'] == 'true' ? 'percy-dev' : 'percy-prod'
130
- request_body = {
131
- action: 'percyScreenshot',
132
- arguments: {
133
- state: 'screenshot',
134
- percyBuildId: Environment.percy_build_id,
135
- screenshotType: screenshotType,
136
- projectId: project_id,
137
- scaleFactor: scale_factor,
138
- options: {
139
- numOfTiles: screen_lengths,
140
- deviceHeight: device_height,
141
- scrollableXpath: scrollable_xpath,
142
- scrollableId: scrollable_id,
143
- topScrollviewOffset: top_scrollview_offset,
144
- bottomScrollviewOffset: bottom_scrollview_offset,
145
- 'FORCE_FULL_PAGE' => ENV['FORCE_FULL_PAGE'] == 'true'
129
+ def execute_percy_screenshot(device_height, screenshotType, screen_lengths, scrollable_xpath = nil,
130
+ scrollable_id = nil, scale_factor = 1, top_scrollview_offset = 0,
131
+ bottom_scrollview_offset = 0)
132
+ project_id = ENV['PERCY_ENABLE_DEV'] == 'true' ? 'percy-dev' : 'percy-prod'
133
+ request_body = {
134
+ action: 'percyScreenshot',
135
+ arguments: {
136
+ state: 'screenshot',
137
+ percyBuildId: Percy::Environment.percy_build_id,
138
+ screenshotType: screenshotType,
139
+ projectId: project_id,
140
+ scaleFactor: scale_factor,
141
+ options: {
142
+ numOfTiles: screen_lengths,
143
+ deviceHeight: device_height,
144
+ scrollableXpath: scrollable_xpath,
145
+ scrollableId: scrollable_id,
146
+ topScrollviewOffset: top_scrollview_offset,
147
+ bottomScrollviewOffset: bottom_scrollview_offset,
148
+ 'FORCE_FULL_PAGE' => ENV['FORCE_FULL_PAGE'] == 'true'
149
+ }
146
150
  }
147
151
  }
148
- }
149
- command = "browserstack_executor: #{request_body.to_json}"
150
- begin
151
- response = metadata.execute_script(command)
152
- JSON.parse(response)
153
- rescue StandardError => e
154
- log('Error occurred during screenshot call', on_debug: true)
155
- log(e, on_debug: true)
156
- raise e
152
+ command = "browserstack_executor: #{request_body.to_json}"
153
+ begin
154
+ response = metadata.execute_script(command)
155
+ JSON.parse(response)
156
+ rescue StandardError => e
157
+ log('Error occurred during screenshot call', on_debug: true)
158
+ log(e, on_debug: true)
159
+ raise e
160
+ end
157
161
  end
158
162
  end
159
163
  end
@@ -9,197 +9,200 @@ require_relative '../lib/cli_wrapper'
9
9
  require_relative '../lib/tile'
10
10
  require_relative '../common/common'
11
11
 
12
- class GenericProvider
13
- attr_accessor :driver, :metadata, :debug_url
12
+ module Percy
13
+ class GenericProvider
14
+ attr_accessor :driver, :metadata, :debug_url
15
+
16
+ def initialize(driver, metadata)
17
+ @driver = driver
18
+ @metadata = metadata
19
+ @debug_url = ''
20
+ end
14
21
 
15
- def initialize(driver, metadata)
16
- @driver = driver
17
- @metadata = metadata
18
- @debug_url = ''
19
- end
22
+ def self.supports(_remote_url)
23
+ true
24
+ end
20
25
 
21
- def self.supports(_remote_url)
22
- true
23
- end
26
+ def screenshot(name, **kwargs)
27
+ tiles = _get_tiles(**kwargs)
28
+ tag = _get_tag(**kwargs)
29
+ ignore_regions = {
30
+ 'ignoreElementsData' => _find_regions(
31
+ xpaths: kwargs.fetch(:ignore_regions_xpaths, []),
32
+ accessibility_ids: kwargs.fetch(:ignore_region_accessibility_ids, []),
33
+ appium_elements: kwargs.fetch(:ignore_region_appium_elements, []),
34
+ custom_locations: kwargs.fetch(:custom_ignore_regions, [])
35
+ )
36
+ }
37
+ consider_regions = {
38
+ 'considerElementsData' => _find_regions(
39
+ xpaths: kwargs.fetch(:consider_regions_xpaths, []),
40
+ accessibility_ids: kwargs.fetch(:consider_region_accessibility_ids, []),
41
+ appium_elements: kwargs.fetch(:consider_region_appium_elements, []),
42
+ custom_locations: kwargs.fetch(:custom_consider_regions, [])
43
+ )
44
+ }
45
+ sync = kwargs.fetch(:sync, nil)
46
+
47
+ _post_screenshots(name, tag, tiles, get_debug_url, ignore_regions, consider_regions, sync)
48
+ end
24
49
 
25
- def screenshot(name, **kwargs)
26
- tiles = _get_tiles(**kwargs)
27
- tag = _get_tag(**kwargs)
28
- ignore_regions = {
29
- 'ignoreElementsData' => _find_regions(
30
- xpaths: kwargs.fetch(:ignore_regions_xpaths, []),
31
- accessibility_ids: kwargs.fetch(:ignore_region_accessibility_ids, []),
32
- appium_elements: kwargs.fetch(:ignore_region_appium_elements, []),
33
- custom_locations: kwargs.fetch(:custom_ignore_regions, [])
34
- )
35
- }
36
- consider_regions = {
37
- 'considerElementsData' => _find_regions(
38
- xpaths: kwargs.fetch(:consider_regions_xpaths, []),
39
- accessibility_ids: kwargs.fetch(:consider_region_accessibility_ids, []),
40
- appium_elements: kwargs.fetch(:consider_region_appium_elements, []),
41
- custom_locations: kwargs.fetch(:custom_consider_regions, [])
42
- )
43
- }
44
-
45
- _post_screenshots(name, tag, tiles, get_debug_url, ignore_regions, consider_regions)
46
- end
50
+ def _get_tag(**kwargs)
51
+ name = kwargs[:device_name] || metadata.device_name
52
+ os_name = metadata.os_name
53
+ os_version = metadata.os_version
54
+ width = metadata.device_screen_size['width'] || 1
55
+ height = metadata.device_screen_size['height'] || 1
56
+ orientation = metadata.get_orientation(**kwargs).downcase
57
+
58
+ {
59
+ 'name' => name,
60
+ 'os_name' => os_name,
61
+ 'os_version' => os_version,
62
+ 'width' => width,
63
+ 'height' => height,
64
+ 'orientation' => orientation
65
+ }
66
+ end
47
67
 
48
- def _get_tag(**kwargs)
49
- name = kwargs[:device_name] || metadata.device_name
50
- os_name = metadata.os_name
51
- os_version = metadata.os_version
52
- width = metadata.device_screen_size['width'] || 1
53
- height = metadata.device_screen_size['height'] || 1
54
- orientation = metadata.get_orientation(**kwargs).downcase
55
-
56
- {
57
- 'name' => name,
58
- 'os_name' => os_name,
59
- 'os_version' => os_version,
60
- 'width' => width,
61
- 'height' => height,
62
- 'orientation' => orientation
63
- }
64
- end
68
+ def _get_tiles(**kwargs)
69
+ fullpage_ss = kwargs[:fullpage] || false
70
+ if fullpage_ss
71
+ log('Full page screenshot is only supported on App Automate. Falling back to single page screenshot.')
72
+ end
65
73
 
66
- def _get_tiles(**kwargs)
67
- fullpage_ss = kwargs[:fullpage] || false
68
- if fullpage_ss
69
- log('Full page screenshot is only supported on App Automate. Falling back to single page screenshot.')
74
+ png_bytes = driver.screenshot_as(:png)
75
+ directory = _get_dir
76
+ path = _write_screenshot(png_bytes, directory)
77
+
78
+ fullscreen = kwargs[:full_screen] || false
79
+ status_bar_height = kwargs[:status_bar_height] || metadata.status_bar_height
80
+ nav_bar_height = kwargs[:nav_bar_height] || metadata.navigation_bar_height
81
+ header_height = 0
82
+ footer_height = 0
83
+ [
84
+ Percy::Tile.new(status_bar_height, nav_bar_height, header_height, footer_height, filepath: path, fullscreen: fullscreen)
85
+ ]
70
86
  end
71
87
 
72
- png_bytes = driver.screenshot_as(:png)
73
- directory = _get_dir
74
- path = _write_screenshot(png_bytes, directory)
75
-
76
- fullscreen = kwargs[:full_screen] || false
77
- status_bar_height = kwargs[:status_bar_height] || metadata.status_bar_height
78
- nav_bar_height = kwargs[:nav_bar_height] || metadata.navigation_bar_height
79
- header_height = 0
80
- footer_height = 0
81
- [
82
- Tile.new(status_bar_height, nav_bar_height, header_height, footer_height, filepath: path, fullscreen: fullscreen)
83
- ]
84
- end
88
+ def _find_regions(xpaths:, accessibility_ids:, appium_elements:, custom_locations:)
89
+ elements_array = []
90
+ get_regions_by_xpath(elements_array, xpaths)
91
+ get_regions_by_ids(elements_array, accessibility_ids)
92
+ get_regions_by_elements(elements_array, appium_elements)
93
+ get_regions_by_location(elements_array, custom_locations)
94
+ elements_array
95
+ end
85
96
 
86
- def _find_regions(xpaths:, accessibility_ids:, appium_elements:, custom_locations:)
87
- elements_array = []
88
- get_regions_by_xpath(elements_array, xpaths)
89
- get_regions_by_ids(elements_array, accessibility_ids)
90
- get_regions_by_elements(elements_array, appium_elements)
91
- get_regions_by_location(elements_array, custom_locations)
92
- elements_array
93
- end
97
+ def _post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions, sync)
98
+ Percy::CLIWrapper.new.post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions, sync)
99
+ end
94
100
 
95
- def _post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions)
96
- CLIWrapper.new.post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions)
97
- end
101
+ def _write_screenshot(png_bytes, directory)
102
+ filepath = _get_path(directory)
103
+ File.open(filepath, 'wb') { |f| f.write(png_bytes) }
104
+ filepath
105
+ end
98
106
 
99
- def _write_screenshot(png_bytes, directory)
100
- filepath = _get_path(directory)
101
- File.open(filepath, 'wb') { |f| f.write(png_bytes) }
102
- filepath
103
- end
107
+ def get_region_object(selector, element)
108
+ scale_factor = metadata.scale_factor
109
+ location = hashed(element.location)
110
+ size = hashed(element.size)
111
+ coordinates = {
112
+ 'top' => location['y'] * scale_factor,
113
+ 'bottom' => (location['y'] + size['height']) * scale_factor,
114
+ 'left' => location['x'] * scale_factor,
115
+ 'right' => (location['x'] + size['width']) * scale_factor
116
+ }
117
+ { 'selector' => selector, 'coOrdinates' => coordinates }
118
+ end
104
119
 
105
- def get_region_object(selector, element)
106
- scale_factor = metadata.scale_factor
107
- location = hashed(element.location)
108
- size = hashed(element.size)
109
- coordinates = {
110
- 'top' => location['y'] * scale_factor,
111
- 'bottom' => (location['y'] + size['height']) * scale_factor,
112
- 'left' => location['x'] * scale_factor,
113
- 'right' => (location['x'] + size['width']) * scale_factor
114
- }
115
- { 'selector' => selector, 'coOrdinates' => coordinates }
116
- end
120
+ def get_regions_by_xpath(elements_array, xpaths)
121
+ xpaths.each do |xpath|
122
+ element = driver.find_element(Appium::Core::Base::SearchContext::FINDERS[:xpath], xpath)
123
+ selector = "xpath: #{xpath}"
124
+ if element
125
+ region = get_region_object(selector, element)
126
+ elements_array << region
127
+ end
128
+ rescue Appium::Core::Error::NoSuchElementError => e
129
+ log("Appium Element with xpath: #{xpath} not found. Ignoring this xpath.")
130
+ log(e, on_debug: true)
131
+ end
132
+ end
117
133
 
118
- def get_regions_by_xpath(elements_array, xpaths)
119
- xpaths.each do |xpath|
120
- element = driver.find_element(Appium::Core::Base::SearchContext::FINDERS[:xpath], xpath)
121
- selector = "xpath: #{xpath}"
122
- if element
134
+ def get_regions_by_ids(elements_array, ids)
135
+ ids.each do |id|
136
+ element = driver.find_element(Appium::Core::Base::SearchContext::FINDERS[:accessibility_id], id)
137
+ selector = "id: #{id}"
123
138
  region = get_region_object(selector, element)
124
139
  elements_array << region
140
+ rescue Appium::Core::Error::NoSuchElementError => e
141
+ log("Appium Element with id: #{id} not found. Ignoring this id.")
142
+ log(e, on_debug: true)
125
143
  end
126
- rescue Appium::Core::Error::NoSuchElementError => e
127
- log("Appium Element with xpath: #{xpath} not found. Ignoring this xpath.")
128
- log(e, on_debug: true)
129
144
  end
130
- end
131
-
132
- def get_regions_by_ids(elements_array, ids)
133
- ids.each do |id|
134
- element = driver.find_element(Appium::Core::Base::SearchContext::FINDERS[:accessibility_id], id)
135
- selector = "id: #{id}"
136
- region = get_region_object(selector, element)
137
- elements_array << region
138
- rescue Appium::Core::Error::NoSuchElementError => e
139
- log("Appium Element with id: #{id} not found. Ignoring this id.")
140
- log(e, on_debug: true)
141
- end
142
- end
143
145
 
144
- def get_regions_by_elements(elements_array, elements)
145
- elements.each_with_index do |element, index|
146
- class_name = element.attribute('class')
147
- selector = "element: #{index} #{class_name}"
148
- region = get_region_object(selector, element)
149
- elements_array << region
150
- rescue Appium::Core::Error::NoSuchElementError => e
151
- log("Correct Element not passed at index #{index}")
152
- log(e, on_debug: true)
146
+ def get_regions_by_elements(elements_array, elements)
147
+ elements.each_with_index do |element, index|
148
+ class_name = element.attribute('class')
149
+ selector = "element: #{index} #{class_name}"
150
+ region = get_region_object(selector, element)
151
+ elements_array << region
152
+ rescue Appium::Core::Error::NoSuchElementError => e
153
+ log("Correct Element not passed at index #{index}")
154
+ log(e, on_debug: true)
155
+ end
153
156
  end
154
- end
155
157
 
156
- def get_regions_by_location(elements_array, custom_locations)
157
- custom_locations.each_with_index do |custom_location, index|
158
- screen_width = metadata.device_screen_size['width']
159
- screen_height = metadata.device_screen_size['height']
160
- if custom_location.valid?(screen_height, screen_width)
161
- region = {
162
- selector: "custom ignore region: #{index}",
163
- coOrdinates: {
164
- top: custom_location.top,
165
- bottom: custom_location.bottom,
166
- left: custom_location.left,
167
- right: custom_location.right
158
+ def get_regions_by_location(elements_array, custom_locations)
159
+ custom_locations.each_with_index do |custom_location, index|
160
+ screen_width = metadata.device_screen_size['width']
161
+ screen_height = metadata.device_screen_size['height']
162
+ if custom_location.valid?(screen_height, screen_width)
163
+ region = {
164
+ selector: "custom ignore region: #{index}",
165
+ coOrdinates: {
166
+ top: custom_location.top,
167
+ bottom: custom_location.bottom,
168
+ left: custom_location.left,
169
+ right: custom_location.right
170
+ }
168
171
  }
169
- }
170
- elements_array << region
171
- else
172
- log("Values passed in custom ignored region at index: #{index} are not valid")
172
+ elements_array << region
173
+ else
174
+ log("Values passed in custom ignored region at index: #{index} are not valid")
175
+ end
173
176
  end
174
177
  end
175
- end
176
178
 
177
- def log(message, on_debug: false)
178
- puts message if on_debug
179
- end
179
+ def log(message, on_debug: false)
180
+ puts message if on_debug
181
+ end
180
182
 
181
- def get_debug_url
182
- debug_url
183
- end
183
+ def get_debug_url
184
+ debug_url
185
+ end
184
186
 
185
- def get_device_name
186
- ''
187
- end
187
+ def get_device_name
188
+ ''
189
+ end
188
190
 
189
- def _get_dir
190
- dir_path = ENV['PERCY_TMP_DIR'] || nil
191
- if dir_path
192
- Pathname.new(dir_path).mkpath
193
- return dir_path
191
+ def _get_dir
192
+ dir_path = ENV['PERCY_TMP_DIR'] || nil
193
+ if dir_path
194
+ Pathname.new(dir_path).mkpath
195
+ return dir_path
196
+ end
197
+ Dir.mktmpdir
194
198
  end
195
- Dir.mktmpdir
196
- end
197
199
 
198
- def _get_path(directory)
199
- suffix = '.png'
200
- prefix = 'percy-appium-'
201
- file = Tempfile.new([prefix, suffix], directory)
202
- file.close
203
- file.path
200
+ def _get_path(directory)
201
+ suffix = '.png'
202
+ prefix = 'percy-appium-'
203
+ file = Tempfile.new([prefix, suffix], directory)
204
+ file.close
205
+ file.path
206
+ end
204
207
  end
205
208
  end