gametel 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Feature: Interacting with Images
2
+
3
+ Scenario: Should be able to click an image
4
+ Given I'm on the image screen
5
+ Then I should be able to click on the first image
6
+
7
+ Scenario: Should be able to get the images view
8
+ Given I'm on the image screen
9
+ Then the first image should have the following properties:
10
+ | property | value |
11
+ | clickable | false |
12
+ | enabled | true |
13
+ | focusable | false |
14
+ | focused | false |
15
+ | selected | false |
16
+ | shown | true |
17
+
18
+ Scenario: Waiting for the drawable to load
19
+ Given I'm on the image screen
20
+ Then I should be able to wait until the images drawable has loaded
@@ -0,0 +1,22 @@
1
+ Given /^I\'m on the image screen$/ do
2
+ on(MainMenuScreen).views
3
+ on(ViewsMenuScreen).image_view
4
+ end
5
+
6
+ Then /^I should be able to click on the first image$/ do
7
+ on(ImageViewScreen).click_first
8
+ end
9
+
10
+ Then /^the first image should have the following properties:$/ do |properties|
11
+ on(ImageViewScreen) do |screen|
12
+ view = screen.first_view
13
+ properties.hashes.each do |property|
14
+ result = view.send("#{property["property"]}?")
15
+ result.to_s.should eq(property["value"]), "for field #{property["property"]}"
16
+ end
17
+ end
18
+ end
19
+
20
+ Then /^I should be able to wait until the images drawable has loaded$/ do
21
+ on(ImageViewScreen).wait_for_first
22
+ end
@@ -0,0 +1,6 @@
1
+ class ImageViewScreen
2
+ include Gametel
3
+
4
+ image(:first, :index => 0)
5
+
6
+ end
data/lib/gametel.rb CHANGED
@@ -6,6 +6,7 @@ require 'gametel/platforms/brazenhead_platform'
6
6
  require 'gametel/views'
7
7
 
8
8
  module Gametel
9
+ include Gametel::Waiter
9
10
 
10
11
  attr_reader :platform
11
12
 
@@ -13,7 +14,7 @@ module Gametel
13
14
  ROBOTIUM_RIGHT = 22
14
15
 
15
16
  def self.included(cls)
16
- cls.extend Gametel::Accessors, Gametel::Waiter
17
+ cls.extend Gametel::Accessors
17
18
  end
18
19
 
19
20
  def initialize(pform = :brazenhead)
@@ -1,5 +1,19 @@
1
1
  module Gametel
2
2
  module Accessors
3
+
4
+ #
5
+ # Generates a method named active? which will wait for the
6
+ # activity to become active
7
+ #
8
+ # returns true when successful
9
+ #
10
+ def activity(activity_name)
11
+ define_method("active?") do
12
+ platform.wait_for_activity activity_name
13
+ platform.last_json
14
+ end
15
+ end
16
+
3
17
  #
4
18
  # Generates methods to enter text into a text field, clear the text
5
19
  # field, get the hint as well as the description
@@ -8,7 +22,7 @@ module Gametel
8
22
  # text(:first_name, :index => 0)
9
23
  # # will generate 'first_name', 'first_name=', 'clear_first_name', 'first_name_hint' and 'first_name_description' methods
10
24
  #
11
- # @param [String] the name used for the generated methods
25
+ # @param [Symbol] the name used for the generated methods
12
26
  # @param [Hash] locator for how the text is found The valid
13
27
  # keys are:
14
28
  # * :id
@@ -36,7 +50,7 @@ module Gametel
36
50
  # button(:save, :text => 'Save')
37
51
  # # will generate 'save' and 'save_enabled?' methods
38
52
  #
39
- # @param [String] the name used for the generated methods
53
+ # @param [Symbol] the name used for the generated methods
40
54
  # @param [Hash] locator for how the button is found The valid
41
55
  # keys are:
42
56
  # * :text
@@ -69,7 +83,7 @@ module Gametel
69
83
  # # will generate 'details' method to select third item in the
70
84
  # # first list
71
85
  #
72
- # @param [String] the name used for the generated methods
86
+ # @param [Symbol] the name used for the generated methods
73
87
  # @param [Hash] locator for how the list item is found The valid
74
88
  # keys are:
75
89
  # * :text
