【问题标题】:LeanFT C# automation; Clicking on a wpf button control throwing exceptionLeanFT C# 自动化;单击 wpf 按钮控件引发异常
【发布时间】:2018-06-24 11:48:48
【问题描述】:

在尝试单击 wpf 按钮时获取HP.LFT.SDK.GeneralReplayException: One or more specified arguments are not valid(使用 LeanFT 和 Visual Studio 2015 中集成的 C#)

给定下面的代码:

// Identify the "LicensingButton" button
var LicensingButton = objAdminApplicationModel.wnd_Adminstration.Describe<IButton>(new ButtonDescription
    {
        Text = @"Licensing",
        ObjectName = @"Licensing"
    });
// Click the Licensing button.
LicensingButton.Click();

但我遇到了异常

Exception is HP.LFT.SDK.GeneralReplayException: One or more specified arguments are not valid.
   at HP.LFT.SDK.Core.ClassModel.TestObjectExecuterBase.HandleReplayError(Int32 errorCode, IDictionary`2 data)
   at HP.LFT.SDK.Core.Communication.CommunicationClient.HandleError(Action`2 onError, Int32 status, IDictionary`2 data)
   at HP.LFT.SDK.Core.Communication.CommunicationClient.Send(String messageType, IDictionary`2 data, Action`2 onError)
   at HP.LFT.SDK.Core.ClassModel.TestObjectExecuter.ExecuteMethod(String methodName, Object[] arguments)
   at HP.LFT.SDK.Core.ClassModel.TestObjectBase.ExecuteMethod(String methodName, Object[] arguments)
   at HP.LFT.SDK.ClickBehaviour.Click(MouseButton button)
   at HP.LFT.SDK.UiObjectBase.<>c__DisplayClassd.<Click>b__c()
   at HP.LFT.SDK.OperationExecutionWrapper.ExecuteWithEvents(ITestObject testObject, Object additionalInfo, Action innerAction, MethodBase methodInfo, Boolean reportOnlyOnError, Object[] arguments)
   at HP.LFT.SDK.OperationExecutionWrapper.ExecuteWithEvents[T1](Action innerAction, Action`1 originalMethod, T1 param1, Boolean reportOnlyOnError, ITestObject testObject, Object additionalInfo)
   at HP.LFT.SDK.UiObjectBase.Click(MouseButton button)
   at Admin4DM.Test.Licensing.Licensing_VerifyStaticTextDisplay() in C:\Source\Automation\Test\Licensing.cs:line 32

【问题讨论】:

  • 您可以尝试通过显式指定MouseButton.Left 参数或通过提供具有ButtonLocation 属性的ClickArgs 对象来调用.Click 吗?
  • LicensingButton.Click(MouseButton.Left);给了我同样的错误。
  • 不知道如何使用 ClickArgs ,你能举个例子吗

标签: c# testing functional-programming automated-tests leanft


【解决方案1】:

这个例外确实具有误导性。乍一看,我认为 ButtonDescription 的构造不正确,这意味着 TextObjectName 属性中的一个需要其他值。

但事实并非如此。

问题完全出在点击操作上。正如您在检查 Click 方法时看到的那样,它有两个重载:

  1. 期待一个MouseButton 枚举;

    当我们调用Click并且我们不传递枚举或对象时,默认使用MouseButton.Left枚举值,但您也可以指定.Middle.Right

  2. 期望ClickArgs 对象,格式为:

    new ClickArgs {
        Button = MouseButton.Left,
        Location = Position.Center
    }
    

    Location 表示单击按钮的位置。 (.BottomLeft.BottomRight.Center.TopLeft.TopRight)。

    实际上如果我们使用MouseButton重载,它仍然使用Position但默认点击Position.Center

现在理论已经结束(phew),让我们看看实践中会发生什么。

我们看到的异常表明,单击该按钮时显然出现了问题,更具体地说,在尝试使用 MouseButton.Left 单击 Position.Center 时引发了异常。由于.Center 是根据按钮的宽度和高度属性计算的,因此按钮可能存在一些导致错误计算的问题(不幸的是,我只能假设这一点,我不能肯定地告诉你)。

顺便说一句,如果这发生在您正在测试的 AUT 的任何按钮上,很可能是开发人员做错了什么,因为这并不常见(例如,在 WPFI正在测试,我的任何按钮都没有问题)。

我们可以尝试以下方法:

  1. 尝试用.Middle.Right点击;
  2. 尝试使用Position 枚举在按钮的其他位置单击;
  3. 尝试使用HP.SDK.LFT.Mouse点击按钮的其他位置;

    // Use Mouse class to click on the button in a fine tuned location
    var loc = LicensingButton.AbsoluteLocation;
    var p = new System.Drawing.Point(loc.X + 5, loc.Y + 5);
    
    Mouse.Click(p, MouseButton.Left);
    
  4. 尝试将对象标识为Insight image-based identification

  5. 尝试使用VRI 识别对象;
  6. 尝试识别某个父对象(如果可能)并执行Click 操作,使其“点击”您想要实际点击的按钮

【讨论】:

  • 谢谢阿德林。它与 UI 中的所有按钮一起使用,而不仅仅是特定的按钮。我将尝试使用 ClickArgs 方法,看看效果如何。目前我正在使用 SendKeys 方法来单击任何按钮。
  • 我只是想发布有关此问题的更新。第 1 项解决方案 - 不起作用。第 2 项解决方案 - 不确定如何使用 Position 枚举。第 3 项解决方案 - 确实有效;但我不得不将其更改为 loc.X+10,loc.Y+10。没试过4,5,6。此外,我还能够复制示例 WPF 应用程序 (FlightGUI.exe) 的登录页面中的 OK 按钮上的 Click 方法问题
  • 嗯,我无法在 FlightGUI 应用程序的环境中重现它。 .Click() 默认在确定按钮上工作
猜你喜欢
  • 2011-01-17
  • 2020-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-24
  • 2021-06-01
  • 1970-01-01
相关资源
最近更新 更多