percy-appium-app 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85a82be9fb7970cea7e6bfbf92341377a6cf4647f07ce09b3a3c4bb52ff25c11
4
- data.tar.gz: 03be307ae51ff85c7853cf0284ded40713a91f8bbf4ce36f8f6b7ae69165d26e
3
+ metadata.gz: cb456ecc7624f0fa71f10f0d4697af3d212a1a611a47ba9af19148f6f4e6314b
4
+ data.tar.gz: e987cb68808d8dd1fd3ea1a021836e5eaef6a38821106d9b347093d2cf07d067
5
5
  SHA512:
6
- metadata.gz: 986183165da611f44bfd356562c084bdb942d7f87a2e38418746562c1d056894e8a373c4fe3e61a5aa2c3a44a48c9c42d7701e845b30eec7727fdafbe2a78faa
7
- data.tar.gz: a21a495cb3cda29740602eb262e23ef67ed7c3fce651d191d1ec91c73bc56b0540f6c8cf55772816da6acdcadf1d07c6040e35a49f4fdfae95e1ca0016ccf2fe
6
+ metadata.gz: 29d57b272a4bedec154cfde69921a9c468554998892c224bfc2443a250742fdac8b0000af483e449d84f9330e8473d026736691bf7f8e9e58f9d2c1a3c9778e7
7
+ data.tar.gz: e90a50582005f371cc002e59dc37004bebc234620e6044ae79d65d0646c2c7e608d54910f69137dcf9b0ccec89262c4fd82e89fe7e95a7420da1be68dbb0c904
@@ -6,6 +6,7 @@ on:
6
6
  workflow_dispatch:
7
7
  inputs:
8
8
  branch:
9
+ description: Which branch of @percy/cli to build from source for this run
9
10
  required: false
10
11
  type: string
11
12
  default: master
@@ -20,7 +21,13 @@ jobs:
20
21
  matrix:
21
22
  os: [ubuntu-latest]
22
23
  ruby: ['2.6', '2.7', '3.0']
24
+ include:
25
+ - os: ubuntu-latest
26
+ ruby: '3.3'
27
+ appium_lib: '~> 16.0'
23
28
  runs-on: ${{ matrix.os }}
29
+ env:
30
+ APPIUM_LIB_VERSION: ${{ matrix.appium_lib || '~> 12.0' }}
24
31
  steps:
25
32
  - uses: actions-ecosystem/action-regex-match@v2
26
33
  id: regex-match
@@ -42,6 +49,24 @@ jobs:
42
49
  key: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/${{ hashFiles('**/Gemfile.lock') }}
43
50
  restore-keys: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/
44
51
  - run: bundle install
52
+ - name: Set up @percy/cli from git
53
+ if: ${{ github.event_name == 'workflow_dispatch' }}
54
+ env:
55
+ BRANCH: ${{ github.event.inputs.branch }}
56
+ WORKSPACE: ${{ github.workspace }}
57
+ run: |
58
+ cd /tmp
59
+ git clone --branch "$BRANCH" --depth 1 https://github.com/percy/cli
60
+ cd cli
61
+ PERCY_PACKAGES=`find packages -mindepth 1 -maxdepth 1 -type d | sed -e 's/packages/@percy/g' | tr '\n' ' '`
62
+ yarn
63
+ yarn build
64
+ yarn global:link
65
+ cd "$WORKSPACE"
66
+ yarn link $PERCY_PACKAGES >/dev/null 2>&1 || true
67
+ echo "$(yarn global bin)" >> "$GITHUB_PATH"
68
+ export PATH="$(yarn global bin):$PATH"
69
+ percy --version
45
70
  # Run each spec via the SimpleCov runner so per-process coverage is
46
71
  # recorded and merged, then collate the merged result and enforce the gate.
