Skip to content

Instantly share code, notes, and snippets.

@jmoody
Created June 26, 2015 11:21
Show Gist options
  • Save jmoody/106d56a73beff1ffc291 to your computer and use it in GitHub Desktop.
Save jmoody/106d56a73beff1ffc291 to your computer and use it in GitHub Desktop.
Calabash iOS: Comprehensive exploration of programmatically changing a UITextField's auto-correct, capitalization, and spell-check settings

Tested on iOS 8 Simulators with all the Keyboard settings "On" (default state).

Partially tested on iOS 7.

  1. You can turn auto-correct on or off.
  2. Changing the capitalization has no effect.
  3. Changing the spell-check settings has no effect.

Any state changes need to be made before the keyboard is presented.

==

image

@keyboard
Feature: Typing on the Keyboard
In order to enter text like a user
As an app tester
I want Calabash to provide a Keyboard API
Background: Get me to the first tab
Given I see the first tab
@travis
Scenario: I should be able to type something
Then I type "Hello"
@no
Scenario: Turn off auto capitalization
And I turn off auto capitalization
Then I touch the text field
When I type "hello", I should see "hello"
@no
Scenario: Turn on ALL caps
And I turn on all caps
Then I touch the text field
When I type "hello", I should see "HELLO"
@no
Scenario: Turn on cap sentences (default)
And I turn on capitalize sentences
Then I touch the text field
When I type "hello. my name is.", I should see "Hello. My name is."
@yes
Scenario: Turn on auto correct
And I turn on auto correct
Then I touch the text field
When I type "exictement" and touch done
Then the text should be "excitement"
@yes
Scenario: Turn off auto correct
And I turn off auto correct
Then I touch the text field
When I type "exictement" and touch done
Then the text should be "exictement"
# Turning on spell checking makes no discernible difference.
@no
Scenario: Turn on spell checking
And I turn off auto correct
And I turn on spell checking
Then I touch the text field
When I type "exictement"
Then the text should be marked as incorrect
# Turning on spell checking makes no discernible difference.
@no
Scenario: Turn off spell checking
And I turn off auto correct
And I turn off spell checking
Then I touch the text field
When I type "exictement" and touch done
Then the text should be "exictement"
module CalSmokeApp
module Keyboard
CAPITALIZATION =
{
none: 0, # UITextAutocapitalizationTypeNone
words: 1, # UITextAutocapitalizationTypeWords
sentences: 2, # UITextAutocapitalizationTypeSentences
all: 3 # UITextAutocapitalizationTypeAllCharacters
}
CORRECTION =
{
default: 0, # UITextAutocorrectionTypeDefault,
off: 1, # UITextAutocorrectionTypeNo,
on: 2 # UITextAutocorrectionTypeYes
}
SPELL_CHECKING =
{
default: 0, # UITextSpellCheckTypeDefault,
off: 1, # UITextSpellCheckTypeNo,
on: 2 # UITextSpellCheckTypeYes
}
def auto_capitalization_type
query('UITextField', :autocapitalizationType).first
end
def set_auto_capitalization_type(name)
if keyboard_visible?
fail('Cannot set the capitalization type if the keyboard is visible')
end
type = CAPITALIZATION[name]
unless type
raise "Unknown capitalization type: '#{name}'. Valid names: :none, :words, :sentences, :all"
end
query('UITextField', [{setAutocapitalizationType:type}])
end
def auto_correct_type
query('UITextField', :autocorrectionType).first
end
def set_auto_correct_type(name)
type = CORRECTION[name]
unless type
raise "Unknown auto correct type: '#{name}'. Valid names: :default, :no, :yes"
end
query('UITextField', [{setAutocorrectionType:type}])
end
def spell_check_type
query('UITextField', :spellCheckingType).first
end
def set_spell_check_type(name)
type = SPELL_CHECKING[name]
unless type
raise "Unknown spell check type: '#{name}'. Valid names: :default, :no, :yes"
end
query('UITextField', [{setSpellCheckingType:type}])
end
end
end
World(CalSmokeApp::Keyboard)
And(/^I turn off auto capitalization$/) do
set_auto_capitalization_type :none
end
And(/^I turn on all caps$/) do
set_auto_capitalization_type :all
end
And(/^I turn on capitalize sentences$/) do
set_auto_capitalization_type :words
end
And(/^I turn (on|off) auto correct$/) do |on_or_off|
set_auto_correct_type(on_or_off.to_sym)
end
And(/^I turn (on|off) spell checking$/) do |on_or_off|
set_spell_check_type(on_or_off.to_sym)
end
Then(/^the text should be marked as incorrect$/) do
pending
end
Then(/^I touch the text field$/) do
touch('UITextField')
wait_for_keyboard
end
When(/^I type "([^"]*)", I should see "([^"]*)"$/) do |typed, expected|
keyboard_enter_text typed
actual = query('UITextField', :text).first
expect(actual).to be == expected
end
When(/^I type "([^"]*)" and touch done$/) do |typed|
keyboard_enter_text typed
tap_keyboard_action_key
end
Then(/^the text should be "([^"]*)"$/) do |expected|
actual = query('UITextField', :text).first
expect(actual).to be == expected
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment