Waiting until Image no longer exists to continue test

Ask general questions here.
smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Waiting until Image no longer exists to continue test

Post by smalldoorman » Wed Sep 29, 2010 11:08 pm

I'm trying to test a Flash game where there is loading sessions between areas but the load times vary dependent on machine several other factors. There is a loading screen between areas, I'm wondering if there is some sort of command that i can put it that tells Ranorex to wait until the preloader images no longer exist then proceed with its test?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Waiting until Image no longer exists to continue test

Post by Ciege » Wed Sep 29, 2010 11:59 pm

Do you have a link to the image object? If so you can do something like this...

Code: Select all

bool ImageVisible = ImageObject.Visible;
while (ImageVisible == true)
{
  Thread.Sleep(500);
  ImageVisible = ImageObject.Visible;
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Waiting until Image no longer exists to continue test

Post by smalldoorman » Fri Oct 01, 2010 7:41 pm

I do have a url link for each loading image. Where would this go (I'm learning C# as time goes so please bear with me), would it replace the ImageObject.Visible?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Waiting until Image no longer exists to continue test

Post by Ciege » Fri Oct 01, 2010 9:13 pm

I'm sorry, I meant an xPath link to the object. In other words have you created a variable that references your object? That is what ImageObject represents in my example code.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Waiting until Image no longer exists to continue test

Post by smalldoorman » Fri Oct 01, 2010 10:57 pm

Oh ok. Now am i creating method solely for this or am i adding it as part of another method? Please do not that I will be creating at least 25 unique checks.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Waiting until Image no longer exists to continue test

Post by Ciege » Fri Oct 01, 2010 11:01 pm

What I would do is create a new method cal WaitUntilExists or something similar that takes an object as a variable. You call that method with the object passed in and it will wait until that object exists.
So, create the method once and use it however many times you want.

Just to be clear, when done you will have created a framework method that can be used with any project you want.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Waiting until Image no longer exists to continue test

Post by smalldoorman » Mon Oct 04, 2010 6:50 pm

I cannot pull an Xpath with Spy since the everything on the screen is being shown as one flat image, Spy isn't picking up every individual piece of art.

Is there any way that i can put the image into the repository and reference the image from there? So far when i substitute the image file name from the repository for ImageObject, I had Ranorex simplify the file path and then put that in place of the ImageObject Variable (assuming that was the correct step). But the method keeps coming back as invalid. Below is the method I'm trying to use.

Code: Select all

public static void ValidateHud()
    {
        bool ImageVisible = .//img[@alt=.Visible;
        while (ImageVisible == True)
        {
            Thread.Sleep(500);
            ImageVisible = .//img[@alt=.Visible:
        }
    }

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Waiting until Image no longer exists to continue test

Post by smalldoorman » Mon Oct 04, 2010 6:54 pm

It is also an option for me to put a check in that instead of waiting for the loading screen to turn off is to put a wait until exists, So that Ranorex is waiting until the HUD shows up, which is one of the last things to load for our flash applet.

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Waiting until Image no longer exists to continue test

Post by sdaly » Tue Oct 05, 2010 12:03 pm

Something like this may be what you are after?


Public Sub waitUntilImageNotExists(strRanorexPath as String, strBmpFilePath as String, intTimeout as Integer)

Dim containingItem as Ranorex.Unknown = strRanorexPath
Dim bmp As System.Drawing.Bitmap = Ranorex.Imaging.Load(strBmpFilePath)
Dim iterations as Integer = 0

While imaging.Contains(containingItem.Element, bmp)
delay.Seconds(1)
iterations += 1
If iterations > intTimeout - 1 Then
report.Failure("Image", strBmpFilePath & " has not dissapered within " & intTimeout.ToString)
Throw New Exception
End If
End While
Report.Info("Image", strBmpFilePath & " no longer exists within " & strRanorexPath)

End Sub

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Waiting until Image no longer exists to continue test

Post by smalldoorman » Mon Oct 11, 2010 7:55 pm

Thanks for all the help guys, I think I'll forgo this step until I finish all my test cases and add this back in as a nice to have, for now I'll just put a large delay time.

User avatar
jasoncleo
Posts: 37
Joined: Mon Jun 08, 2015 7:37 am

Re: Waiting until Image no longer exists to continue test

Post by jasoncleo » Tue Aug 04, 2015 5:44 am

Sorry to resurrect an old thread, but I was surprised that no-one posted a solution for the OP. We have a couple of projects starting up that require similar items to this so what we use is something similar to the following:

Helper method:

Code: Select all

        private void WaitForImageNotExists(Bitmap img, TimeSpan waitTime)
        {
        	var start = System.DateTime.Now;
        	do
        	{
        		if (!Imaging.Contains(MyRepository.Instance.MyAppWindow.Self, img))
        			return;
        	} while(System.DateTime.Now.Subtract(start).TotalMilliseconds < waitTime.TotalMilliseconds);
        	throw new Exception("Time out looking for image");
        }
Then invoking it when needed is:

Code: Select all

            Bitmap img = Imaging.Load(@"path\imageOfInterest.bmp");
            Imaging.FindOptions.Default.Similarity = 0.95;
            try
            {
            	WaitForImageNotExists(img, TimeSpan.FromSeconds(10));
            }
            catch
            {
            	// Do handling here. Abort or whatever.
            }
To ensure that you test case is truly portable, make sure that your reference images are all added to the project and set "Copy to output directory" as Always/PreserveNewest.

That way, when you load the image, you can use a relative path, and know that the relative path will always be true in relation to the executable.