3

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.

Stampi
  • 51
  • 6
  • Just pre-start the iOS simulator and leave it running. – SushiHangover Feb 13 '19 at 13:42
  • Unfortunatly, that does not help. The simulator gets restarted when I start the test. Is it possible, the Mac is just too slow to start everything in time? I can start my app from Windows in the Simulator with no problems, but using the Mac feels like watching paint dry. – Stampi Feb 13 '19 at 15:36
  • `Is it possible, the Mac is just too slow to start everything in time...` Certainly that can be the case.... the simulator is a disk IO hog (it loves SSDs and hates spindled drives, at least in terms of startup speed) and if your mac is memory limited and is swapping pages that will kill perf. How long does it take to manually start the simulator and get to the springboard(home) screen? (Simulator.app (that is within the installed Xcode bundle)) – SushiHangover Feb 13 '19 at 15:50
  • From clicking to seeing the home screen took 1:25. Working directly on the Mac without teamviewer seems to be positive for performance (I took the time while working directly on the Mac), but I only got into REPL once and it crashed shortly afterwards. It's a Mac mini 2014 i7 with 8GB RAM and no SSD – Stampi Feb 13 '19 at 16:23
  • Depending upon the Mac that I am using 15/20 seconds for a cold-boot of the simulator is a long time :-/ But all of those are SSD-based, I have a MacBook Pro that is spindle-based, and 2+ minutes is not uncommon (CPU/i7 and RAM/16gb are not the issue in this case, just the spindle drive speed) – SushiHangover Feb 13 '19 at 16:33
  • Are you able to run UITests on the MacBook? Since it worked once, sometimes gets to the DeviceAgent problem and sometimes to the exception about wrong linking it feels like a timing/performance issue. – Stampi Feb 14 '19 at 09:10

4 Answers4

6

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.

bcr
  • 1,983
  • 27
  • 30
  • The exact same issue happened to me as well. Totally forgot that the build sequence does not include app refresh on the device. – CodeMylife Sep 07 '21 at 13:30
1

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.

Stampi
  • 51
  • 6
1

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
Kapusch
  • 287
  • 1
  • 13
0

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

Lug
  • 420
  • 5
  • 15