iOS Simulator Crashing On First Command

Hello everyone,
New Appium user here. I recently upgraded to XCode 7 and am having an issue when attempting to run an appium test from a Ruby file. Here is the test:

require 'rubygems'
require 'appium_lib'

APP_PATH = '../../MyApp.app'

desired_caps = {
    caps: {
	    platformName: 'iOS',
	    versionNumber: '9.0',
	    deviceName: 'iPhone 5s',
	    app: APP_PATH

    },
    appium_lib: {
	    sauce_username: nil,
	    sauce_access_key: nil
    }
}

Appium::Driver.new(desired_caps).start_driver

module MyApp
    module IOS

	    Appium.promote_singleton_appium_methods MyApp

	    links = tags('UIALink').map { |link| link.name }
	    wait { text(links[0]).click }


	    driver_quit
    end
end

Here is the output in the node console:

info: [debug] [INST] 2015-09-21 20:35:33 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-09-21 20:35:33 +0000 Debug: Lookup returned [object UIAStaticText] with the name "Start Using iRule" (id: 2).
info: [debug] [INST] 2015-09-21 20:35:33 +0000 Debug: responding with:
info: [debug] [INST] 2015-09-21 20:35:33 +0000 Debug: Running system command #7: /usr/local/bin/node /Users/brandon/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":[{"ELEMENT":"2"}]}...
info: [debug] Socket data received (40 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":[{"ELEMENT":"2"}]}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"2"}],"sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}
info: <-- POST /wd/hub/session/911b3b29-b6ea-45d1-85ef-a759e3d7860b/execute 200 935.841 ms - 89 {"status":0,"value":[{"ELEMENT":"2"}],"sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}
info: --> POST /wd/hub/session/911b3b29-b6ea-45d1-85ef-a759e3d7860b/element/2/click {}
info: [debug] Pushing command to appium work queue: "au.tapById('2')"
info: [debug] Sending command to instruments: au.tapById('2')
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: Got new command 7 from instruments: au.tapById('2')
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: evaluating au.tapById('2')
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: target.frontMostApp().mainWindow().elements()[0].elements()[0].elements()[4].elements()[0].tap()
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: responding with:
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Debug: Running system command #8: /usr/local/bin/node /Users/brandon/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}
info: <-- POST /wd/hub/session/911b3b29-b6ea-45d1-85ef-a759e3d7860b/element/2/click 200 1150.311 ms - 74 {"status":0,"value":"","sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}
info: --> DELETE /wd/hub/session/911b3b29-b6ea-45d1-85ef-a759e3d7860b {}
info: Shutting down appium session
info: [debug] Stopping ios
info: [debug] Destroying instruments client socket.
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Sending sigterm to instruments
info: [debug] [INST] 2015-09-21 20:35:34 +0000 Stopped: Script was stopped by the user
info: [debug] [INST STDERR] 2015-09-21 16:35:34.656 instruments[11892:420185] Attempting to change event horizon while disengage
info: [debug] [INST] Instruments Trace Complete (Duration : 25.703119s; Output : /tmp/appium-instruments/instrumentscli0.trace)
info: [debug] [INSTSERVER] Instruments exited with code 0
info: [debug] Cleaning up after instruments exit
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killing any other simulator daemons
info: [debug] Killall iOS Simulator
info: [debug] Cleaning sim data files
info: node-simctl: Executing: xcrun with args: simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E and timeout: 2000
info: node-simctl: Executing: xcrun with args: simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E and timeout: 2000
info: node-simctl: Executing: xcrun with args: simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E and timeout: 2000
info: node-simctl: Executing: xcrun with args: simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E and timeout: 2000
info: node-simctl: Executing: xcrun with args: simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E and timeout: 2000
error: Could not reset simulator. Leaving as is. Error: Command 'xcrun simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E' exited with code 159
info: [debug] Cleaning app data files
warn: Applications directory /Users/brandon/Library/Developer/CoreSimulator/Devices/43DDA937-831C-4786-8E9A-A7414757DD3E/data/Applications doesn't exist. Have you run this simulator before?
info: Couldn't find app directories to delete. Probably it's not installed
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}
info: <-- DELETE /wd/hub/session/911b3b29-b6ea-45d1-85ef-a759e3d7860b 200 11018.126 ms - 76 {"status":0,"value":null,"sessionId":"911b3b29-b6ea-45d1-85ef-a759e3d7860b"}

In practice, what happens is that the simulator is able to launch the app, but then stops when I try to send the click command. I haven’t been able to locate anyone else experiencing this same issue and would very much appreciate some help if anyone has any insight. Thank you!

-Brandon

Couple of questions for you:

  1. Did this work previously?

  2. What does ‘driver_quit’ do? If you comment that out, do you get the same crash?

  3. How many ‘UIALink’ elements are there on this screen? Seems like 2 of them are clicked ok.

1 Like

Hi @wreed,

Thanks for your quick reply! Taking ‘driver_quit’ out absolutely solved this issue. I will certainly need to be more careful when using their example code and make sure I really understand what they’re doing and when. Thanks!

-Brandon

Glad that worked out for you. In your logs I was seeing a crash when the simulator is being reset. This command: ‘xcrun simctl erase 43DDA937-831C-4786-8E9A-A7414757DD3E’ is what is causing your problem.

You may have a corrupt simulator. Please see this previous post about fixing this: