how to reset the app to first launch state?

30 views
Skip to first unread message

zy199...@163.com

unread,
Mar 12, 2015, 3:58:29 AM3/12/15
to frank-...@googlegroups.com
I want to make my frank test suite be able to login repeatedly. And I've found 'Resetting the app to first launch state' at http://www.testingwithfrank.com/user_steps.html :

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.yourcompany.#{APPNAME}.dist.plist"
  Dir.foreach(APPLICATIONS_DIR) do |item|
    next if item == '.' or item == '..'
    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

=.= I've changed the "SDK" to "7.1" , but it seems not work, and I got this error:
uninitialized constant APPNAME (NameError)
=.= I checked the directory - /Users/#{ENV['USER']}/Library/Application Support/iPhone Simulator/#{SDK}/Applications , but I can't find
the app I'm testing ... I'm using xcode6.2
can anyone help me to solve this problem? thanks! sorry I'm not good at English...

Michael Buckley

unread,
Mar 12, 2015, 10:17:47 PM3/12/15
to frank-...@googlegroups.com
Hi,

Try replacing the value of USERDEFAULTS_PLIST to your app's bundle identifier

Given /^I reset the (iphone|ipad) app$/ do |device|
  steps "When I quit the simulator"
  SDK    = "7.1"
  APPLICATIONS_DIR = "/Users/#{ENV['USER']}/Library/Application Support/iPhone Simulator/#{SDK}/Applications"
  USERDEFAULTS_PLIST = "Library/Preferences/com.example.MyApp.dist.plist" # Replace com.example.MyApp with your app's bundle identifier
  Dir.foreach(APPLICATIONS_DIR) do |item|
    next if item == '.' or item == '..'
    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


Also, you may have to set the SDK to "7.1-64", Have a look at the folders in ~/Library/Application\ Support/iPhone\ Simulator

Each folder in there is a possible SDK value. You can find which one has your app on the command line like this

find ~/Library/Application\ Support/iPhone\ Simulator | grep com.example.MyApp



--
You received this message because you are subscribed to the Google Groups "Frank" group.
To unsubscribe from this group and stop receiving emails from it, send an email to frank-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

zy199...@163.com

unread,
Mar 13, 2015, 8:44:07 PM3/13/15
to frank-...@googlegroups.com
Hi, Michael , thanks for your help
I log the bundlePath of the app, and It's like this :
/Users/user_name/Library/
Developer/CoreSimulator/Devices/2214EA44-01D2-4F86-8BA3-469062E28B32/data/Applications/..........
i guess xcode6(which I'm using) change the path of app installed to the simulator? so I change the 'reset app' method and now it works for me :

APPLICATIONS_DIR_1 = "/Users/#{ENV['USER']}/Library/Developer/CoreSimulator/Devices"
USERDEFAULTS_PLIST = "Library/Preferences/com.companyName.myApp.frankified.plist"

def app_folder
    Dir.foreach(APPLICATIONS_DIR_1) do |item|
       
        next if item.index(".") == 0
        _applications_dir_2 = "#{APPLICATIONS_DIR_1}/#{item}/data/Applications"
        next if !File.directory?( _applications_dir_2 )
        Dir.foreach( _applications_dir_2 ) do |item|
           
            next if item.index(".") == 0
            if File.file?("#{_applications_dir_2}/#{item}/#{USERDEFAULTS_PLIST}")
                puts "found the app_folder"
                return "#{_applications_dir_2}/#{item}"
            end
           
        end
       
    end
   
    return nil
end

Given /^I reset the app on simulator$/ do

    steps "When I quit the simulator"
   
    _app_folder = app_folder
    if _app_foldert != nil
        FileUtils.rm "#{_app_folder}/#{USERDEFAULTS_PLIST}"
    end

    steps "Given I launch the app"
end

Given /^I delete the app on simulator$/ do

    steps "When I quit the simulator"
   
    _app_folder = app_folder
    if _app_folder != nil
        FileUtils.rm_rf _app_folder
    end
   
    steps "Given I launch the app"
end


在 2015年3月13日星期五 UTC+8上午10:17:47,Michael Buckley写道:
Reply all
Reply to author
Forward
0 new messages