Skip to content

Commit

Permalink
can use :class in Gametel#has_view?
Browse files Browse the repository at this point in the history
  • Loading branch information
leviwilson committed Jul 3, 2013
1 parent e450ca7 commit 62f137c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions features/has_view.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Feature: Determining whether or not a view exists
Scenario: Checking the existence of a view
When I'm on the buttons screen
Then we should know that the view with id "button_normal" exists
And we should know that the view with class "android.widget.Button" exists

Scenario: Checking the absence of a view
When I'm on the buttons screen
Then we should know that the view with id "checkbox_button" does not exist
And we should know that the view with class "android.widget.ListView" does not exist
10 changes: 6 additions & 4 deletions features/step_definitions/has_view_steps.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Then /^we should know that the view with id "(.*?)" exists$/ do |with_this_id|
Then /^we should know that the view with (\w+) "(.*?)" exists$/ do |how, what|
on(ButtonScreen) do |screen|
screen.should have_view(with_this_id)
locator = {}; locator[how.to_sym] = what
screen.should have_view(locator)
end
end

Then /^we should know that the view with id "(.*?)" does not exist$/ do |with_this_id|
Then /^we should know that the view with (\w+) "(.*?)" does not exist$/ do |how, what|
on(ButtonScreen) do |screen|
screen.should_not have_view(with_this_id)
locator = {}; locator[how.to_sym] = what
screen.should_not have_view(locator)
end
end

2 changes: 1 addition & 1 deletion lib/gametel/platforms/brazenhead/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_view_by_index(clazz, index, &block)
device.get_class_loader :variable => '@@loader@@'
device.get_class
device.for_name clazz, false, '@@loader@@', :variable => '@@the_type@@'
device.get_view '@@the_type@@', index, :target => 'Robotium', :variable => '@@the_view@@'
device.get_view '@@the_type@@', index || 0, :target => 'Robotium', :variable => '@@the_view@@'
block.call device if block
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/gametel/platforms/brazenhead_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def has_text?(text)
#
def has_view?(locator)
begin
result = get_view_by_id(locator)
result = get_view_by_id(locator[:id]) if locator[:id]
result = get_view_by_index(locator[:class], locator[:index]) if locator[:class]
result.body.include? 'windowLocation'
rescue Exception
false
Expand Down
18 changes: 12 additions & 6 deletions spec/lib/gametel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ class GametelSampleScreen
screen.should be_enabled('some_id')
end

it "should know if a view exists" do
it "should know if a view exists by id" do
result.should_receive(:body).and_return('windowLocation')
platform.should_receive(:get_view_by_id).and_return(result)
screen.should have_view('some_id')
platform.should_receive(:get_view_by_id).with('some_id').and_return(result)
screen.should have_view(:id => 'some_id')
end

it "should know if a view does not exist" do
it "should know if a view exists by class" do
result.should_receive(:body).and_return('windowLocation')
platform.should_receive(:get_view_by_index).with('some_class', 0).and_return(result)
screen.should have_view(:class => 'some_class', :index => 0)
end

it "should know if a view does not exist by id" do
result.should_receive(:body).and_return('')
platform.should_receive(:get_view_by_id).and_return(result)
screen.should_not have_view('some_id')
platform.should_receive(:get_view_by_id).with('some_id').and_return(result)
screen.should_not have_view(:id => 'some_id')
end


Expand Down

0 comments on commit 62f137c

Please sign in to comment.