【问题标题】:Xamarin.UITest System.Xml.XmlExceptionXamarin.UITest System.Xml.XmlException
【发布时间】:2017-02-14 23:26:28
【问题描述】:

我正在为我的 Xamarin.Forms 应用程序创建 UI 测试。当我尝试开始 iOS 项目的第一个测试时,我得到了一个 System.Xml.XmlException(详情如下)。这个基本测试应该有效,对吧?

更新:如果我从模拟器中卸载应用程序,测试将首次运行。之后,我不断收到所有后续运行的异常。

我正在使用 Xamarin Studio(6.1.3 build 19)和 Xamarin.UITest 包 (2.0.5)

namespace UITest
{
    [TestFixture (Platform.Android)]
    [TestFixture (Platform.iOS)]
    public class Tests
    {
        IApp app;
        Platform platform;

        public Tests (Platform platform)
        {
            this.platform = platform;
        }

        [SetUp]
        public void BeforeEachTest ()
        {
            app = AppInitializer.StartApp (platform);
        }

        [Test]
        public void AppLaunches ()
        {
            try {
                app.WaitForElement ("Waiting for fake element", "Timeout", new TimeSpan (0, 0, 20));
            } catch (TimeoutException ex) {
                int i = 5;
            }

            app.Screenshot ("Welcome screen.");
            app.Tap ("TestButton");
            app.Screenshot ("New test screen.");
        }
    }

    public class AppInitializer
    {
        public static IApp StartApp (Platform platform)
        {

            if (platform == Platform.Android) {
                return ConfigureApp
                    .Android

                    .StartApp ();
            }

            return ConfigureApp
                .iOS

                .Debug ()
                .EnableLocalScreenshots ()
                .StartApp ();
        }
    }
}

异常详情:

SetUp : System.Xml.XmlException : '', hexadecimal value 0x01, is an invalid character. Line 11, position 11.
    Stack trace:
      at Xamarin.UITest.iOS.iOSAppLauncher.LaunchAppLocal (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, System.Boolean clearAppData) [0x0020a] in <e747267e258a4a668973c7ca7e9014a8>:0 
      at Xamarin.UITest.iOS.iOSAppLauncher.LaunchApp (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, Xamarin.UITest.TestCloud.TestCloudiOSAppConfiguration testCloudAppConfiguration, Xamarin.UITest.Shared.Http.HttpClient testCloudWsClient, Xamarin.UITest.Shared.Http.HttpClient xtcServicesClient, System.Boolean testCloudUseDeviceAgent) [0x0007a] in <e747267e258a4a668973c7ca7e9014a8>:0 
      at Xamarin.UITest.iOS.iOSApp..ctor (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration) [0x00302] in <e747267e258a4a668973c7ca7e9014a8>:0 
      at Xamarin.UITest.Configuration.iOSAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <e747267e258a4a668973c7ca7e9014a8>:0 
      at UITest.AppInitializer.StartApp (Xamarin.UITest.Platform platform) [0x0001f] in /Users/samg/projects/myapp-mobile/myapp-mobile-2/UITest/AppInitializer.cs:38 
      at UITest.Tests.BeforeEachTest () [0x00008] in /Users/samg/projects/myapp-mobile/myapp-mobile-2/UITest/Tests.cs:26 
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 

【问题讨论】:

  • 显示标有[SetUp] 标记的方法中的内容,因为错误开始于我认为其中有问题。
  • 添加了包含Setup方法的测试类。
  • 当你说你得到以下运行异常时,你的意思是没有任何代码更改;例如只是停止运行然后再次运行?或者您是否正在对 UITest 项目和/或应用程序本身在运行和失败之间进行更改?
  • 无代码更改。只是第二次运行相同的测试 + 应用程序代码会引发异常。
  • 如果您删除 try-catch 块,您是否仍然看到问题?如果 app.WaitForElement 没有找到结果,它应该直接失败测试并出现超时异常;所以我不确定您的自定义处理可能会改变什么。 (注意,您的方法仍然可能有效/这是一个错误,但我要求进行比较。)

标签: xamarin.ios xamarin.forms xamarin.uitest


【解决方案1】:

我知道这是一个老问题,但它可能对其他人有所帮助。我遇到了上述相同的问题,并通过重置 iOS 模拟器解决了它。

实现此目的的一种方法是采取以下步骤:

  • 确保 iPhone/iPad 模拟器正在运行;
  • 转到顶部菜单并选择“iOS 模拟器”->“重置内容和设置...”

【讨论】:

  • 我同意,有时 iOS 模拟器会达到“疯狂”状态并表现出 OP 定义的行为。只需将模拟器“重置”为干净状态,直到它表现出相同的行为。当那个时间发生时,我们会再次重置它!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-06
  • 1970-01-01
  • 2020-01-25
相关资源
最近更新 更多