我正在尝试让Xamarin Forms与UITest一起使用,但似乎无法在iOS中设置StyleId属性(我没有Android许可)。

我已经阅读了所有文档,到目前为止,这些是我已经采取的步骤:

AppDelegate:

static readonly IntPtr setAccessibilityIdentifier_Handle = Selector.GetHandle("setAccessibilityIdentifier:");

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    Forms.Init();

    Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) => {
        // http://developer.xamarin.com/recipes/testcloud/set-accessibilityidentifier-ios/
        if (null != e.View.StyleId) {
            e.NativeView.AccessibilityIdentifier = e.View.StyleId;
            Console.WriteLine("Set AccessibilityIdentifier: " + e.View.StyleId);
        }
    };

    ...

    #if DEBUG
    Xamarin.Calabash.Start();
    #endif

    ...
}

XAML ContentPage:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Ignite.Abacus.Mobile.OptionsView"
             Title="Options">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Test" StyleId="Test" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

现在,这是踢球者:

如果我调试应用程序,则可以清楚地看到StyleId已设置,因为Console.WriteLineForms.ViewInitialized处理程序中的AppDelegate调用正在写入应用程序输出。但是,如果我调试了我拥有的单元测试并从REPL中查询它,则它似乎并没有连接StyleId属性,因为app.Query(c => c.Marked("Test"))返回零结果。

我很想在测试范围内运行该应用程序时看到其控制台输出-但它似乎不会向“应用程序输出”窗口或“测试结果”窗口中输出任何内容(打开输出)...

关于我所缺少的任何想法吗?

最佳答案

今天就到这里有一个比手动“文件->重置模拟器”更简单的解决方法,那就是将[SetUp]配置为自动为您执行此操作:

using System.Diagnostics;

[SetUp]
public override void SetUp()
{
    const string simulatorId = "2261E5E1-758A-4967-8BF2-181E8099379F"; // iPhone 5s iOS 8.2
    ResetSimulator(simulatorId);

    // an API key is required to publish on Xamarin Test Cloud for remote, multi-device testing
    app = ConfigureApp.iOS.AppBundle(PathToIPA).DeviceIdentifier(simulatorId).EnableLocalScreenshots().ApiKey(Constants.XamarinTestCloudApiKey).StartApp();
}

public static void ResetSimulator(string deviceId)
{
    var shutdownProcess = Process.Start("xcrun", string.Format("simctl shutdown {0}", deviceId));
    shutdownProcess.WaitForExit();
    var eraseProcess = Process.Start("xcrun", string.Format("simctl erase {0}", deviceId));
    eraseProcess.WaitForExit();
}

10-06 13:52