@@ -93,7 +107,7 @@ module Gametel
93
107
  # checkbox(:enable, :text => 'Enable')
94
108
  # # will generate 'enable' method
95
109
  #
96
- # @param [String] the name used for the generated methods
110
+ # @param [Symbol] the name used for the generated methods
97
111
  # @param [Hash] locator for how the checkbox is found The valid
98
112
  # keys are:
99
113
  # * :text
@@ -116,7 +130,7 @@ module Gametel
116
130
  # radio_button(:circle, :text => 'Circle')
117
131
  # # will generate 'circle' method
118
132
  #
119
- # @param [String] the name used for the generated methods
133
+ # @param [Symbol] the name used for the generated methods
120
134
  # @param [Hash] locator for how the checkbox is found The valid
121
135
  # keys are:
122
136
  # * :text
@@ -138,7 +152,7 @@ module Gametel
138
152
  # view(:clickable_text, :id => 'id_name_of_your_control')
139
153
  # # will generate 'clickable_text' method
140
154
  #
141
- # @param [String] the name used for the generated methods
155
+ # @param [Symbol] the name used for the generated methods
142
156
  # @param [Hash] locator indicating an id for how the view is found.
143
157
  # The only valid keys are:
144
158
  # * :id
@@ -160,7 +174,7 @@ module Gametel
160
174
  # spinner(:progress_item, :id => 'id_name_of_your_control')
161
175
  # # will generate progress_item, progress_item=, progress_item_secondary, progress_item_secondary=
162
176
  #
163
- # @param [String] the name used for the generated methods
177
+ # @param [Symbol] the name used for the generated methods
164
178
  # @param [Hash] locator indicating an id for how the progress bar is found.
165
179
  # The only valid keys are:
166
180
  # * :id
@@ -188,12 +202,15 @@ module Gametel
188
202
  end
189
203
 
190
204
  #
191
- # Generates one method to get the selected item text.
205
+ # Generates three method to interact with a spinner
192
206
  # @example
193
207
  # spinner(:spinner_item, :id => 'id_name_of_your_control')
194
- # # will generate 'spinner_item' method
208
+ # # will generate 'spinner_item' method to return the spinner
209
+ # # value, 'select_spinner_item(value) to set the spinner value
210
+ # # and 'spinner_view' to return the view
211
+
195
212
  #
196
- # @param [String] the name used for the generated methods
213
+ # @param [Symbol] the name used for the generated methods
197
214
  # @param [Hash] locator indicating an id for how the spinner is found.
198
215
  # The only valid keys are:
199
216
  # * :id
@@ -210,6 +227,34 @@ module Gametel
210
227
  Gametel::Views::Spinner.new(platform, locator)
211
228
  end
212
229
  end
230
+
231
+ #
232
+ # Generaes method to interact with an image.
233
+ #
234
+ # @example
235
+ # image(:headshot, :id => 'headshot')
236
+ # # will generate 'click_headshot' method to click the image,
237
+ # # 'wait_for_headshot' which will wait until the image has
238
+ # # loaded a drawable and 'headshot_view' to return the view
239
+ #
240
+ # @param [Symbol] the name used for the generated methods
241
+ # @param [Hash] locator indicating an id for how the image is found.
242
+ # The only valid keys are:
243
+ # * :index
244
+ #
245
+ def image(name, locator)
246
+ define_method("click_#{name}") do
247
+ platform.click_image(locator)
248
+ end
249
+ define_method("wait_for_#{name}") do
250
+ wait_until do
251
+ platform.has_drawable?(locator)
252
+ end
253
+ end
254
+ define_method("#{name}_view") do
255
+ Gametel::Views::Image.new(platform, locator)
256
+ end
257
+ end
213
258
  end
214
259
  end
215
260
 
@@ -89,6 +89,14 @@ module Gametel
89
89
  result = click_on_radio_button(locator[:index]) if locator[:index]
90
90
  end
91
91
 
92
+ #
93
+ # click an image
94
+ #
95
+ def click_image(locator)
96
+ result = click_on_image(locator[:index]) if locator[:index]
97
+ result = click_on_view_by_id(locator[:id]) if locator[:id]
98
+ end
99
+
92
100
  #
93
101
  # get the selected spinner value
94
102
  #
@@ -130,6 +138,15 @@ module Gametel
130
138
  result.body.include? 'windowLocation'
