【发布时间】: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)
我已经阅读了以下帖子和文章,但没有成功
- TestStack White doesn't find TextBox in WPF Application
- https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/
- http://putridparrot.com/blog/teststack-white-gotchatips/
也许有人可以给我一个原始示例如何触发方法Foo() 或HtButton 的触发事件FooEvent。
【问题讨论】:
-
很久很久以前,我写了这篇关于在 WinRT 商店应用程序中寻找控件的文章:pmichaels.net/2013/03/04/…IIRC 前提是在 WPF 中做同样的事情。我并没有声称这是对您问题的回答,但它可能会有所帮助。
-
你解决了吗?
-
实际上我切换到了 FlaUI github.com/Roemer/FlaUI 一个改进版的 TestStack.White。你的答案没有像预期的那样工作。也许我必须看看这篇文章.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…
-
好吧,过了一会儿我改了:D
标签: c# wpf automated-tests white-framework teststack