0

I have a custom Control HtButton which inherits from Control.

I made a custom FrameworkElementAutomationPeer and override the OnCreateAutomationPeer() in HtButton.

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);
    }
}

To get all of them, I use the following call:

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

I receive a list of CustomUIItem:

enter image description here

The following call throws an 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)
    {

    }
}

enter image description here

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)

I have read the following posts and articles without success


Maybe someone could give me a primitive example how to trigger method Foo() or fire event FooEvent of HtButton.

Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77
  • A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: https://www.pmichaels.net/2013/03/04/always-in-the-last-place-you-look-pragmatically-finding-controls-in-a-c-xaml-store-app/ IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help. – Paul Michaels Nov 27 '18 at 13:31
  • Did you solve this? – Francesco B. Nov 30 '18 at 14:33
  • 1
    Actually I switched to **FlaUI** https://github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. https://github.com/TestStack/uia-custom-pattern-managed/blob/master/README.md – Dominic Jonas Dec 03 '18 at 09:11
  • Well I changed it after a while :D – Francesco B. Jan 09 '19 at 07:45

0 Answers0