131
139
  end
132
140
 
141
+ #
142
+ # return if a view has a drawable
143
+ #
144
+ def has_drawable?(locator)
145
+ view = get_view_by_id(locator) if locator[:id]
146
+ view = get_image(locator[:index]) if locator[:index]
147
+ last_json['hasDrawable']
148
+ end
149
+
133
150
  #
134
151
  # determine if a view is enabled
135
152
  #
@@ -1,3 +1,3 @@
1
1
  module Gametel
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
data/lib/gametel/views.rb CHANGED
@@ -6,3 +6,4 @@ require 'gametel/views/checkbox'
6
6
  require 'gametel/views/progress'
7
7
  require 'gametel/views/spinner'
8
8
  require 'gametel/views/list_item'
9
+ require 'gametel/views/image'
@@ -0,0 +1,27 @@
1
+ module Gametel
2
+ module Views
3
+ class Image < View
4
+ IMAGE_VIEW_CLASS = 'android.widget.ImageView'
5
+
6
+ protected
7
+
8
+ def build_property_methods
9
+ metaclass = class << self; self; end
10
+ properties.each do |property|
11
+ metaclass.send(:define_method, "#{property}?".to_sym) do
12
+
13
+ platform.get_view_by_id(locator[:id]) do |device|
14
+ device.send "is_#{property}"
15
+ end if locator[:id]
16
+
17
+ platform.get_view_by_index(IMAGE_VIEW_CLASS, locator[:index]) do |device|
18
+ device.send "is_#{property}"
19
+ end if locator[:index]
20
+
21
+ platform.last_response.body == "true"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,6 +3,8 @@ require 'spec_helper'
3
3
  class AccessorsSampleScreen
4
4
  include Gametel
5
5
 
6
+ activity "SomeActivity"
7
+
6
8
  list_item(:first_list_item_text, :text => 'first item')
7
9
  list_item(:first_list_item_index, :index => 0)
8
10
  list_item(:first_list_item_index_list, :index => 0, :list => 1)
@@ -24,6 +26,8 @@ class AccessorsSampleScreen
24
26
  spinner(:spinner_index, :index => 1)
25
27
  progress(:progress_id, :id => 'progress_id')
26
28
  progress(:progress_index, :index => 1)
29
+ image(:image_index, :index => 0)
30
+ image(:image_id, :id => 'image_id')
27
31
  end
28
32
 
29
33
  describe Gametel::Accessors do
@@ -43,6 +47,18 @@ describe Gametel::Accessors do
43
47
  device.stub(:send).and_return(result)
44
48
  end
45
49
 
50
+ context "defining the activity on a screen" do
51
+ it "should define the active? method" do
52
+ screen.should respond_to :active?
53
+ end
54
+
55
+ it "should wait for the activity to become active" do
56
+ platform.should_receive(:wait_for_activity).with("SomeActivity")
57
+ platform.should_receive(:last_json)
58
+ screen.active?
59
+ end
60
+ end
61
+
46
62
  context "list items" do
47
63
  it "should know how to be chosen by text" do
48
64
  platform.should_receive(:click_on_text)
@@ -738,5 +754,29 @@ describe Gametel::Accessors do
738
754
  end
739
755
  end
740
756
  end
757
+
758
+ context "images" do
759
+ it "should click an image using the index" do
760
+ platform.should_receive(:click_on_image).with(0)
761
+ screen.click_image_index
762
+ end
763
+
764
+ it "should click an image by id" do
765
+ platform.should_receive(:click_on_view_by_id).with('image_id')
766
+ screen.click_image_id
767
+ end
768
+
769
+ it "should wait for a drawable when using index" do
770
+ platform.should_receive(:get_image).with(0)
771
+ platform.should_receive(:last_json).and_return({'hasDrawable' => 'true'})
772
+ screen.wait_for_image_index
773
+ end
774
+
775
+ it "should wait for a drawable when using index" do
776
+ platform.should_receive(:get_view_by_id).with(:id => 'image_id')
777
+ platform.should_receive(:last_json).and_return({'hasDrawable' => 'true'})
778
+ screen.wait_for_image_id
779
+ end
780
+ end
741
781
  end
