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
@@ -2,39 +2,41 @@
|
|
2
2
|
|
3
3
|
require_relative '../lib/cache'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Percy
|
6
|
+
class DriverMetadata
|
7
|
+
def initialize(driver)
|
8
|
+
@driver = driver
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def session_id
|
12
|
+
@driver.session_id
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def command_executor_url
|
16
|
+
url = Percy::Cache.get_cache(session_id, Percy::Cache::COMMAND_EXECUTOR_URL)
|
17
|
+
if url.nil?
|
18
|
+
url = @driver.instance_variable_get(:@bridge).instance_variable_get(:@http).instance_variable_get(:@server_url).to_s
|
19
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::COMMAND_EXECUTOR_URL, url)
|
20
|
+
end
|
21
|
+
url
|
19
22
|
end
|
20
|
-
url
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def capabilities
|
25
|
+
caps = Percy::Cache.get_cache(session_id, Percy::Cache::SESSION_CAPABILITIES)
|
26
|
+
if caps.nil?
|
27
|
+
caps = @driver.capabilities.dup # In Ruby, use dup to create a shallow copy of the hash
|
28
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::SESSION_CAPABILITIES, caps)
|
29
|
+
end
|
30
|
+
caps
|
28
31
|
end
|
29
|
-
caps
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def session_capabilities
|
34
|
+
session_caps = Percy::Cache.get_cache(session_id, Percy::Cache::SESSION_CAPABILITIES)
|
35
|
+
if session_caps.nil?
|
36
|
+
session_caps = @driver.desired_capabilities.dup # Assuming there is a desired_capabilities method
|
37
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::SESSION_CAPABILITIES, session_caps)
|
38
|
+
end
|
39
|
+
session_caps
|
37
40
|
end
|
38
|
-
session_caps
|
39
41
|
end
|
40
42
|
end
|
@@ -3,81 +3,83 @@
|
|
3
3
|
require_relative 'metadata'
|
4
4
|
require_relative '../lib/cache'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Percy
|
7
|
+
class IOSMetadata < Percy::Metadata
|
8
|
+
attr_reader :_window_size
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize(driver)
|
11
|
+
super(driver)
|
12
|
+
@_viewport = {}
|
13
|
+
@_window_size = {}
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def device_screen_size
|
17
|
+
vp = viewport
|
18
|
+
height = vp.fetch('top', 0) + vp.fetch('height', 0)
|
19
|
+
width = vp.fetch('width', 0)
|
20
|
+
if height.zero? && width.zero?
|
21
|
+
scale_factor = value_from_devices_info('scale_factor', device_name)
|
22
|
+
height = get_window_size['height'] * scale_factor
|
23
|
+
width = get_window_size['width'] * scale_factor
|
24
|
+
end
|
25
|
+
{ 'width' => width, 'height' => height }
|
23
26
|
end
|
24
|
-
{ 'width' => width, 'height' => height }
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
def status_bar
|
29
|
+
height = 0
|
30
|
+
view_port = viewport
|
31
|
+
if view_port.fetch('top', 0) != 0
|
32
|
+
height = view_port['top']
|
33
|
+
else
|
34
|
+
scale_factor = value_from_devices_info('scale_factor', device_name)
|
35
|
+
status_bar_height = value_from_devices_info('status_bar', device_name)
|
36
|
+
height = status_bar_height.to_i * scale_factor.to_i
|
37
|
+
end
|
38
|
+
{ 'height' => height }
|
36
39
|
end
|
37
|
-
{ 'height' => height }
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def navigation_bar
|
42
|
+
{ 'height' => 0 }
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
def get_window_size
|
46
|
+
@_window_size = Percy::Cache.get_cache(session_id, Percy::Cache::WINDOW_SIZE)
|
47
|
+
unless @_window_size
|
48
|
+
@_window_size = driver.get_window_size
|
49
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::WINDOW_SIZE, @_window_size)
|
50
|
+
end
|
51
|
+
@_window_size
|
49
52
|
end
|
50
|
-
@_window_size
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
def viewport
|
55
|
+
@_viewport = Percy::Cache.get_cache(session_id, Percy::Cache::VIEWPORT)
|
56
|
+
if @_viewport.nil? || (@_viewport.is_a?(Hash) && @_viewport.empty?)
|
57
|
+
begin
|
58
|
+
@_viewport = execute_script('mobile: viewportRect')
|
59
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::VIEWPORT, @_viewport)
|
60
|
+
rescue StandardError
|
61
|
+
log('Could not use viewportRect; using static config', on_debug: true)
|
62
|
+
# setting `viewport` as empty hash so that it's not nil anymore
|
63
|
+
Percy::Cache.set_cache(session_id, Percy::Cache::VIEWPORT, {})
|
64
|
+
end
|
63
65
|
end
|
66
|
+
@_viewport || { 'top' => 0, 'height' => 0, 'width' => 0 }
|
64
67
|
end
|
65
|
-
@_viewport || { 'top' => 0, 'height' => 0, 'width' => 0 }
|
66
|
-
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
def device_name
|
70
|
+
if @device_name.nil?
|
71
|
+
caps = capabilities
|
72
|
+
caps = caps.as_json unless caps.is_a?(Hash)
|
73
|
+
@device_name = caps['deviceName']
|
74
|
+
end
|
75
|
+
@device_name
|
73
76
|
end
|
74
|
-
@device_name
|
75
|
-
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def scale_factor
|
79
|
+
scale_factor = value_from_devices_info('scale_factor', device_name)
|
80
|
+
return viewport['width'] / get_window_size['width'] if scale_factor.zero?
|
80
81
|
|
81
|
-
|
82
|
+
scale_factor
|
83
|
+
end
|
82
84
|
end
|
83
|
-
end
|
85
|
+
end
|
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
|
|