1

Getting HP.LFT.SDK.GeneralReplayException: One or more specified arguments are not valid, while trying to click on a wpf button (using LeanFT with C# integrated in Visual Studio 2015 )

Given the code below:

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

But I am getting below exception

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
Adelin
  • 7,809
  • 5
  • 37
  • 65

1 Answers1

1

The exception is indeed misleading. On a first look I thought the ButtonDescription is incorrectly constructed, meaning that one of Text or ObjectName property expects some other value.

But that's not the case.

The problem lies entirely in the click operation. As you can see when inspecting the Click method, it has two overloads:

  1. Expecting a MouseButton enum;

    When we call Click and we don't pass the enum or the object, MouseButton.Left enum value is used by default but you can also specify .Middle or .Right.

  2. Expecting a ClickArgs object, in the form of:

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

    Location indicates where to click the button. (.BottomLeft, .BottomRight, .Center, .TopLeft and .TopRight).

    Actually if we use the MouseButton overload, it still uses the Position but clicks on Position.Center by default.

Now that the theory is over (phew), let's see what happens in practice.

The exception we see shows us that something obviously went wrong when clicking on that button, more specifically an exception was thrown while attempting to click on Position.Center with the MouseButton.Left. As .Center is calculated based on button's width and height property, probably there is some issue with the button that causes wrong calculations (unfortunatelly I can only assume this, I can't tell you for sure).

By the way, if this happens on any button of the AUT you're testing, most probably the devs are doing something wrong, as it's not common (for example, on the WPF I'm testing, I don't have the issue on any of the buttons).

What we can do is to attempt the followings:

  1. Try clicking with .Middle or .Right;
  2. Try clicking in other positions of the button using the Position enum;
  3. Try clicking in other positions of the button using 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. Try identifying the object as Insight image-based identification;

  5. Try identifying the object using VRI;
  6. Try identifying some parent object (if possible) and execute the Click operation in such a way that it "hits" the button you want to actually click
Adelin
  • 7,809
  • 5
  • 37
  • 65
  • Thanks Adelin. It's with all the buttons in the UI, not only with the specific one. I will try to use the ClickArgs method and will see how it goes.Currently I am working around with SendKeys method to click on any button. – user9220852 Jan 17 '18 at 15:34
  • I just wanted to post an update on the issue . Item 1 solution- did not work.Item 2 solution- not sure how to use the Position enum. Item 3 solution - did work; but I had to change the to loc.X+10,loc.Y+10. Did not try 4,5,6. Also I was able to duplicate the Click method issue on the OK button found in the Login Page of the Sample WPF application (FlightGUI.exe) – user9220852 Jan 23 '18 at 19:49
  • Hmm I can't reproduce it on my environment on the FlightGUI application. `.Click()` works by default on the ok button – Adelin Jan 25 '18 at 12:25