xamarin - 使用 Xamarin.UITest 测试我的 Xamarin.Forms iOS 应用程序 : The first test always fails

标签 xamarin xamarin.ios automated-tests ui-testing xamarin.uitest

我正在使用 Xamarin.UITest 在真实设备(带有 iOS 12.1 的 iPhone 6s)上测试 Xamarin.iOS 应用程序。 当我运行我的几个 UI 测试时,由于相同的错误(见下文),第一个测试总是崩溃(无论测试内部发生了什么)。

环境是:

  • Xamarin.UITest 2.2.7

  • NUnitTestAdapter 2.1.1

  • NUnit 2.6.3

  • Xamarin.TestCloud.Agent 0.21.7

设置为:

[SetUp]
public void Setup(){
     this.app = ConfigureApp.iOS
        .EnableLocalScreenshots()
                .InstalledApp("my.app.bundle")
                .DeviceIdentifier("My-iPhone6s-UDID-With-iOS12.1")  
                .StartApp();
}

[Test]
public void FirstTestThatCouldBeEmpty(){
     //But doesn't have to be empty to produce the error    
}

结果错误:

2019-01-17T14:11:20.4902700Z 1 - ClearData:> 2019-01-17T14:11:20.4916340Z bundleId: my.app.bundle 2019-01-17T14:11:20.4929580Z deviceId: My-iPhone6s-UDID-With-iOS12.1

2019-01-17T14:11:33.7561260Z 3 - LaunchTestAsync:

2019-01-17T14:11:33.7574050Z deviceId: My-iPhone6s-UDID-With-iOS12.1

2019-01-17T14:11:33.9279420Z 5 - HTTP request failed, retry limit hit

2019-01-17T14:11:33.9302300Z Exception: System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Unable to read data from the transport connection: Connection reset by peer. ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer

2019-01-17T14:11:33.9322710Z at System.Net.Sockets.Socket.EndReceive (System.IAsyncResult asyncResult) [0x00012] in <23340a11bb41423aa895298bf881ed68>:0

2019-01-17T14:11:33.9340560Z at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x00057] in <23340a11bb41423aa895298bf881ed68>:0

2019-01-17T14:11:33.9358740Z --- End of inner exception stack trace ---

2019-01-17T14:11:33.9377100Z at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x0009b] in <23340a11bb41423aa895298bf881ed68>:0

2019-01-17T14:11:33.9398100Z at System.IO.Stream+<>c.b__43_1 (System.IO.Stream stream, System.IAsyncResult asyncResult) [0x00000] in <98fac219bd4e453693d76fda7bd96ab0>:0

2019-01-17T14:11:33.9415720Z at System.Threading.Tasks.TaskFactory1+FromAsyncTrimPromise1[TResult,TInstance].Complete (TInstance thisRef, System.Func`3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x00000] in <98fac219bd4e453693d76fda7bd96ab0>:0

有时会出现这样的错误:

SetUp : Xamarin.UITest.XDB.Exceptions.DeviceAgentException : Unable to end session: An error occurred while sending the request

System.Net.Http.HttpRequestException : An error occurred while sending the request

System.Net.WebException : Unable to read data from the transport connection: Connection reset by peer.

System.IO.IOException : Unable to read data from the transport connection: Connection reset by peer.

System.Net.Sockets.SocketException : Connection reset by peer

有什么办法可以解决这个问题吗? 做 nuget 包的版本难题让我到目前为止,除了这个测试之外,所有测试都在工作。

虚拟测试是一种可能性,但是使用这些测试进行的无数构建将永远不会处于“成功”状态,因为这个测试失败了 =(

最佳答案

我能够找到解决此问题的方法,以及设备代理未连接到正在测试的应用程序的任何问题。

        public static IApp StartApp(Platform platform)
        {
            if (platform == Platform.iOS)
            {
                try
                {
                    return ConfigureApp.iOS
                       .InstalledApp("com.example")
#if DEBUG
                       .Debug()
#endif
                       .StartApp();
                }
                catch
                {
                    return ConfigureApp.iOS
                       .InstalledApp("com.example")
#if DEBUG
                        .Debug()
#endif
                       .ConnectToApp();
                }
            }

用简单的语言来说:“如果您尝试启动应用程序,但出现问题,请尝试查看被测试的应用程序是否已启动并连接到它”

注意:如https://stackoverflow.com/users/1214857/iupchris10评论中提到,这种方法的一个警告是,当您连续运行测试时,虽然 StartApp 调用理论上会可靠地关闭应用程序,但失败点是重新连接(如果没有)并且您连续运行测试,您只需以任何状态连接到正在运行的应用程序实例。此方法不提供追索权。 Xamarin 的 StartApp 将抛出 Exception,而不是类型化异常,因此缓解此问题将依赖于您解析 InnerException.Message 并保留预期失败表。

关于xamarin - 使用 Xamarin.UITest 测试我的 Xamarin.Forms iOS 应用程序 : The first test always fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54238759/

相关文章:

authentication - Servicestack、Xamarin 和身份验证

ios - MonoTouch 支持模块初始化程序吗?

xamarin - 如何在 Xamarin 中卸载项目?

c# - Windows Server 2019 上的 Xamarin 模拟器

android - Xamarin.Forms 如何将应用程序带回前台?安卓

visual-studio - 将xml嵌入到dll中

ios - Xamarin.iOS/Akavache - 使用自定义 EncryptionProvider 的加密缓存

unit-testing - 您应该在单元测试中使用 Moq 提供的 "Verify"和 "VerifyAll"方法吗?

c# - Azure DevOps 2019 Server 无法执行具有代码覆盖率的测试

unit-testing - 单元测试写作的最佳实践