742
782
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gametel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-01 00:00:00.000000000 Z
13
+ date: 2013-04-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: brazenhead
@@ -67,7 +67,7 @@ dependencies:
67
67
  requirements:
68
68
  - - ! '>='
69
69
  - !ruby/object:Gem::Version
70
- version: 2.6.0
70
+ version: 2.13.0
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  requirements:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
- version: 2.6.0
78
+ version: 2.13.0
79
79
  - !ruby/object:Gem::Dependency
80
80
  name: cucumber
81
81
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  requirements:
84
84
  - - ! '>='
85
85
  - !ruby/object:Gem::Version
86
- version: '0'
86
+ version: 1.2.0
87
87
  type: :development
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,7 +91,7 @@ dependencies:
91
91
  requirements:
92
92
  - - ! '>='
93
93
  - !ruby/object:Gem::Version
94
- version: '0'
94
+ version: 1.2.0
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: require_all
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ files:
119
119
  - features/button.feature
120
120
  - features/checkbox.feature
121
121
  - features/has_view.feature
122
+ - features/image.feature
122
123
  - features/is_enabled.feature
123
124
  - features/list_item.feature
124
125
  - features/main_screen.feature
@@ -130,6 +131,7 @@ files:
130
131
  - features/step_definitions/checkbox_steps.rb
131
132
  - features/step_definitions/controls_steps.rb
132
133
  - features/step_definitions/has_view_steps.rb
134
+ - features/step_definitions/image_steps.rb
133
135
  - features/step_definitions/is_enabled_steps.rb
134
136
  - features/step_definitions/list_item_steps.rb
135
137
  - features/step_definitions/main_screen_steps.rb
@@ -153,6 +155,7 @@ files:
153
155
  - features/support/screens/controls_screen.rb
154
156
  - features/support/screens/custom_items_screen.rb
155
157
  - features/support/screens/efficient_adapter_screen.rb
158
+ - features/support/screens/image_view_screen.rb
156
159
  - features/support/screens/lists_menu_screen.rb
157
160
  - features/support/screens/main_menu_screen.rb
158
161
  - features/support/screens/never_will_exist.rb
@@ -175,6 +178,7 @@ files:
175
178
  - lib/gametel/views.rb
176
179
  - lib/gametel/views/button.rb
177
180
  - lib/gametel/views/checkbox.rb
181
+ - lib/gametel/views/image.rb
178
182
  - lib/gametel/views/list_item.rb
179
183
  - lib/gametel/views/progress.rb
180
184
  - lib/gametel/views/radio_button.rb
@@ -199,18 +203,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
203
  - - ! '>='
200
204
  - !ruby/object:Gem::Version
201
205
  version: '0'
202
- segments:
203
- - 0
204
- hash: -1788323344300920655
205
206
  required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  none: false
207
208
  requirements:
208
209
  - - ! '>='
209
210
  - !ruby/object:Gem::Version
210
211
  version: '0'
211
- segments:
212
- - 0
213
- hash: -1788323344300920655
214
212
  requirements: []
215
213
  rubyforge_project:
216
214
  rubygems_version: 1.8.25
@@ -221,6 +219,7 @@ test_files:
221
219
  - features/button.feature
222
220
  - features/checkbox.feature
223
221
  - features/has_view.feature
222
+ - features/image.feature
224
223
  - features/is_enabled.feature
225
224
  - features/list_item.feature
226
225
  - features/main_screen.feature
@@ -232,6 +231,7 @@ test_files:
232
231
  - features/step_definitions/checkbox_steps.rb
233
232
  - features/step_definitions/controls_steps.rb
234
233
  - features/step_definitions/has_view_steps.rb
234
+ - features/step_definitions/image_steps.rb
235
235
  - features/step_definitions/is_enabled_steps.rb
236
236
  - features/step_definitions/list_item_steps.rb
237
237
  - features/step_definitions/main_screen_steps.rb
@@ -255,6 +255,7 @@ test_files:
255
255
  - features/support/screens/controls_screen.rb
256
256
  - features/support/screens/custom_items_screen.rb
257
257
  - features/support/screens/efficient_adapter_screen.rb
258
+ - features/support/screens/image_view_screen.rb
258
259
  - features/support/screens/lists_menu_screen.rb
259
260
  - features/support/screens/main_menu_screen.rb
260
261
  - features/support/screens/never_will_exist.rb