gametel 0.7 → 0.8

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.
@@ -3,7 +3,9 @@ Feature: Determining whether or not a view exists
3
3
  Scenario: Checking the existence of a view
4
4
  When I'm on the buttons screen
5
5
  Then we should know that the view with id "button_normal" exists
6
+ And we should know that the view with class "android.widget.Button" exists
6
7
 
7
8
  Scenario: Checking the absence of a view
8
9
  When I'm on the buttons screen
9
10
  Then we should know that the view with id "checkbox_button" does not exist
11
+ And we should know that the view with class "android.widget.ListView" does not exist
@@ -4,3 +4,8 @@ Then /^I should be able to click a checkbox by "(.*?)"$/ do |how|
4
4
  screen.send("checkbox_#{how}_view").should be_checked
5
5
  end
6
6
  end
7
+
8
+ Then /^the checkbox identified by "(.*?)" should be checked$/ do |how|
9
+ on(ControlsScreen).send("checkbox_#{how}_checked?").should be_true
10
+ end
11
+
@@ -1,12 +1,14 @@
1
- Then /^we should know that the view with id "(.*?)" exists$/ do |with_this_id|
1
+ Then /^we should know that the view with (\w+) "(.*?)" exists$/ do |how, what|
2
2
  on(ButtonScreen) do |screen|
3
- screen.should have_view(with_this_id)
3
+ locator = {}; locator[how.to_sym] = what
4
+ screen.should have_view(locator)
4
5
  end
5
6
  end
6
7
 
7
- Then /^we should know that the view with id "(.*?)" does not exist$/ do |with_this_id|
8
+ Then /^we should know that the view with (\w+) "(.*?)" does not exist$/ do |how, what|
8
9
  on(ButtonScreen) do |screen|
9
- screen.should_not have_view(with_this_id)
10
+ locator = {}; locator[how.to_sym] = what
11
+ screen.should_not have_view(locator)
10
12
  end
11
13
  end
12
14
 
@@ -1,14 +1,83 @@
1
1
  Given(/^I have navigated to the webview screen$/) do
2
- on(WebviewMainScreen).goto_webview
2
+ on(MainMenuScreen) do |screen|
3
+ screen.views
4
+ screen.wait_for_text 'Buttons'
5
+ end
6
+ on(ViewsMenuScreen).webview
3
7
  end
4
8
 
5
- When(/^I click the text "(.*?)" in a webview$/) do |text|
6
- on(WebviewScreen).click_on_text text
9
+ When(/^I click the text "(.*?)" in a webview$/) do |text|
10
+ on(MixedWebviewScreen).click_on_text text
7
11
  end
8
12
 
9
13
  Then(/^I should see the text "(.*?)" in a webview$/) do |text|
14
+ on(MixedWebviewScreen).should have_text(text)
15
+ end
16
+
17
+ When(/^I look for elements in the webview$/) do
18
+ on(MixedWebviewScreen) do |screen|
19
+ screen.wait_for_text 'Welcome to Foundation'
20
+ @webview = screen.web_view
21
+ end
22
+ end
23
+
24
+ Then(/^I should know the following elements exist:$/) do |table|
25
+ table.hashes.each do |hsh|
26
+ @webview.should have_element(hsh['locator'], hsh['value'])
27
+ end
28
+ end
29
+
30
+ When(/^I click on the anchor with the text "(.*?)"$/) do |text|
31
+ @webview.click('textContent', text)
32
+ end
33
+
34
+ Then(/^I should be able to enter "(.*?)" into the text field$/) do |text|
35
+ on(MixedWebviewScreen).scroll_down
36
+ @webview.enter_text('id', 'tf', text)
37
+ end
38
+
39
+ Then(/^I should be able to type "(.*?)" into the text field$/) do |text|
40
+ on(MixedWebviewScreen).scroll_down
41
+ @webview.type_text('id', 'tf', text)
42
+ end
43
+
44
+ Then(/^I should be able to clear the text of the text field$/) do
45
+ @webview.clear_text('id', 'tf')
46
+ end
47
+
48
+ Then(/^I should be able to wait for the text field$/) do
49
+ @webview.wait_for_element('id', 'tf')
50
+ end
51
+
52
+ When(/^I click the text "(.*?)" in a webview screen$/) do |text|
53
+ on(WebviewScreen).click_on_text text
54
+ end
55
+
56
+ Then(/^I should see the text "(.*?)" in a webview screen$/) do |text|
57
+ on(WebviewScreen).should have_text(text)
58
+ end
59
+
60
+ When(/^I look for elements in the webview screen$/) do
61
+ on(WebviewScreen).wait_for_text 'Welcome to Foundation'
62
+ end
63
+
64
+ Then(/^I should know the following webview elements exist:$/) do |table|
65
+ table.hashes.each do |hsh|
66
+ on(WebviewScreen).should have_element(hsh['locator'], hsh['value'])
67
+ end
68
+ end
69
+
70
+ When(/^I click on the anchor with the text "Some Other Page" on that screen$/) do
71
+ on(WebviewScreen).some_other_page
72
+ end
73
+
74
+ Then(/^I should be able to enter "(.*?)" into the text field on that screen$/) do |text|
10
75
  on(WebviewScreen) do |screen|
11
- screen.wait_for_text text
12
- screen.has_text? text
76
+ screen.scroll_down
77
+ screen.address = text
13
78
  end
14
79
  end
80
+
81
+ Then(/^I should be able to clear the text of the text field on that screen$/) do
82
+ on(WebviewScreen).clear_address
83
+ end
@@ -29,16 +29,11 @@ Gametel.keystore = {
29
29
  }
30
30
 
31
31
 
