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.
@@ -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
- class Metadata
11
- attr_reader :driver, :device_info
12
- attr_accessor :device_name, :os_version, :device_info
13
-
14
- def initialize(driver)
15
- @driver = driver
16
- @device_name = nil
17
- @os_version = nil
18
- @device_info = {}
19
- end
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
- def session_id
28
- driver.session_id
29
- end
22
+ def capabilities
23
+ caps = driver.capabilities
24
+ caps = caps.as_json unless caps.is_a?(Hash)
25
+ caps
26
+ end
30
27
 
31
- def os_name
32
- capabilities['platformName']
33
- end
28
+ def session_id
29
+ driver.session_id
30
+ end
34
31
 
35
- def os_version
36
- caps = capabilities
37
- caps = caps.as_json unless caps.is_a?(Hash)
32
+ def os_name
33
+ capabilities['platformName']
34
+ end
38
35
 
39
- os_version = caps['os_version'] || caps['platformVersion'] || ''
40
- os_version = @os_version || os_version
41
- begin
42
- os_version.to_f.to_i.to_s
43
- rescue StandardError
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
- def remote_url
49
- driver.instance_variable_get(:@bridge).instance_variable_get(:@http).instance_variable_get(:@server_url).to_s
50
- end
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
- def get_orientation(**kwargs)
53
- orientation = kwargs[:orientation] || capabilities['orientation'] || 'PORTRAIT'
54
- orientation = orientation.downcase
55
- orientation = orientation == 'auto' ? _orientation : orientation
56
- orientation.upcase
57
- end
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
- def _orientation
60
- driver.orientation.downcase
61
- end
60
+ def _orientation
61
+ driver.orientation.downcase
62
+ end
62
63
 
63
- def device_screen_size
64
- raise NotImplementedError
65
- end
64
+ def device_screen_size
65
+ raise NotImplementedError
66
+ end
66
67
 
67
- def _device_name
68
- raise NotImplementedError
69
- end
68
+ def _device_name
69
+ raise NotImplementedError
70
+ end
70
71
 
71
- def status_bar
72
- raise NotImplementedError
73
- end
72
+ def status_bar
73
+ raise NotImplementedError
74
+ end
74
75
 
75
- def status_bar_height
76
- status_bar['height']
77
- end
76
+ def status_bar_height
77
+ status_bar['height']
78
+ end
78
79
 
79
- def navigation_bar
80
- raise NotImplementedError
81
- end
80
+ def navigation_bar
81
+ raise NotImplementedError
82
+ end
82
83
 
83
- def navigation_bar_height
84
- navigation_bar['height']
85
- end
84
+ def navigation_bar_height
85
+ navigation_bar['height']
86
+ end
86
87
 
87
- def viewport
88
- raise NotImplementedError
89
- end
88
+ def viewport
89
+ raise NotImplementedError
90
+ end
90
91
 
91
- def execute_script(command)
92
- driver.execute_script(command)
93
- end
92
+ def execute_script(command)
93
+ driver.execute_script(command)
94
+ end
94
95
 
95
- def value_from_devices_info(key, device_name, os_version = nil)
96
- device_info = get_device_info(device_name)
97
- device_info = device_info[os_version] || {} if os_version
98
- device_info[key].to_i || 0
99
- end
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
- def get_device_info(device_name)
102
- return @device_info unless @device_info.empty?
102
+ def get_device_info(device_name)
103
+ return @device_info unless @device_info.empty?
103
104
 
104
- @device_info = DEVICE_INFO[device_name.downcase] || {}
105
- log("#{device_name.downcase} does not exist in config.") if @device_info.empty?
106
- @device_info
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
- class MetadataResolver
8
- def self.resolve(driver)
9
- capabilities = driver.capabilities
10
- capabilities = capabilities.as_json unless capabilities.is_a?(Hash)
11
- platform_name = capabilities.fetch('platformName', '').downcase
12
- case platform_name
13
- when 'android'
14
- AndroidMetadata.new(driver)
15
- when 'ios'
16
- IOSMetadata.new(driver)
17
- else
18
- raise PlatformNotSupported
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
- 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