calabash 2.0.0.pre3 → 2.0.0.pre4

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
  SHA1:
3
- metadata.gz: 99f4bb2a90e0b3d0e826f6afe73b213a36e984e0
4
- data.tar.gz: 2056799cd44ee3504b986351da16bb834f72e382
3
+ metadata.gz: 46648485266c6c561e26a5b25214c4b75efc0f18
4
+ data.tar.gz: e128516fcd291fe34c8e4322041b170966c53493
5
5
  SHA512:
6
- metadata.gz: 1ba0e8c86de9a8682affd9712cbfc4d7b50bf472bc285c8375e210ae5f99146910f6229ff140cc316ab6dea697ecfbc0bc75e415f750b8706940981080bfa2a1
7
- data.tar.gz: 2a71fcf01eb79e7cb15d294a70b7cd9ba42111c09ef82966e4b9d7522221e7b726df29483683b6ef6640412b75f2e2edc80c0e4084567d57a02b1a1c68102140
6
+ metadata.gz: 39c208b6932d9ed0940a25e9bf6fe8fe7688c49cda6b12ee0f97e1063fd038f8ca540d1fbc73609185cfc6cd52b3f20cc4e444570774e7182dfcf5a3bb4c1792
7
+ data.tar.gz: 57d8c44ed1996097fec90970f6757a4e423f1cc0f41646a866715e0f1edeabfd53e266f5c06ed278f00bf64b26d17936b4acf413ed10f85f321cd5fcaa18aec2
@@ -0,0 +1,115 @@
1
+ module Calabash
2
+ module Android
3
+ # Scrolling invokes methods on the views to get to the right items. This
4
+ # behaviour is not doable by the users. For real gestures interacting with
5
+ # the screen, see {Calabash::Gestures}.
6
+ module Scroll
7
+ # Scroll the first view matched by `query` in `direction`.
8
+ #
9
+ # @param [String, Hash, Calabash::Query] query A query describing the
10
+ # view to scroll.
11
+ # @param [Symbol] direction The direction to scroll. Valid directions are:
12
+ # :up, :down, :left, and :right
13
+ def scroll(query, direction)
14
+ allowed_directions = [:up, :down, :left, :right]
15
+
16
+ dir_symbol = direction.to_sym
17
+
18
+ unless allowed_directions.include?(dir_symbol)
19
+ raise ArgumentError,
20
+ "Expected '#{direction}' to be one of #{allowed_directions.join(',')}"
21
+ end
22
+
23
+ view = wait_for_view(query, timeout: Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT)
24
+
25
+ result = query("#{Query.new(query)} index:0", :getFirstVisiblePosition)
26
+
27
+ if result.length == 0
28
+ raise "Failed to scroll view '#{query}'"
29
+ end
30
+
31
+ if result.first.is_a?(Hash) && result.first.has_key?("error")
32
+ # View is not of type android.widget.AbsListView
33
+ scroll_x = 0
34
+ scroll_y = 0
35
+ width = view['rect']['width']
36
+ height = view['rect']['height']
37
+
38
+ if direction == :up
39
+ scroll_y = -height / 2
40
+ elsif direction == :down
41
+ scroll_y = height / 2
42
+ elsif direction == :left
43
+ scroll_x = -width / 2
44
+ elsif direction == :right
45
+ scroll_x = width / 2
46
+ end
47
+
48
+ result = query("#{Query.new(query)} index:0", {scrollBy: [scroll_x.to_i, scroll_y.to_i]})
49
+
50
+ if result.length == 0
51
+ raise "Failed to scroll view '#{query}'"
52
+ end
53
+
54
+ if result.first.is_a?(Hash) && result.first.has_key?('error')
55
+ raise "Failed to scroll view: #{result.first['error']}"
56
+ end
57
+ else
58
+ # View is of type android.widget.AbsListView
59
+ unless [:up, :down].include?(dir_symbol)
60
+ raise ArgumentError,
61
+ "Can only scroll listviews :up or :down, not #{direction}"
62
+ end
63
+
64
+ first_position = result.first.to_i
65
+ result = query("#{Query.new(query)} index:0", :getLastVisiblePosition)
66
+
67
+ if result.length == 0
68
+ raise "Failed to scroll view '#{Query.new(query)}'"
69
+ end
70
+
71
+ last_position = result.first.to_i
72
+
73
+
74
+ selection_index = if direction == :up
75
+ [first_position + [first_position - last_position + 1, -1].min, 0].max
76
+ elsif direction == :down
77
+ first_position + [last_position - first_position, 1].max
78
+ end
79
+
80
+ result = query("#{Query.new(query)} index:0", setSelection: selection_index)
81
+
82
+ if result.length == 0
83
+ raise "Failed to scroll view '#{query}'"
84
+ end
85
+ end
86
+
87
+ true
88
+ end
89
+
90
+ # Scroll to `item` in `query`. If `query` matches multiple views, the
91
+ # first view matching `query` is scrolled.
92
+ #
93
+ # @param [String, Hash, Calabash::Query] query A query describing the
94
+ # view to scroll.
95
+ # @param [Numeric] item The item number to scroll to. This value is
96
+ # 0-indexed.
97
+ def scroll_to_row(query, item)
98
+ wait_for_view(query, timeout: Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT)
99
+ result = query("#{Query.new(query)} index:0", setSelection: item)
100
+
101
+ if result.length == 0
102
+ raise "Failed to scroll view '#{query}'"
103
+ end
104
+
105
+ result.length.times do |i|
106
+ if result[i].is_a?(Hash) && result[i].has_key?('error')
107
+ raise "Unable to scroll view number '#{i}' matching '#{query}'. #{result[i]['error']}"
108
+ end
109
+ end
110
+
111
+ true
112
+ end
113
+ end
114
+ end
115
+ end
@@ -38,6 +38,7 @@ module Calabash
38
38
  require 'calabash/android/text'
