How to run UIAutomation on simulator using Xcode bots - strange behaviour - ios

I would like to run UIAutomation tests on simulator using Xcode bots. I add this command to past-actions script launched after ARCHIVE phase in xcode:
instruments -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate" /Users/ktos/appliation.app -l 10000 -v
Xcode bots log followinng error:
instruments[6702:507] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Error Domain=com.apple.instruments Code=1 "Error Starting Recording" UserInfo=0x7fc053b3a310 {NSLocalizedDescription=Error Starting Recording, NSLocalizedRecoverySuggestion=At least one target failed to launch; aborting run}
Instruments Trace Error : Failed to start trace.
When I use exactly the same command in my terminal, on the same computer the instruments runs simulator without any problems. Do you have any idea what could be wrong ?

It may also be possible that Instruments is running in the background. Do a $ps -A and check and kill it.

Related

How to solve 'Test runner exited before starting test execution' error for iPhone Devices

Context -
We have E2E Testing running on the CI on the iPhone devices.
The script performs the following steps -
Build the Test runner app from code.
Extracts the app file from the IPA.
Re-codesign the app with the required Provision Profiles.
Creates a .xctestrun file
Uses the xcodebuild command like the following to run the test -
xcodebuild -sdk iphoneos -destination id=<device_id> -xctestrun <path_to_xctestrun_file> -resultBundlePath <path_to_test_bundle_file> test-without-building -only-testing:E2ETestsBundle.xctest/<test_filter>
The above command installs the runner and target app into the device and starts executing the test.
The apps get installed and uninstalled at each run during a single execution.
Problem -
During the execution, the xcodebuild CLI tool, suddenly loses connection to the device and is not able to install the apps into the device and then results in the following error -
Testing failed:
E2ETestsBundle.xctest:
E2ETestsBundle-Runner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying Error: Test runner exited before starting test execution. If you believe this error represents a bug, please attach the log file at /var/folders/1r/0xlnbmzd0yj3m_cc7p95yb4r0000gn/T/tmpl7d9p1s6/testResults.bundle/Staging/1_Test/Diagnostics/E2ETestsBundle-Configuration-Test Scheme Action-Iteration-1/E2ETestsBundle/Session-E2ETestsBundle-2022-04-13_205520-muaMCx.log))
** TEST EXECUTE FAILED **
Points to note -
The xcodebuild CLI tool will keep on failing with the error once it occurred until recovered.
Even while the xcodebuild is in a failed state, the devices are still accessible via Xcode IDE and other CLI tools like libimobiledevice and are able to install both the test runner and target applications.
This is occurring intermittently across all devices models and across subversions of iOS 14 and 15.
Recovery -
The only way to recover is to reboot the device.
Even after a reboot, the devices start facing this exception again after a few days of execution.
As we can’t keep on rebooting the device every time before execution, we need a solution to fix this problem.
Any help would be appreciated!!

RoutingHTTPServer not found build using xcodebuild

Mac OS: 10.13.4
Xcode: 9.3
Appium: 1.7.2
I am unable to build WebDriverAgent and install WebDriverAgent using xcode. I've reinstalled Appium and the current user does have R/W permissions in the folder where the appium modules are installed. I've also followed the real device setup tutorial
2018-04-12 10:47:58.039414-0500 WebDriverAgentRunner-Runner[233:6835] Running tests...
2018-04-12 10:47:58.924245-0500 WebDriverAgentRunner-Runner[233:6835] The bundle “WebDriverAgentRunner” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2018-04-12 10:47:58.925176-0500 WebDriverAgentRunner-Runner[233:6835] (dlopen_preflight(/var/containers/Bundle/Application/D2529C60-100A-4A31-AD0D-C5F4A33920F2/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner): Library not loaded: #rpath/RoutingHTTPServer.framework/RoutingHTTPServer
Referenced from: /private/var/containers/Bundle/Application/D2529C60-100A-4A31-AD0D-C5F4A33920F2/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/WebDriverAgentLib.framework/WebDriverAgentLib
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/D2529C60-100A-4A31-AD0D-C5F4A33920F2/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/WebDriverAgentLib.framework/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer: required code signature missing for '/private/var/containers/Bundle/Application/D2529C60-100A-4A31-AD0D-C5F4A33920F2/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/WebDriverAgentLib.framework/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer'
)
2018-04-12 10:47:59.008 xcodebuild[68163:1492596] Error Domain=IDETestOperationsObserverErrorDomain Code=6 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted}
Testing failed:
Early unexpected exit, operation never finished bootstrapping - no restart will be attempted
** TEST FAILED **
Follow below step:
Go to your appium installed path and go node_modules/appium-xcuitest-driver/WebDriverAgent and run below command from WebDriverAgent:
bashbash Scripts/bootstrap.sh -d Scripts/bootstrap.sh -d
and then execute below command from same folder
mkdir -p /Resources/WebDriverAgent.bundle
This will solve your problem
To fix this issue link the RoutingHTTPServer.framework in xcode on the general tab in the section Linked Frameworks and Libraries. Look here to see where to do this in xcode
Also if you're running on simulators you'll have to use appium's 1.8 beta

