iOS UI Automation deactivateAppForDuration failure - ios

I'm working on my first UI Automation script and am encountering a failure at the deactivateAppForDuration line below:
// Verify password field is shown when app is moved to the foreground
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(10);
UIALogger.logMessage("move app to foreground");
The error I get from Instruments is:
Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]
What I see on the test device is that the app has been switched to the background and the iOS app switcher is showing. I can see my app (TimeClock). It appears from both the error message and the device screen that UI Automation isn't able to select my app for transition to the foreground.
Has anyone else encountered this problem? Is there a work-around?
Thanks.

I have tried your code and it works fine here. If you run the following code (nothing else) in a new Instruments file, does that work?
var target = UIATarget.localTarget();
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(1);
UIALogger.logMessage("move app to foreground");
Please note: Instruments is not always showing you exactly where an error happens. Sometimes its a few lines above or below the line it's showing.
BUT: the reason why the error happens is correct. I admit that you have a bug in this line, that I guess you are calling after coming back from the Springboard:
Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]
Are you sure the element switcherScrollView().buttons()["TimeClock"] exists in your app and are accessible?

I have had the same problem. Rebooting my device solved it for me.

Related

Xcode 9 crashing when running split view app on iPhone

After working just fine on both iPhone and iPad for a month, my Xcode 9 app has consistently started crashing causing me the following fatal problem: When I build & run it on an iPhone (simulator or device) Xcode completes loading the app and then crashes too fast for me to copy/paste the error from the debugger. When I run on iPad it works fine leading me to believe this is a result of something related to the split master/detail view.
If I use either an exception breakpoint or an "all C++ exceptions" it will stop at the AppDelegate class and crash if I hit play. If I use only an "all Objective-C exceptions" it will crash as before.
In the debug view hierarchy I get the following errors as well:
Error: Unable to capture view hierarchy.
Details: Log Title: Data source expression execution failure.
Log Details: error evaluating expression “(id)
[[(Class)objc_getClass("DBGTargetHub") sharedHub]
performRequestWithRequestInBase64:#"...
Log Method: -[DBGDataSourceConnectionLibViewDebugger
_executeLLDBExpression:forRequest:onPotentialThread:iteration:]
_block_invoke_2
Method: -[DBGViewDebugger updateDebugHierarchy]_block_invoke_2
I have tested other apps and this issue is unique to the app I am working on. Any ideas or debugging tips for how to proceed? I might just have to redo this whole project again if I can't even find the root cause of this! Appreciate any help.
Quick solution: Reset Simulator Device
I managed to resolve the above issue thanks to some serious digging. First, to resolve the instantaneous crash problem, I set a breakpoint at every line in the app delegate. That allowed me to narrow the error to a memory handling problem. From there I started running the code on one of each device available, and realized the crash only occurred on devices I had used earlier in development. Resetting those devices solved the problem.
The core issue here is that when you clean/rebuild your xcode program, it updates the app code on the device, but not necessarily the data model information. So when I changed my data model by including new data and renaming old data it was not properly updated.

Swift keyboard extension SIGQUIT, Execution was interrupted, reason: EXC_BREAKPOINT

When I try to build and run my keyboard extension, it sometimes just crashes with a Thread 1: signal SIGQUIT.
I am not able to reproduce the error. Sometimes I can build and run my app but most of the time the keyboard just quits. This happens on an actual device. In the simulator it does not open my keyboard and says Waiting to Attach.
The console does not output any errors at first. However, if I change the dropdown to View UI Hierachy in the Debug navigator I get the following description:
Details: No plist data for fetching view hierarchy: error evaluating expression “(id)[(Class)objc_getClass("DBGViewDebuggerSupport_iOS") fetchViewHierarchyWithOptions:(id)[(Class)objc_getClass("NSDictionary") dictionaryWithObjects:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:1]] arrayByAddingObject:(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:#"_UIVisualEffectBackdropView"] arrayByAddingObject:#"_UIBackdropEffectView"]] arrayByAddingObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:0]] forKeys:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:#"DBGViewDebuggerUseLayersAsSnapshots"] arrayByAddingObject:#"DBGViewDebuggerEffectViewsToSnapshotAsImage"] arrayByAddingObject:#"DBGViewDebuggerAlwaysEncodeLayers"]]]”: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18daddc34).
The process has been returned to the state before expression evaluation.
Method: -[DBGAbstractViewDescriber handleFetchedViewInfo:fetchError:resultHandler:]
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
I also took a screenshot of the processes.
Am I doing something wrong and how could I prevent that my keyboard extension quits all the time when running it? Is it actually a bug as it says in the description?
DISCLAIMER
It seems like something in xCode 8.2.1 is broken and the debugger is not correctly attaching to the correct process or the hosting process is not properly loading the new code.
This is a not a permanent solution but a temporary workaround.
WORKAROUND
I have been able to work around this issue by following the steps below.
Kill any process that is using your keyboard (important!)
Launch the application using the debugger so the latest code is deployed to the device
Navigate to Settings > General > Keyboards > etc.
Remove your custom keyboard
Re-add your custom keyboard
Debug the application once again
The reason this works is because removing the keyboard kills the process that is hosting the extension allowing Xcode to attach to the new binary.
As I understand this is a bug in Xcode 8.2.1. because before update my custom keyboard was working very well.
this is a temporary solution.
Run your code like always!
Bring up your keyboard until the error (SIGQUIT) appear!
Goto xcode > debug > detach
Goto again Xcode > debug > Attach to Process: attach the keyboard (it should be first process)
now, your breakpoints will work. but there are no log output unfortunately! I hope it temporary solve your problem

WKWebView error calling any javascript in iOS 10 while debugging

Fun error that ONLY happens in iOS 10, when debugging on a physical device. It does not happen in the simulator, or when running on the physical device (while not debugging). It also does not happen on an iOS 9 device in any situation...only iOS 10 while debugging and after any javascript call has been executed.
I have a hybrid web app, written in Swift 2.3, after the xwebview loads I call various javascript methods...actually, any in this case. Anyway, after the javascript method has finished I get a malloc error saying I'm trying to free a pointer.
malloc: *** error for object 0x1740b5060: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
So I set the break point...and it never breaks on the breakpoint, it just keeps telling me to set a breakpoint.
If I remove all of my javascript calls, the error never happens. I've tried enabling them one by one, it doesn't matter, they all break after the callback returns.
I've been after this for about 2 weeks, I'm out of extra hair to pull out. At this point I'd love to hear if someone else is seeing the same thing.
It looks like its a safari bug and therefore only appears when you are debugging your webview with safari. In Safari under Develop->Your_Device_Name uncheck "Automatically Show Web Inspector for JSContexts".
This should resolve your issue.

HockeySDK Warning - How to test crash reporting?

I got this warning when running my application with HockeyApp integration:
[HockeySDK] WARNING: Detecting crashes is NOT enabled due to running the app with a debugger attached.
Crash reports are not sent and no alert is displayed when opening the app again.
Any one have any idea how to resolve this issue?
This has very simple reasons:
If you are running the app with Xcode attached, your app is connected to lldb, Xcode's debugger. When lldb is attached, it will of course do its job as a debugger and catch any exception or crash that occurs. This means that the crash can never reach the HockeyApp SDK or any other crash reporting SDK while lldb is attached at the same time.
The solution is also pretty simple. If you just want to make sure the SDK is integrated properly and will catch crashes, do the following:
Do a quick "Build & Run" to install the current version of the app on the simulator or device.
Click the "Stop" button in Xcode to stop the debugging session.
Manually start the app on the device or simulator by tapping or clicking the app icon.
Cause a crash.
Restart the app. Now the HockeySDK should process the crash report and show a dialog to approve crash log sending.
One thing to keep in mind: Make sure to not make the app crash immediately after app start as this would not give the SDK enough time to process and send the crash report before crashing again.
Hockey app sdk by default does not send report when a debugger is attached. There is nothing wrong with this.
It will send report when a archive build that release to ur tester cause a crash. I personally think this should and remain as this because you are trying to track crashes from your tester not when you are developing.

iOS: App freezes and gives me an SIGABRT in xcode

When I start my app everything goes well. But if I close it, I mean really close it, and then opens it again it shows me the last open view and the app is totally freezed and xcode shows an SIGABRT error.
I have done so much, it's not that easy to just step backwards and see where it breaks. Any ideas?
Have you added an Exception Breakpoint in XCode? If something's wrong in your execution (possibly as a result of stored state from the previous execution that is now being loaded?), then you'll be able to see exactly where an exception happened before the program received the SIGABRT.
Ehm ok I might have done a noobie misstake...
I disconnected my phone from my computer (with the app totally closed) opened it and closed it again. Now when I open it, everything works. I guess you can't do that when running from xcode... he he...

Resources