使用 Xamarin.UITest 测试我的 Xamarin.Forms iOS 应用程序:第一个测试总是失败
Testing my Xamarin.Forms iOS Application with Xamarin.UITest: The first test always fails
我正在使用 Xamarin.UITest 在真实设备上测试 Xamarin.iOS 应用程序(iPhone 6s,iOS 12.1)。
当我运行我的几个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+FromAsyncTrimPromise
1[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();
}
}
通俗地说:"If you tried to start the app, and something went wrong, try to see if the app under test was started anyway and connect to it"
注意:正如 https://whosebug.com/users/1214857/iupchris10 在评论中提到的,这种方法的一个警告是当您 运行 连续测试时,而 StartApp 调用将 理论上 可靠地关闭应用程序,失败点是重新连接,如果它没有并且你连续 运行ning 测试,你将简单地连接到 运行ning 应用程序实例,无论它处于什么状态被留在了。这种方法没有追索权。 Xamarin 的 StartApp 将抛出异常,而不是类型化异常,因此缓解这种情况将依赖于您解析 InnerException.Message 并保持 table 预期失败。
我正在使用 Xamarin.UITest 在真实设备上测试 Xamarin.iOS 应用程序(iPhone 6s,iOS 12.1)。 当我运行我的几个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.TaskFactory
1+FromAsyncTrimPromise
1[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();
}
}
通俗地说:"If you tried to start the app, and something went wrong, try to see if the app under test was started anyway and connect to it"
注意:正如 https://whosebug.com/users/1214857/iupchris10 在评论中提到的,这种方法的一个警告是当您 运行 连续测试时,而 StartApp 调用将 理论上 可靠地关闭应用程序,失败点是重新连接,如果它没有并且你连续 运行ning 测试,你将简单地连接到 运行ning 应用程序实例,无论它处于什么状态被留在了。这种方法没有追索权。 Xamarin 的 StartApp 将抛出异常,而不是类型化异常,因此缓解这种情况将依赖于您解析 InnerException.Message 并保持 table 预期失败。