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.
@@ -4,110 +4,110 @@ require 'minitest/autorun'
4
4
  require 'minitest/mock'
5
5
  require_relative '../percy/lib/percy_options'
6
6
 
7
- # Test suite for the PercyOptions class
7
+ # Test suite for the Percy::PercyOptions class
8
8
  class TestPercyOptions < Minitest::Test
9
9
  # Defaults
10
10
  def test_percy_options_not_provided
11
11
  capabilities = {}
12
- percy_options = PercyOptions.new(capabilities)
12
+ percy_options = Percy::PercyOptions.new(capabilities)
13
13
  assert_equal true, percy_options.enabled
14
14
  assert_equal true, percy_options.ignore_errors
15
15
  end
16
16
 
17
17
  def test_percy_options_w3c_enabled
18
18
  capabilities = { 'percy:options' => { 'enabled' => true } }
19
- percy_options = PercyOptions.new(capabilities)
19
+ percy_options = Percy::PercyOptions.new(capabilities)
20
20
  assert_equal true, percy_options.enabled
21
21
  assert_equal true, percy_options.ignore_errors
22
22
  end
23
23
 
24
24
  def test_percy_options_json_wire_enabled
25
25
  capabilities = { 'percy.enabled' => true }
26
- percy_options = PercyOptions.new(capabilities)
26
+ percy_options = Percy::PercyOptions.new(capabilities)
27
27
  assert_equal true, percy_options.enabled
28
28
  assert_equal true, percy_options.ignore_errors
29
29
  end
30
30
 
31
31
  def test_percy_options_w3c_not_enabled
32
32
  capabilities = { 'percy:options' => { 'enabled' => false } }
33
- percy_options = PercyOptions.new(capabilities)
33
+ percy_options = Percy::PercyOptions.new(capabilities)
34
34
  assert_equal false, percy_options.enabled
35
35
  assert_equal true, percy_options.ignore_errors
36
36
  end
37
37
 
38
38
  def test_percy_options_json_wire_not_enabled
39
39
  capabilities = { 'percy.enabled' => false }
40
- percy_options = PercyOptions.new(capabilities)
40
+ percy_options = Percy::PercyOptions.new(capabilities)
41
41
  assert_equal false, percy_options.enabled
42
42
  assert_equal true, percy_options.ignore_errors
43
43
  end
44
44
 
45
45
  def test_percy_options_w3c_ignore_errors
46
46
  capabilities = { 'percy:options' => { 'ignoreErrors' => true } }
47
- percy_options = PercyOptions.new(capabilities)
47
+ percy_options = Percy::PercyOptions.new(capabilities)
48
48
  assert_equal true, percy_options.ignore_errors
49
49
  assert_equal true, percy_options.enabled
50
50
  end
51
51
 
52
52
  def test_percy_options_json_wire_ignore_errors
53
53
  capabilities = { 'percy.ignoreErrors' => true }
54
- percy_options = PercyOptions.new(capabilities)
54
+ percy_options = Percy::PercyOptions.new(capabilities)
55
55
  assert_equal true, percy_options.ignore_errors
56
56
  assert_equal true, percy_options.enabled
57
57
  end
58
58
 
59
59
  def test_percy_options_w3c_not_ignore_errors
60
60
  capabilities = { 'percy:options' => { 'ignoreErrors' => false } }
61
- percy_options = PercyOptions.new(capabilities)
61
+ percy_options = Percy::PercyOptions.new(capabilities)
62
62
  assert_equal false, percy_options.ignore_errors
63
63
  assert_equal true, percy_options.enabled
64
64
  end
65
65
 
66
66
  def test_percy_options_json_wire_not_ignore_errors
67
67
  capabilities = { 'percy.ignoreErrors' => false }
68
- percy_options = PercyOptions.new(capabilities)
68
+ percy_options = Percy::PercyOptions.new(capabilities)
69
69
  assert_equal false, percy_options.ignore_errors
70
70
  assert_equal true, percy_options.enabled
71
71
  end
72
72
 
73
73
  def test_percy_options_w3c_all_options_false
74
74
  capabilities = { 'percy:options' => { 'ignoreErrors' => false, 'enabled' => false } }
75
- percy_options = PercyOptions.new(capabilities)
75
+ percy_options = Percy::PercyOptions.new(capabilities)
76
76
  assert_equal false, percy_options.ignore_errors
77
77
  assert_equal false, percy_options.enabled
78
78
  end
79
79
 
80
80
  def test_percy_options_json_wire_all_options_false
81
81
  capabilities = { 'percy.ignoreErrors' => false, 'percy.enabled' => false }
82
- percy_options = PercyOptions.new(capabilities)
82
+ percy_options = Percy::PercyOptions.new(capabilities)
83
83
  assert_equal false, percy_options.ignore_errors
84
84
  # assert_equal false, percy_options.enabled
85
85
  end
86
86
 
87
87
  def test_percy_options_w3c_all_options_true
88
88
  capabilities = { 'percy:options' => { 'ignoreErrors' => true, 'enabled' => true } }
89
- percy_options = PercyOptions.new(capabilities)
89
+ percy_options = Percy::PercyOptions.new(capabilities)
90
90
  assert_equal true, percy_options.ignore_errors
91
91
  assert_equal true, percy_options.enabled
92
92
  end
93
93
 
94
94
  def test_percy_options_json_wire_all_options_true
95
95
  capabilities = { 'percy.ignoreErrors' => true, 'percy.enabled' => true }
96
- percy_options = PercyOptions.new(capabilities)
96
+ percy_options = Percy::PercyOptions.new(capabilities)
97
97
  assert_equal true, percy_options.ignore_errors
98
98
  assert_equal true, percy_options.enabled
99
99
  end
100
100
 
101
101
  def test_percy_options_json_wire_and_w3c_case_1
102
102
  capabilities = { 'percy.ignoreErrors' => false, 'percy:options' => { 'enabled' => false } }
103
- percy_options = PercyOptions.new(capabilities)
103
+ percy_options = Percy::PercyOptions.new(capabilities)
104
104
  assert_equal false, percy_options.ignore_errors
105
105
  assert_equal false, percy_options.enabled
106
106
  end
107
107
 
108
108
  def test_percy_options_json_wire_and_w3c_case_2
109
109
  capabilities = { 'percy.enabled' => false, 'percy:options' => { 'ignoreErrors' => false } }
110
- percy_options = PercyOptions.new(capabilities)
110
+ percy_options = Percy::PercyOptions.new(capabilities)
111
111
  assert_equal false, percy_options.ignore_errors
112
112
  assert_equal false, percy_options.enabled
113
113
  end
data/specs/screenshot.rb CHANGED
@@ -1,15 +1,12 @@
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 'json'
8
5
  require 'webmock/minitest'
9
6
  require 'appium_lib'
10
7
  require 'webrick'
11
8
 
12
- require_relative '../percy/screenshot'
9
+ require_relative '../percy/percy-appium-app'
13
10
  require_relative '../percy/lib/app_percy'
14
11
  require_relative 'mocks/mock_methods'
15
12
 
@@ -27,7 +24,7 @@ mock_server.mount('/', MockServerRequestHandler)
27
24
  mock_server_thread = Thread.new { mock_server.start }
28
25
 
29
26
  # Mock helpers
30
- def mock_healthcheck(fail: false, fail_how: 'error', type: 'AppPercy')
27
+ def mock_healthcheck(fail: false, fail_how: 'error', type: 'Percy::AppPercy')
31
28
  health_body = JSON.dump(success: true, build: { 'id' => '123', 'url' => 'dummy_url' }, type: type)
32
29
  health_headers = { 'X-Percy-Core-Version' => '1.27.0-beta.1' }
33
30
  health_status = 200
@@ -57,14 +54,14 @@ def mock_healthcheck(fail: false, fail_how: 'error', type: 'AppPercy')
57
54
  .to_return(status: health_status, body: health_body, headers: health_headers)
58
55
  end
59
56
 
60
- def mock_screenshot(fail: false)
57
+ def mock_screenshot(fail: false, data: false)
61
58
  stub_request(:post, 'http://localhost:5338/percy/comparison')
