Skip to content
Browse files

Add some new core Frank steps

  • Loading branch information...
1 parent 20e4a1d commit e77618bc98e06025d162d8a66c0f62b42a7877e2 @moredip committed
View
119 gem/lib/frank-cucumber/core_frank_steps.rb
@@ -59,11 +59,58 @@
end
end
+Then /I should not see the following:/ do |table|
+ values = frankly_map( 'view', 'accessibilityLabel' )
+ table.raw.each do |expected_mark|
+ values.should_not include( expected_mark.first )
+ end
+end
+
Then /^I should see a navigation bar titled "([^\"]*)"$/ do |expected_mark|
values = frankly_map( 'navigationItemView', 'accessibilityLabel' )
values.should include(expected_mark)
end
+Then /^I should see an alert view titled "([^\"]*)"$/ do |expected_mark|
+ values = frankly_map( 'alertView', 'message')
+ puts values
+ values.should include(expected_mark)
+end
+
+Then /^I should not see an alert view$/ do
+ check_element_does_not_exist( 'alertView' )
+end
+
+Then /^I should see an element of class "([^\"]*)" with name "([^\"]*)" with the following labels: "([^\"]*)"$/ do |className, classLabel, listOfLabels|
+ arrayOfLabels = listOfLabels.split(',');
+ arrayOfLabels.each do |label|
+ check_element_exists("view marked:'#{classLabel}' parent view:'#{className}' descendant view marked:'#{label}'")
+ end
+end
+
+Then /^I should see an element of class "([^\"]*)" with name "([^\"]*)" with a "([^\"]*)" button$/ do |className, classLabel, buttonName|
+ check_element_exists("view marked:'#{classLabel}' parent view:'#{className}' descendant button marked:'#{buttonName}'")
+end
+
+Then /^I should not see a hidden button marked "([^\"]*)"$/ do |expected_mark|
+ element_is_not_hidden("button marked:'#{expected_mark}'").should be_false
+end
+
+Then /^I should see a nonhidden button marked "([^\"]*)"$/ do |expected_mark|
+ element_is_not_hidden("button marked:'#{expected_mark}'").should be_true
+end
+
+Then /^I should see an element of class "([^\"]*)"$/ do |className|
+ element_is_not_hidden("view:'#{className}'")
+end
+
+Then /^I should not see an element of class "([^\"]*)"$/ do |className|
+ selector = "view:'#{className}'"
+ element_exists_and_is_not_hidden = element_exists( selector ) && element_is_not_hidden(selector)
+ element_exists_and_is_not_hidden.should be_false
+end
+
+
# -- Type/Fill in -- #
When /^I type "([^\"]*)" into the "([^\"]*)" text field$/ do |text_to_type, field_name|
@@ -84,7 +131,13 @@
end
# -- Rotate -- #
-Given /^the device is in (a )?landscape orientation$/ do
+Given /^the device is in (a )?landscape orientation$/ do |ignored|
+ # for some reason the simulator sometimes starts of reporting its orientation as 'flat'. Workaround for this is to rotate the device then wait a bit
+ if 'flat' == frankly_current_orientation
+ rotate_simulator_right
+ sleep 1
+ end
+
unless frankly_oriented_landscape?
rotate_simulator_left
sleep 1
@@ -92,11 +145,17 @@
end
end
-Given /^the device is in (a )?portrait orientation$/ do
+Given /^the device is in (a )?portrait orientation$/ do |ignored|
+ # for some reason the simulator sometimes starts of reporting its orientation as 'flat'. Workaround for this is to rotate the device then wait a bit
+ if 'flat' == frankly_current_orientation
+ rotate_simulator_right
+ sleep 1
+ end
+
unless frankly_oriented_portrait?
rotate_simulator_left
sleep 1
- raise "expected orientation to be portrait after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_portrait?
+ raise "Expected orientation to be portrait after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_portrait?
end
end
@@ -110,21 +169,44 @@
elsif direction == "left"
rotate_simulator_left
else
- puts "[" + red('ERROR') + "] Direction specified is INVALID!!"
+ raise %Q|Rotation direction specified ("#{direction}") is invalid. Please specify right or left.|
end
sleep 1
end
# -- touch -- #
When /^I touch "([^\"]*)"$/ do |mark|
- if element_exists("view marked:'#{mark}'")
- touch( "view marked:'#{mark}'" )
+ selector = "view marked:'#{mark}' first"
+ if element_exists(selector)
+ touch( selector )
else
- raise "[" + red('FAIL') + "] Can't touch. Element #{mark} does NOT exist!!"
+ raise "Could not touch [#{mark}], it does not exist."
end
sleep 1
end
+When /^I touch "([^\"]*)" if exists$/ do |mark|
+ sleep 1
+ selector = "view marked:'#{mark}' first"
+ if element_exists(selector)
+ touch(selector)
+ sleep 1
+ end
+end
+
+When /^I touch the first table cell$/ do
+ touch("tableViewCell first")
+end
+
+When /^I touch the table cell marked "([^\"]*)"$/ do |mark|
+ touch("tableViewCell marked:'#{mark}'")
+end
+
+When /^I touch the (\d*)(?:st|nd|rd|th)? table cell$/ do |ordinal|
+ ordinal = ordinal.to_i - 1
+ touch("tableViewCell index:#{ordinal}")
+end
+
Then /I touch the following:/ do |table|
values = frankly_map( 'view', 'accessibilityLabel' )
table.raw.each do |expected_mark|
@@ -146,8 +228,25 @@
touch( "actionSheet threePartButton tag:#{ordinal}" )
end
+When /^I touch the (\d*)(?:st|nd|rd|th)? alert view button$/ do |ordinal|
+ ordinal = ordinal.to_i
+ touch( "alertView threePartButton tag:#{ordinal}" )
+end
+
# -- switch -- #
+When /^I flip switch "([^\"]*)" on$/ do |mark|
+ selector = "view:'UISwitch' marked:'#{mark}'"
+ views_switched = frankly_map( selector, 'setOn:animated:', true, true )
+ raise "could not find anything matching [#{uiquery}] to switch" if views_switched.empty?
+end
+
+When /^I flip switch "([^\"]*)" off$/ do |mark|
+ selector = "view:'UISwitch' marked:'#{mark}'"
+ views_switched = frankly_map( selector, 'setOn:animated:', false, true )
+ raise "could not find anything matching [#{uiquery}] to switch" if views_switched.empty?
+end
+
When /^I flip switch "([^\"]*)"$/ do |mark|
touch("view:'UISwitch' marked:'#{mark}'")
end
@@ -179,6 +278,12 @@
# -- misc -- #
+
+When /^I wait for ([\d\.]+) second(?:s)?$/ do |num_seconds|
+ num_seconds = num_seconds.to_f
+ sleep num_seconds
+end
+
Then /^a pop\-over menu is displayed with the following:$/ do |table|
sleep 1
table.raw.each do |expected_mark|
View
7 gem/lib/frank-cucumber/frank_helper.rb
@@ -35,6 +35,13 @@ def check_view_with_mark_exists(expected_mark)
check_element_exists( "view marked:'#{expected_mark}'" )
end
+ # a better name would be element_exists_and_is_not_hidden
+ def element_is_not_hidden(query)
+ matches = frankly_map( query, 'isHidden' )
+ matches.delete(true)
+ !matches.empty?
+ end
+
def app_exec(method_name, *method_args)
operation_map = {
:method_name => method_name,
View
2 gem/lib/frank-cucumber/version.rb
@@ -1,5 +1,5 @@
module Frank
module Cucumber
- VERSION = "0.5.0"
+ VERSION = "0.5.1"
end
end

0 comments on commit e77618b

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