Delay

Best practices, code snippets for common functionality, examples, and guidelines.
siti
Posts: 8
Joined: Tue Oct 20, 2015 8:23 am

Delay

Post by siti » Tue Oct 20, 2015 9:10 am

Hi, I'm new to both testing and Ranorex.

So, I have a test case of process initialization.
I have to validate whether it is successful or not using an image.
The initialization process takes time to complete.
Therefore, the image I want to validate also will load only after the initialization is complete.
Currently I'm using delay action before validating the image.
However, time may varies according to factors like network traffic and etc.
so, test case will fail when the searched image is not found after certain delay & timeouts is up.
This makes the constant delay not practical anymore.
So, is there any way Ranorex can detect the completion of the initialization process automatically?
Thus validating the image without using delay.

Cheers,
Siti

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Delay

Post by odklizec » Wed Oct 21, 2015 1:29 pm

Hi Siti and welcome here,

Instead of hardcoded Delay, you should use something called WaitFor Exists/NotExists. This method makes the test to wait until appearance or disappearance of a given element.

Unfortunately, I don't have a clue what exactly does your mentioned "initialization process" and what's the expected result, so it's hard to tell how exactly you should implement WaitFor method in your test. Could you please describe your AUT and test in more details? If possible, post your test suite. If you cannot post entire solution/AUT, try to create a sample solution with for example calc.exe, notepad, or similar app ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

siti
Posts: 8
Joined: Tue Oct 20, 2015 8:23 am

Re: Delay

Post by siti » Thu Oct 22, 2015 2:28 am

Hi,

Basically, there is a Grid View.
And inside this one cell, image will be displayed to indicate the state of a process that I run.(either running/pending/successful)
when I run a process, an image to indicate process is running is displayed.
After a while(time varies),in that same cell, the image will change from 'running' to 'success'.
So, how do I detect and validate this changes without using delay?
It seems that I can't use repo.Main.StatusRow1Info.WaitForExists because an image already exist in the first place.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Delay

Post by odklizec » Thu Oct 22, 2015 7:41 am

Hi,

It would be very helpful if you could post a Ranorex snapshot of the element in question. Ideally, create and post two snapshots. One with image indicating 'running' process and the other one with image indicating 'success'.

Also, what happens with the image after the process is finished? Does it stay displayed indefinitely or does it disappear after a while? If it disappears, you can use WaitForNotExists to continue with test after the image disappears.

If the image stays displayed forever (or until users' next action) and there is no other way to validate running/success process from another element, then I think you will have to write your own "Wait" method, based of the image validation. Using image validation is not optimal solution, but it could be the way to achieve what you want? Here is a pseudocode of such custom-built wait...

Code: Select all

    int timeOut = 30000; //30 sec timeout
    int elapsedTime = 0;
    bool success = false; 
        while (!success  && (elapsedTime < timeOut)) 
        {
             Thread.Sleep(100);
             elapsedTime += 100;
             success = Validate.CompareImage(params); //you need to check Ranorex API and maybe some samples here at forum for exact usage of CompareImage method
        }
        if (success) 
        {
             Report.Log(ReportLevel.Success,string);
        }
        else
        {
             Report.Log(ReportLevel.Failure,string);
        }
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration