SubscribeEvent for click event in C#

Class library usage, coding and language questions.
JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

SubscribeEvent for click event in C#

Post by JSH_QA » Mon Nov 03, 2014 1:20 pm

Within our C# test framework that sits over the top of the Ranorex API, we want to have one of our methods called when the application under test acts on a mouse click resulting from us using adapter.Click().

When testing web apps through a browser, we can use the Ranorex ExecuteScript method to inject some JavaScript that is called when the ‘click’ event is triggered on a web element.

We also test Windows (WPF) client software and would like to do something similar with WPF controls – having a method in our framework called when a click resulting from adapter.Click() is actually handled by the WPF control. To do this, I was thinking that the Ranorex SubscribeEvent method might be used. Would this be the approach to take, or is there an alternative that could ideally be done through the Ranorex API? If SubscribeEvent is the way to go, is there an example available of using it from C# to be notified of click events?

As to why we want to do this sort of thing, there are two main reasons:
(1) With a responsive UI, clicking on Location.Center on things like hyperlinks doesn’t always hit the hyperlink, which may have been wrapped onto a second line, but with the second line not being long enough to reach Location.Center. We start by clicking on Location.Center, but if that doesn’t result in the click event being triggered in the JavaScript, we then iterate through other Location values until the hyperlink is successfully clicked (and if that doesn’t work, then we fall back onto PerformClick, but log the fact that attempting to use the mouse failed). Why not use PerformClick in the first place? Quite simply, that we want to test using the same actions that a user would – if they clicked with no result, they would move the mouse slightly and click again.
(2) We have had occasions where mouse events have been lost for no obvious reason. One that has been discussed in another thread is during drag & drop, where we had to add a “wiggle” movement in one particular scenario. However, we have had other instances of mouse clicks being lost when automating actions on WPF controls. These are still being investigated. If we can be notified by the application under test when a click is truly successful, we can put in additional code for the cases where the click is unsuccessful, and hopefully identify the underlying cause of the click being lost.

Many thanks,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: SubscribeEvent for click event in C#

Post by Support Team » Wed Nov 05, 2014 1:49 pm

Hello John,

Unfortunately, Ranorex does currently not offer a possibility to subscribe events from the application under test since the Ranorex plugins do not support events.

I would suggest validating an element, which becomes visible on the UI in order to check whether the operateion has worked.

Regards,
Robert
.
Image