windows-phone-7 - 调试 WindowsPhoneTestFramework AutomationClient

标签 windows-phone-7 wp7test

我使用过 WindowsPhoneTestFramework,它很棒,但它不支持我需要的一些功能,例如设置元素的宽度和高度,更改模拟器的布局以在横向和纵向中进行测试等。虽然尝试添加简单的命令,如宽度和高度,由于某种原因它不起作用,这里需要调试 AutomationClient。 例如,我需要查看我在 WindowsPhoneTestFramework.Client.AutomationClient.Remote 中创建的 SetWidthCommand 中发生了什么,并了解为什么该属性未在被测应用程序中更新。

我已经创建了 SetWidth 命令并从控制台调用,如:setWidth id=widthValue

我可以调试,直到我到达 ApplicationAutomationController,其中的命令 AutomationIdentifier 和值已创建,在 SyncExecuteCommand 之后我得到的结果为 false。这意味着客户端有问题,那么我该如何调试 Client.AutomationClient.Remote 中的 SetWidthCommand 这是 Client.AutomationClient.Remote 中的 SetWidthCommand

public partial class SetWidthCommand
{
    protected override void DoImpl()
    {

        var element = GetUIElement();
        if (element == null)
            return;

        if (AutomationElementFinder.SetElementProperty(element, "Width", Value))
        {
            SendSuccessResult();
            return;
        }
        //setWidth ContentPanel 400
        if (ValueCommandHelper.TrySetValue(element, Value.ToString(CultureInfo.InvariantCulture)))
        {
            SendSuccessResult();
            return;
        }
        // if width is missing... then give up
        SendNotFoundResult();
    }

谢谢。

最佳答案

框架的工作原理是:

主持人

客户端

添加命令或结果

因为这个机制使用了WCF,那么如果你想在处理中添加一个新的Command或者一个新的Result,那么你首先需要将这些添加到Host中,然后你就需要更新客户端代码——做为此,您需要使用 Visual Studio 工具更新 https://github.com/Expensify/WindowsPhoneTestFramework/tree/master/Client/AutomationClient/Service%20References 中自动生成的 WCF 类

此 WCF 更新可能非常繁琐 - 但它是“正常”WCF 操作 - http://msdn.microsoft.com/en-us/library/bb628652.aspx

更新这些后,您就可以在客户端中为新命令编写部分类代码。

另一种选择

作为替代方法,有一个“通用”命令和结果对可用 -

如果您希望使用这些,那么通用命令将传递给在 https://github.com/Expensify/WindowsPhoneTestFramework/blob/master/Client/AutomationClient/Remote/GenericCommand.cs 中静态注册的处理程序

例如你可以注册这样的东西:

GenericCommand.AddHandlerFactory("MyKey", (command, action) => {
    return (command) => {
        var result = new SuccessResult() {ResultText = "some example text" };
        result.Send(command.Configuration);
    };
});

这将用于处理任何具有“MyKey”的 pleaseDo 字段的 GenericCommand

调试

从你的问题来看,我假设你已经成功地调试了主机。

调试客户端最简单的方法是:


我希望有帮助...如果没有,也许尝试发布更大的代码示例(可能使用 gist 或 github)

关于windows-phone-7 - 调试 WindowsPhoneTestFramework AutomationClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502018/

相关文章:

database - Windows 手机 7 : MVVMLight and Messenger

windows-phone-7 - 显示地理坐标对象的折线

windows-phone-7 - 获取 ListPicker 中选定项的值

windows-phone-7 - WP7区域格式测试

c# - WP7.1应用程序中的WebClient仅调用一次

silverlight - Windows Phone 7 中的语音到文本

c# - WebClient.DownloadStringAsync 不适用于 WP7 模拟器