32
- Before('~@webview') do
32
+ Before do
33
33
  Gametel.apk_path = 'features/support/ApiDemos.apk'
34
34
  @driver = Gametel.start('ApiDemos')
35
35
  end
36
36
 
37
- Before('@webview') do
38
- Gametel.apk_path = 'webview_sample/bin/webview_sample-debug.apk'
39
- driver = Gametel.start('MainActivity')
40
- end
41
-
42
37
  After do
43
38
  Gametel.stop
44
39
  end
@@ -6,6 +6,7 @@ class ControlsScreen
6
6
  text(:text_field_name, :content_description => 'Edit Description')
7
7
  view(:view_field_id, :id => 'edit')
8
8
  view(:view_field_text, :text => 'textColorPrimary')
9
+ view(:view_field_class, :class => 'android.widget.CheckBox', :index => 1)
9
10
  text(:button_field_id, :id => 'button')
10
11
  text(:button_disabled_field_id, :id => 'button_disabled')
11
12
  button(:enabled_save, :index => 0)
@@ -0,0 +1,8 @@
1
+ class MixedWebviewScreen
2
+ include Gametel
3
+
4
+ activity 'WebView1'
5
+
6
+ webview(:web, :id => 'wv1')
7
+
8
+ end
@@ -1,6 +1,7 @@
1
1
  class WebviewScreen
2
- include Gametel
2
+ include Gametel::Webview
3
3
 
4
- webview(:web, :id => 'webView1')
4
+ link(:some_other_page, :text => 'Some Other Page')
5
+ text(:address, :id => 'tf')
5
6
 
6
7
  end
@@ -5,6 +5,11 @@ Feature: Interacting with view elements
5
5
  And I choose the List Dialogs button by id
6
6
  Then I should see the "Command one" list item
7
7
 
8
+ Scenario: Clicking on views by their class
9
+ When I'm on the controls screen
10
+ Then I should be able to click a view by "class"
11
+ And the checkbox identified by "text" should be checked
12
+
8
13
  Scenario: Clicking on view by their text
9
14
  When I'm on the controls screen
10
15
  Then I should be able to click a view by "text"
@@ -19,3 +24,14 @@ Feature: Interacting with view elements
19
24
  | focused | true |
20
25
  | selected | false |
21
26
  | shown | true |
27
+
28
+ Scenario: Determining properties of a view
29
+ When I'm on the controls screen
30
+ Then the "view" field identified by "class" can determine the following properties:
31
+ | property | value |
32
+ | clickable | true |
33
+ | enabled | true |
34
+ | focusable | true |
35
+ | focused | false |
36
+ | selected | false |
37
+ | shown | true |
@@ -1,14 +1,69 @@
1
- @webview
2
1
  Feature: Adding support for webviews
3
2
 
4
3
  Background:
5
4
  Given I have navigated to the webview screen
6
5
 
6
+ Scenario: Clicking on text and checking if text exists
7
+ When I click the text "Some Other Page" in a webview
8
+ Then I should see the text "Welcome to Some Other Page" in a webview
9
+
10
+ Scenario: Checking for the existance of elements
11
+ When I look for elements in the webview
12
+ Then I should know the following elements exist:
13
+ | locator | value |
14
+ | className | panel |
15
+ | cssSelector | div.panel |
16
+ | tagName | p |
17
+ | textContent | Six columns |
18
+
19
+ Scenario: Clicking on a web element
20
+ When I look for elements in the webview
21
+ And I click on the anchor with the text "Some Other Page"
22
+ Then I should see the text "Welcome to Some Other Page" in a webview
23
+
24
+ Scenario: Entering text in a web element
25
+ When I look for elements in the webview
26
+ Then I should be able to enter "Some Text" into the text field
27
+
28
+ Scenario: Typing text in a web element
29
+ When I look for elements in the webview
30
+ Then I should be able to type "Some Text" into the text field
31
+
7
32
  @focus
8
- Scenario: Clicking a link in a WebView
9
- When I click the text "Coffee" in a webview
10
- Then I should see the text "Starbucks" in a webview
33
+ Scenario: Clearing the text in a web welement
34
+ When I look for elements in the webview
35
+ Then I should be able to enter "Some Text" into the text field
36
+ And I should be able to clear the text of the text field
37
+
38
+ Scenario: Waiting for a web element
39
+ When I look for elements in the webview
40
+ Then I should be able to wait for the text field
11
41
 
42
+ Scenario: Clicking on text and checking if text exists on webview screen
43
+ When I click the text "Some Other Page" in a webview screen
44
+ Then I should see the text "Welcome to Some Other Page" in a webview screen
45
+
46
+ Scenario: Checking for the existance of elements on webview screen
47
+ When I look for elements in the webview screen
48
+ Then I should know the following webview elements exist:
49
+ | locator | value |
50
+ | className | panel |
51
+ | cssSelector | div.panel |
52
+ | tagName | p |
53
+ | textContent | Six columns |
54
+
55
+ Scenario: Clicking on a web element on a webview screen
56
+ When I look for elements in the webview screen
57
+ And I click on the anchor with the text "Some Other Page" on that screen
58
+ Then I should see the text "Welcome to Some Other Page" in a webview screen
59
+
60
+ Scenario: Entering text in a web element on a webview screen
61
+ When I look for elements in the webview screen
62
+ Then I should be able to enter "Some Text" into the text field on that screen
63
+
64
+ @focus
65
+ Scenario: Clearing the text in a web welement on a webview screen
66
+ When I look for elements in the webview screen
67
+ Then I should be able to enter "Some Text" into the text field on that screen
68
+ And I should be able to clear the text of the text field on that screen
12
69
 
