appium icon indicating copy to clipboard operation
appium copied to clipboard

Notification alert in iOS8 causes Appium session start to fail due to reported instruments crash on startup

Open chrigrahcisco opened this issue 12 years ago • 98 comments

THE FIX / WORKAROUND IS AS FOLLOWS:

What you need to do is insert a 5-8 second sleep IN THE SOURCE CODE OF YOUR APP just before the notification code IN THE SOURCE CODE OF YOUR APP. Caps are simply for emphasis so it's totally clear where the fix / workaround occurs as it has absolutely nothing to do with Appium. :)

For example, I open my project in Xcode and in my app's source code I find the notification code and add this simple sleep line of code:

 // Register for notifications
 sleep(8);

Ask your developers to help you with this. I have the the ability to pull source and generate my own builds but still needed help from my dev team to locate the proper module and proper notification code to properly inject the sleep.

This will let Appium load your app. You can then handle the notification UIAAlert via your test code.


Original problem report follows

Mac OSX 10.9.5 Xcode 6.1 Appium.app 1.3.3 Python 2.7

My AUT includes notification support. When installing the app on a real device on any iOS version you receive a startup notification dialog to allow / don't allow the app to send notifications. Using an iOS7.x simulator, this notification dialog is not presented. Based on initial research it appears a change with the latest Xcode and iOS8.x simulators allows this notification dialog to be presented within the simulator even though you cannot physically register the simulator for notifications.

This appears to present a problem when Appium initially tries to create the session, apparently because the AUT isn't successfully detected due to the notification, at least that is my guess at this time. I would say 90%+ of the time tests fail due to this issue, however occasionally it does manage to work and the tests proceed successfully.

Here is a snippet from the log.

2014-11-26 17:19:48:789 - info: [IOS_SYSLOG_ROW ] Nov 26 12:19:48 CHRIGRAH-M-2038 ScriptAgent[35039]: Warning - Target app is not frontmost

2014-11-26 17:19:48:815 - info: [debug] [INST] 2014-11-26 17:19:48 +0000 Fail: Could not start script, target application is not frontmost.

2014-11-26 17:19:48:925 - info: [IOS_SYSLOG_ROW ] Nov 26 12:19:48 CHRIGRAH-M-2038 com.apple.CoreSimulator.SimDevice.9C0D7887-CCD5-4A1A-BEBA-E079FBE1663E.launchd_sim34839: Service exited due to signal: Killed: 9

2014-11-26 17:19:49:036 - info: [IOS_SYSLOG_ROW ] Nov 26 12:19:49 CHRIGRAH-M-2038 SpringBoard[34850]: Application 'UIKitApplication:com.MYAPP[0x6ac2]' exited abnormally via signal.

2014-11-26 17:19:49:037 - info: [IOS_SYSLOG_ROW ] Nov 26 12:19:49 CHRIGRAH-M-2038 assertiond[34854]: notify_suspend_pid() failed with error 7 2014-11-26 17:19:49:037 - info: [IOS_SYSLOG_ROW ] Nov 26 12:19:49 CHRIGRAH-M-2038 assertiond[34854]: assertion failed: 13F34 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1

2014-11-26 17:19:49:698 - info: [debug] [INST] Instruments Trace Complete (Duration : 36.580814s; Output : /tmp/appium-instruments/instrumentscli0.trace)

2014-11-26 17:19:49:720 - info: [debug] [INSTSERVER] Instruments exited with code 0

2014-11-26 17:19:49:720 - info: [debug] Killall instruments

2014-11-26 17:19:49:722 - info: [debug] Instruments crashed on startup 2014-11-26 17:19:49:722 - info: [debug] Attempting to retry launching instruments, this is retry #1

chrigrahcisco avatar Nov 26 '14 17:11 chrigrahcisco

Does the autoAcceptAlerts capability not work in this case?

imurchie avatar Nov 26 '14 18:11 imurchie

No, it has no bearing.

chrigrahcisco avatar Nov 26 '14 19:11 chrigrahcisco

