Simple XCTest for UITest is failing all the time? - ios

I start a new project from File -> New -> project
I add a button to ViewController.
I open UITest folder which created by xcode by default. Run the test code.
It fails:
2016-03-16 12:57:09.191 XCTRunner[3511:150419] Continuing to run tests in the background with task ID 1
t = 10.18s Assertion Failure: UI Testing Failure - Failed to background test runner.
/Users/Bernard/Desktop/ExampleTestApplication/ExampleTestApplicationUITests/test2.m:27: error: -[test2 testExample] : UI Testing Failure - Failed to background test runner.
2016-03-16 12:57:12.789 XCTRunner[3511:150419] *** Terminating app due to uncaught exception '_XCTestCaseInterruptionException', reason: 'Interrupting test'
Now I add a break point as follow:
Now test is successful! Anyone can explain the reason?

I was also facing same issues and none of the available solutions worked for me. Issue was not letting app to attach to the simulator itself.
I checked the log and saw that i did a mistake in code while locating the element. for Predicate instead of BEGINSWITH i wrote STARTSWITH and this was stopping the app to get attached.
So check your logs in the test report to get the issue.

I was getting this error happening when the iOS simulator was already launched (which may not necessarily mean you can see it in the OS X dock). You can check the state of the various simulators using the simctl command.
I.e.
xcrun simctl list devices
Then, ensure that any devices listed as "Booted" are shutdown:
xcrun simctl shutdown <device-udid-here>
Then, try running your UI tests again.

Related

iOS UITests failed: IDETestOperationsObserverErrorDomain Code=13

