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.
@@ -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
- 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')
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
- 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
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
- 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
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
- 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]
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
- end
68
+ tiles = []
69
+ status_bar_height = metadata.status_bar_height
70
+ nav_bar_height = metadata.navigation_bar_height
80
71
 
81
- tiles
82
- end
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
- 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
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
- 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
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
- 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
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
- 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)
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
- 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'
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
- 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
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