13
-
14
-
@@ -6,14 +6,12 @@ require 'gametel/waiter'
6
6
  require 'gametel/version'
7
7
  require 'gametel/platforms/brazenhead_platform'
8
8
  require 'gametel/views'
9
+ require 'gametel/webview'
10
+ require 'gametel/webviewable'
9
11
 
10
12
  module Gametel
11
13
  include Gametel::Waiter
12
-
13
- attr_reader :platform
14
-
15
- ROBOTIUM_LEFT = 21
16
- ROBOTIUM_RIGHT = 22
14
+ include Gametel::Webviewable
17
15
 
18
16
  def self.included(cls)
19
17
  cls.extend Gametel::Accessors
@@ -46,24 +44,6 @@ module Gametel
46
44
  default_server.stop
47
45
  end
48
46
 
49
- def initialize(pform = :brazenhead)
50
- @platform = Gametel::Platforms::BrazenheadPlatform.new if pform == :brazenhead
51
- end
52
-
53
- #
54
- # click on the provided text
55
- #
56
- def click_on_text(text)
57
- platform.click_on_text text
58
- end
59
-
60
- #
61
- # Returns true if the provided text is found on the screen
62
- #
63
- def has_text?(text)
64
- platform.has_text?(text)
65
- end
66
-
67
47
  #
68
48
  # Returns true if the view is enabled
69
49
  #
@@ -109,41 +89,6 @@ module Gametel
109
89
  platform.enter
110
90
  end
111
91
 
112
- #
113
- # scroll down
114
- #
115
- def scroll_down
116
- platform.scroll_down
117
- end
118
-
119
- #
120
- # scroll up
121
- #
122
- def scroll_up
123
- platform.scroll_up
124
- end
125
-
126
- #
127
- # scroll left
128
- #
129
- def scroll_left
130
- platform.scroll_to_side ROBOTIUM_LEFT
131
- end
132
-
133
- #
134
- # scroll right
135
- #
136
- def scroll_right
137
- platform.scroll_to_side ROBOTIUM_RIGHT
138
- end
139
-
140
- #
141
- # Wait for the provided text to appear
142
- #
143
- def wait_for_text(text_to_find)
144
- platform.wait_for_text(text_to_find)
145
- raise "Timed out waiting for the text '#{text_to_find}'" unless platform.last_json
146
- end
147
92
 
148
93
  end
149
94
 
@@ -118,6 +118,9 @@ module Gametel
118
118
  define_method(name) do
119
119
  platform.click_checkbox(locator)
120
120
  end
121
+ define_method("#{name}_checked?") do
122
+ Gametel::Views::CheckBox.new(platform, locator).checked?
123
+ end
121
124
  define_method("#{name}_view") do
122
125
  Gametel::Views::CheckBox.new(platform, locator)
123
126
  end
@@ -157,6 +160,7 @@ module Gametel
157
160
  # The only valid keys are:
158
161
  # * :id
159
162
  # * :text
163
+ # * :class (:index => 0 implied)
160
164
  #
161
165
  def view(name, locator)
162
166
  define_method(name) do
@@ -257,7 +261,9 @@ module Gametel
257
261
  end
258
262
 
259
263
  def webview(name, locator)
260
-
264
+ define_method("#{name}_view") do
265
+ Gametel::Views::WebView.new(platform, locator)
266
+ end
261
267
  end
262
268
 
263
269
  def action_item(name, locator)
@@ -16,27 +16,6 @@ module Gametel
16
16
  block.call device if block
17
17
  end
18
18
  end
19
-
20
- def get_button_property_by_index(index, property)
21
- get_button_by_index(index) do |device|
22
- device.send "is_#{property}"
23
- end
24
- last_response.body
25
- end
26
-
27
- def get_button_property_by_id(id, property)
28
- get_view_by_id(id) do |device|
29
- device.send "is_#{property}"
30
- end
31
- last_response.body
32
- end
33
-
34
- def get_button_property_by_text(text, property)
35
- get_button_by_text(text) do |device|
36
- device.send "is_#{property}"
37
- end
38
- last_response.body
39
- end
40
19
  end
41
20
  end
42
21
  end
@@ -10,6 +10,12 @@ module Gametel
10
10
  end
11
11
  end
12
12
 
13
+ def click_on_view_by_class(clazz, index)
14
+ get_view_by_index(clazz, index) do |device|
15
+ device.click_on_view('@@the_view@@', :target => 'Robotium')
16
+ end
17
+ end
18
+
13
19
  def get_view_by_id(id, &block)
14
20
  chain_calls do |device|
15
21
  device.id_from_name(id, :target => 'Brazenhead', :variable => '@@view_id@@')
@@ -21,8 +27,10 @@ module Gametel
21
27
  def get_view_by_index(clazz, index, &block)
22
28
  chain_calls do |device|
23
29
  device.get_class
24
- device.for_name clazz, :variable => '@@the_type@@'
25
- device.get_view '@@the_type@@', index, :target => 'Robotium', :variable => '@@the_view@@'
30
+ device.get_class_loader :variable => '@@loader@@'
31
+ device.get_class
32
+ device.for_name clazz, false, '@@loader@@', :variable => '@@the_type@@'
33
+ device.get_view '@@the_type@@', index || 0, :target => 'Robotium', :variable => '@@the_view@@'
26
34
  block.call device if block
27
35
  end
28
36
  end
