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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +193 -1
- data/percy/environment.rb +15 -13
- data/percy/exceptions/exceptions.rb +0 -2
- data/percy/lib/app_percy.rb +35 -34
- data/percy/lib/cache.rb +42 -41
- data/percy/lib/cli_wrapper.rb +103 -95
- data/percy/lib/ignore_region.rb +4 -3
- data/percy/lib/percy_automate.rb +45 -42
- data/percy/lib/percy_options.rb +30 -28
- data/percy/lib/region.rb +15 -13
- data/percy/lib/tile.rb +24 -22
- data/percy/metadata/android_metadata.rb +60 -58
- data/percy/metadata/driver_metadata.rb +29 -27
- data/percy/metadata/ios_metadata.rb +64 -62
- data/percy/metadata/metadata.rb +80 -78
- data/percy/metadata/metadata_resolver.rb +14 -12
- data/percy/{screenshot.rb → percy-appium-app.rb} +3 -3
- data/percy/providers/app_automate.rb +132 -128
- data/percy/providers/generic_provider.rb +167 -164
- data/percy/providers/provider_resolver.rb +9 -7
- data/percy/version.rb +1 -1
- data/percy-appium-app.gemspec +1 -0
- data/specs/android_metadata.rb +2 -4
- data/specs/app_automate.rb +10 -13
- data/specs/app_percy.rb +20 -22
- data/specs/cache.rb +16 -16
- data/specs/cli_wrapper.rb +6 -8
- data/specs/driver_metadata.rb +2 -4
- data/specs/generic_providers.rb +9 -12
- data/specs/ignore_regions.rb +10 -12
- data/specs/ios_metadata.rb +2 -2
- data/specs/metadata.rb +2 -5
- data/specs/metadata_resolver.rb +6 -6
- data/specs/mocks/mock_methods.rb +0 -2
- data/specs/percy_options.rb +16 -16
- data/specs/screenshot.rb +90 -15
- data/specs/tile.rb +2 -2
- metadata +20 -6
@@ -6,154 +6,158 @@ require_relative '../lib/tile'
|
|
6
6
|
require_relative 'generic_provider'
|
7
7
|
require_relative '../environment'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
r_index
|
14
|
-
|
15
|
-
|
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
|
-
|
20
|
-
|
20
|
+
def screenshot(name, **kwargs)
|
21
|
+
session_details = execute_percy_screenshot_begin(name)
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
69
|
+
tiles = []
|
70
|
+
status_bar_height = metadata.status_bar_height
|
71
|
+
nav_bar_height = metadata.navigation_bar_height
|
80
72
|
|
81
|
-
|
82
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@debug_url = ''
|
19
|
-
end
|
22
|
+
def self.supports(_remote_url)
|
23
|
+
true
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
'
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
179
|
+
def log(message, on_debug: false)
|
180
|
+
puts message if on_debug
|
181
|
+
end
|
180
182
|
|
181
|
-
|
182
|
-
|
183
|
-
|
183
|
+
def get_debug_url
|
184
|
+
debug_url
|
185
|
+
end
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
-
|
187
|
+
def get_device_name
|
188
|
+
''
|
189
|
+
end
|
188
190
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|