Page 1 of 1

How to set the time out for Validate Enabled=True?

Posted: Thu Jan 29, 2015 1:41 am
by JohnWashburn
Our application does a number of initialization tasks on startup. Depending on the machine and more importantly the number of sensors visible on the network the initialization can range from 10 seconds to 3 minutes.

The event that signals to the user (and one would hope Ranorex) that initialization is complete is that the main menu bar transitions from disabled to enabled.

So the first two steps of any test recording with our Explorer as the application under test are:
1) start the application
2) wait for the main menu bar to become enabled

Ranorex does not seem to be polling the application (e.g. with exponential back off) in order to wait for the control to achieve the expectation of the call to Validate.Attribute(). In this case that would be Enabled = True. Search time out for the repo item seems to only control the state transition from not exists to does exist. What property on the repo item or on the line line within the recording must be set so that the recording will have the following behavior:

1) Wait until the menu bar is enabled or wait 4 minutes which ever duration is shorter.
2) proceed to the next test step or report a failure.

Here is an excerpt of the generated code:

Code: Select all

Report.Log(ReportLevel.Info, "Application", "Run application 'C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe' with arguments '' in normal mode.", new RecordItemIndex(0));
Host.Local.RunApplication("C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe", "", "C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0", false);
Delay.Milliseconds(100);

Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Enabled='True') on item 'ExplorerForm.MainMenuBar'.", repo.ExplorerForm.MainMenuBarInfo, new RecordItemIndex(1));
Validate.Attribute(repo.ExplorerForm.MainMenuBarInfo, "Enabled", "True");
Delay.Milliseconds(100);
I want a duration parameter for Validate.Attribute() as there is for Validate.Exists(). A resulting code snippet would be similar to:

Code: Select all

Validate.Attribute(repo.ExplorerForm.MainMenuBarInfo, "Enabled", "True", new Duration(new TimeSpan(0,4,0)));
I.E. Wait until the Enabled attribute of the main menu bar acquires a value of TRUE, but wait no longer the 4 minutes for this state transition within the attribute. If, after 4 minutes, the Enabled attribute has not become TRUE, then report this as a failure

I have looked through the documentation on Validate at:
http://www.ranorex.com/Documentation/Ra ... lidate.htm
and don't see how such an elementary synchronization with an application under test can be done.

What am I missing here?

Re: How to set the time out for Validate Enabled=True?

Posted: Thu Jan 29, 2015 9:29 am
by odklizec
Hi,

I think the easiest solution of your problem would be using WaitForExists method. Just add the "enabled=true" to the repository element in question. Then simply call this code...

Code: Select all

Duration newDuration = new Duration(240000);
repo.ExplorerForm.MainMenuBarInfo.WaitForExists(newDuration);
This code will pause the playback of test until the MainMenuBarInfo is not enabled, but no longer than 4 minutes. Hope this helps?

Re: How to set the time out for Validate Enabled=True?

Posted: Thu Jan 29, 2015 5:01 pm
by JohnWashburn
The menu bar exist almost immediately, but is disabled while initialization is being performed on a worker thread. When the worker thread comes back, then the menu bar state is changed from disabled to enabled. the user (and Ranorex) may now proceed to use the Explorer.

I think we are talking passed each other. How do perform the task you described?

Currently, I have 2 validation steps after the line that starts up the application:
Validate exists on MainMenuBar with a duration of 1 minute
Validate Enabled on MainMenuBar with a duration of 4 minutes

The behavior of Ranorex is:
1) Waits 1 full minute regardless of whether the MainMenuBar exists or not. On a fast machine the wait is 55 seconds too long. On a slow machine the wait is 20 seconds too long.
2) Tests for existence of the MainMenuBar (passes)
3) Waits 4 full minutes regardless of whether the MainMenuBar is enabled or not. On a machine connected to a network with a few dozen sensors the wait is about 3 minutes and 30 seconds too long. On a machine connected to a network with hundreds of sensors the wait is about 30 seconds too long.
4) Tests the Enabled attribute of the MainMenuBar for a current state of TRUE (passes)

If I run with Shift-Pause (no -pauses), then the test does not run at all because the test for existence is performed before the menu bar has is created. The screen capture of the failure is the splash page.