@@ -0,0 +1,33 @@
1
+ require 'brazenhead'
2
+
3
+ module Gametel
4
+ module Platforms
5
+ module Webview
6
+
7
+ def click_on_webview(how, what, index=0, scroll=true)
8
+ find_web_element_by(how, what) do |device, by|
9
+ device.click_on_web_element(by, index, scroll, :target => :Robotium)
10
+ end
11
+ end
12
+
13
+ def enter_text_in_webview(how, what, text)
14
+ find_web_element_by(how, what) do |device, by|
15
+ device.enter_text_in_web_element(by, text, :target => :Robotium)
16
+ end
17
+ end
18
+
19
+ def clear_text_in_webview(how, what)
20
+ find_web_element_by(how, what) do |device, by|
21
+ device.clear_text_in_web_element(by, :target => :Robotium)
22
+ end
23
+ end
24
+
25
+ def find_web_element_by(how, what)
26
+ chain_calls do |device|
27
+ device.web_view_by(how, what, :variable => '@@by@@', :target => :Brazenhead)
28
+ yield device, '@@by@@'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,6 +7,7 @@ require File.join(File.dirname(__FILE__), 'brazenhead', 'spinner')
7
7
  require File.join(File.dirname(__FILE__), 'brazenhead', 'text')
8
8
  require File.join(File.dirname(__FILE__), 'brazenhead', 'view')
9
9
  require File.join(File.dirname(__FILE__), 'brazenhead', 'list_item')
10
+ require File.join(File.dirname(__FILE__), 'brazenhead', 'webview')
10
11
 
11
12
 
12
13
  module Gametel
@@ -21,6 +22,7 @@ module Gametel
21
22
  include Gametel::Platforms::View
22
23
  include Gametel::Platforms::ListItem
23
24
  include Gametel::Platforms::Menu
25
+ include Gametel::Platforms::Webview
24
26
 
25
27
  ENTER_KEY = 66
26
28
 
@@ -131,6 +133,7 @@ module Gametel
131
133
  def click_view(locator)
132
134
  result = click_on_text(locator[:text]) if locator[:text]
133
135
  result = click_on_view_by_id(locator[:id]) if locator[:id]
136
+ result = click_on_view_by_class(locator[:class], locator[:index]) if locator[:class]
134
137
  end
135
138
 
136
139
  #
@@ -146,7 +149,8 @@ module Gametel
146
149
  #
147
150
  def has_view?(locator)
148
151
  begin
149
- result = get_view_by_id(locator)
152
+ result = get_view_by_id(locator[:id]) if locator[:id]
153
+ result = get_view_by_index(locator[:class], locator[:index]) if locator[:class]
150
154
  result.body.include? 'windowLocation'
151
155
  rescue Exception
152
156
  false
@@ -1,3 +1,3 @@
1
1
  module Gametel
2
- VERSION = "0.7"
2
+ VERSION = "0.8"
3
3
  end
@@ -7,3 +7,4 @@ require 'gametel/views/progress'
7
7
  require 'gametel/views/spinner'
8
8
  require 'gametel/views/list_item'
9
9
  require 'gametel/views/image'
10
+ require 'gametel/views/web_view'
@@ -4,26 +4,12 @@ module Gametel
4
4
 
5
5
  protected
6
6
 
7
- def build_property_methods
8
- metaclass = class << self; self; end
9
- properties.each do |property|
10
- metaclass.send(:define_method, "#{property}?".to_sym) do
11
-
12
- platform.get_view_by_id(locator[:id]) do |device|
13
- device.send "is_#{property}"
14
- end if locator[:id]
15
-
16
- platform.get_button_by_index(locator[:index]) do |device|
17
- device.send "is_#{property}"
18
- end if locator[:index]
7
+ def get_view_by_index(clazz, index, &block)
8
+ platform.get_button_by_index(index, &block)
9
+ end
19
10
 
20
- platform.get_button_by_text(locator[:text]) do |device|
21
- device.send "is_#{property}"
22
- end if locator[:text]
23
-
24
- platform.last_response.body == "true"
25
- end
26
- end
11
+ def get_view_by_text(text, &block)
12
+ platform.get_button_by_text(text, &block)
27
13
  end
28
14
  end
29
15
  end
@@ -1,26 +1,8 @@
1
1
  module Gametel
2
2
  module Views
3
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
4
+ def view_class
5
+ 'android.widget.ImageView'
24
6
  end
25
7
  end
26
8
  end
@@ -2,28 +2,9 @@ module Gametel
2
2
  module Views
3
3
  class Progress < View
4
4
 
5
- PROGRESS_BAR_CLASS = 'android.widget.ProgressBar'
6
-
7
- protected
8
-
9
- def build_property_methods
10
- metaclass = class << self; self; end
11
- properties.each do |property|
12
- metaclass.send(:define_method, "#{property}?".to_sym) do
13
-
14
- platform.get_view_by_id(locator[:id]) do |device|
15
- device.send "is_#{property}"
16
- end if locator[:id]
17
-
18
- platform.get_view_by_index(PROGRESS_BAR_CLASS, locator[:index]) do |device|
19
- device.send "is_#{property}"
20
- end if locator[:index]
21
-
22
- platform.last_response.body == "true"
23
- end
24
- end
5
+ def view_class
6
+ 'android.widget.ProgressBar'
25
7
  end
26
-
27
8
 
28
9
  end
29
10
  end
@@ -2,28 +2,9 @@ module Gametel
2
2
  module Views
3
3
  class Spinner < View
4
4
 
5
- SPINNER_CLASS = 'android.widget.Spinner'
6
-
7
- protected
8
-
9
- def build_property_methods
10
- metaclass = class << self; self; end
11
- properties.each do |property|
12
- metaclass.send(:define_method, "#{property}?".to_sym) do
13
-
14
- platform.get_view_by_id(locator[:id]) do |device|
15
- device.send "is_#{property}"
16
- end if locator[:id]
17
-
18
- platform.get_view_by_index(SPINNER_CLASS, locator[:index]) do |device|
19
- device.send "is_#{property}"
20
- end if locator[:index]
21
-
22
- platform.last_response.body == "true"
23
- end
24
- end
5
+ def view_class
6
+ 'android.widget.Spinner'
25
7
  end