The problem is a race condition, between the notification coming up and the auto accepting happening. We currently push the loading of our code into the iOS instrumentation as early as possible. Unfortunately that is not (usually) early enough, hence the failure. Usually we recommend that you try to delay the request that opens the alert until as late as possible, as there is nothing Appium can do to get processing on the device earlier.

imurchie avatar Nov 26 '14 19:11 imurchie

I have no control over the alert. It is a system generated alert invoked automatically by iOS the first time you launch a newly installed app that has notifications enabled. Not a single line of my test code gets launched.

WebDriverException: Message: u'A new session could not be created. (Original error: Instruments crashed on startup)'

chrigrahcisco avatar Nov 26 '14 19:11 chrigrahcisco

I'm attempting to clarify the scenario.

"The problem is a race condition, between the notification coming up and the auto accepting happening. "

Note I have never used auto accept alerts in the past and have only enabled it per your request to test that scenario. I do not prefer to actually use auto accept as it dismisses all alerts, including other UIAlerts that occur within the app, such as a "What's New" UIAlert that is invoked at app startup, and the Logout UIAlert that I need to interact with.

chrigrahcisco avatar Dec 01 '14 18:12 chrigrahcisco

I've added this caps to deal with this kind of issue, and try to figure out a good solution. https://github.com/appium/appium/commit/9dc85d28fb7230d761c5c725add084c3dad6a952

Will be published in next release.

sebv avatar Dec 01 '14 18:12 sebv

I'm having the same issue - the AUT is throwing up a notifications alert on the app startup, and in 1.3.3, Appium would die because the target app wasn't foremost. As I mentioned in #4190, I'm updated to 1.3.4 but it's saying that waitForAppScripts is an unrecognized key.

gempesaw avatar Dec 10 '14 18:12 gempesaw

I have not yet tested this as I'm using Appium.app and it has not yet been updated to 1.3.4 I'll report back once the .app is current.

chrigrahcisco avatar Dec 10 '14 19:12 chrigrahcisco

I have been using the master branch and I still have this problem. I have to manually tap the OK (allow push notifications) to let the test start running. It does work every now and then, but not often. why would the app version make a difference? Im running server: Appium v1.3.4 (REV bdb8221d18b6edadb2c39a450fc3b11a5c58008a)

It just doesn't see the app as having been launched if there is an alert present.

thanks

hallbeck avatar Dec 12 '14 18:12 hallbeck

Pretty sure the cap isn't recognized in master yet (as of bdb8221); the relevant one line PR is #4253.

The app version only matters since the fix wasn't in 1.3.3, and it was supposed to be in 1.3.4, but due to a tiny bug, waitForAppScript is not active in the 1.3.4 tag.

Currently I'm just using autoAcceptAlerts until it gets fixed, but I'm not sure what script I'd pass to waitForAppScript for it dismiss the alert...

gempesaw avatar Dec 12 '14 18:12 gempesaw

Having same problem.

Appium stays in: info: [debug] And launch timeouts (in ms): {"global":90000} info: [debug] [INST] Waiting for device to boot...

Locally I can close the alert and appium resumes, but I am running things on SauceLabs, and don't have that option. I am using Appium 1.3.4

SenhorCastor avatar Dec 12 '14 18:12 SenhorCastor

Hi @sebv , sorry to bother, do you have an estimate of when 1.3.5 will go out with this fix?

Thanks in Advance

SenhorCastor avatar Dec 16 '14 19:12 SenhorCastor

Im having a problem using master now, so I'll have to wait for 1.3.5 as well. I hope it fixes it.

hallbeck avatar Dec 16 '14 19:12 hallbeck

I have the same problem too: when I run the tests one by one it is ok. But when I run them as a bunch ( using maven) it beaks all the time. Hopefully they will fix it with 1.3.5

bthuan avatar Jan 08 '15 04:01 bthuan

I installed 1.3.5-beta version of Appium.app using this link: https://bitbucket.org/appium/appium.app/downloads/appium-1.3.5-beta.dmg

