Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
renamed Page class to Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Jun 14, 2010
1 parent 425e47d commit 0be195b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
36 changes: 18 additions & 18 deletions lib/icuke/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'icuke/simulator'
require 'icuke/simulate'
require 'icuke/page'
require 'icuke/screen'

class ICukeWorld
include ICuke::Simulate::Gestures
Expand All @@ -21,8 +21,8 @@ def quit
@simulator.quit
end

def page
@page ||= Page.new(response)
def screen
@screen ||= Screen.new(response)
end

def response
Expand All @@ -38,8 +38,8 @@ def tap(label, options = {}, &block)
:pause => true
}.merge(options)

element = page.first_tappable_element(label)
x, y = page.element_position(element)
element = screen.first_tappable_element(label)
x, y = screen.element_position(element)

@simulator.fire_event(Tap.new(x, y, options))

Expand All @@ -51,7 +51,7 @@ def tap(label, options = {}, &block)
end

def swipe(direction, options = {})
x,y,x2,y2 = page.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
Expand All @@ -70,8 +70,8 @@ def drag_with_source(source, destination)
end

def drag_slider_to(label, direction, distance)
element = page.first_slider_element(label)
x, y = page.find_slider_button(element)
element = screen.first_slider_element(label)
x, y = screen.find_slider_button(element)

dest_x, dest_y = x, y
modifier = direction_modifier(direction)
Expand All @@ -86,9 +86,9 @@ def drag_slider_to(label, direction, distance)
end

def drag_slider_to_percentage(label, percentage)
element = page.first_slider_element(label)
x, y = page.find_slider_button(element)
dest_x, dest_y = page.find_slider_percentage_location(element, percentage)
element = screen.first_slider_element(label)
x, y = screen.find_slider_button(element)
dest_x, dest_y = screen.find_slider_percentage_location(element, percentage)
drag(x,y,dest_x,dest_y)
end

Expand Down Expand Up @@ -141,12 +141,12 @@ def type(textfield, text, options = {})
end