I am running an AppUITests for an iOS app from Jenkins build script. Unit tests (AppTests) running fine but AppUITests are failed because of the below issue. How can I resolve this issue?
09:19:53.506 XCTRunner[22911:77924] Failed to background test runner
within 30.0s. 09:19:53.507 xcodebuild[22835:77541]
-[IDETestOperationCoordinator testRunnerSession:initializationForUITestingDidFailWithError:]
09:19:53.507 XCTRunner[22911:77924] Calling completion. 09:19:53.507
xcodebuild[22835:77541] Test operation failure: Failed to background
test runner. 09:19:53.507 xcodebuild[22835:77541]
_finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=13 "Failed to background test runner."
UserInfo={NSLocalizedDescription=Failed to background test runner.}
didCancel: 1
I had the same issue in our app. It was caused by a permission alert displayed on launch (APN in this case, but it's likely to be the same for any other alert).
Steps to reproduce
use an app which will display a permission alert on launch
make sure the simulator is clean (in order to show the alert)
run all Tests
Result
app launches, shows the alert and runs the (normal) Tests just fine
BUT when coming to UITests, the simulator will stay black and after a short while, it fails with following error:
Error Domain=IDETestOperationsObserverErrorDomain Code=13 "Failed to
background test runner.
Solution
Run the UITests before the normal Tests (just change the order in edit scheme => Test => Info)
Notes:
Maybe you have to make sure, the UITests will handle the alert by using XTests addUIInterruptionMonitor method. Or otherwise it could be possible the (normal) Tests will fail the same way (didn't test this scenario).
If you really don't want to run the UITests first, you could add an additional UITest target, which is run first, and just handles the alert. Then you should be able to run the (normal) Tests followed by your UITests.
Related
https://discuss.bitrise.io/t/test-ui-xcode-9/2313

Build successful but unable to run on iOS simulator

I am making a demo of cordova app. The console log is showing me build successful but after sometime it shows this error and run fails :
2016-07-30 09:34:47.609 instruments[9268:1431174] WebKit Threading
Violation - initial use of WebKit from a secondary thread. Instruments
Usage Error: Unknown device specified:
"B7257830-92A2-4C85-A4BA-342D7237F9A8"
Known Devices:
test's iPhone (8.4.1) [7fdfcc5aaeb179fdb53a86343ba18796a1825bc4]
The error is to replace UDID with known devices but I am unable find the file where it is mentioned.
Please share the path of file or file name or anything related to this error. Thanks in advance.
I solved this error simply following two steps.
Step 1: Go to Run Options and select Run Configuration as image shown below.
Step 2 : Now a window will open as shown below & select your device from simulator list.

_XCTFailInCurrentTest should only be called while a test is running

I am now doing for UITesting with Xcode and I got this error.
* Assertion failure in void _XCTFailInCurrentTest(NSString *,
...)(),
/Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63
2016-05-13 22:31:54.961 XCTRunner[15428:168507] * Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'_XCTFailInCurrentTest should only be called while a test is running.
Failure description: Failed to receive completion for
I have seen other similar post here.
Cannot run Xcode (7.3) UI tests in Jenkins
I am using Jenkins but for now, I am directly running from Xcode and I can't even run from Xcode. How shall I do?
Background
I faced this issue in Xcode 7.3 (7D175) and iOS Simulator 9.3.
The symptoms were as follows
the Test Runner launches normally and exits.
Following this, the app under test never launches.
(if the app under test was not installed, Xcode will also never install the app prior to starting the test).
(a side symptom is that recording also does not work for me - I took inspiration from this SO post.)
After 30 seconds the test times out with:
XCTRunner[36260:489138] Continuing to run tests in the background with task ID 1
2016-05-18 16:17:25.720 XCTRunner[36260:489138] *** Assertion failure in void _XCTFailInCurrentTest(NSString *, ...)(), /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63
2016-05-18 16:17:25.723 XCTRunner[36260:489138] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_XCTFailInCurrentTest should only be called while a test is running.
Failure description: Failed to receive completion for <XCDeviceEvent:0x7fddc241f970 page 12 usage 64 duration 0.01s within 30.0s'
The fix that worked for me was:
reset the simulator.
check whether the deployment target is set to iOS 9.x in the build settings for the UI Test Target. (in my case it was set to iOS 8)
after changing the target, clean and rebuild.
After following these steps, Xcode was able to install the app prior to the test, recording worked, and the error went away.
By some reason simulator got corrupted. In my case it was not possible to launch any test once get at the same point. In my case what it worked was reset simulator (Menu Simulator|Reset Contents and Settings...) or switch to any other simulator.
We tried the tips from the other responses, which did not work for us.
A complete reinstall of Xcode 7.3 fixed our issue.
remove Xcode
restart
reinstall Xcode
success

UI Tests no longer working on Xcode 7.3

I have a set of XCUITests that run with our iOS app. They used to run fine on Xcode 7.2.1, but upgrading to 7.3 causes tests to fail in the "Set Up -> Wait for app to idle" phase with the following error:
UI Testing Failure - Failed to perform AX action for monitoring the animations of <XCUIApplicationProcess: 0x7f82450288c0 [appName here] (25670)>, error: Error -25204 performing AXAction 2043
This failure is seen on every single UI test, both on bots and when running locally.
Has anyone else seen this or have any workarounds?
In case anyone still has this issue - for me it was activating the Optimizely framework that caused this error. Disabling the framework when running XCUITest solved it for me.
Note to self: Don't have code that crashes your app on purpose while tests are trying to run. D:
Basically there was a call to terminate the app within the launch phase of the app for a certain scheme (in our case, the TEST scheme). Be thorough in checking what the app is doing when it launches for testing, because there might be errant behavior.

calabash-ios physical device test, app starts but crashes

Running calabash-ios cucumber for simple iPhone app. Simulator is working perfectly. When trying on physical device, app loads, crashes, then loads again, and crashes again, on a loop.
Error message:
Unable to start. Make sure you've set APP_BUNDLE_PATH to a build supported by this simulator version
Calabash::Cucumber::Launcher::StartError: Time out waiting for UIAutomation run-loop Error while writing to fifo. RunLoop::Fifo::NoReaderConfiguredError.
Logfile /var/folders/9s/yttj4cz93m98hqs6bfw2x8xr0000gn/T/run_loop20150522-12657-dr3m49/run_loop.out
2015-05-22 19:58:11 +0000 Fail: An error occurred while trying to run the script.
Instruments Trace Complete (Duration : 2.594758s; Output : /var/folders/9s/yttj4cz93m98hqs6bfw2x8xr0000gn/T/run_loop20150522-12657-dr3m49/trace.trace)
to run the script. UIAScriptAgentSignaledException
(Calabash::Cucumber::Launcher::StartError)
/Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.14.3/lib/calabash-cucumber/launcher.rb:766:in `new_run_loop'
/Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.14.3/lib/calabash-cucumber/launcher.rb:631:in `relaunch'
Steps:
loaded app-cal on device
ran in command-line using:
$ DEVICE_TARGET=udid BUNDLE_ID=com.company.app DEVICE_ENDPOINT=http://ip:37265
Error while writing to fifo. RunLoop::Fifo::NoReaderConfiguredError
The probably cause of this is that the device is not enabled for UIAutomation. The device must be enabled for development. A device is enabled for development if it appears in Xcode's Device's window (Shift + Command +2) and you must enable on-device testing manually by visiting the device's Settings.app > Developer tab.
If you have recently upgraded the iOS version we recommend that you check the UIAutomation settings again and perform a restart. Often, after an upgrade, Xcode cannot download debugging information from the device. Look at Xcode's Device's window. The device must appear without any warnings.
Sometimes devices get into a bad state and Xcode cannot communicate with it. We recommend trying to interact with the device with Apple's Instruments to clear this bad state.
All this information and more can be found on the Calabash iOS Hot Topics page. https://github.com/calabash/calabash-ios/wiki/Hot-Topics#6-errnoeintr-interrupted-system-call

Resources