26
-
27
8
 
28
9
  end
29
10
  end
@@ -13,19 +13,36 @@ module Gametel
13
13
  'android.view.View'
14
14
  end
15
15
 
16
+ def raw_view(&block)
17
+ get_view_by_id(locator[:id], &block) if locator[:id]
18
+ get_view_by_index(view_class, locator[:index], &block) if locator[:index]
19
+ get_view_by_index(locator[:class], locator[:index] || 0, &block) if locator[:class]
20
+ get_view_by_text(locator[:text], &block) if locator[:text]
21
+ end
22
+
16
23
  protected
17
24
 
18
25
  def properties
19
26
  [:clickable, :enabled, :focusable, :focused, :selected, :shown]
20
27
  end
21
28
 
29
+ def get_view_by_id(id, &block)
30
+ platform.get_view_by_id(id, &block)
31
+ end
32
+
33
+ def get_view_by_index(clazz, index, &block)
34
+ platform.get_view_by_index(clazz, index, &block)
35
+ end
36
+
37
+ def get_view_by_text(text, &block)
38
+ raise NotImplementedError
39
+ end
40
+
22
41
  def build_property_methods
23
42
  metaclass = class << self; self; end
24
43
  properties.each do |property|
25
44
  metaclass.send(:define_method, "#{property}?".to_sym) do
26
- query_property = lambda {|device| device.send "is_#{property}" }
27
- platform.get_view_by_id(locator[:id], &query_property) if locator[:id]
28
- platform.get_view_by_index(view_class, locator[:index], &query_property) if locator[:index]
45
+ raw_view {|device| device.send "is_#{property}" }
29
46
  platform.last_response.body == "true"
30
47
  end
31
48
  end
@@ -0,0 +1,44 @@
1
+ module Gametel
2
+ module Views
3
+ class WebView < View
4
+
5
+ def click(how, what, index=0, scroll=true)
6
+ platform.click_on_webview(how, what, index, scroll)
7
+ end
8
+
9
+ def enter_text(how, what, text)
10
+ platform.enter_text_in_webview(how, what, text)
11
+ end
12
+
13
+ def type_text(how, what, text, index=0)
14
+ find_element_by(how, what) do |device, by|
15
+ device.type_text_in_web_element(by, text, index, :target => :Robotium)
16
+ end
17
+ end
18
+
19
+ def clear_text(how, what)
20
+ platform.clear_text_in_webview(how, what)
21
+ end
22
+
23
+ def wait_for_element(how, what, timeout=20, scroll=true)
24
+ find_element_by(how, what) do |device, by|
25
+ device.wait_for_web_element(by, timeout, scroll, :target => :Robotium)
26
+ end
27
+ end
28
+
29
+ def has_element?(how, what)
30
+ platform.get_web_views_by(how, what, :target => :Brazenhead)
31
+ not platform.last_json.empty?
32
+ end
33
+
34
+ protected
35
+
36
+ def find_element_by(how, what)
37
+ platform.chain_calls do |device|
38
+ device.web_view_by(how, what, :variable => '@@by@@', :target => :Brazenhead)
39
+ yield device, '@@by@@'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ require 'gametel/webviewable'
2
+ require 'gametel/webview/accessors'
3
+
4
+ module Gametel
5
+ module Webview
6
+ include Gametel::Webviewable
7
+
8
+ def self.included(cls)
9
+ cls.extend Gametel::Webview::Accessors
10
+ end
11
+
12
+
13
+ def has_element?(how, what)
14
+ platform.get_web_views_by(how, what, :target => :Brazenhead)
15
+ not platform.last_json.empty?
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require 'gametel/views/web_view'
2
+
3
+ module Gametel
4
+ module Webview
5
+ module Accessors
6
+
7
+ def link(name, locator)
8
+ index = value_or_default(locator, :index, 0)
9
+ locator = cleanup(locator)
10
+ define_method name do
11
+ platform.click_on_webview(locator.first[0], locator.first[1], index)
12
+ end
13
+ end
14
+
15
+ def text(name, locator)
16
+ locator = cleanup(locator)
17
+ define_method "#{name}=" do |text|
18
+ platform.enter_text_in_webview(locator.first[0], locator.first[1], text)
19
+ end
20
+ define_method "clear_#{name}" do
21
+ platform.clear_text_in_webview(locator.first[0], locator.first[1])
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def cleanup(locator)
28
+ loc = locator.first
29
+ key = nil
30
+ case loc[0]
31
+ when :text
32
+ locator.delete(:text)
33
+ key = :textContent
34
+ when :css
35
+ locator.delete(:css)
36
+ key = :cssSelector
37
+ when :class
38
+ locator.delete(:class)
39
+ key = :className
40
+ when :tag
41
+ locator.delete(:tag)
42
+ key = :tagName
43
+ end
44
+ locator[key] = loc[1] if key
45
+ locator
46
+ end
47
+
48
+ def value_or_default(locator, value, default)
49
+ locator[value] ? locator.delete(value) : default
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,67 @@
1
+ module Gametel
2
+ module Webviewable
3
+
4
+ attr_reader :platform
5
+
6
+ ROBOTIUM_LEFT = 21
7
+ ROBOTIUM_RIGHT = 22
8
+
9
+
10
+ def initialize(pform = :brazenhead)
11
+ @platform = Gametel::Platforms::BrazenheadPlatform.new if pform == :brazenhead
12
+ end
13
+
14
+ #
15
+ # click on the provided text
16
+ #
17
+ def click_on_text(text)
18
+ platform.click_on_text text
19
+ end
20
+
21
+
22
+ #
23
+ # Returns true if the provided text is found on the screen
24
+ #
25
+ def has_text?(text)
26
+ platform.has_text?(text)
27
+ end
28
+
29
+
30
+ #
31
+ # Wait for the provided text to appear
32
+ #
33
+ def wait_for_text(text_to_find)
34
+ platform.wait_for_text(text_to_find)
35
+ raise "Timed out waiting for the text '#{text_to_find}'" unless platform.last_json
36
+ end
37
+
38
+ #
39
+ # scroll down
40
+ #
41
+ def scroll_down
42
+ platform.scroll_down
43
+ end
44
+
45
+ #
46
+ # scroll up
47
+ #
48
+ def scroll_up
49
+ platform.scroll_up
50
+ end
51
+
52
+ #
53
+ # scroll left
54
+ #
55
+ def scroll_left
56
+ platform.scroll_to_side ROBOTIUM_LEFT
57
+ end
58
+
59
+ #
60
+ # scroll right
61
+ #
62
+ def scroll_right
63
+ platform.scroll_to_side ROBOTIUM_RIGHT
64
+ end
65
+
66
+ end
67
+ end
@@ -22,6 +22,7 @@ class AccessorsSampleScreen
22
22
  radio_button(:radio_index, :index => 1)
