percy-appium-app 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +191 -1
- data/percy/environment.rb +15 -13
- data/percy/exceptions/exceptions.rb +0 -2
- data/percy/lib/app_percy.rb +36 -34
- data/percy/lib/cache.rb +42 -41
- data/percy/lib/cli_wrapper.rb +94 -92
- data/percy/lib/ignore_region.rb +4 -3
- data/percy/lib/percy_automate.rb +44 -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 +131 -129
- data/percy/providers/generic_provider.rb +166 -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 +7 -10
- data/specs/tile.rb +2 -2
- metadata +17 -3
data/percy/metadata/metadata.rb
CHANGED
@@ -7,102 +7,104 @@ require_relative '../common/common'
|
|
7
7
|
DEVICE_INFO_FILE_PATH = File.join(File.dirname(__FILE__), '..', 'configs', 'devices.json')
|
8
8
|
DEVICE_INFO = JSON.parse(File.read(DEVICE_INFO_FILE_PATH))
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def capabilities
|
22
|
-
caps = driver.capabilities
|
23
|
-
caps = caps.as_json unless caps.is_a?(Hash)
|
24
|
-
caps
|
25
|
-
end
|
10
|
+
module Percy
|
11
|
+
class Metadata
|
12
|
+
attr_reader :driver, :device_info
|
13
|
+
attr_accessor :device_name, :os_version, :device_info
|
14
|
+
|
15
|
+
def initialize(driver)
|
16
|
+
@driver = driver
|
17
|
+
@device_name = nil
|
18
|
+
@os_version = nil
|
19
|
+
@device_info = {}
|
20
|
+
end
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def capabilities
|
23
|
+
caps = driver.capabilities
|
24
|
+
caps = caps.as_json unless caps.is_a?(Hash)
|
25
|
+
caps
|
26
|
+
end
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
def session_id
|
29
|
+
driver.session_id
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def os_name
|
33
|
+
capabilities['platformName']
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
def os_version
|
37
|
+
caps = capabilities
|
38
|
+
caps = caps.as_json unless caps.is_a?(Hash)
|
39
|
+
|
40
|
+
os_version = caps['os_version'] || caps['platformVersion'] || ''
|
41
|
+
os_version = @os_version || os_version
|
42
|
+
begin
|
43
|
+
os_version.to_f.to_i.to_s
|
44
|
+
rescue StandardError
|
45
|
+
''
|
46
|
+
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def remote_url
|
50
|
+
driver.instance_variable_get(:@bridge).instance_variable_get(:@http).instance_variable_get(:@server_url).to_s
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
def get_orientation(**kwargs)
|
54
|
+
orientation = kwargs[:orientation] || capabilities['orientation'] || 'PORTRAIT'
|
55
|
+
orientation = orientation.downcase
|
56
|
+
orientation = orientation == 'auto' ? _orientation : orientation
|
57
|
+
orientation.upcase
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def _orientation
|
61
|
+
driver.orientation.downcase
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def device_screen_size
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def _device_name
|
69
|
+
raise NotImplementedError
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def status_bar
|
73
|
+
raise NotImplementedError
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def status_bar_height
|
77
|
+
status_bar['height']
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
def navigation_bar
|
81
|
+
raise NotImplementedError
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
def navigation_bar_height
|
85
|
+
navigation_bar['height']
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
def viewport
|
89
|
+
raise NotImplementedError
|
90
|
+
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
92
|
+
def execute_script(command)
|
93
|
+
driver.execute_script(command)
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
def value_from_devices_info(key, device_name, os_version = nil)
|
97
|
+
device_info = get_device_info(device_name)
|
98
|
+
device_info = device_info[os_version] || {} if os_version
|
99
|
+
device_info[key].to_i || 0
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
-
|
102
|
+
def get_device_info(device_name)
|
103
|
+
return @device_info unless @device_info.empty?
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
@device_info = DEVICE_INFO[device_name.downcase] || {}
|
106
|
+
log("#{device_name.downcase} does not exist in config.") if @device_info.empty?
|
107
|
+
@device_info
|
108
|
+
end
|
107
109
|
end
|
108
110
|
end
|
@@ -4,18 +4,20 @@ require_relative '../exceptions/exceptions'
|
|
4
4
|
require_relative 'android_metadata'
|
5
5
|
require_relative 'ios_metadata'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
module Percy
|
8
|
+
class MetadataResolver
|
9
|
+
def self.resolve(driver)
|
10
|
+
capabilities = driver.capabilities
|
11
|
+
capabilities = capabilities.as_json unless capabilities.is_a?(Hash)
|
12
|
+
platform_name = capabilities.fetch('platformName', '').downcase
|
13
|
+
case platform_name
|
14
|
+
when 'android'
|
15
|
+
Percy::AndroidMetadata.new(driver)
|
16
|
+
when 'ios'
|
17
|
+
Percy::IOSMetadata.new(driver)
|
18
|
+
else
|
19
|
+
raise PlatformNotSupported
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -7,14 +7,14 @@ require_relative 'lib/cli_wrapper'
|
|
7
7
|
require_relative 'environment'
|
8
8
|
|
9
9
|
def percy_screenshot(driver, name, **kwargs)
|
10
|
-
return nil unless CLIWrapper.percy_enabled?
|
10
|
+
return nil unless Percy::CLIWrapper.percy_enabled?
|
11
11
|
|
12
12
|
app_percy = nil
|
13
|
-
provider_class = Environment.session_type == 'automate' ? PercyOnAutomate : AppPercy
|
13
|
+
provider_class = Percy::Environment.session_type == 'automate' ? Percy::PercyOnAutomate : Percy::AppPercy
|
14
14
|
app_percy = provider_class.new(driver)
|
15
15
|
app_percy.screenshot(name, **kwargs)
|
16
16
|
rescue StandardError => e
|
17
|
-
CLIWrapper.post_failed_event(e.to_s)
|
17
|
+
Percy::CLIWrapper.post_failed_event(e.to_s)
|
18
18
|
log("Could not take screenshot \"#{name}\"")
|
19
19
|
raise e if app_percy && !app_percy.percy_options.ignore_errors
|
20
20
|
|
@@ -6,154 +6,156 @@ 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')
|
33
|
+
rescue StandardError => e
|
34
|
+
execute_percy_screenshot_end(name, percy_screenshot_url, 'failure', e.message)
|
35
|
+
raise e
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
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
|
39
|
+
def set_debug_url(session_details)
|
40
|
+
build_hash = session_details['buildHash'].to_s
|
41
|
+
session_hash = session_details['sessionHash'].to_s
|
42
|
+
@debug_url = "https://app-automate.browserstack.com/dashboard/v2/builds/#{build_hash}/sessions/#{session_hash}"
|
49
43
|
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
44
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
nav_bar_height = metadata.navigation_bar_height
|
45
|
+
def _get_tiles(**kwargs)
|
46
|
+
fullpage_ss = kwargs[:fullpage] || false
|
47
|
+
if ENV['PERCY_DISABLE_REMOTE_UPLOADS'] == 'true'
|
48
|
+
puts("Full page screenshots are only supported when 'PERCY_DISABLE_REMOTE_UPLOADS' is not set") if fullpage_ss
|
49
|
+
return super(**kwargs) unless fullpage_ss
|
50
|
+
end
|
51
|
+
screenshot_type = fullpage_ss ? 'fullpage' : 'singlepage'
|
52
|
+
screen_lengths = kwargs[:screen_lengths] || 4
|
53
|
+
scrollable_xpath = kwargs[:scollable_xpath]
|
54
|
+
scrollable_id = kwargs[:scrollable_id]
|
55
|
+
top_scrollview_offset = kwargs[:top_scrollview_offset]
|
56
|
+
bottom_scrollview_offset = kwargs[:top_scrollview_offset]
|
70
57
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
data = execute_percy_screenshot(
|
59
|
+
metadata.device_screen_size.fetch('height', 1),
|
60
|
+
screenshot_type,
|
61
|
+
screen_lengths,
|
62
|
+
scrollable_xpath,
|
63
|
+
scrollable_id,
|
64
|
+
metadata.scale_factor,
|
65
|
+
top_scrollview_offset,
|
66
|
+
bottom_scrollview_offset
|
78
67
|
)
|
79
|
-
|
68
|
+
tiles = []
|
69
|
+
status_bar_height = metadata.status_bar_height
|
70
|
+
nav_bar_height = metadata.navigation_bar_height
|
80
71
|
|
81
|
-
|
82
|
-
|
72
|
+
JSON.parse(data['result']).each do |tile_data|
|
73
|
+
tiles << Percy::Tile.new(
|
74
|
+
status_bar_height,
|
75
|
+
nav_bar_height,
|
76
|
+
tile_data['header_height'],
|
77
|
+
tile_data['footer_height'],
|
78
|
+
sha: tile_data['sha'].split('-')[0]
|
79
|
+
)
|
80
|
+
end
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
82
|
+
tiles
|
83
|
+
end
|
84
|
+
|
85
|
+
def execute_percy_screenshot_begin(name)
|
86
|
+
request_body = {
|
87
|
+
action: 'percyScreenshot',
|
88
|
+
arguments: {
|
89
|
+
state: 'begin',
|
90
|
+
percyBuildId: Percy::Environment.percy_build_id,
|
91
|
+
percyBuildUrl: Percy::Environment.percy_build_url,
|
92
|
+
name: name
|
93
|
+
}
|
92
94
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
95
|
+
command = "browserstack_executor: #{request_body.to_json}"
|
96
|
+
begin
|
97
|
+
response = metadata.execute_script(command)
|
98
|
+
JSON.parse(response)
|
99
|
+
rescue StandardError => e
|
100
|
+
log('Could not set session as Percy session')
|
101
|
+
log('Error occurred during begin call', on_debug: true)
|
102
|
+
log(e, on_debug: true)
|
103
|
+
nil
|
104
|
+
end
|
103
105
|
end
|
104
|
-
end
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
def execute_percy_screenshot_end(name, percy_screenshot_url, status, status_message = nil)
|
108
|
+
request_body = {
|
109
|
+
action: 'percyScreenshot',
|
110
|
+
arguments: {
|
111
|
+
state: 'end',
|
112
|
+
percyScreenshotUrl: percy_screenshot_url,
|
113
|
+
name: name,
|
114
|
+
status: status
|
115
|
+
}
|
114
116
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
request_body[:arguments][:statusMessage] = status_message if status_message
|
118
|
+
command = "browserstack_executor: #{request_body.to_json}"
|
119
|
+
begin
|
120
|
+
metadata.execute_script(command)
|
121
|
+
rescue StandardError => e
|
122
|
+
log('Error occurred during end call', on_debug: true)
|
123
|
+
log(e, on_debug: true)
|
124
|
+
end
|
123
125
|
end
|
124
|
-
end
|
125
126
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
127
|
+
def execute_percy_screenshot(device_height, screenshotType, screen_lengths, scrollable_xpath = nil,
|
128
|
+
scrollable_id = nil, scale_factor = 1, top_scrollview_offset = 0,
|
129
|
+
bottom_scrollview_offset = 0)
|
130
|
+
project_id = ENV['PERCY_ENABLE_DEV'] == 'true' ? 'percy-dev' : 'percy-prod'
|
131
|
+
request_body = {
|
132
|
+
action: 'percyScreenshot',
|
133
|
+
arguments: {
|
134
|
+
state: 'screenshot',
|
135
|
+
percyBuildId: Percy::Environment.percy_build_id,
|
136
|
+
screenshotType: screenshotType,
|
137
|
+
projectId: project_id,
|
138
|
+
scaleFactor: scale_factor,
|
139
|
+
options: {
|
140
|
+
numOfTiles: screen_lengths,
|
141
|
+
deviceHeight: device_height,
|
142
|
+
scrollableXpath: scrollable_xpath,
|
143
|
+
scrollableId: scrollable_id,
|
144
|
+
topScrollviewOffset: top_scrollview_offset,
|
145
|
+
bottomScrollviewOffset: bottom_scrollview_offset,
|
146
|
+
'FORCE_FULL_PAGE' => ENV['FORCE_FULL_PAGE'] == 'true'
|
147
|
+
}
|
146
148
|
}
|
147
149
|
}
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
command = "browserstack_executor: #{request_body.to_json}"
|
151
|
+
begin
|
152
|
+
response = metadata.execute_script(command)
|
153
|
+
JSON.parse(response)
|
154
|
+
rescue StandardError => e
|
155
|
+
log('Error occurred during screenshot call', on_debug: true)
|
156
|
+
log(e, on_debug: true)
|
157
|
+
raise e
|
158
|
+
end
|
157
159
|
end
|
158
160
|
end
|
159
|
-
end
|
161
|
+
end
|