【问题标题】:TestStack | How to find custom controls and invoke methods / fire events测试堆栈 |如何查找自定义控件和调用方法/触发事件
【发布时间】:2018-11-27 13:16:36
【问题描述】:

我有一个自定义控件HtButton,它继承自Control

我自定义了FrameworkElementAutomationPeer 并覆盖了HtButton 中的OnCreateAutomationPeer()

public class HtButtonAutomationPeer : FrameworkElementAutomationPeer
{
    public HtButtonAutomationPeer([NotNull] FrameworkElement owner) : base(owner)
    {
    }

    protected override string GetClassNameCore()
    {
        return "HtButton";
    }
}

public abstract class HtButtonBase : Control
{
}

public class HtButton : HtButtonBase
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new HtButtonAutomationPeer(this);
    }
}

要获取所有这些,我使用以下调用:

var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));

我收到CustomUIItem的列表:

以下调用会引发ArgumentException: At least two conditions must be specified.

myButtons = Window.GetMultiple(SearchCriteria.ByControlType(typeof(HtButton), WindowsFramework.Wpf));
foreach (IUIItem myControl in myButtons)
{
    if (myControl is HtButton b)
    {

    }
}

Die Testmethode "HtFramework.WhiteUnitTest.HtPlcFrameworkTest.NavigationTest" hat eine Ausnahme ausgelöst: 
System.ArgumentException: Es müssen mindestens zwei Bedingungen angegeben werden.
    bei System.Windows.Automation.OrCondition..ctor(Condition[] conditions)
   bei TestStack.White.UIItems.Finders.OrSearchCondition.get_AutomationCondition() in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\Finders\OrSearchCondition.cs:Zeile 27.
   bei TestStack.White.UIItems.Finders.SearchCriteria.get_AutomationSearchCondition() in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\Finders\SearchCriteria.cs:Zeile 140.
   bei TestStack.White.Factory.PrimaryUIItemFactory.CreateAll(SearchCriteria searchCriteria, ActionListener actionListener) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Factory\PrimaryUIItemFactory.cs:Zeile 80.
   bei TestStack.White.UIItems.Container.NonCachedContainerItemFactory.GetAll(SearchCriteria searchCriteria) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\Container\NonCachedContainerItemFactory.cs:Zeile 30.
   bei TestStack.White.UIItems.Container.CurrentContainerItemFactory.FindAll(SearchCriteria criteria) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\Container\CurrentContainerItemFactory.cs:Zeile 78.
   bei TestStack.White.UIItems.UIItemContainer.GetMultiple(SearchCriteria criteria) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\UIItems\UIItemContainer.cs:Zeile 205.
   bei HtFramework.WhiteUnitTest.MainWindow.NavigateTo() in ...hiddenPath...\HtFramework.WhiteUnitTest\UnitTest1.cs:Zeile 34.
   bei HtFramework.WhiteUnitTest.HtPlcFrameworkTest.<NavigationTest>d__6.MoveNext() in ...hiddenPath...\HtFramework.WhiteUnitTest\UnitTest1.cs:Zeile 196.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

我已经阅读了以下帖子和文章,但没有成功


也许有人可以给我一个原始示例如何触发方法Foo()HtButton 的触发事件FooEvent

【问题讨论】:

标签: c# wpf automated-tests white-framework teststack


【解决方案1】:

我猜还有其他解决方案,其中一些涉及到我的观点(即创建自定义 UIItem 子类等)。

我最终的目标是:

var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
foreach (var button in myButtons )
{
    dynamic t = button;
    t.Foo();
}

它确实有效,它很短,只需要您参考Microsoft.CSharp

【讨论】:

  • 两年后随机匿名投反对票,不评论,不解释。这……没用。
猜你喜欢
  • 2019-08-12
  • 1970-01-01
  • 2019-04-12
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 2011-08-02
  • 2018-07-16
  • 1970-01-01
相关资源
最近更新 更多