23
23
  view(:view_id, :id => 'some_view_id')
24
24
  view(:view_text, :text => 'Any view text')
25
+ view(:view_class, :class => 'com.example.views.YourCustomView', :index => 0)
25
26
  spinner(:spinner_id, :id => 'spinner_id')
26
27
  spinner(:spinner_index, :index => 1)
27
28
  progress(:progress_id, :id => 'progress_id')
@@ -30,6 +31,15 @@ class AccessorsSampleScreen
30
31
  image(:image_id, :id => 'image_id')
31
32
  end
32
33
 
34
+ RSpec::Matchers.define :load_the_class do |class_name|
35
+ match do |actual|
36
+ actual.should_receive(:get_class).ordered
37
+ actual.should_receive(:get_class_loader).with(:variable => '@@loader@@').ordered
38
+ actual.should_receive(:get_class).ordered
39
+ actual.should_receive(:for_name).with(class_name, false, '@@loader@@', :variable => '@@the_type@@').ordered
40
+ end
41
+ end
42
+
33
43
  describe Gametel::Accessors do
34
44
  context "when using Brazenhead" do
35
45
  let(:screen) { AccessorsSampleScreen.new }
@@ -113,8 +123,7 @@ describe Gametel::Accessors do
113
123
  end
114
124
 
115
125
  it "should know how to get text by index" do
116
- accumulator.should_receive(:get_class)
117
- accumulator.should_receive(:for_name).with('android.widget.EditText', :variable => '@@the_type@@')
126
+ accumulator.should load_the_class('android.widget.EditText')
118
127
  accumulator.should_receive(:get_view).with('@@the_type@@', 2, :target => 'Robotium', :variable => '@@the_view@@')
119
128
  accumulator.should_receive(:get_text)
120
129
  accumulator.should_receive(:to_string)
@@ -464,11 +473,16 @@ describe Gametel::Accessors do
464
473
  screen.view_id
465
474
  end
466
475
 
467
- it "should know how to be clicked by test" do
476
+ it "should know how to be clicked by text" do
468
477
  platform.should_receive(:click_on_text).with('Any view text')
469
478
  screen.view_text
470
479
  end
471
480
 
481
+ it "should know how to be clicked by class" do
482
+ platform.should_receive(:click_on_view_by_class).with('com.example.views.YourCustomView', 0)
483
+ screen.view_class
484
+ end
485
+
472
486
  context "when looking at properties" do
473
487
 
474
488
  it "should know if they are enabled" do
@@ -547,8 +561,7 @@ describe Gametel::Accessors do
547
561
 
548
562
  context "identified by index" do
549
563
  it "should be able to determine their selected item" do
550
- accumulator.should_receive(:get_class)
551
- accumulator.should_receive(:for_name).with('android.widget.Spinner', anything)
564
+ accumulator.should load_the_class('android.widget.Spinner')
552
565
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, anything)
553
566
  accumulator.should_receive(:get_selected_item)
554
567
  accumulator.should_receive(:to_string)
@@ -663,25 +676,23 @@ describe Gametel::Accessors do
663
676
  end
664
677
 
665
678
  context "identified by index" do
679
+ before(:each) do
680
+ accumulator.should load_the_class('android.widget.ProgressBar')
681
+ end
682
+
666
683
  it "should be able to set the progress" do
667
- accumulator.should_receive(:get_class)
668
- accumulator.should_receive(:for_name).with('android.widget.ProgressBar', :variable => '@@the_type@@')
669
684
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, :target => 'Robotium', :variable => '@@the_view@@')
670
685
  accumulator.should_receive(:set_progress_bar).with('@@the_view@@', 37, :target => 'Robotium')
671
686
  screen.progress_index = 37
672
687
  end
673
688
 
674
689
  it "should be able to set the secondary progress" do
675
- accumulator.should_receive(:get_class)
676
- accumulator.should_receive(:for_name).with('android.widget.ProgressBar', :variable => '@@the_type@@')
677
690
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, :target => 'Robotium', :variable => '@@the_view@@')
678
691
  accumulator.should_receive(:set_secondary_progress).with(74)
679
692
  screen.progress_index_secondary = 74
