【问题标题】:Cannot access Tree Nodes using TestStack.White无法使用 TestStack.White 访问树节点
【发布时间】:2016-07-26 20:06:30
【问题描述】:

我尝试使用 TestStack.White 自动化 Ms Outlook 日历视图,但我无法处理树和树项。

在 Outlook 的日历视图中有一个 日历文件夹树,其结构如下:

SearchCriteria searchCriteria = SearchCriteria.ByText("Calendar Folders").AndControlType(ControlType.Tree).AndIndex(0);
Tree calendarTree = (Tree)WhiteWindows.mainWindow.Get(searchCriteria);

calendarTree.Click(); // this action is performed correctly - clicks on the tree

Console.WriteLine("No. of nodes: " + calendarTree.Nodes.Count); // this line throws an exception

某事:

Result StackTrace:  
at TestStack.White.Mappings.ControlDictionary.GetTestControlType(String className, String name, ControlType controlType, String frameWorkId, Boolean isNativeControl) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Mappings\ControlDictionary.cs:line 157
   at TestStack.White.Mappings.ControlDictionary.GetTestControlType(AutomationElement automationElement) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Mappings\ControlDictionary.cs:line 218
   at TestStack.White.Factory.DictionaryMappedItemFactory.Create(AutomationElement automationElement, ActionListener actionListener) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Factory\DictionaryMappedItemFactory.cs:line 13
   at TestStack.White.UIItemList`1..ctor(List`1 collection, UIItemFactory factory, ActionListener actionListener) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItemList.cs:line 26
   at TestStack.White.UIItems.TreeItems.Tree.get_Nodes() in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\TreeItems\Tree.cs:line 54
   at TestStack.White.Bricks.DelegateInvoker.ActionInvokerWrapper`1.Call(Object[] args) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Bricks\DelegateInvoker.cs:line 198
   at TestStack.White.Bricks.DynamicProxyInterceptors.Process(IInvocation invocation, CoreInterceptContext interceptedContext) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Bricks\DynamicProxyInterceptors.cs:line 21
   at TestStack.White.Interceptors.CoreInterceptor.Intercept(IInvocation invocation) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Interceptors\CoreInterceptor.cs:line 31
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.TreeProxy.get_Nodes()
   at UI.Tests.StepDefinitions.TempSteps.WhenCalendarIsSelectedOnPage(String p0, String p1) in StepDefinitions\TempSteps.cs:line 183
   at lambda_method(Closure , IContextManager , String , String )
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
   at UI.Tests.Features.PlaygroundFeature.ScenarioCleanup() in UI.Tests\Features\Playground.feature.cs:line 0
   at UI.Tests.Features.PlaygroundFeature.SelectNewCalendar() in UITests\Features\Playground.feature:line 11
Result Message: 
Test method UI.Tests.Features.PlaygroundFeature.SelectNewCalendar threw exception: 
TestStack.White.Mappings.ControlDictionaryException: Multiple TestControls found for ControlType=tree view item and FrameworkId: - TestStack.White.UIItems.TreeItems.Win32TreeNode, TestStack.White.UIItems.TreeItems.WPFTreeNode, TestStack.White.UIItems.TreeItems.Win32TreeNode

对于以下代码,发生了同样的异常:

foreach(TreeNode node in calendarTree.Nodes) // Exception thrown here
{
    //perform action on nodes
}

有人有解决办法吗?

【问题讨论】:

    标签: white-framework


    【解决方案1】:

    我们遇到了完全相同的问题。这似乎是一个错误。我们开发的解决方法是将节点作为 IUIItems 而不是 TreeNodes 进行交互。您必须围绕与它们交互编写更多自定义代码,但至少它允许您执行点击操作等。

    【讨论】:

    • 你能详细说明一下吗?我遇到了同样的问题。
    【解决方案2】:

    看起来它已经开始工作了。 TestStack.White [0.13.3] + UIAComWrapper [1.1.0.14](我的配置,但你可以尝试不使用最后一个):

    Tree tree = mainWindow.Get<Tree>("treeMenu"); //primaryId
    tree.Click();
    MessageBox.Show(tree.Nodes.Count.ToString());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      • 2018-07-22
      • 1970-01-01
      • 2021-08-12
      • 2017-07-09
      相关资源
      最近更新 更多