47
72
  - run: for file in specs/*.rb; do echo "$file"; bundle exec ruby specs/support/run_spec.rb "$file"; done
data/Gemfile CHANGED
@@ -2,14 +2,17 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Pin appium_lib to the 12.x line so all Ruby legs (2.6/2.7/3.0) resolve
6
- # appium_lib_core ~> 5.0, which still exposes Appium::Core::Base::SearchContext.
7
- # Unpinned, Ruby 3.0 resolved appium_lib 15 / appium_lib_core 9.x, which removed
8
- # that constant and broke the specs. appium_console 3.0.0 requires appium_lib = 12.0.0.
9
- gem 'appium_console', '~> 3.0'
10
- gem 'appium_lib', '~> 12.0'
5
+ # appium_lib defaults to the 12.x line so the Ruby 2.6/2.7/3.0 legs resolve
6
+ # appium_lib_core ~> 5.0. CI also runs a leg on the current major via
7
+ # APPIUM_LIB_VERSION, since appium_lib_core 11+ changed where the driver keeps its
8
+ # hub URL. appium_console 3.0.0 requires appium_lib = 12.0.0, so it only joins the
9
+ # 12.x resolution.
10
+ appium_lib_version = ENV.fetch('APPIUM_LIB_VERSION', '~> 12.0')
11
+ gem 'appium_console', '~> 3.0' if appium_lib_version.include?('12.')
12
+ gem 'appium_lib', appium_lib_version
11
13
  gem 'dotenv'
12
- gem 'minitest'
14
+ # minitest 6 moved Minitest::Mock into the separate minitest-mock gem.
15
+ gem 'minitest', '~> 5.0'
13
16
  gem 'rubocop', require: false
14
17
  gem 'tempfile'
15
18
  gem 'webmock', '~> 3.18', '>= 3.18.1'
@@ -9,12 +9,11 @@ module Percy
9
9
  def initialize(driver)
10
10
  super(driver)
11
11
  @_bars = nil
12
- # Intentionally left as the original lookup: this path already degrades to
13
- # driver.get_system_bars consistently across all appium_lib_core versions
14
- # (the rect read yields a non-Hash, so the rect arithmetic in
15
- # get_system_bars rescues to nil and falls back), so it is out of scope for
16
- # the snake_case capability fix.
17
- @_viewport_rect = capabilities.to_json['viewportRect']
12
+ # Read the rect as a Hash. The previous `capabilities.to_json['viewportRect']`
13
+ # indexed a JSON String, so the rect was never used and every call fell back
14
+ # to driver.get_system_bars, which appium_lib_core 13+ sends as the
15
+ # Appium 2-only `mobile: getSystemBars` command.
16
+ @_viewport_rect = viewport
18
17
  end
19
18
 
20
19
  def device_screen_size
@@ -71,7 +70,8 @@ module Percy
71
70
  end
72
71
 
73
72
  def viewport
74
- capabilities.to_json['viewportRect']
73
+ rect = get_capability_value('viewportRect')
74
+ rect.is_a?(Hash) ? rect : nil
75
75
  end
76
76
 
77
77
  def scale_factor
@@ -8,6 +8,23 @@ module Percy
8
8
  @driver = driver
9
9
  end
10
10
 
11
+ # Returns the hub URL the driver talks to. appium_lib_core <= 10 keeps it in
12
+ # the HTTP client's @server_url; 11+ (selenium-webdriver ClientConfig) moved it
13
+ # to client_config.server_url and leaves @server_url unset, which made every
14
+ # BrowserStack session look like a generic remote (no AppAutomate provider,
15
+ # no device name, empty executor URL for Percy on Automate).
16
+ def self.server_url(driver)
17
+ http = driver.instance_variable_get(:@bridge).instance_variable_get(:@http)
18
+ url = http.instance_variable_get(:@server_url).to_s
19
+ return url unless url.empty?
20
+
21
+ client_config = http.respond_to?(:client_config) ? http.client_config : nil
22
+ client_config ||= http.instance_variable_get(:@client_config)
23
+ return '' unless client_config.respond_to?(:server_url)
24
+
25
+ client_config.server_url.to_s.chomp('/')
26
+ end
27
+
11
28
  def session_id
12
29
  @driver.session_id
13
30
  end
@@ -15,7 +32,7 @@ module Percy
15
32
  def command_executor_url
16
33
  url = Percy::Cache.get_cache(session_id, Percy::Cache::COMMAND_EXECUTOR_URL)
17
34
  if url.nil?
18
- url = @driver.instance_variable_get(:@bridge).instance_variable_get(:@http).instance_variable_get(:@server_url).to_s
35
+ url = self.class.server_url(@driver)
19
36
  Percy::Cache.set_cache(session_id, Percy::Cache::COMMAND_EXECUTOR_URL, url)
20
37
  end
21
38
  url
@@ -3,6 +3,7 @@
3
3
  require 'json'
4
4
  require 'pathname'
5
5
  require_relative '../common/common'
6
+ require_relative 'driver_metadata'
6
7
 
7
8
  DEVICE_INFO_FILE_PATH = File.join(File.dirname(__FILE__), '..', 'configs', 'devices.json')
8
9
  DEVICE_INFO = JSON.parse(File.read(DEVICE_INFO_FILE_PATH))
@@ -82,7 +83,7 @@ module Percy
82
83
  end
83
84
 
84
85
  def remote_url
85
- driver.instance_variable_get(:@bridge).instance_variable_get(:@http).instance_variable_get(:@server_url).to_s
86
+ Percy::DriverMetadata.server_url(driver)
86
87
  end
87
88
 
88
89
  def get_orientation(**kwargs)
data/percy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Percy
4
- VERSION = '1.0.1'.freeze
4
+ VERSION = '1.0.2'.freeze
5
5
  end
@@ -28,7 +28,7 @@ class TestAndroidMetadata < Minitest::Test
28
28
  android_capabilities = get_android_capabilities
29
29
  @mock_webdriver.expect(:capabilities, android_capabilities.merge('viewportRect' => viewport))
30
30
 
31
- assert(viewport, @android_metadata.viewport)
31
+ assert_equal(viewport, @android_metadata.viewport)
32
32
  @mock_webdriver.verify
33
33
  end
34
34
 
@@ -61,19 +61,30 @@ class TestAndroidMetadata < Minitest::Test
61
61
  @mock_webdriver.verify
62
62
  end
63
63
 
64
- def test_get_system_bars
64
+ def test_get_system_bars_falls_back_to_driver_without_viewport_rect
65
65
  system_bars = {
66
66
  'statusBar' => { 'height' => 83 },
67
67
  'navigationBar' => { 'height' => 44 }
68
68
  }
69
- android_capabilities = get_android_capabilities
70
- session_id = 'session_id_123'
71
- @mock_webdriver.expect(:session_id, session_id)
72
- @mock_webdriver.expect(:session_id, session_id)
73
- @mock_webdriver.expect(:capabilities, android_capabilities.merge('viewportRect' => nil))
74
- @mock_webdriver.expect(:get_system_bars, system_bars)
69
+ driver = Minitest::Mock.new
70
+ driver.expect(:capabilities, get_android_capabilities.merge('viewportRect' => nil))
71
+ metadata = Percy::AndroidMetadata.new(driver)
72
+ driver.expect(:session_id, 'session_id_no_rect')
73
+ driver.expect(:session_id, 'session_id_no_rect')
74
+ driver.expect(:get_system_bars, system_bars)
75
+
76
+ assert_equal(system_bars, metadata.get_system_bars)
77
+ driver.verify
78
+ end
79
+
80
+ def test_get_system_bars_uses_viewport_rect
81
+ # viewportRect top=83, height=2153 on a 1080x2280 screen (see get_android_capabilities)
82
+ @mock_webdriver.expect(:session_id, 'session_id_rect')
83
+ @mock_webdriver.expect(:capabilities, get_android_capabilities)
84
+
85
+ bars = @android_metadata.get_system_bars
75
86
 
76
- assert(system_bars, @android_metadata.get_system_bars)
87
+ assert_equal({ 'statusBar' => { 'height' => 83 }, 'navigationBar' => { 'height' => 44 } }, bars)
77
88
  @mock_webdriver.verify
78
89
  end
79
90
 
@@ -39,6 +39,38 @@ class TestDriverMetadata < Minitest::Test
39
39
  assert(url, @metadata.command_executor_url)
40
40
  end
41
41
 
42
+ # appium_lib_core 11+ leaves the HTTP client's @server_url unset and keeps the
43
+ # hub URL in client_config.server_url (a URI with a trailing slash).
44
+ class ClientConfigHttp
45
+ attr_reader :client_config
46
+
47
+ def initialize(client_config)
48
+ @client_config = client_config
49
+ end
50
+ end
51
+
52
+ def driver_with_http(http)
53
+ bridge = Object.new
54
+ bridge.instance_variable_set(:@http, http)
55
+ driver = Object.new
56
+ driver.instance_variable_set(:@bridge, bridge)
57
+ driver.define_singleton_method(:session_id) { "session_#{object_id}" }
58
+ driver
59
+ end
60
+
61
+ def test_command_executor_url_reads_client_config_when_server_url_unset
62
+ client_config = Struct.new(:server_url).new(URI('https://hub-cloud.browserstack.com/wd/hub/'))
63
+ driver = driver_with_http(ClientConfigHttp.new(client_config))
64
+
65
+ assert_equal('https://hub-cloud.browserstack.com/wd/hub', Percy::DriverMetadata.new(driver).command_executor_url)
66
+ end
67
+
68
+ def test_server_url_is_empty_when_no_known_location_has_it
69
+ driver = driver_with_http(ClientConfigHttp.new(nil))
70
+
71
+ assert_equal('', Percy::DriverMetadata.server_url(driver))
72
+ end
73
+
42
74
  def test_capabilities
43
75
  session_id = 'session_id_123'
44
76
  2.times do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-appium-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - BroswerStack