Xamarin.UITest Unable to contact test backend running in app - ios

I'm trying to test my Xamarin.Forms app with Xamarin.UITest. Android works fine, but the iOS part has problems. When executing my first test to get into REPL I get the following error:
SetUp : System.Exception : Unable to contact test backend running in app. A common cause is that the app is not properly linked with Calabash. Please verify that it includes the Calabash component.
The strange thing is, when uploading the app to the Microsoft App Center it starts a test. It just hangs because it fails to find my toolbaritems. I wanted to check for a valid query with REPL by doing the iOS test on my Mac, while I'm usually working on Visual Studio on Windows.
I tried the solutions I found online with no luck
My .iOS project includes the Xamarin.TestCloud.Agent
In the AppDelegate.cs I have Xamarin.Calabash.Start() directly after global::Xamarin.Forms.Forms.Init().
I have NUnit 2.6.4 and NUnitTestAdapter 2.1.1 in the UITest project
I am using my Debug/IPhoneSimulator configuration
I am compiling an .app file from Visual Studio on Windows connected to a Mac and start the iOS test on the Mac.
This is my current code for the AppInitializer:
return ConfigureApp.iOS.AppBundle(sPathToiOS).PreferIdeSettings().StartApp();
Sometimes I also get a different error:
SetUp : Xamarin.UITest.XDB.Exceptions.DeviceAgentException : Unable to contact DeviceAgent
----> System.AggregateException : One or more errors occurred.
----> Xamarin.UITest.XDB.Exceptions.DeviceAgentException : Unable to contact DeviceAgent on 127.0.0.1
----> System.Net.Http.HttpRequestException : An error occurred while sending the request
----> System.Net.WebException : Error: ConnectFailure (Connection refused)
----> System.Net.Sockets.SocketException : Connection refused
This seems to be happening when the simulator is not running when starting the test and it takes to long to start the simulator.

I had to make sure I had re-deployed the app onto the simulator I am going to test on, with all the necessary steps in place.
What happened to me specifically is that I added the Xamarin.Calabash.Start() to the AppDelegate.cs file, but I had to make sure to redeploy to the simulator (by just starting the app in debug mode in my case), exiting out, then starting up the UI test(s).
This will ensure that the correct version of the app is on the simulator. This is the only way to test on the simulator; it won't deploy the app for you before running the tests.

So if someone has a similar problem like me and comes into this question: My solution is to connect a physical device to the the Mac and run my UI-Test on it. Keep in mind that you have to activate UIAutomation in the developersettings on the device. Now I can run my tests with no problem.

In my case, Calabash was not included in the build of my Xamarin.iOS solution when running my Xamarin.UITest.
I've fixed my problem by following this documentation :
adding Xamarin.TestCloud.Agent in the Xamarin.iOS project
launch Xamarin.Calabash.Start() in AppDelegate.cs file