62
- .to_return(body: "{\"success\": #{fail ? 'false, "error": "test"' : 'true'}}", status: (fail ? 500 : 200))
59
+ .to_return(body: "{\"success\": #{fail ? 'false, "error": "test"' : 'true'} #{data ? ',"data": "sync-data"' : ""}}", status: (fail ? 500 : 200))
63
60
  end
64
61
 
65
- def mock_poa_screenshot(fail: false)
62
+ def mock_poa_screenshot(fail: false, data: false)
66
63
  stub_request(:post, 'http://localhost:5338/percy/automateScreenshot')
67
- .to_return(body: "{\"success\": #{fail ? 'false, "error": "test"' : 'true'}}", status: (fail ? 500 : 200))
64
+ .to_return(body: "{\"success\": #{fail ? 'false, "error": "test"' : 'true'} #{data ? ',"data": "sync-data"' : ""}}", status: (fail ? 500 : 200))
68
65
  end
69
66
 
70
67
  def mock_session_request
@@ -104,12 +101,12 @@ class TestPercyScreenshot < Minitest::Test
104
101
  @server_url.expect(:to_s, 'https://hub-cloud.browserstack.com/wd/hub')
105
102
  end
106
103
 
107
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot(123) }
108
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot('screenshot 1', device_name: 123) }
109
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot('screenshot 1', full_screen: 123) }
110
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot('screenshot 1', orientation: 123) }
111
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot('screenshot 1', status_bar_height: 'height') }
112
- assert_raises(TypeError) { AppPercy.new(@mock_webdriver).screenshot('screenshot 1', nav_bar_height: 'height') }
104
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot(123) }
105
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot('screenshot 1', device_name: 123) }
106
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot('screenshot 1', full_screen: 123) }
107
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot('screenshot 1', orientation: 123) }
108
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot('screenshot 1', status_bar_height: 'height') }
109
+ assert_raises(TypeError) { Percy::AppPercy.new(@mock_webdriver).screenshot('screenshot 1', nav_bar_height: 'height') }
113
110
  end
114
111
 
115
112
  def test_throws_error_when_a_driver_is_not_provided
@@ -207,6 +204,37 @@ class TestPercyScreenshot < Minitest::Test
207
204
  assert_equal(['Consider_Dummy_id'], s2['options']['consider_region_elements'])
208
205
  end
209
206
 
207
+ def test_posts_screenshot_poa_with_sync
208
+ mock_healthcheck(type: 'automate')
209
+ mock_poa_screenshot(data: true)
210
+ mock_session_request
211
+
212
+ driver = Minitest::Mock.new
213
+ @bridge = Minitest::Mock.new
214
+ @http = Minitest::Mock.new
215
+ @server_url = Minitest::Mock.new
216
+
217
+ driver.expect(:is_a?, true, [Appium::Core::Base::Driver])
218
+ driver.expect(:desired_capabilities, { 'key' => 'value' })
219
+ driver.expect(:instance_variable_get, @bridge, [:@bridge])
220
+ @http.expect(:instance_variable_get, @server_url, [:@server_url])
221
+ @bridge.expect(:instance_variable_get, @http, [:@http])
222
+ @server_url.expect(:to_s, 'https://hub-cloud.browserstack.com/wd/hub')
223
+
224
+ 10.times do
225
+ driver.expect(:session_id, 'Dummy_session_id')
226
+ end
227
+ 2.times do
228
+ driver.expect(:capabilities, { 'key' => 'value' })
229
+ end
230
+ @mock_webdriver.expect(:capabilities, { 'key' => 'value' })
231
+
232
+ res = percy_screenshot(driver, 'Snapshot 1', options: { sync: true })
233
+
234
+ assert_equal('sync-data', res)
235
+ assert_equal('/percy/automateScreenshot', @requests.last.uri.path)
236
+ end
237
+
210
238
  def test_posts_multiple_screenshots_to_the_local_percy_server
211
239
  mock_healthcheck
212
240
  mock_screenshot
@@ -259,6 +287,53 @@ class TestPercyScreenshot < Minitest::Test
259
287
  assert_match(%r{ruby/\d+\.\d+\.\d+}, body['environment_info'][1])
260
288
  end