def scroll_to(text, options = {})
x,y,x2,y2 = page.swipe_coordinates(swipe_direction(options[:direction]))
x,y,x2,y2 = screen.swipe_coordinates(swipe_direction(options[:direction]))
previous_response = response.dup
while not page.onscreen?(text) do
while not screen.onscreen?(text) do
@simulator.fire_event(Swipe.new(x, y, x2, y2, 0.15, options))
refresh
raise %Q{Content "#{text}" not found in: #{page}} if response == previous_response
raise %Q{Content "#{text}" not found in: #{screen}} if response == previous_response
end
end

Expand All @@ -162,7 +162,7 @@ def set_application_defaults(defaults)

def refresh
@response = nil
@page = nil
@screen = nil
end

def swipe_direction(direction)
Expand Down Expand Up @@ -193,11 +193,11 @@ def direction_modifier(direction)
end

Then /^I should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, scope|
raise %Q{Content "#{text}" not found in: #{page}} unless page.exists?(text, scope)
raise %Q{Content "#{text}" not found in: #{screen}} unless screen.exists?(text, scope)
end

Then /^I should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, scope|
raise %Q{Content "#{text}" was found but was not expected in: #{page}} if page.exists?(text, scope)
raise %Q{Content "#{text}" was found but was not expected in: #{screen}} if screen.exists?(text, scope)
end

When /^I tap "([^\"]*)"$/ do |label|
Expand Down Expand Up @@ -233,5 +233,5 @@ def direction_modifier(direction)
end

Then /^show me the screen$/ do
puts page.xml.to_s
puts screen.xml.to_s
end
2 changes: 1 addition & 1 deletion lib/icuke/page.rb → lib/icuke/screen.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'nokogiri'

class Page
class Screen
attr_reader :xml

def initialize(root)
Expand Down
20 changes: 10 additions & 10 deletions spec/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
context "when draging a slider" do

before(:each) do
@page = []
@page.should_receive(:first_slider_element).at_least(:once)
@page.should_receive(:find_slider_button).at_least(:once).and_return([244, 287])
Page.should_receive(:new).at_least(:once).and_return(@page)
@screen = []
@screen.should_receive(:first_slider_element).at_least(:once)
@screen.should_receive(:find_slider_button).at_least(:once).and_return([244, 287])
Screen.should_receive(:new).at_least(:once).and_return(@screen)
end

it "should set the destination properly" do
Expand All @@ -108,14 +108,14 @@

before(:each) do
@element = []
@page = []
@page.should_receive(:first_slider_element).and_return(@element)
@page.should_receive(:find_slider_button).and_return([244, 287])
Page.should_receive(:new).and_return(@page)
@screen = []
@screen.should_receive(:first_slider_element).and_return(@element)
@screen.should_receive(:find_slider_button).and_return([244, 287])
Screen.should_receive(:new).and_return(@screen)
end

it "should identify the destination on the page" do
@page.should_receive(:find_slider_percentage_location).with(@element, 30).
it "should identify the destination on the screen" do
@screen.should_receive(:find_slider_percentage_location).with(@element, 30).
and_return([230, 287])
ICuke::Simulate::Gestures::Swipe.should_receive(:new).
with(244, 287, 230, 287, 0.15, {})
Expand Down
48 changes: 24 additions & 24 deletions spec/page_spec.rb → spec/screen_spec.rb
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
require 'spec/spec_helper'
require 'icuke/page'
require 'icuke/screen'

describe Page do
describe Screen do
before(:all) do
@xml = File.read('spec/fixtures/controls_page.xml')
end

before(:each) do
@page = Page.new(@xml)
@screen = Screen.new(@xml)
end

context "when testing if an element exists" do

it "should be able to search for a label" do
@page.exists?("Customized Slider").should be_true
@screen.exists?("Customized Slider").should be_true
end

it "should be able to search for a label within a scope" do
# why does this not work with any scope?
@page.exists?("Customized Slider", "UIWindow").should be_true
@screen.exists?("Customized Slider", "UIWindow").should be_true
end

it "should be able to search for a value" do
@page.exists?("50%").should be_true
@screen.exists?("50%").should be_true
end

it "should be able to search for a node" do
@page.exists?("UISlider").should be_true
@screen.exists?("UISlider").should be_true
end

it "should know when an element is visible on the screen" do
@page.onscreen?("Standard Slider").should be_true
@screen.onscreen?("Standard Slider").should be_true
end

end

context "when finding a tappable element" do

it "should find an element with a button trait" do
@page.first_tappable_element("Standard switch").name.should == "UISwitch"
@screen.first_tappable_element("Standard switch").name.should == "UISwitch"
end

it "should find an element with an updates_frequently trait" do
@page.first_tappable_element("Custom").name.should == "UIAccessibilityElementMockView"
@screen.first_tappable_element("Custom").name.should == "UIAccessibilityElementMockView"
end

it "should find an element by its label" do
@page.first_tappable_element("Customized Slider").name.should == "UILabel"
@screen.first_tappable_element("Customized Slider").name.should == "UILabel"
end

it "should raise an exception when the element is not found" do
lambda{@page.first_tappable_element("does_not_exist")}.should raise_error
lambda{@screen.first_tappable_element("does_not_exist")}.should raise_error
end

end

context "when finding a slider element" do

it "should find a slider by its label" do
@page.first_slider_element("Standard slider").name.should == "UISlider"
@screen.first_slider_element("Standard slider").name.should == "UISlider"
end

it "should find a slider by a UILabel withing the same parent" do
@page.first_slider_element("Standard Slider").name.should == "UISlider"
@screen.first_slider_element("Standard Slider").name.should == "UISlider"
end

it "should raise an exception when the element is not found" do
lambda{@page.first_slider_element("does_not_exist")}.should raise_error
lambda{@screen.first_slider_element("does_not_exist")}.should raise_error
end

end
Expand All @@ -83,7 +83,7 @@
set_frame_values(184,275,120,24)
{'50%' => 244, '100%' => 294, '75%' => 269, '25%' => 219, '0%' => 194}.each do |v|
@element['value'] = v[0]
x, y = @page.find_slider_button(@element)
x, y = @screen.find_slider_button(@element)
x.should == v[1]
y.should == 287
end
Expand All @@ -93,7 +93,7 @@
set_frame_values(184,175,24,120)
{'50%' => 235, '100%' => 285, '75%' => 260,'25%' => 210, '0%' => 185}.each do |v|
@element['value'] = v[0]
x,y = @page.find_slider_button(@element)
x,y = @screen.find_slider_button(@element)
x.should == 196
y.should == v[1]
end
Expand All @@ -112,7 +112,7 @@
it "should find percentage coordinate when slider is horizontal" do
set_frame_values(184,275,120,24)
{50 => 244, 100 => 294, 75 => 269, 25 => 219, 0 => 194}.each do |v|
x,y = @page.find_slider_percentage_location(@element, v[0])
x,y = @screen.find_slider_percentage_location(@element, v[0])
x.should == v[1]
y.should == 287
end
Expand All @@ -121,7 +121,7 @@
it "should find percentage coordinate when slider is vertical" do
set_frame_values(184,175,24,120)
{50 => 235, 100 => 285, 75 => 260, 25 => 210, 0 => 185}.each do |v|
x,y = @page.find_slider_percentage_location(@element, v[0])
x,y = @screen.find_slider_percentage_location(@element, v[0])
x.should == 196
y.should == v[1]
end
Expand All @@ -132,31 +132,31 @@
context "when finding the coordinates for a swipe" do

it "should start the coordinates with the center of the screen" do
x,y,x2,y2 = @page.swipe_coordinates(:down)
x,y,x2,y2 = @screen.swipe_coordinates(:down)
x.should == 160
y.should == 240
end

it "should end the swipe at the top center when swiping up" do
x,y,x2,y2 = @page.swipe_coordinates(:up)
x,y,x2,y2 = @screen.swipe_coordinates(:up)
x2.should == 160
y2.should == 0
end

it "should end the swipe at the bottom center when swiping down" do
x,y,x2,y2 = @page.swipe_coordinates(:down)
x,y,x2,y2 = @screen.swipe_coordinates(:down)
x2.should == 160
y2.should == 480
end

it "should end the swipe at the right center when swiping right" do
x,y,x2,y2 = @page.swipe_coordinates(:right)
x,y,x2,y2 = @screen.swipe_coordinates(:right)
x2.should == 320
y2.should == 240
end

it "should end the swipe at the left center when swiping left" do
x,y,x2,y2 = @page.swipe_coordinates(:left)
x,y,x2,y2 = @screen.swipe_coordinates(:left)
x2.should == 0
y2.should == 240
end
Expand Down

0 comments on commit 0be195b

Please sign in to comment.