I added this to my desired_capabilities: desired_caps['waitForAppScript'] = True

However, I'm not seeing any type of logging that indicates this is being utilized.

Unfortunately, the issue does not appear to be corrected and my tests continue to fail to execute a significant amount of the time (86% fail rate on my last test run). Let me know what I can do to help expedite a successful resolution.

PERTINENT APPIUM LOG SNIPPET

2015-01-27 19:24:38:441 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 ScriptAgent[15360]: Warning - Target app is not frontmost

2015-01-27 19:24:38:479 - info: [debug] [INST] 2015-01-27 19:24:38 +0000 Fail: Could not start script, target application is not frontmost.

2015-01-27 19:24:38:588 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 SpringBoard[15207]: Unable to get short BSD proc info for 15286: No such process

2015-01-27 19:24:38:596 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 com.apple.CoreSimulator.SimDevice.FBDF8D36-411C-46A6-A39D-3C609C79C079.launchd_sim15196: Service exited due to signal: Killed: 9

2015-01-27 19:24:38:705 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 SpringBoard[15207]: Application 'UIKitApplication:MYUAT[0xc789]' exited abnormally via signal. 2015-01-27 19:24:38:705 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 assertiond[15211]: assertion failed: 14B25 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1 2015-01-27 19:24:38:706 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 assertiond[15211]: notify_suspend_pid() failed with error 7 2015-01-27 19:24:38:706 - info: [IOS_SYSLOG_ROW ] Jan 27 14:24:38 CHRIGRAH-M-2038 assertiond[15211]: assertion failed: 14B25 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1

2015-01-27 19:24:39:231 - info: [debug] [INST] Instruments Trace Complete (Duration : 36.381435s; Output : /tmp/appium-instruments/instrumentscli0.trace)

2015-01-27 19:24:39:254 - info: [debug] [INSTSERVER] Instruments exited with code 0 2015-01-27 19:24:39:254 - info: [debug] Killall instruments

2015-01-27 19:24:39:259 - info: [debug] Instruments crashed on startup

chrigrahcisco avatar Jan 27 '15 20:01 chrigrahcisco

@chrigrahcisco the waitForAppScript cap is not a boolean--you actually need to write in a uiautomation js script in a string that appium will execute until it returns true

jlipps avatar Jan 27 '15 20:01 jlipps

A piece of sample code would be very helpful. Since this impacts most users, it should be as simple as possible.

hallbeck avatar Jan 27 '15 20:01 hallbeck

@hallbeck I disagree, Appium's default script should be sufficient for most users. The waitForAppScript cap is available for people for whom the default script doesn't work, and who know what they are doing. Are you saying the default script isn't working for most people? The default script simply waits for there to be at least one element in the UI hierarchy.

If it turns out that's a bad default script, we should replace it with a more functional one. Not sure what that would be, though.

jlipps avatar Jan 27 '15 20:01 jlipps

Im not doing anything tricky, or complicated. Our app doesn't either. But if I run my tests on a iOS8.x simulator I have to manually dismiss the "we would like to send you push notifications". On iOS 7.x it doesn't have the popups because iOS changed how they asked in iOS8. My tests were running fine until recently. Even when the pop up was there I could click OK in code. I'll have to check when I wrote the first issue on it here, but that was when it all broke for me. I believe that many have this problem and their workaround is to test on iOS 7 for now till you guys fix it. As it stands I cannot have my tests kick off and run without me sitting here to click OK. I tried the dismiss alerts, and that's fine if I'm not testing that a popup comes up in an error condition. So, I stopped doing that. I don't know about everyone else. But I need that example. I'm not "good" enough to be able to "just figure it out and write in a uiautomation js script ...." that completely lost me. I just want it to work.

hallbeck avatar Jan 27 '15 20:01 hallbeck

@hallbeck I agree that it would be ideal for appium to just work and handle this alert case. I'm not sure what that has to do with the waitForAppScript cap or why @sebv thinks that cap can handle this case. I guess we're talking about different things.

jlipps avatar Jan 27 '15 21:01 jlipps