In my case Xamarin.Calabash.Start() was under a preprocessor directive (#if TEST) that was not executed. Just make sure the directive is in place to solve the issue

Related

Issue with using On-Demand Resource through Xamarin.iOS on iOS simulator

I have run into an issue where I am unable to access assets tagged for use in Apple’s On-Demand Resource feature through a Xamarin.iOS app, but only when run on the simulator. This only occurred after updating my environment. I was previously on Visual Studio for Mac version 8.3.9 and Xcode version 11.2.1, and my app was able to access ODR resources without issue on both simulator and physical device.
Now I am on Visual Studio version 8.4.2 and Xcode version 11.3.1, and my app is not functioning correctly. However, I am only seeing issues when running on an iOS simulator (for any iOS version). I can build and run on a physical device (running iOS version 13.0)and am seeing no problems.
I am creating and tagging an asset for use in Apple ODR through Visual Studio for Mac. I have a ZIP file that I add into my app’s iOS project directly as a resource. In its properties, I set the BuildAction as BundleResource, select “Do Not Copy” to output directory, and give it an On-Demand Resource tag.
When I build my solution, I can see this ZIP file nested in a *.assetpack directory under bin/iPhone/Debug/device-builds/iphone12.3-13.0/OnDemandResources. I believe it is supposed to be put in bin/iPhone/Debug/OnDemandResources/ instead. When I run the code that calls NSBundleResourceRequest’s BeginAccessingResourcesAsync, it seemingly does nothing. I see the following error message in the Application Output debug window in VS after that function is called:
Begin: Request 0x0x600002566100 response: Error: Error Domain=NSCocoaErrorDomain Code=4994 "The requested application data doesn’t exist." UserInfo={NSLocalizedFailureReason=InvalidTag}
There’s no other error or exception being thrown. When I try to get the resource path from the NSBundleResourceRequest.Bundle object, it expectedly returns null.
Any reason why this is happening, and why this is only occurring on the iOS simulator and not on a physical device? I haven’t been able to find anything useful when searching for the above error message. Did something change in Visual Studio regarding how bundled assets are built in Debug mode?
Not really an answer, but more of a workaround. Using version 8.3.9 of VS for Mac seems to not throw this error, so I reverted back to that version

Error when build app on xcode (Failed to load bundle)

I'm facing this error after tried to build a new project from xCode and Command Line. Last month stuff was working fine on mac, same wifi connection, same device, same programmer (hehe) same everything. And now this... also, it's important to say that my boss created a new user on mac to start work on his projects of React (not Native, just React) and I think he probably installed some stuff there and maybe this is the cause of this error, idk...
also I got this on my node commandLine, it has correlation with the error above?

Deploying Xamarin.Forms app to iOS: MT1006 EOF Error (error: 0xe800000e)

I am trying to run a Xamarin.Forms app on my iPad and getting the following error:
Launch failed. The app 'AppIOS' could not be launched on 'My iPad'. Error: error MT1006: Could not install the application '/Users/mycompany/Library/Caches/Xamarin/mtbs/builds/AppIOS/someguid/bin/iPhone/Debug/my.app' on the device 'My iPad': EOF Error (error: 0xe800000e).. Please check the logs for more details.
This app has previously ran fine on the same device. The iOS build and deployment process seems very unstable so it often takes multiple attempts so I'm used to having to restart Visual Studio, the Mac it builds on and the iPad and generally wasting a whole lot of time. I have restarted everything involved here multiple times but this error persists. I have checked the device logs and there are no related messages or even any messages at the appropriate times.
I'm using Visual Studio 2017 (15.9.4), Xamarin.iOS and Xamarin.Mac SDK (12.2.1.12), building on a Mac Mini running macOS Mojave and XCode 10.1, deploying to an iPad Air (A1474) running iOS 12.1.1. As far as I'm aware there have been no updates to any of these since I last had it working. The UWP version of the app runs fine.
I can find a lot of MT1006 issues but none with EOF Error (error: 0xe800000e) and I can find no information about this specific error at all. Can anyone enlighten me on what this means?
Sounds overly simple, but I just had this issue and I solved it by restarting the iOS device and redeploying it. Specifically, I was deploying to an iPod 6th Gen and I held the power and home buttons until the screen turned black, this is more of a hard restart. Then let the device reboot and try deploying again.
NOTE: Don't hold the power and home buttons too long, because if you do, the iPod will go into a factory reset restart.
Try pulling up the device in Xcodes' devices tab. I did and realized the device had an error within the tab. I then disabled the "Connect via network" button, then things started to work properly.
I am agree, Xamarin build environment on iOS part is very buggy.
In any case of unknown error in such config: VS<->MAC<->iOS Device try these steps:
Try to switch Off and On Mac wifi.
Reconnect VS to Macbook and Macbook to IPhone.
Delete bin and obj folders on Macbook
Check your PList and Entitlements file(as example wrong aps-environment setting can cause installing errors)
Check your sign project settings
5a. Check your provisoning profile term
unistall application from ios
rebuild and run project again
I'll appent new lines in case i'll remember something else.
What you described happened to me and solved by 1,2,7

Tests on CI server are failing (Xcode 9) iOS

Trying to setup continuous integration for my iOS app. Wrote bunch of unit tests that run fine locally for both phone and simulator.
However, when I run my CI bots the tests are failing with this error:
" Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted) "
There is no more explanation to be found in the logs or anything like that. The bot is set up to use only iPhone 7 iOS 11.2 simulator.
Any kind of help is highly appreciated.
EDIT: I partially fixed this issue by changing Runpath Search Paths on my Test target in Build Settings to $(FRAMEWORK_SEARCH_PATHS).
However, I still get this error if I use more than one simulator on the bot :( So if I use only one simulator everything works fine, but if I use more than one it would fail for all of them or at least for one of them with this same error...

How to debug generic React Native error messages on iOS?

Unless I enable debugging (Esc > Cmd+D > Debug JS Remotely) then I see this error:
Module AppRegistry is not a registered callable module
This also means that I'm unable to view the bundled app on device. If I try to view the app on device, but still use the dev server (remembering to use an IP address in AppDelegate.m instead of localhost) then I instead get this error:
WebSocket connection failed with error Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"
even though I've verified that I can open the dev server URL in a browser on the device.
I'm not an iOS developer, so maybe this is really obvious, but how do I go about debugging why these errors are happening, or just not having these errors in the first place?
One reason could be App Transport Security that was added in iOS 9. Please see https://facebook.github.io/react-native/docs/running-on-device-ios.html#app-transport-security for reference. You have to add the NSAllowsArbitraryLoads entry to your Info.plist yourself if you didn't use the React Native CLI to generate your project.
Although this doesn't really answer the 'How do I debug these kinds of generic errors' question, I've found out that in my case the problem was that I created my app using an older version of RN (maybe 0.26?) that had a bug in the scaffolding code it creates (which I stupidly ignored at the time when I found i could work around it by enabling debugging) and updating to newer versions of the app hasn't fixed the issue because that doesn't cause the scaffolding to be updated. By creating a fresh app under RN 0.29, and copying my code into it, everything is now working as expected.

Resources