UIAlertViews
General
These are handled pretty well in Frank. If you interact with your app in frank launch and track the changes in the symbiote that frank inspect launches with
button on, you can find the accessibility label that is associated with the Alert.
For an invalid login test, our alert’s title property was “Alert Title”, and the symbiote showed it to be a UILabel. Writing the following code allowed Frank to see the alert:
Then(/^I should see the 'Alert Title' alert$/) do
selector = "view:'UILabel' marked:'Alert Title'"
wait_for_element_to_exist( selector )
check_element_exists( selector )
endSystem Generated Alerts
However, some UIAlertViews are generated by a system call-back. Since these are not activated by a user, these do not show up on the View Hierarchy in the symbiote.
How To Simulate User’s Location
The frank discussion group on Google + gives a template as to what to do. I am going to explain how and why it works.
What ACTUALLY happens - in iOS Simulator - when you click “OK”
What ACTUALLY happens - in iOS Simulator - when you click “OK”
As on your phone, the iOS simulator holds application relevant data in a directory on your device. In this case, your device is the iOS simulator.
The iOS Simulator data’s folder is on your computer. cd into this folder and ls through each directory to get an idea of what you are working with:
~/Library/Application Support/iPhone Simulator/<version>/Library/Caches/
When you click “OK” to use “Current Location, a directory and document is created inside the iOS Simulator’s Caches directory:
/locationd/clients.plist
This document (and directory) remains when you:
- Quit or stop the iOS Simulator
- Reboot/shutdown computer
- Sleep mode of the computer
The document (and directory) is removed when you:
- Reset iOS Simulator
- When you do frank launch
The “Work-Around”
In order to simulate a user’s location, we will use the above information to simulate that the app already has the user’s location information, and so the system call-back to request confirm location information is not even called. Nice!
Basically: Write code that adds a valid /locationd/clients.plist to the iOS Simulator’s Caches directory.
The “Work-Around”: Step 1 - Create a “Frankified” location file
- Open your iOS simulator and find its version (mine was 7.0.3)
- Reset the simulator
- Quit the simulator
- Open a Terminal (Bash) window - (“window1”) and cd to ~/Library/Application Support/iPhone Simulator/<version>/Library/Caches/
- Type ls to see the list of directories and files.
- Open another Bash window - (“window2”)
- run frank launch from your app’s folder
- interact with your app and click OK on “location” alert.
- See /locationd/clients.plist created in window1 (if not, check iOS simulator’s version or reset simulator and cd into a different version - perhaps “-64”)
- quit simulator - important! Now you know exactly where to get your clients.plist from.
- copy this file to a location on desktop
- The following copies the file into the User’s “Documents” directory cp ~/Library/Application\ Support/iPhone\ Simulator/<version>/Library/Caches/locationd/clients.plist ~/Documents/
- Note: The forward slash, \ , used in directory names that have spaces. Without them the directory path ends prematurely, and the directory can’t be found.
The “Work-Around”: Step 2 - Insert a “Before” hook in test
A “Before” hook is sometimes called a “step”, but it is really a ruby call-back. It runs before the first step of each “Scenario” in your test suite. While “Background” will run after a “Before”, but also before any “Scenario steps.
Technically, once it is done once in your test suite, all the tests do not need to do it again. But if you do a frank launch or reset the simulator, it will need to be there. So keep the clients.plist in a safe place.
sudo vim Frank/features/newtest.feature
Insert anywhere - between “Feature:” and “Scenario:”
Feature: Navigating between screens
Before
Scenario: Moving from the ‘Home’ screen to the ‘Events’ screen
Given I launch the app
Then I should be on the Home screen
When I navigate to “Events”
Then I should be on the Events screen
sudo vim Frank/features/step_definitions/newtest_steps.rb
Insert “Before” step into you step_definitions file
Before do
FileUtils.cp ‘~/Documents/’, ‘~/Library/Application Support/iPhone Simulator/<version>/Library/Caches/locationd/’
end
Then /^I should be on the Home screen$/ do
check_element_exists “view:’UIImageView’ marked:’Home”
end
When /^I navigate to Events$/ do
touch “view:’UIButton’ marked:’Events’”
end
Then /^I should be on the Events screen$/ do
check_element_exist “view:’UIButton’ marked:’Events’”
end
run cucumber Frank/features/newtest.feature
Feature: Navigating between screens
Before
Scenario: Moving from 'Home' screen to 'Events' screen to 'Friends' screen # Frank/features/newtest.feature:
Given I launch the app # Frank/features/step_definitions/launch_steps.rb:5
Then I should be on the Home screen # Frank/features/step_definitions/newtest_steps.rb:5
When I navigate to “Events” # Frank/features/step_definitions/newtest_steps.rb:9
Then I should be on the Events screen # Frank/features/step_definitions/newtest_steps.rb:13
1 scenario (1 passed)
4 steps (4 passed)
CUKE SUCCESS!
Or… just enjoy the success...
p.s. I love xkcd comic strip at http://xkcd.com. These comics are from there. If you love them too, do go buy his book and/or see him on his"What If" book tour!
No comments:
Post a Comment