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
@@ -5,13 +5,15 @@ require_relative '../metadata/metadata_resolver'
|
|
5
5
|
require_relative 'app_automate'
|
6
6
|
require_relative 'generic_provider'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
module Percy
|
9
|
+
class ProviderResolver
|
10
|
+
def self.resolve(driver)
|
11
|
+
metadata = Percy::MetadataResolver.resolve(driver)
|
12
|
+
providers = [Percy::AppAutomate, Percy::GenericProvider]
|
13
|
+
providers.each do |provider|
|
14
|
+
return provider.new(driver, metadata) if provider.supports(metadata.remote_url)
|
15
|
+
end
|
16
|
+
raise UnknownProvider
|
14
17
|
end
|
15
|
-
raise UnknownProvider
|
16
18
|
end
|
17
19
|
end
|
data/percy/version.rb
CHANGED
data/percy-appium-app.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['percy']
|
27
27
|
|
28
28
|
spec.add_runtime_dependency 'appium_lib', '~> 12.0'
|
29
|
+
spec.add_runtime_dependency 'dotenv', '~> 2.8'
|
29
30
|
|
30
31
|
spec.add_development_dependency 'bundler', '~> 2.4'
|
31
32
|
spec.add_development_dependency 'minitest', '~> 5.20'
|
data/specs/android_metadata.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
|
5
3
|
require 'minitest/autorun'
|
6
4
|
require 'minitest/mock'
|
7
5
|
require 'appium_lib'
|
8
6
|
require_relative 'mocks/mock_methods'
|
9
7
|
require_relative '../percy/metadata/android_metadata'
|
10
8
|
|
11
|
-
# Test suite for the AndroidMetadata class
|
9
|
+
# Test suite for the Percy::AndroidMetadata class
|
12
10
|
class TestAndroidMetadata < Minitest::Test
|
13
11
|
def setup
|
14
12
|
@mock_webdriver = Minitest::Mock.new
|
15
13
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
16
|
-
@android_metadata = AndroidMetadata.new(@mock_webdriver)
|
14
|
+
@android_metadata = Percy::AndroidMetadata.new(@mock_webdriver)
|
17
15
|
end
|
18
16
|
|
19
17
|
def test_android_execute_script
|
data/specs/app_automate.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
# rubocop:disable Metrics/AbcSize
|
5
|
-
|
6
3
|
require 'minitest/autorun'
|
7
4
|
require 'minitest/mock'
|
8
5
|
require_relative '../percy/providers/app_automate'
|
9
6
|
require_relative '../percy/metadata/android_metadata'
|
10
7
|
require_relative 'mocks/mock_methods'
|
11
8
|
|
12
|
-
# Test suite for the AppAutomate class
|
9
|
+
# Test suite for the Percy::AppAutomate class
|
13
10
|
class TestAppAutomate < Minitest::Test
|
14
11
|
COMPARISON_RESPONSE = { 'success' => true, 'link' => 'https://snapshots-url' }.freeze
|
15
12
|
|
16
13
|
def setup
|
17
14
|
@mock_webdriver = Minitest::Mock.new
|
18
15
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
19
|
-
@metadata = AndroidMetadata.new(@mock_webdriver)
|
20
|
-
@app_automate = AppAutomate.new(@mock_webdriver, @metadata)
|
16
|
+
@metadata = Percy::AndroidMetadata.new(@mock_webdriver)
|
17
|
+
@app_automate = Percy::AppAutomate.new(@mock_webdriver, @metadata)
|
21
18
|
end
|
22
19
|
|
23
20
|
def test_app_automate_get_debug_url
|
@@ -28,18 +25,18 @@ class TestAppAutomate < Minitest::Test
|
|
28
25
|
end
|
29
26
|
|
30
27
|
def test_app_automate_supports_with_correct_url
|
31
|
-
app_automate_session = AppAutomate.supports('https://hub-cloud.browserstack.com/wd/hub')
|
28
|
+
app_automate_session = Percy::AppAutomate.supports('https://hub-cloud.browserstack.com/wd/hub')
|
32
29
|
assert_equal true, app_automate_session
|
33
30
|
end
|
34
31
|
|
35
32
|
def test_app_automate_supports_with_incorrect_url
|
36
|
-
app_automate_session = AppAutomate.supports('https://hub-cloud.generic.com/wd/hub')
|
33
|
+
app_automate_session = Percy::AppAutomate.supports('https://hub-cloud.generic.com/wd/hub')
|
37
34
|
assert_equal false, app_automate_session
|
38
35
|
end
|
39
36
|
|
40
37
|
def test_app_automate_supports_with_AA_DOMAIN
|
41
38
|
ENV['AA_DOMAIN'] = 'bsstag'
|
42
|
-
app_automate_session = AppAutomate.supports('bsstag.com')
|
39
|
+
app_automate_session = Percy::AppAutomate.supports('bsstag.com')
|
43
40
|
assert_equal true, app_automate_session
|
44
41
|
ENV['AA_DOMAIN'] = nil
|
45
42
|
end
|
@@ -80,23 +77,23 @@ class TestAppAutomate < Minitest::Test
|
|
80
77
|
end
|
81
78
|
|
82
79
|
def test_get_tiles
|
83
|
-
# Mocking Metadata's session_id method
|
80
|
+
# Mocking Percy::Metadata's session_id method
|
84
81
|
metadata_mock = Minitest::Mock.new
|
85
82
|
metadata_mock.expect(:session_id, 'session_id_123')
|
86
83
|
|
87
|
-
# Mocking AndroidMetadata's methods
|
84
|
+
# Mocking Percy::AndroidMetadata's methods
|
88
85
|
android_metadata_mock = Minitest::Mock.new
|
89
86
|
android_metadata_mock.expect(:device_screen_size, { 'width' => 1080, 'height' => 1920 })
|
90
87
|
android_metadata_mock.expect(:navigation_bar_height, 150)
|
91
88
|
android_metadata_mock.expect(:status_bar_height, 100)
|
92
89
|
|
93
|
-
Metadata.class_eval do
|
90
|
+
Percy::Metadata.class_eval do
|
94
91
|
define_method(:session_id) do
|
95
92
|
metadata_mock.session_id
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
99
|
-
AndroidMetadata.class_eval do
|
96
|
+
Percy::AndroidMetadata.class_eval do
|
100
97
|
define_method(:device_screen_size) do
|
101
98
|
android_metadata_mock.device_screen_size
|
102
99
|
end
|
data/specs/app_percy.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
|
5
3
|
require 'minitest/autorun'
|
6
4
|
# require 'webmock/minitest'
|
7
5
|
require_relative '../percy/lib/app_percy'
|
@@ -12,7 +10,7 @@ require_relative '../percy/providers/generic_provider'
|
|
12
10
|
require_relative '../percy/lib/cli_wrapper'
|
13
11
|
require_relative 'mocks/mock_methods'
|
14
12
|
|
15
|
-
# Test suite for the AppPercy class
|
13
|
+
# Test suite for the Percy::AppPercy class
|
16
14
|
class TestAppPercy < Minitest::Test
|
17
15
|
COMPARISON_RESPONSE = { 'link' => 'https://snapshot_url', 'success' => true }.freeze
|
18
16
|
|
@@ -38,10 +36,10 @@ class TestAppPercy < Minitest::Test
|
|
38
36
|
|
39
37
|
ENV['PERCY_DISABLE_REMOTE_UPLOADS'] = 'true'
|
40
38
|
|
41
|
-
app_percy = AppPercy.new(@mock_android_webdriver)
|
39
|
+
app_percy = Percy::AppPercy.new(@mock_android_webdriver)
|
42
40
|
|
43
|
-
assert_instance_of(AndroidMetadata, app_percy.metadata)
|
44
|
-
assert_instance_of(AppAutomate, app_percy.provider)
|
41
|
+
assert_instance_of(Percy::AndroidMetadata, app_percy.metadata)
|
42
|
+
assert_instance_of(Percy::AppAutomate, app_percy.provider)
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_android_on_non_app_automate
|
@@ -57,9 +55,9 @@ class TestAppPercy < Minitest::Test
|
|
57
55
|
5.times do
|
58
56
|
@mock_android_webdriver.expect(:capabilities, get_android_capabilities)
|
59
57
|
end
|
60
|
-
app_percy = AppPercy.new(@mock_android_webdriver)
|
61
|
-
assert_instance_of(AndroidMetadata, app_percy.metadata)
|
62
|
-
assert_instance_of(GenericProvider, app_percy.provider)
|
58
|
+
app_percy = Percy::AppPercy.new(@mock_android_webdriver)
|
59
|
+
assert_instance_of(Percy::AndroidMetadata, app_percy.metadata)
|
60
|
+
assert_instance_of(Percy::GenericProvider, app_percy.provider)
|
63
61
|
end
|
64
62
|
|
65
63
|
def test_ios_on_app_automate
|
@@ -68,9 +66,9 @@ class TestAppPercy < Minitest::Test
|
|
68
66
|
5.times do
|
69
67
|
@mock_ios_webdriver.expect(:capabilities, get_ios_capabilities)
|
70
68
|
end
|
71
|
-
app_percy = AppPercy.new(@mock_ios_webdriver)
|
72
|
-
assert_instance_of(IOSMetadata, app_percy.metadata)
|
73
|
-
assert_instance_of(AppAutomate, app_percy.provider)
|
69
|
+
app_percy = Percy::AppPercy.new(@mock_ios_webdriver)
|
70
|
+
assert_instance_of(Percy::IOSMetadata, app_percy.metadata)
|
71
|
+
assert_instance_of(Percy::AppAutomate, app_percy.provider)
|
74
72
|
end
|
75
73
|
|
76
74
|
def test_ios_on_non_app_automate
|
@@ -84,16 +82,16 @@ class TestAppPercy < Minitest::Test
|
|
84
82
|
3.times do
|
85
83
|
@mock_ios_webdriver.expect(:capabilities, get_ios_capabilities)
|
86
84
|
end
|
87
|
-
app_percy = AppPercy.new(@mock_ios_webdriver)
|
88
|
-
assert_instance_of(IOSMetadata, app_percy.metadata)
|
89
|
-
assert_instance_of(GenericProvider, app_percy.provider)
|
85
|
+
app_percy = Percy::AppPercy.new(@mock_ios_webdriver)
|
86
|
+
assert_instance_of(Percy::IOSMetadata, app_percy.metadata)
|
87
|
+
assert_instance_of(Percy::GenericProvider, app_percy.provider)
|
90
88
|
end
|
91
89
|
|
92
90
|
def test_screenshot_with_percy_options_disabled
|
93
91
|
disable_percy_options(@mock_android_webdriver, num = 5)
|
94
92
|
make_mock_driver_appium(@mock_android_webdriver)
|
95
93
|
mock_driver_remote_url(@mock_android_webdriver, 'some-other-url', num = 2)
|
96
|
-
app_percy = AppPercy.new(@mock_android_webdriver)
|
94
|
+
app_percy = Percy::AppPercy.new(@mock_android_webdriver)
|
97
95
|
assert_nil app_percy.screenshot('screenshot 1')
|
98
96
|
end
|
99
97
|
|
@@ -101,7 +99,7 @@ class TestAppPercy < Minitest::Test
|
|
101
99
|
disable_percy_options(@mock_android_webdriver, num = 5)
|
102
100
|
make_mock_driver_appium(@mock_android_webdriver)
|
103
101
|
mock_driver_remote_url(@mock_android_webdriver, 'some-other-url', num = 2)
|
104
|
-
app_percy = AppPercy.new(@mock_android_webdriver)
|
102
|
+
app_percy = Percy::AppPercy.new(@mock_android_webdriver)
|
105
103
|
assert_nil app_percy.screenshot('screenshot 1')
|
106
104
|
end
|
107
105
|
|
@@ -112,7 +110,7 @@ class TestAppPercy < Minitest::Test
|
|
112
110
|
})
|
113
111
|
|
114
112
|
assert_raises(Exception) do
|
115
|
-
AppPercy.screenshot(@mock_android_webdriver, 'screenshot')
|
113
|
+
Percy::AppPercy.screenshot(@mock_android_webdriver, 'screenshot')
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
@@ -125,16 +123,16 @@ class TestAppPercy < Minitest::Test
|
|
125
123
|
@mock_android_webdriver.expect(:capabilities, caps)
|
126
124
|
end
|
127
125
|
|
128
|
-
GenericProvider.stub(:supports, false) do
|
126
|
+
Percy::GenericProvider.stub(:supports, false) do
|
129
127
|
assert_raises(UnknownProvider) do
|
130
|
-
_provider = AppPercy.new(@mock_android_webdriver).provider
|
128
|
+
_provider = Percy::AppPercy.new(@mock_android_webdriver).provider
|
131
129
|
end
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
133
|
def test_invalid_driver
|
136
134
|
assert_raises(DriverNotSupported) do
|
137
|
-
AppPercy.new(Object.new)
|
135
|
+
Percy::AppPercy.new(Object.new)
|
138
136
|
end
|
139
137
|
end
|
140
138
|
|
@@ -169,7 +167,7 @@ class TestAppPercy < Minitest::Test
|
|
169
167
|
})
|
170
168
|
|
171
169
|
assert_raises(Exception) do
|
172
|
-
AppPercy.screenshot(mock_webdriver, 'screenshot')
|
170
|
+
Percy::AppPercy.screenshot(mock_webdriver, 'screenshot')
|
173
171
|
end
|
174
172
|
end
|
175
173
|
end
|
data/specs/cache.rb
CHANGED
@@ -5,52 +5,52 @@ require 'minitest/mock'
|
|
5
5
|
require 'time'
|
6
6
|
require_relative '../percy/lib/cache'
|
7
7
|
|
8
|
-
# Test suite for the Cache class
|
8
|
+
# Test suite for the Percy::Cache class
|
9
9
|
class TestCache < Minitest::Test
|
10
10
|
def setup
|
11
|
-
@cache = Cache.new
|
11
|
+
@cache = Percy::Cache.new
|
12
12
|
@session_id = 'session_id_123'
|
13
13
|
@prop = 'window_size'
|
14
14
|
@value = { 'top' => 'Top Value' }
|
15
|
-
Cache.set_cache(@session_id, @prop, @value)
|
15
|
+
Percy::Cache.set_cache(@session_id, @prop, @value)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_set_cache
|
19
|
-
assert_raises(Exception) { Cache.set_cache(123, 123, 123) }
|
20
|
-
assert_raises(Exception) { Cache.set_cache(@session_id, 123, 123) }
|
19
|
+
assert_raises(Exception) { Percy::Cache.set_cache(123, 123, 123) }
|
20
|
+
assert_raises(Exception) { Percy::Cache.set_cache(@session_id, 123, 123) }
|
21
21
|
|
22
22
|
assert_includes @cache.cache, @session_id
|
23
23
|
assert_equal @cache.cache[@session_id][@prop], @value
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_get_cache_invalid_args
|
27
|
-
assert_raises(Exception) { Cache.get_cache(123, 123) }
|
28
|
-
assert_raises(Exception) { Cache.get_cache(@session_id, 123) }
|
27
|
+
assert_raises(Exception) { Percy::Cache.get_cache(123, 123) }
|
28
|
+
assert_raises(Exception) { Percy::Cache.get_cache(@session_id, 123) }
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_get_cache_success
|
32
32
|
mock_cleanup_cache = Minitest::Mock.new
|
33
33
|
mock_cleanup_cache.expect(:call, nil)
|
34
34
|
|
35
|
-
Cache.stub(:cleanup_cache, -> { mock_cleanup_cache.call }) do
|
36
|
-
window_size = Cache.get_cache(@session_id, @prop)
|
35
|
+
Percy::Cache.stub(:cleanup_cache, -> { mock_cleanup_cache.call }) do
|
36
|
+
window_size = Percy::Cache.get_cache(@session_id, @prop)
|
37
37
|
assert_equal @value, window_size
|
38
38
|
mock_cleanup_cache.verify
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_cleanup_cache
|
43
|
-
previous_value = Cache::CACHE_TIMEOUT
|
44
|
-
Cache.send(:remove_const, :CACHE_TIMEOUT)
|
45
|
-
Cache.const_set(:CACHE_TIMEOUT, 1)
|
43
|
+
previous_value = Percy::Cache::CACHE_TIMEOUT
|
44
|
+
Percy::Cache.send(:remove_const, :CACHE_TIMEOUT)
|
45
|
+
Percy::Cache.const_set(:CACHE_TIMEOUT, 1)
|
46
46
|
|
47
|
-
cache_timeout = Cache::CACHE_TIMEOUT
|
47
|
+
cache_timeout = Percy::Cache::CACHE_TIMEOUT
|
48
48
|
sleep(cache_timeout + 1)
|
49
49
|
assert_includes @cache.cache, @session_id
|
50
|
-
Cache.cleanup_cache
|
50
|
+
Percy::Cache.cleanup_cache
|
51
51
|
refute_includes @cache.cache, @session_id
|
52
52
|
|
53
|
-
Cache.send(:remove_const, :CACHE_TIMEOUT)
|
54
|
-
Cache.const_set(:CACHE_TIMEOUT, previous_value)
|
53
|
+
Percy::Cache.send(:remove_const, :CACHE_TIMEOUT)
|
54
|
+
Percy::Cache.const_set(:CACHE_TIMEOUT, previous_value)
|
55
55
|
end
|
56
56
|
end
|
data/specs/cli_wrapper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
|
5
3
|
require 'minitest/autorun'
|
6
4
|
require 'webmock/minitest'
|
7
5
|
require 'json'
|
@@ -18,10 +16,10 @@ def mock_poa_screenshot(fail: false)
|
|
18
16
|
.to_return(body: "{\"success\": #{fail ? 'false, "error": "test"' : 'true'}}", status: (fail ? 500 : 200))
|
19
17
|
end
|
20
18
|
|
21
|
-
# Test suite for the CLIWrapper class
|
19
|
+
# Test suite for the Percy::CLIWrapper class
|
22
20
|
class TestCLIWrapper < Minitest::Test
|
23
21
|
def setup
|
24
|
-
@cli_wrapper = CLIWrapper.new
|
22
|
+
@cli_wrapper = Percy::CLIWrapper.new
|
25
23
|
@ignored_elements_data = {
|
26
24
|
'ignore_elements_data' => {
|
27
25
|
'selector' => 'xpath: some_xpath',
|
@@ -85,7 +83,7 @@ class TestCLIWrapper < Minitest::Test
|
|
85
83
|
mock_screenshot
|
86
84
|
|
87
85
|
assert_equal(
|
88
|
-
@cli_wrapper.post_screenshots('some-name', {}, [Tile.new(10, 10, 20, 20, filepath: 'some-file-path')],
|
86
|
+
@cli_wrapper.post_screenshots('some-name', {}, [Percy::Tile.new(10, 10, 20, 20, filepath: 'some-file-path')],
|
89
87
|
'some-debug-url'),
|
90
88
|
{ 'link' => 'snapshot-url-link', 'success' => true }
|
91
89
|
)
|
@@ -95,14 +93,14 @@ class TestCLIWrapper < Minitest::Test
|
|
95
93
|
mock_screenshot
|
96
94
|
|
97
95
|
assert_equal(
|
98
|
-
@cli_wrapper.post_screenshots('some-name', {}, [Tile.new(10, 10, 20, 20, filepath: 'some-file-path')],
|
96
|
+
@cli_wrapper.post_screenshots('some-name', {}, [Percy::Tile.new(10, 10, 20, 20, filepath: 'some-file-path')],
|
99
97
|
'some-debug-url', @ignored_elements_data),
|
100
98
|
{ 'link' => 'snapshot-url-link', 'success' => true }
|
101
99
|
)
|
102
100
|
end
|
103
101
|
|
104
102
|
def test_request_body
|
105
|
-
tile = Tile.new(10, 10, 20, 20, filepath: 'some-file-path')
|
103
|
+
tile = Percy::Tile.new(10, 10, 20, 20, filepath: 'some-file-path')
|
106
104
|
tag = { 'name' => 'Tag' }
|
107
105
|
name = 'some-name'
|
108
106
|
debug_url = 'debug-url'
|
@@ -117,7 +115,7 @@ class TestCLIWrapper < Minitest::Test
|
|
117
115
|
end
|
118
116
|
|
119
117
|
def test_request_body_when_optional_values_are_null
|
120
|
-
tile = Tile.new(10, 10, 20, 20, filepath: 'some-file-path')
|
118
|
+
tile = Percy::Tile.new(10, 10, 20, 20, filepath: 'some-file-path')
|
121
119
|
tag = { 'name' => 'Tag' }
|
122
120
|
name = 'some-name'
|
123
121
|
debug_url = nil
|
data/specs/driver_metadata.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
|
5
3
|
require 'minitest/autorun'
|
6
4
|
require 'minitest/mock'
|
7
5
|
require 'appium_lib'
|
8
6
|
|
9
7
|
require_relative '../percy/metadata/driver_metadata'
|
10
8
|
|
11
|
-
# Test suite for the DriverMetadata class
|
9
|
+
# Test suite for the Percy::DriverMetadata class
|
12
10
|
class TestDriverMetadata < Minitest::Test
|
13
11
|
def setup
|
14
12
|
@mock_webdriver = Minitest::Mock.new
|
@@ -16,7 +14,7 @@ class TestDriverMetadata < Minitest::Test
|
|
16
14
|
@bridge = Minitest::Mock.new
|
17
15
|
@server_url = Minitest::Mock.new
|
18
16
|
|
19
|
-
@metadata = DriverMetadata.new(@mock_webdriver)
|
17
|
+
@metadata = Percy::DriverMetadata.new(@mock_webdriver)
|
20
18
|
end
|
21
19
|
|
22
20
|
def test_session_id
|
data/specs/generic_providers.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
# rubocop:disable Metrics/AbcSize
|
5
|
-
|
6
3
|
require 'minitest/autorun'
|
7
4
|
require 'securerandom'
|
8
5
|
require 'appium_lib'
|
@@ -11,7 +8,7 @@ require_relative '../percy/metadata/android_metadata'
|
|
11
8
|
require_relative '../percy/lib/region'
|
12
9
|
require_relative 'mocks/mock_methods'
|
13
10
|
|
14
|
-
# Test suite for the GenericProvider class
|
11
|
+
# Test suite for the Percy::GenericProvider class
|
15
12
|
class TestGenericProvider < Minitest::Test
|
16
13
|
include Appium
|
17
14
|
COMPARISON_RESPONSE = { 'comparison' => { 'id' => 123, 'url' => 'https://percy-build-url' } }.freeze
|
@@ -31,8 +28,8 @@ class TestGenericProvider < Minitest::Test
|
|
31
28
|
png_bytes = 'some random bytes'
|
32
29
|
@mock_webdriver.expect(:screenshot_as, png_bytes, [:png])
|
33
30
|
|
34
|
-
@android_metadata = AndroidMetadata.new(@mock_webdriver)
|
35
|
-
@generic_provider = GenericProvider.new(@mock_webdriver, @android_metadata)
|
31
|
+
@android_metadata = Percy::AndroidMetadata.new(@mock_webdriver)
|
32
|
+
@generic_provider = Percy::GenericProvider.new(@mock_webdriver, @android_metadata)
|
36
33
|
end
|
37
34
|
|
38
35
|
def teardown
|
@@ -166,13 +163,13 @@ class TestGenericProvider < Minitest::Test
|
|
166
163
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
167
164
|
end
|
168
165
|
|
169
|
-
Metadata.class_eval do
|
166
|
+
Percy::Metadata.class_eval do
|
170
167
|
define_method(:session_id) do
|
171
168
|
mock.session_id
|
172
169
|
end
|
173
170
|
end
|
174
171
|
|
175
|
-
AndroidMetadata.class_eval do
|
172
|
+
Percy::AndroidMetadata.class_eval do
|
176
173
|
6.times do
|
177
174
|
define_method(:get_system_bars) do
|
178
175
|
mock.get_system_bars
|
@@ -192,7 +189,7 @@ class TestGenericProvider < Minitest::Test
|
|
192
189
|
end
|
193
190
|
|
194
191
|
def test_supports
|
195
|
-
assert GenericProvider.supports('some-dummy-url')
|
192
|
+
assert Percy::GenericProvider.supports('some-dummy-url')
|
196
193
|
end
|
197
194
|
|
198
195
|
def test_non_app_automate
|
@@ -202,7 +199,7 @@ class TestGenericProvider < Minitest::Test
|
|
202
199
|
mock.expect(:session_id, session_id)
|
203
200
|
end
|
204
201
|
|
205
|
-
Metadata.class_eval do
|
202
|
+
Percy::Metadata.class_eval do
|
206
203
|
4.times do
|
207
204
|
define_method(:session_id) do
|
208
205
|
mock.session_id
|
@@ -353,8 +350,8 @@ class TestGenericProvider < Minitest::Test
|
|
353
350
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
354
351
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
355
352
|
@mock_webdriver.expect(:capabilities, get_android_capabilities)
|
356
|
-
valid_ignore_region = Region.new(100, 200, 200, 300)
|
357
|
-
invalid_ignore_region = Region.new(100, 2390, 200, 300)
|
353
|
+
valid_ignore_region = Percy::Region.new(100, 200, 200, 300)
|
354
|
+
invalid_ignore_region = Percy::Region.new(100, 2390, 200, 300)
|
358
355
|
|
359
356
|
elements_array = []
|
360
357
|
custom_locations = [valid_ignore_region, invalid_ignore_region]
|
data/specs/ignore_regions.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
|
5
3
|
require 'minitest/autorun'
|
6
4
|
require_relative '../percy/lib/ignore_region'
|
7
5
|
|
@@ -12,7 +10,7 @@ class TestIgnoreRegion < Minitest::Test
|
|
12
10
|
bottom = 20
|
13
11
|
left = 30
|
14
12
|
right = 40
|
15
|
-
ignore_region = IgnoreRegion.new(top, bottom, left, right)
|
13
|
+
ignore_region = Percy::IgnoreRegion.new(top, bottom, left, right)
|
16
14
|
|
17
15
|
assert_equal ignore_region.top, top
|
18
16
|
assert_equal ignore_region.bottom, bottom
|
@@ -21,29 +19,29 @@ class TestIgnoreRegion < Minitest::Test
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def test_ignore_region_negative_input
|
24
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(-10, 20, 30, 40) }
|
25
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(10, 20, -30, 40) }
|
26
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(10, 20, 30, -40) }
|
27
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(-10, -20, -30, -40) }
|
22
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(-10, 20, 30, 40) }
|
23
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(10, 20, -30, 40) }
|
24
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(10, 20, 30, -40) }
|
25
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(-10, -20, -30, -40) }
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_ignore_region_invalid_input
|
31
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(20, 10, 30, 40) } # bottom < top
|
32
|
-
assert_raises(ArgumentError) { IgnoreRegion.new(10, 20, 40, 30) } # right < left
|
29
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(20, 10, 30, 40) } # bottom < top
|
30
|
+
assert_raises(ArgumentError) { Percy::IgnoreRegion.new(10, 20, 40, 30) } # right < left
|
33
31
|
end
|
34
32
|
|
35
33
|
def test_ignore_region_is_valid
|
36
|
-
ignore_region = IgnoreRegion.new(10, 20, 30, 40)
|
34
|
+
ignore_region = Percy::IgnoreRegion.new(10, 20, 30, 40)
|
37
35
|
screen_height = 100
|
38
36
|
screen_width = 200
|
39
37
|
assert_equal true, ignore_region.valid?(screen_height, screen_width)
|
40
38
|
|
41
|
-
ignore_region = IgnoreRegion.new(10, 200, 30, 400)
|
39
|
+
ignore_region = Percy::IgnoreRegion.new(10, 200, 30, 400)
|
42
40
|
height = 100
|
43
41
|
width = 200
|
44
42
|
assert_equal false, ignore_region.valid?(height, width)
|
45
43
|
|
46
|
-
ignore_region = IgnoreRegion.new(10, 20, 30, 40)
|
44
|
+
ignore_region = Percy::IgnoreRegion.new(10, 20, 30, 40)
|
47
45
|
screen_height = 5
|
48
46
|
screen_width = 10
|
49
47
|
assert_equal false, ignore_region.valid?(screen_height, screen_width)
|
data/specs/ios_metadata.rb
CHANGED
@@ -5,14 +5,14 @@ require 'minitest/mock'
|
|
5
5
|
require_relative 'mocks/mock_methods'
|
6
6
|
require_relative '../percy/metadata/ios_metadata'
|
7
7
|
|
8
|
-
# Test suite for the IOSMetadata class
|
8
|
+
# Test suite for the Percy::IOSMetadata class
|
9
9
|
class TestIOSMetadata < Minitest::Test
|
10
10
|
def setup
|
11
11
|
@mock_webdriver = Minitest::Mock.new
|
12
12
|
@bridge = Minitest::Mock.new
|
13
13
|
@http = Minitest::Mock.new
|
14
14
|
@server_url = Minitest::Mock.new
|
15
|
-
@ios_metadata = IOSMetadata.new(@mock_webdriver)
|
15
|
+
@ios_metadata = Percy::IOSMetadata.new(@mock_webdriver)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_ios_execute_script
|
data/specs/metadata.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/MethodLength
|
4
|
-
# rubocop:disable Metrics/AbcSize
|
5
|
-
|
6
3
|
require 'minitest/autorun'
|
7
4
|
require_relative '../percy/metadata/metadata'
|
8
5
|
|
9
|
-
# Test suite for the Metadata class
|
6
|
+
# Test suite for the Percy::Metadata class
|
10
7
|
class TestMetadata < Minitest::Test
|
11
8
|
def setup
|
12
9
|
@mock_webdriver = Minitest::Mock.new
|
13
|
-
@metadata = Metadata.new(@mock_webdriver)
|
10
|
+
@metadata = Percy::Metadata.new(@mock_webdriver)
|
14
11
|
end
|
15
12
|
|
16
13
|
def test_metadata_properties
|
data/specs/metadata_resolver.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative '../percy/metadata/android_metadata'
|
|
6
6
|
require_relative '../percy/metadata/ios_metadata'
|
7
7
|
require_relative '../percy/metadata/metadata_resolver'
|
8
8
|
|
9
|
-
# Test suite for the MetadataResolver class
|
9
|
+
# Test suite for the Percy::MetadataResolver class
|
10
10
|
class MetadataResolverTestCase < Minitest::Test
|
11
11
|
def setup
|
12
12
|
@mock_webdriver = Minitest::Mock.new
|
@@ -15,17 +15,17 @@ class MetadataResolverTestCase < Minitest::Test
|
|
15
15
|
def test_android_resolved
|
16
16
|
@mock_webdriver.expect(:capabilities, { 'platformName' => 'Android' })
|
17
17
|
@mock_webdriver.expect(:capabilities, { 'platformName' => 'Android' })
|
18
|
-
resolved_metadata = MetadataResolver.resolve(@mock_webdriver)
|
18
|
+
resolved_metadata = Percy::MetadataResolver.resolve(@mock_webdriver)
|
19
19
|
|
20
|
-
assert_instance_of(AndroidMetadata, resolved_metadata)
|
20
|
+
assert_instance_of(Percy::AndroidMetadata, resolved_metadata)
|
21
21
|
@mock_webdriver.verify
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_ios_resolved
|
25
25
|
@mock_webdriver.expect(:capabilities, { 'platformName' => 'iOS' })
|
26
|
-
resolved_metadata = MetadataResolver.resolve(@mock_webdriver)
|
26
|
+
resolved_metadata = Percy::MetadataResolver.resolve(@mock_webdriver)
|
27
27
|
|
28
|
-
assert_instance_of(IOSMetadata, resolved_metadata)
|
28
|
+
assert_instance_of(Percy::IOSMetadata, resolved_metadata)
|
29
29
|
@mock_webdriver.verify
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ class MetadataResolverTestCase < Minitest::Test
|
|
33
33
|
@mock_webdriver.expect(:capabilities, { 'platformName' => 'Something Random' })
|
34
34
|
|
35
35
|
assert_raises(Exception) do
|
36
|
-
MetadataResolver.resolve(@mock_webdriver)
|
36
|
+
Percy::MetadataResolver.resolve(@mock_webdriver)
|
37
37
|
end
|
38
38
|
|
39
39
|
@mock_webdriver.verify
|