Skip to content

Step Definition compendium

foozmeat edited this page Mar 23, 2011 · 19 revisions

What's this?

This page is intended to act as a place for useful Frank step definitions which aren't quite standard enough to add to the core frank steps. Please feel free to contribute your own useful codez.

Editing a text field using the keyboard

(see this thread for details)

This works for Pete's team:

    When /^I use the keyboard to fill in the textfield marked "([^\\"]*)" with "([^\\"]*)"$/ do |text_field_mark, text_to_type|
      text_field_selector =  "view marked:'#{text_field_mark}'"
      check_element_exists( text_field_selector )
      touch( text_field_selector )
      frankly_map( text_field_selector, 'setText:', text_to_type )
      frankly_map( text_field_selector, 'endEditing:', true )
    end

This works for Martin:

    When /^I use the keyboard to fill in the textfield marked "([^\\"]*)" with "([^\\"]*)"$/ do |text_field_mark, text_to_type| 
     text_field_selector =  "view marked:'#{text_field_mark}'" 
     check_element_exists( text_field_selector ) 
     frankly_map( text_field_selector, 'becomeFirstResponder' ) 
     frankly_map( text_field_selector, 'setText:', text_to_type ) 
     frankly_map( text_field_selector, 'endEditing:', true ) 
    end 

Resetting the app to first launch state

Given /^I reset the (iphone|ipad) app$/ do |device|
  steps "When I quit the simulator"
  SDK    = "4.3"
  APPLICATIONS_DIR = "/Users/#{ENV['USER']}/Library/Application Support/iPhone Simulator/#{SDK}/Applications"
  USERDEFAULTS_PLIST = "Library/Preferences/com.panic.#{APPNAME}.dist.plist"
  Dir.foreach(APPLICATIONS_DIR) do |item|
    next if item == '.' or item == '..' or item == '.DS_Store'
    if File::exists?( "#{APPLICATIONS_DIR}/#{item}/#{USERDEFAULTS_PLIST}")
      FileUtils.rm "#{APPLICATIONS_DIR}/#{item}/#{USERDEFAULTS_PLIST}" 
    end
  end
  steps "Given I launch the #{device} app"
end
Clone this wiki locally