我使用过 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();
}
谢谢。
最佳答案
框架的工作原理是:
主持人
- 测试主机是specflow脚本或控制台应用程序
- 此测试主机提供了一个提供 WCF 服务的 HTTP 服务器 - https://github.com/Expensify/WindowsPhoneTestFramework/blob/master/Server/WCFHostedAutomationController/Service/IPhoneAutomationService.cs
- 这里提供的主要方法是
GetNextCommand
和SubmitResult
GetNextCommand
返回从CommandBase
派生的任何类 - 这些类之一 - https://github.com/Expensify/WindowsPhoneTestFramework/tree/master/Server/WCFHostedAutomationController/CommandsSubmitResult
需要从ResultBase
派生的任何类 - 这些类之一 - https://github.com/Expensify/WindowsPhoneTestFramework/tree/master/Server/WCFHostedAutomationController/Results
客户端
- 客户端在应用内的一个线程上运行
- 客户端连接到服务,然后不断轮询命令
- 当客户端收到命令时,它使用代码的“部分类”部分处理命令 - 例如在 https://github.com/Expensify/WindowsPhoneTestFramework/tree/master/Client/AutomationClient/Remote
- 作为该处理的一部分,客户端必须始终向服务返回结果
添加命令或结果
因为这个机制使用了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/Server/WCFHostedAutomationController/Commands/GenericCommand.cs
- SuccessResult - “ResultText”可用于任何消息 - https://github.com/Expensify/WindowsPhoneTestFramework/blob/master/Server/WCFHostedAutomationController/Results/SuccessResult.cs
如果您希望使用这些,那么通用命令将传递给在 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
调试
从你的问题来看,我假设你已经成功地调试了主机。
调试客户端最简单的方法是:
- 首先启动主机(例如调试器中的控制台)
- 然后在调试器中启动应用程序 - 它应该启动并连接到主机内的 WCF 服务。
- 您可以在 Command 分部类中正常设置断点。
- 主运行循环在 https://github.com/Expensify/WindowsPhoneTestFramework/blob/master/Client/AutomationClient/AutomationClient.cs 中
GetAndProcessNextCommand
是Run loop中处理循环的核心。
我希望有帮助...如果没有,也许尝试发布更大的代码示例(可能使用 gist 或 github)
关于windows-phone-7 - 调试 WindowsPhoneTestFramework AutomationClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502018/