If I wait until the menu bar is up before hitting SHIFT-Pause (while the execution is dawdling with the first 1m duration), then the Validate.Enabled fails because the test on the attribute state is performed immediately which is before the initialization is done. Yes after 15 seconds the menu bar is not enabled. After 2- 3 minutes it is enabled.

The duration settings seem to be arbitrary long poles within the test execution. How is a test case supposed to maintain synchronization with the application under test if the test script cannot detect simple state transitions? State transitions such as:
Not Exist -> Exists
Disabled -> Enabled
Enabled -> Disabled
Hidden -> Visible

The duration parameter set within the studio seems to be a fixed delay, not a specification of the maximum time out within which the desired state transition must occur.

Here is the code generated by the studio:

Code: Select all

Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;

Init();

Report.Log(ReportLevel.Info, "Application", "Run application 'C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe' with arguments '' in normal mode.", new RecordItemIndex(0));
Host.Local.RunApplication("C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe", "", "C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0", false);
Delay.Milliseconds(1000);

Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'ExplorerForm.MainMenuBar'.", repo.ExplorerForm.MainMenuBarInfo, new RecordItemIndex(1));
Validate.Exists(repo.ExplorerForm.MainMenuBarInfo);
Delay.Milliseconds(60000);

Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Enabled='True') on item 'ExplorerForm.MainMenuBar'.", repo.ExplorerForm.MainMenuBarInfo, new RecordItemIndex(2));
Validate.Attribute(repo.ExplorerForm.MainMenuBarInfo, "Enabled", "True");
Delay.Milliseconds(240000);
What do I change within Recording1.rxrec (e.g the properties dialog boxes within the recorder) so the generated code is as you suggest? So the generated code within recording1.cs becomes:

Code: Select all

Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;

Init();

Report.Log(ReportLevel.Info, "Application", "Run application 'C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe' with arguments '' in normal mode.", new RecordItemIndex(0));
Host.Local.RunApplication("C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0\\In-Sight Explorer.exe", "", "C:\\Program Files (x86)\\Cognex\\In-Sight\\In-Sight Explorer 5.1.0", false);
Delay.Milliseconds(1000);

Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'ExplorerForm.MainMenuBar'.", repo.ExplorerForm.MainMenuBarInfo, new RecordItemIndex(1));
repo.ExplorerForm.MainMenuBarInfo.WaitForExists(new Duration(60000));

Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Enabled='True') on item 'ExplorerForm.MainMenuBar'.", repo.ExplorerForm.MainMenuBarInfo, new RecordItemIndex(2));
repo.ExplorerForm.MainMenuBarInfo.WaitForAttributeState("Enabled", true, new Duration(240000));
I don't see any method within the RepoItemInfo class analogous to WaitForExists() such as WaitForAttributeState().

The suggestion:

Code: Select all

Then simply call this code...
Duration newDuration = new Duration(240000);
repo.ExplorerForm.MainMenuBarInfo.WaitForExists(newDuration);
seems to be that I become a developer an write the C# code myself.

What is the point of the recorder generating C# code for use non-developers, if I have to mutate and maintain the generated C# code directly from that point on?

Re: How to set the time out for Validate Enabled=True?

Posted: Thu Jan 29, 2015 8:30 pm
by odklizec
Hi,

After reading your intial post, I got an impression you prefer to use coded-way instead of recording? Anyway, there is of course also recording-based "WaitFor" action, which means you don't have to use code if you don't want to. Just drag&drop the repo element from the repository to Recording of your choice then from the appeared menu select "WaitFor" action,cset its option to "Exists" and of course the timeout value.

As for the WaitFor action, it does not wait for the existence/non-existence of the element as such (like for example your menu bar) but rather for existence/non-existence of the xpath behind the repo element! Which means, that you just have to add "enabled" attribute to the xpath behind the menu bar in question. Just go to repository and edit the xpath for menu bar by adding this...

Code: Select all

[@enabled='True']
Or simply click the edit button next to the repo item and select the "enabled" attribute with value "true" via Ranorex xpath editor.

Once all the above steps are finished, the WaitForExists should pause the test execution until the menu bar in question is not enabled. Hope this helps?

Re: How to set the time out for Validate Enabled=True?

Posted: Wed Feb 11, 2015 8:37 pm
by JohnWashburn
Yes, it helps quite a bit.