680
693
  end
681
694
 
682
695
  it "should be able to get the progress" do
683
- accumulator.should_receive(:get_class)
684
- accumulator.should_receive(:for_name).with('android.widget.ProgressBar', :variable => '@@the_type@@')
685
696
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, :target => 'Robotium', :variable => '@@the_view@@')
686
697
  accumulator.should_receive(:get_progress)
687
698
  result.should_receive(:body).and_return("37")
@@ -689,8 +700,6 @@ describe Gametel::Accessors do
689
700
  end
690
701
 
691
702
  it "should be able to get the secondary progress" do
692
- accumulator.should_receive(:get_class)
693
- accumulator.should_receive(:for_name).with('android.widget.ProgressBar', :variable => '@@the_type@@')
694
703
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, :target => 'Robotium', :variable => '@@the_view@@')
695
704
  accumulator.should_receive(:get_secondary_progress)
696
705
  result.should_receive(:body).and_return("74")
@@ -698,8 +707,6 @@ describe Gametel::Accessors do
698
707
  end
699
708
 
700
709
  it "should be able to get the max" do
701
- accumulator.should_receive(:get_class)
702
- accumulator.should_receive(:for_name).with('android.widget.ProgressBar', :variable => '@@the_type@@')
703
710
  accumulator.should_receive(:get_view).with('@@the_type@@', 1, :target => 'Robotium', :variable => '@@the_view@@')
704
711
  accumulator.should_receive(:get_max)
705
712
  result.should_receive(:body).and_return("100")
@@ -70,16 +70,22 @@ describe Gametel do
70
70
  screen.should be_enabled('some_id')
71
71
  end
72
72
 
73
- it "should know if a view exists" do
73
+ it "should know if a view exists by id" do
74
74
  result.should_receive(:body).and_return('windowLocation')
75
- platform.should_receive(:get_view_by_id).and_return(result)
76
- screen.should have_view('some_id')
75
+ platform.should_receive(:get_view_by_id).with('some_id').and_return(result)
76
+ screen.should have_view(:id => 'some_id')
77
77
  end
78
78
 
79
- it "should know if a view does not exist" do
79
+ it "should know if a view exists by class" do
80
+ result.should_receive(:body).and_return('windowLocation')
81
+ platform.should_receive(:get_view_by_index).with('some_class', 0).and_return(result)
82
+ screen.should have_view(:class => 'some_class', :index => 0)
83
+ end
84
+
85
+ it "should know if a view does not exist by id" do
80
86
  result.should_receive(:body).and_return('')
81
- platform.should_receive(:get_view_by_id).and_return(result)
82
- screen.should_not have_view('some_id')
87
+ platform.should_receive(:get_view_by_id).with('some_id').and_return(result)
88
+ screen.should_not have_view(:id => 'some_id')
83
89
  end
84
90
 
85
91
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gametel
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jeffrey S. Morgan
@@ -9,81 +10,92 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-06-08 00:00:00.000000000 Z
13
+ date: 2013-08-23 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: brazenhead
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
- version: 0.4.7
22
+ version: 0.4.8
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ! '>='
26
29
  - !ruby/object:Gem::Version
27
- version: 0.4.7
30
+ version: 0.4.8
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: ADB
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ! '>='
33
37
  - !ruby/object:Gem::Version
34
- version: 0.5.5
38
+ version: 0.5.6
35
39
  type: :runtime
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ! '>='
40
45
  - !ruby/object:Gem::Version
41
- version: 0.5.5
46
+ version: 0.5.6
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: page_navigation
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
52
  - - ! '>='
47
53
  - !ruby/object:Gem::Version
48
- version: '0.7'
54
+ version: '0.9'
49
55
  type: :runtime
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
60
  - - ! '>='
54
61
  - !ruby/object:Gem::Version
55
- version: '0.7'
62
+ version: '0.9'
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: rspec
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
68
  - - ! '>='
61
69
  - !ruby/object:Gem::Version
62
- version: 2.13.0
70
+ version: 2.14.0
63
71
  type: :development
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
76
  - - ! '>='
68
77
  - !ruby/object:Gem::Version
69
- version: 2.13.0
78
+ version: 2.14.0
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: cucumber
72
81
  requirement: !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
84
  - - ! '>='
75
85
  - !ruby/object:Gem::Version
76
- version: 1.2.0
86
+ version: 1.3.6
77
87
  type: :development
78
88
  prerelease: false
79
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
80
91
  requirements:
81
92
  - - ! '>='
82
93
  - !ruby/object:Gem::Version
83
- version: 1.2.0
94
+ version: 1.3.6
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: require_all
86
97
  requirement: !ruby/object:Gem::Requirement
98
+ none: false
87
99
  requirements:
88
100
  - - ! '>='
89
101
  - !ruby/object:Gem::Version
@@ -91,6 +103,7 @@ dependencies:
91
103
  type: :development
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
108
  - - ! '>='
96
109
  - !ruby/object:Gem::Version
@@ -131,9 +144,7 @@ files:
131
144
  - features/step_definitions/text_steps.rb
132
145
  - features/step_definitions/view_steps.rb
133
146
  - features/step_definitions/webview_steps.rb
134
- - features/support/ApiDemos.apk
135
147
  - features/support/core_ext/string.rb
136
- - features/support/debug.keystore
137
148
  - features/support/env.rb
138
149
  - features/support/hooks.rb
139
150
  - features/support/screens/action_bar.rb
@@ -150,10 +161,10 @@ files:
150
161
  - features/support/screens/image_view_screen.rb
151
162
  - features/support/screens/lists_menu_screen.rb
152
163
  - features/support/screens/main_menu_screen.rb