Error when running Appium on SauceLabs --> posix spawn failure, code 253

I am attempting to run my tests suit on SauceLabs cloud (using Appium) for a trial and I am repeatedly getting the following message in the log:
[33m[INST STDERR] posix spawn failure; aborting launch (binary == /var/folders/bl/1800rz_j7blcqx8pthyrq59h0000gn/T/tmpb4mJhr/myApp.app/myApp).[39m
2015-03-29 14:02:07:379 -
info: [debug] [33m[INST STDERR] Instruments Trace Error : Error Starting Recording[39m
2015-03-29 14:02:07:444 -
info: [debug] [90m[INSTSERVER] Instruments exited with code 253[39m
I think it has something to do with the way our app is compiled but the test works flawlessly on my local Mac and on my device as well (compiled for Debug).
I tried the same with their sample app and it works just fine. Is there something I am missing?
Thanks in advance, Pavel
If you're running on saucelabs you're probably in the iPhone simulator, which runs on x86_64 architecture. Its likely you're sending it an app compiled to run on ARM (what real iDevices use), which the simulator doesn't understand.
If you're using the xcodebuild command to build your app from the terminal, you can add the flag -sdk iphonesimulator8.1 or similar. It will handle the rest, and you should be able to run that on saucelabs.

Instruments Usage Error : Specified target process is invalid:

I'm running a test from the command line with UIAutomation and Instruments but have just got this error.
Instruments Usage Error : Specified target process is invalid: /path/to/app
instruments, version 6.1 (56160)
Restarting the iPhone simulator, Instruments and Xcode seems to fix the problem but it would be good to understand the problem and work out an easier / quicker fix.

Automation testing with instruments on device

I am trying to follow this post to run UIAutomation scripts on iOS devices from command line, but i can't make it work.
This is the command i am currently using :
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/X/Library/Developer/Xcode/DerivedData/TestiPhoneAutomation2-dyufpxsavtdqkybpagcoawdudzid/Build/Products/Debug-iphoneos/TestiPhoneAutomation2.app -e UIASCRIPT "/Users/X/Workspaces/TestiPhoneAutomation/test2.js" -e UIARESULTSPATH "/Users/X/Workspaces/TestiPhoneAutomation2/" -w 80bf5b...UDID...dfb52543 -v
It works well on simulator (replacing the Debug-iphoneos by Debug-iphonesimulator, it also ignore the -w in this case), but if i launch it using an application compiled for device it crash (i tried with release and debug, i get the same result).
The error i'm getting is :
posix spawn failure; aborting launch (binary ==
/Users/X/Library/Developer/Xcode/DerivedData/TestiPhoneAutomation2-dyufpxsavtdqkybpagcoawdudzid/Build/Products/Debug-iphoneos/TestiPhoneAutomation2.app/TestiPhoneAutomation2).
2012-10-03 12:10:36.609 instruments[76151:1603] Recording cancelled :
At least one target failed to launch; aborting run Instruments Trace
Error : Failed to start trace.
I got this same error, but I didn't have multiple copies of Instruments running. I got this working by putting the -w UDID arguments before the application, and only using the name of the application (with the application already deployed to the device).
The command line I used is the following (with Xcode 4.6):
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w <device_id> <app_name> -e UIASCRIPT <path_to_script> -e UIARESULTSPATH <path_to_results>
Pls check the sequence of UDID in command line in fact for all parameters also run on debug version of build only. Hope this works, because its working for me.
For anyone else having this problem, I'll explain what worked for me and how I solved this.
I did the ps command to see which processes are running. I found that instruments was still running. I then did killall instruments and that killed the instruments process. I then did my instruments command and it worked perfect after that.

Resources