繁体   English   中英

TestStack | 如何查找自定义控件和调用方法/触发事件

[英]TestStack | How to find custom controls and invoke methods / fire events

我有一个自定义Control 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()或触发FooEvent的事件HtButton

我猜还有其他解决方案,其中有些涉及我的选择(即创建自定义UIItem子类,依此类推)。

我最终追求的是:

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

它确实可以工作,它很简短,只需要您引用Microsoft.CSharp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM