Control/Form.SubscribeEvent

Class library usage, coding and language questions.
Jürgen
Posts: 2
Joined: Tue Feb 10, 2009 9:55 am

Control/Form.SubscribeEvent

Post by Jürgen » Tue Feb 10, 2009 10:12 am

Hello,

at our automated tests we have to fill huge forms (sometimes about 300 controls or more), where every control can (in the case of input-errors) show an error-dialog. So if we always wait for a message-box to appear (or not in normal case) it lasts very long. For this reason we want to make use of "Control.SubscribeEvent".
In my test-scenario i have three steps that have to repeat some hundred times. First, set the form to editmode = edit; second, fill the controls; third, save the data. At the first turn, the delegate is added to the event handlers-list as usual. But at the second (and every further) turn it doesn't work.

Because of i am the programmer and the test-writer in one person, i was able to change one of the events to a custom event-type, so i can look what happen, if "Control.SubscribeEvent" was callen. For the first time the delegate is added to the events handlers-list, as usual. For the second and any further time the events "addhandler"-method isn't called?

Can anyone explain my mistake? If i try this with a (ranorex) form-object, the delegate is never added to the events handlers-list...

Ah, it's Ranorex.net 1.5 and i am automating controls that where derived from Infragistics-Net-Controls. The forms are directly derived from Windows-Forms...

Regards
Jürgen

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

Post by Support Team » Tue Feb 10, 2009 3:50 pm

Hi Jürgen!

The behavior you described is by design. When you call SubscribeEvent on the same control more than once, the event at the corresponding WinForms control (in the automated application) is only subscribed the first time. The other times we internally store the subscribed event handlers and execute them when the event is fired at the real control.

We need to do that because the communication between processes takes a lot of time. Using this algorithm an event fired at the automated control is only communicated once to the automating process which then executes all subscribed event handlers. This should usually make no difference except for speed.

I can't tell why the form event is not subscribed at all. Could you please post some source code or send a sample to support_at_ranorex.com?

Regards,
Alex
Ranorex Support Team

Jürgen
Posts: 2
Joined: Tue Feb 10, 2009 9:55 am

Post by Jürgen » Tue Feb 10, 2009 5:15 pm

Hello Alex!

Thanks for your explanation. But I think I haven't explain my problem right ;(

In our tests, our forms are filled with different amounts of data to see, if the reactions are right if there are formatting problem at date/time-fields, missing obligatory fields, and so on...
So, after every field that is filled and tabbed out, there may be showing a failure-form if there's any problem or not if the entry is ok. Unfortunaly, at some fields the failure form needs about four or five seconds to load and show, due to complex validations, at other fields it's popping up immediatly.
So if i want to wait if the failure-form shows up, after every field i had to wait five seconds (better ten, if some data grows) and the hole filling of the form takes to much time (remember, some of our form are loaded with about 300 controls). Thus i want to catch the validated event, wich is immediatly fired after validation (who cares? :twisted: ). So at the most controls it's about 20-50 miliseconds after filling, only at a couple of controls it needs more time.

I achived this by a loop that waits for either the validated-event or the failure-form, like this:

Code: Select all

Private Shared myLastValidatedControl As String

Function FillControl(control As Ranorex.Control, value as String) As Ranorex.Form
   myLastValidatedControl = String.Empty
   
   control.SubscribeEvent("Validated", AddressOf ControlValidated)
   control.SendKeys(value & "{TAB}")

   Dim lFailureForm As Ranorex.Form = Application.FindFormTitle("Failure")
   Do Until lFailureForm IsNot Nothing Or (Not String.IsNullOrEmpty(myLastValidatedControl) AndAlso myLastValidatedControl = control.Name)
      lFailureForm = Application.FindFormTitle("Failure")
   Loop

   control.UnsubscribeEvent("Validated", AddressOf ControlValidated)

   Return lFailureForm
End Sub

Shared Sub ControlValidated(sender As object, e As System.EventArgs)
   myLastValidatedControl = CType(sender, RanorexSpy.ControlProxy).GetValue("Name").Value
End Sub
The "FillControl"-Procedure is called for every control on my form and every thing works perfect (the "Validated"-event is caught by the "ControlValidated"-sub). But if the procedure ist called a second time for the same control, there happens nothing.

Is it "wrong handling" to "subscribe, unsubscribe, subscribe, unsubscribe"? Did I better subscribe all and everything, then do my work and unsubscribe at the end?

A sample for my "form-problem" I can post tomorrow. But it's nearly the same code as for the controls.

Regards
Jürgen

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

Post by Support Team » Wed Feb 11, 2009 1:24 pm

Jürgen wrote:Is it "wrong handling" to "subscribe, unsubscribe, subscribe, unsubscribe"? Did I better subscribe all and everything, then do my work and unsubscribe at the end?
No, that's ok, but we had a bug in the UnsubscribeEvent method so that subscribe -> unsubscribe -> subscribe did not work. So, you can either change your code to subscribe only once and not unsubscribe at all, or you download the bug-fixed Ranorex 1.5.1 version from our homepage:
http://www.ranorex.com/download/Ranorex-1.5.1.msi

Regards,
Alex
Ranorex Support Team