Last active
December 18, 2015 09:29
-
-
Save rhgills/5761416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When(/^I hit the home button and reopen the app later$/) do | |
press_home_on_simulator | |
open_app_via_url | |
end | |
def open_app_via_url | |
# you have to define a scheme to start your application, let's use app-scheme:// | |
#this code creates a html page redirecting immediately to the given URL | |
html_format = "<!DOCTYPE HTML><html><head><title></title><meta http-equiv=\"refresh\" content=\"0;URL='%{LINK}'\"></head><body></body></html>" | |
html = html_format % { :LINK => 'x-yourapp://launch' } | |
# let's save the HTML to a temporary file | |
file = Tempfile.new(['launch', '.html']) | |
begin | |
file.write(html) | |
ensure | |
file.close | |
end | |
# open the html file in the simulator | |
%x( /usr/bin/open "#{file.path}" -a #{ios_simulator_path} ) | |
# wait until the app has closed and safari has opened | |
wait_until do | |
!element_exists('view isVisible') | |
end | |
# wait until the app is open or opening | |
wait_until do | |
element_exists('view isVisible') | |
end | |
file.unlink # only AFTER the file has actually been opened in the simulator | |
end | |
def ios_simulator_path | |
'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feel free to replace ios_simulator_path with "iPhone Simulator". This works, as long as you don't have two versions of Xcode installed for some reason. ;)