261
289
 
290
+ def test_post_screenshot_with_sync
291
+ mock_healthcheck
292
+ mock_screenshot(data: true)
293
+
294
+ driver = Minitest::Mock.new
295
+
296
+ driver.expect(:is_a?, true, [Appium::Core::Base::Driver])
297
+ driver.expect(:instance_variable_get, @bridge, [:@bridge])
298
+ @http.expect(:instance_variable_get, @server_url, [:@server_url])
299
+ @bridge.expect(:instance_variable_get, @http, [:@http])
300
+ @server_url.expect(:to_s, 'https://hub-cloud.browserstack.com/wd/hub')
301
+
302
+ 5.times do
303
+ driver.expect(:session_id, 'Dummy_session_id')
304
+ end
305
+
306
+ 13.times do
307
+ driver.expect(:capabilities, get_android_capabilities)
308
+ end
309
+
310
+ 3.times do
311
+ driver.expect(
312
+ :execute_script,
313
+ '{"success":true,"result":"[{\"sha\":\"sha-something\",\"status_bar\":null'\
314
+ ',\"nav_bar\":null,\"header_height\":0,\"footer_height\":0,\"index\":0}]"}',
315
+ [String]
316
+ )
317
+ end
318
+
319
+ 2.times do
320
+ driver.expect(:get_system_bars, {
321
+ 'statusBar' => { 'height' => 10, 'width' => 20 },
322
+ 'navigationBar' => { 'height' => 10, 'width' => 20 }
323
+ })
324
+ end
325
+
326
+ res = percy_screenshot(driver, 'screenshot 2', sync: true)
327
+
328
+ assert_equal('sync-data', res)
329
+ assert_equal('/percy/comparison', @requests.last.uri.path)
330
+
331
+ body = JSON.parse(@requests[-1].body)
332
+ assert_match(%r{percy-appium-app/\d+}, body['client_info'])
333
+ assert_match(%r{appium/\d+}, body['environment_info'][0])
334
+ assert_match(%r{ruby/\d+\.\d+\.\d+}, body['environment_info'][1])
335
+ end
336
+
262
337
  def test_ignore_region_screenshots_to_the_local_percy_server
263
338
  mock_healthcheck
264
339
  mock_screenshot
data/specs/tile.rb CHANGED
@@ -3,10 +3,10 @@
3
3
  require 'minitest/autorun'
4
4
  require_relative '../percy/lib/tile'
5
5
 
6
- # Test suite for the Tile class.
6
+ # Test suite for the Percy::Tile class.
7
7
  class TileTest < Minitest::Test
8
8
  def setup
9
- @tile = Tile.new(20, 120, 150, 0, filepath: 'some-file-path', sha: 'some-sha')
9
+ @tile = Percy::Tile.new(20, 120, 150, 0, filepath: 'some-file-path', sha: 'some-sha')
10
10
  @hash_tile = @tile.to_h
11
11
  end
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-appium-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.pre.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BroswerStack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
11
+ date: 2024-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appium_lib
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -146,10 +160,10 @@ files:
146
160
  - percy/metadata/ios_metadata.rb
147
161
  - percy/metadata/metadata.rb
148
162
  - percy/metadata/metadata_resolver.rb
163
+ - percy/percy-appium-app.rb
149
164
  - percy/providers/app_automate.rb
150
165
  - percy/providers/generic_provider.rb
151
166
  - percy/providers/provider_resolver.rb
152
- - percy/screenshot.rb
153
167
  - percy/version.rb
154
168
  - specs/android_metadata.rb
155
169
  - specs/app_automate.rb
@@ -183,11 +197,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
197
  version: 2.6.0
184
198
  required_rubygems_version: !ruby/object:Gem::Requirement
185
199
  requirements:
186
- - - ">="
200
+ - - ">"
187
201
  - !ruby/object:Gem::Version
188
- version: '0'
202
+ version: 1.3.1
189
203
  requirements: []
190
- rubygems_version: 3.2.3
204
+ rubygems_version: 3.4.19
191
205
  signing_key:
192
206
  specification_version: 4
193
207
  summary: Percy visual testing for Ruby Appium Mobile Apps