Run UITests from command line Apple Watch - ios

I'm having troubles while running XCUITests on iPhone and paired apple watch (simulators) simultaneously using terminal. I can do it by hitting "test button" for each of my uitests targets separately, it works just fine, but I need to do it
1 - from command line
2 - simultaneously
However, I am able to run uitests from command line for the same iPhone simulator (that is paired with apple watch simulator) using
xcodebuild -workspace MyApp.xcworkspace -scheme 'MyApp' -destination 'name=iPhone 11' test
It works as expected- launches simulator and run tests
The problem is:
When I do the same for paired apple watch (it doesn't matter separately or simultaneously with this iPhone) tests for apple watch doesn't launch at all
xcodebuild -workspace MyApp.xcworkspace -scheme 'MyApp WatchKit App' -destination 'name=iPhone 11' test
Terminal says that:
The requested device could not be found because no available devices matched the request.
Available destinations for the "WatchTesterApp WatchKit App" scheme:
{ platform:iOS Simulator, id:2B6CA009-BF6B-4437-9E80-18D53EB003BA, OS:14.5, name:iPhone 11 }
But this device is here and listed as available
So, any suggestions? maybe someone had similar issue?
I will appreciate any help

So, after a long investigation and a long list of possible fixes that resolved nothing, I updated Xcode and tried to run the same command, which didn't work either and only after creating new clean project using new Xcode it finally worked.
I used:
xcodebuild test -workspace WatchTesterAppExample.xcworkspace -scheme 'WatchTesterAppExample WatchKit App' -destination 'platform=WatchOS Simulator,name=Apple Watch Series 7 - 45mm' &
xcodebuild test -workspace WatchTesterAppExample.xcworkspace -scheme 'WatchTesterAppExample' -destination 'platform=iOS Simulator,name=iPhone 13'
It worked for me on the simulators, didn't try it on real device yet
Interesting fact: I am still able to see this error in some case, especially when I don't specify platform in the 'destination'

Related

WatchOS 9.1/iOS 16.1 xcodebuild run on Apple Watch fails

Recently I updated my devices to the newest version and with this update I am having troubles to run xcodebuild commands when destination is my Apple Watch.
The problem is in the scheme configuration or devices visibility for scheme, or both
it is working when I use generic destination:
xcodebuild -project MyApp.xcodeproj -scheme 'MyApp WatchKit App' -destination generic/platform=watchOS build
command I used:
xcodebuild -workspace MyApp.xcworkspace -scheme 'MyApp WatchKit App' -destination 'platform=watchOS,id=Watch's ID'
And I see this error:
xcodebuild: error: The run destination My iPhone is not valid for Running the scheme 'MyApp WatchKit App'.
(null) needs to connect to determine its availability.
Check the connection between the device and its companion iPhone, and the connection between the iPhone and Xcode.
Both devices may also need to be restarted and unlocked.
Restarting and unlocking doesn't help.

Starting the simulator in XCode 9 (not headless)

I am trying to run both my unit and ui tests with xcodebuild like:
$ xcodebuild -scheme "MyAppScheme" -destination 'platform=iOS Simulator,name=iPhone 7 Plus,OS=11.0' build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
The problem is that the simulator doesn't start but instead is running heedlessly.
I am aware of the so called "headless simulator" introduced in XCode 9. Any ideas of how to run the tests with xcodebuild and launch the emulator ?
As far as I know there are no options to allow you to run the tests on a not headless Simulator.
However if a Simulator is already launched the tests will run on that Simulator instead of a headless one. So you can first launch the Simulator and then run the tests:
$ open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app && xcodebuild -scheme "MyAppScheme" -destination 'platform=iOS Simulator,name=iPhone 7 Plus,OS=11.0' build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

xctool doesn't run with the requested iOS version

I am running iOS tests on Circle CI using Xcode 6.4 and iOS 8.4 with this command:
xctool -workspace ios.xcworkspace -scheme ios test -sdk iphonesimulator8.4
But when the simulator runs, it fails to run my tests and I receive this error:
Test did not run: The simulator failed to start, or the TEST_HOST
application failed to run. Simulator error: Exception encountered
connecting to CoreSimulatorBridge: Unable to connect to
CoreSimulatorBridge
Looking at the logs, it looks like the simulator actually tries to run against iOS 9:
run-test iosTests.xctest (iphonesimulator9.0, iPhone 4s, application-test)
Is there a way to force it to run on iOS 8.4 so the tests would run?
I had the same issue recently on Circle CI. I'm not sure if it's related to xctool's newest version (0.2.7) or not, but adding this fixed it for me:
-destination platform='iOS Simulator,OS=8.4,name=iPhone 6'
So the full command in your case should be:
xctool -workspace ios.xcworkspace -scheme ios test -sdk iphonesimulator8.4 -destination platform='iOS Simulator,OS=8.4,name=iPhone 6'

XCode 6 Unit Testing Without Building

Is there a way to prevent the app from building when I am just unit testing? When I run the test it builds the app and that takes minutes. I have written the tests in Swift and targets ios 8.
In Xcode 8+, you can pass the "test-without-building" option.
$ xcodebuild -workspace <your_xcworkspace> -scheme <your_scheme> -sdk iphonesimulator -destination ‘platform=iOS Simulator,name=<your_simulator>,OS=10.2’ test-without-building
Read more here: https://medium.com/xcblog/speed-up-ios-ci-using-test-without-building-xctestrun-and-fastlane-a982b0060676

"You can’t open the application because it is not supported on this type of Mac." xcodebuild

When I try to build my xcode project using the following command:
xcodebuild -workspace "Converse.xcworkspace" -sch
eme "Converse" -configuration “Debug” -sdk iphonesimulator7.1 -arch i386 ONLY_
ACTIVE_ARCH=NO
It builds fine, but when I try to double click on the app it generates, it says: You can’t open the application because it is not supported on this type of Mac. Does anyone know why this is happening?
iOS apps need the simulator to run. You can just, as you said run them from Xcode. If you do not have the project then you need to deploy them like :
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication /Path/ToIso.app/AppName
Use Xcode, not xcodebuild, to run your app on the simulator.

Resources