164
+ - features/support/screens/midex_webview_screen.rb
153
165
  - features/support/screens/never_will_exist.rb
154
166
  - features/support/screens/seek_bar_screen.rb
155
167
  - features/support/screens/views_menu_screen.rb
156
- - features/support/screens/webview_main_screen.rb
157
168
  - features/support/screens/webview_screen.rb
158
169
  - features/text.feature
159
170
  - features/view.feature
@@ -170,6 +181,7 @@ files:
170
181
  - lib/gametel/platforms/brazenhead/spinner.rb
171
182
  - lib/gametel/platforms/brazenhead/text.rb
172
183
  - lib/gametel/platforms/brazenhead/view.rb
184
+ - lib/gametel/platforms/brazenhead/webview.rb
173
185
  - lib/gametel/platforms/brazenhead_platform.rb
174
186
  - lib/gametel/version.rb
175
187
  - lib/gametel/views.rb
@@ -182,7 +194,11 @@ files:
182
194
  - lib/gametel/views/spinner.rb
183
195
  - lib/gametel/views/text.rb
184
196
  - lib/gametel/views/view.rb
197
+ - lib/gametel/views/web_view.rb
185
198
  - lib/gametel/waiter.rb
199
+ - lib/gametel/webview.rb
200
+ - lib/gametel/webview/accessors.rb
201
+ - lib/gametel/webviewable.rb
186
202
  - spec/lib/gametel/accessors/menu_spec.rb
187
203
  - spec/lib/gametel/accessors/text_spec.rb
188
204
  - spec/lib/gametel/accessors_spec.rb
@@ -191,27 +207,35 @@ files:
191
207
  - spec/lib/gametel_spec.rb
192
208
  - spec/spec_helper.rb
193
209
  homepage: http://github.com/leandog/gametel
194
- licenses: []
195
- metadata: {}
210
+ licenses:
211
+ - MIT
196
212
  post_install_message:
197
213
  rdoc_options: []
198
214
  require_paths:
199
215
  - lib
200
216
  required_ruby_version: !ruby/object:Gem::Requirement
217
+ none: false
201
218
  requirements:
202
219
  - - ! '>='
203
220
  - !ruby/object:Gem::Version
204
221
  version: '0'
222
+ segments:
223
+ - 0
224
+ hash: 2311635935970847416
205
225
  required_rubygems_version: !ruby/object:Gem::Requirement
226
+ none: false
206
227
  requirements:
207
228
  - - ! '>='
208
229
  - !ruby/object:Gem::Version
209
230
  version: '0'
231
+ segments:
232
+ - 0
233
+ hash: 2311635935970847416
210
234
  requirements: []
211
235
  rubyforge_project:
212
- rubygems_version: 2.0.3
236
+ rubygems_version: 1.8.25
213
237
  signing_key:
214
- specification_version: 4
238
+ specification_version: 3
215
239
  summary: High level wrapper around android drivers
216
240
  test_files:
217
241
  - features/button.feature
@@ -242,9 +266,7 @@ test_files:
242
266
  - features/step_definitions/text_steps.rb
243
267
  - features/step_definitions/view_steps.rb
244
268
  - features/step_definitions/webview_steps.rb
245
- - features/support/ApiDemos.apk
246
269
  - features/support/core_ext/string.rb
247
- - features/support/debug.keystore
248
270
  - features/support/env.rb
249
271
  - features/support/hooks.rb
250
272
  - features/support/screens/action_bar.rb
@@ -261,10 +283,10 @@ test_files:
261
283
  - features/support/screens/image_view_screen.rb
262
284
  - features/support/screens/lists_menu_screen.rb
263
285
  - features/support/screens/main_menu_screen.rb
286
+ - features/support/screens/midex_webview_screen.rb
264
287
  - features/support/screens/never_will_exist.rb
265
288
  - features/support/screens/seek_bar_screen.rb
266
289
  - features/support/screens/views_menu_screen.rb
267
- - features/support/screens/webview_main_screen.rb
268
290
  - features/support/screens/webview_screen.rb
269
291
  - features/text.feature
270
292
  - features/view.feature
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjEzOWQ4NTk3NWFmMDY3NmViMWY2NGI0YmUyZGNiNmEwMjRlNDI5Mg==
5
- data.tar.gz: !binary |-
6
- MDBhMDBhZjQ5MzZhODQyNzYzNmI2NzdiMGNmMjU5MTk4YTE1NGE3Yg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDhhZjlmY2NlYTQ3MDJiMDFlM2I0MGQwODdjNWE0MWE5NDhlNTRjZjNhY2Mx
10
- OTFmZGY2NTVkZjcyODUwZDQ3YzQ5ODRhNjI3MTUwODdjMDk2ZDhkZjA4NzE2
11
- ZDRkNTg3NDg2M2RjOWRiM2IxY2VhNGNlMTJkNzdlMTFmYzJmMjQ=
12
- data.tar.gz: !binary |-
13
- OTM4YTMzMjNjODhmNzdkMDEwOThmODIxM2QyYjJiMTk4ZWY5MTdkNWUwMTNl
14
- NjUwY2Q5Y2UwNzU2YTBhMTQ5ZGRiNDJjNmU1YzY3NGM2OWNhZjc5NjQ0MmU4
15
- NjY0ODZmOTk4Y2FmMGQxOTkzMTU2OTRhYTBlOGExZWNlZmYyODE=
@@ -1,8 +0,0 @@
1
- class WebviewMainScreen
2
- include Gametel
3
-
4
- activity 'MainActivity'
5
-
6
- button(:goto_webview, :text => 'Go to http://www.google.com')
7
-
8
- end