首页 > 解决方案 > Xamarin.UITest 无法联系在应用程序中运行的测试后端

问题描述

我正在尝试使用 Xamarin.UITest 测试我的 Xamarin.Forms 应用程序。Android工作正常,但iOS部分有问题。在执行我的第一个测试以进入 REPL 时,我收到以下错误:

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.

奇怪的是,当将应用程序上传到 Microsoft 应用程序中心时,它会开始测试。它只是挂起,因为它找不到我的工具栏项。我想通过在我的 Mac 上进行 iOS 测试来检查 REPL 的有效查询,而我通常在 Windows 上使用 Visual Studio。

我尝试了我在网上找到的解决方案,但没有运气

我正在从连接到 Mac 的 Windows 上的 Visual Studio 编译一个 .app 文件,并在 Mac 上启动 iOS 测试。

这是我当前的 AppInitializer 代码:

return ConfigureApp.iOS.AppBundle(sPathToiOS).PreferIdeSettings().StartApp();

有时我也会得到一个不同的错误:

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

当启动测试时模拟器没有运行并且启动模拟器需要很长时间时,这似乎会发生。

标签: iosxamarinxamarin.formsvisual-studio-macxamarin.uitest

解决方案


我必须确保我已将应用程序重新部署到我要测试的模拟器上,并且所有必要的步骤都已到位。

具体发生在我身上的是我Xamarin.Calabash.Start()AppDelegate.cs. )。

这将确保应用程序的正确版本在模拟器上。这是在模拟器上测试的唯一方法;在运行测试之前,它不会为您部署应用程序。


推荐阅读