39
39
  require 'calabash/android/console_helpers'
40
40
  require 'calabash/android/life_cycle'
41
+ require 'calabash/android/scroll'
41
42
 
42
43
  include Calabash::Android::Gestures
43
44
  include Calabash::Android::Interactions
@@ -45,6 +46,7 @@ module Calabash
45
46
  include Calabash::Android::Orientation
46
47
  include Calabash::Android::PhysicalButtons
47
48
  include Calabash::Android::Text
49
+ include Calabash::Android::Scroll
48
50
 
49
51
  # @!visibility private
50
52
  def self.binary_location(name, abi, using_pie)
@@ -78,7 +78,7 @@ module Calabash
78
78
  identifier = Environment::DEVICE_IDENTIFIER
79
79
 
80
80
  if identifier.nil?
81
- connected_devices = RunLoop::XCTools.new.instruments(:devices)
81
+ connected_devices = RunLoop::Instruments.new.physical_devices
82
82
  if connected_devices.empty?
83
83
  raise 'There are no physical devices connected.'
84
84
  elsif connected_devices.count > 1
@@ -639,8 +639,8 @@ module Calabash
639
639
  # @!visibility private
640
640
  # Very expensive!
641
641
  def Device.fetch_matching_physical_device(udid_or_name)
642
- xctools = RunLoop::XCTools.new
643
- xctools.instruments(:devices).detect do |device|
642
+ instruments = RunLoop::Instruments.new
643
+ instruments.physical_devices.detect do |device|
644
644
  device.name == udid_or_name ||
645
645
  device.udid == udid_or_name
646
646
  end
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
 
3
3
  # @!visibility private
4
- VERSION = '2.0.0.pre3'
4
+ VERSION = '2.0.0.pre4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre3
4
+ version: 2.0.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Maturana Larsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-08-09 00:00:00.000000000 Z
14
+ date: 2015-09-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: edn
@@ -93,7 +93,7 @@ dependencies:
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 1.4.1
96
+ version: 1.5.0
97
97
  - - "<"
98
98
  - !ruby/object:Gem::Version
99
99
  version: '2.0'
@@ -103,7 +103,7 @@ dependencies:
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 1.4.1
106
+ version: 1.5.0
107
107
  - - "<"
108
108
  - !ruby/object:Gem::Version
109
109
  version: '2.0'
@@ -411,6 +411,7 @@ files:
411
411
  - lib/calabash/android/orientation.rb
412
412
  - lib/calabash/android/physical_buttons.rb
413
413
  - lib/calabash/android/screenshot.rb
414
+ - lib/calabash/android/scroll.rb
414
415
  - lib/calabash/android/server.rb
415
416
  - lib/calabash/android/text.rb
416
417
  - lib/calabash/application.rb