Skip to content
Browse files

Make the screen size dynamic so that iPad's will work.

  • Loading branch information...
1 parent 6c81171 commit 1dc6616be89caf47d2ac95a2eaca734002eb5bdd Rob Holland committed Jun 14, 2010
Showing with 14 additions and 13 deletions.
  1. +2 −2 lib/icuke/cucumber.rb
  2. +12 −11 lib/icuke/screen.rb
View
4 lib/icuke/cucumber.rb
@@ -40,7 +40,7 @@ def tap(label, options = {}, &block)
}.merge(options)
element = screen.first_tappable_element(label)
- x, y = screen.element_position(element)
+ x, y = screen.element_center(element)
@simulator.fire_event(Tap.new(x, y, options))
@@ -52,7 +52,7 @@ def tap(label, options = {}, &block)
end
def swipe(direction, options = {})
- x,y,x2,y2 = screen.swipe_coordinates(direction)
+ x, y, x2, y2 = screen.swipe_coordinates(direction)
@simulator.fire_event(Swipe.new(x, y, x2, y2, 0.015, options))
sleep(1)
refresh
View
23 lib/icuke/screen.rb
@@ -1,10 +1,13 @@
require 'nokogiri'
class Screen
- attr_reader :xml
+ attr_reader :xml, :x, :y, :width, :height
def initialize(root)
@xml = Nokogiri::XML::Document.parse(root).root
+ frame = @xml.at_xpath('/screen/frame')
+ @x, @y = frame['x'].to_f, frame['y'].to_f
+ @width, @height = frame['width'].to_f, frame['height'].to_f
end
def exists?(text, scope = '')
@@ -13,18 +16,16 @@ def exists?(text, scope = '')
def visible?(text, scope='')
element = find_element(text, scope).first
- x, y = element_position(element)
- return x >= 0 && y >= 0 && x < 320 && y < 480
+ _x, _y = element_center(element)
+ return _x >= self.x && _y >= self.y && _x < self.width && _y < self.height
end
- def element_position(element)
- # This seems brittle, revist how to fetch the frame without relying on it being the only child
- frame = element.child
+ def element_center(element)
+ frame = element.at_xpath('./frame')
x = frame['x'].to_f
y = frame['y'].to_f
- # Hit the element in the middle
x += (frame['width'].to_f / 2)
y += (frame['height'].to_f / 2)
@@ -54,16 +55,16 @@ def first_slider_element(label)
def find_slider_button(element)
percentage = 0.01 * element['value'].to_f
- calculate_percentage_with_adjustment(element.child,percentage)
+ calculate_percentage_with_adjustment(element.child, percentage)
end
def find_slider_percentage_location(element, percentage)
percentage = 0.01 * percentage
- calculate_percentage_with_adjustment(element.child,percentage)
+ calculate_percentage_with_adjustment(element.child, percentage)
end
def center_coordinates
- return 320 / 2, 480 / 2
+ @center ||= element_center(@xml.at_xpath('/screen'))
end
def swipe_coordinates(direction)
@@ -80,7 +81,7 @@ def swipe_coordinates(direction)
private
- def calculate_percentage_with_adjustment(frame,percentage,adjustment=10)
+ def calculate_percentage_with_adjustment(frame, percentage, adjustment=10)
# need to adjust for padding around control - using 10 pixels default
x, y = frame['x'].to_f, frame['y'].to_f
width, height = frame['width'].to_f, frame['height'].to_f

0 comments on commit 1dc6616

Please sign in to comment.
Something went wrong with that request. Please try again.